Changeset 0ee8226 in rtems-central


Ignore:
Timestamp:
May 9, 2020, 3:47:24 PM (5 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
02c58ef
Parents:
99c6449
git-author:
Sebastian Huber <sebastian.huber@…> (05/09/20 15:47:24)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/28/20 08:38:22)
Message:

interface: Support item-level enabled-by

Location:
rtemsqual
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • rtemsqual/interface.py

    r99c6449 r0ee8226  
    8585        raise KeyError
    8686
     87    def enabled_by_to_defined(self, enabled_by: str) -> str:
     88        """
     89        Maps an item-level enabled-by attribute value to the corresponding
     90        defined expression.
     91        """
     92        return self._node.header_file.enabled_by_defined[enabled_by]
     93
    8794
    8895class _InterfaceExpressionMapper(ExpressionMapper):
     
    93100    def map(self, symbol: str) -> str:
    94101        return self._mapper.substitute(symbol)
     102
     103
     104class _ItemLevelExpressionMapper(ExpressionMapper):
     105    def __init__(self, mapper: _InterfaceMapper):
     106        super().__init__()
     107        self._mapper = mapper
     108
     109    def map(self, symbol: str) -> str:
     110        return self._mapper.substitute(
     111            self._mapper.enabled_by_to_defined(symbol))
    95112
    96113
     
    188205            self.content.append(f"}} {name};")
    189206
     207    def _generate(self) -> None:
     208        _NODE_GENERATORS[self.item["interface-type"]](self)
     209
    190210    def generate(self) -> None:
    191211        """ Generates a node to generate the node content. """
    192         _NODE_GENERATORS[self.item["interface-type"]](self)
     212        enabled_by = self.item["enabled-by"]
     213        if enabled_by:
     214            mapper = _ItemLevelExpressionMapper(self.mapper)
     215            self.content.add(f"#if {enabled_by_to_exp(enabled_by, mapper)}")
     216            with self.content.indent():
     217                self._generate()
     218            self.content.add("#endif")
     219        else:
     220            self._generate()
    193221
    194222    def generate_compound(self) -> None:
     
    364392class HeaderFile:
    365393    """ A header file. """
    366     def __init__(self):
     394    def __init__(self, enabled_by_defined: Dict[str, str]):
    367395        self._content = CContent()
    368396        self._ingroups = {}  # type: ItemMap
    369397        self._includes = []  # type: List[Item]
    370398        self._nodes = {}  # type: Dict[str, Node]
     399        self.enabled_by_defined = enabled_by_defined
    371400
    372401    def add_includes(self, item: Item) -> None:
    373402        """ Adds the includes of the item to the header file includes. """
    374403        for link in item.links_to_parents():
    375             if link["role"] == "interface-placement":
     404            if link["role"] == "interface-placement" and link.item[
     405                    "interface-type"] == "header-file":
    376406                self._includes.append(link.item)
    377407
     
    460490
    461491
    462 def _generate_header_file(item: Item, domains: Dict[str, str]) -> None:
     492def _generate_header_file(item: Item, domains: Dict[str, str],
     493                          enabled_by_defined: Dict[str, str]) -> None:
    463494    domain_path = domains.get(item["interface-domain"], None)
    464495    if domain_path is None:
    465496        return
    466     header_file = HeaderFile()
     497    header_file = HeaderFile(enabled_by_defined)
    467498    header_file.generate_nodes(item)
    468499    header_file.finalize(item)
     
    471502
    472503
    473 def _visit_header_files(item: Item, domains: Dict[str, str]) -> None:
     504def _visit_header_files(item: Item, domains: Dict[str, str],
     505                        enabled_by_defined: Dict[str, str]) -> None:
    474506    for child in item.children():
    475         _visit_header_files(child, domains)
     507        _visit_header_files(child, domains, enabled_by_defined)
    476508    if item["type"] == "interface" and item["interface-type"] == "header-file":
    477         _generate_header_file(item, domains)
     509        _generate_header_file(item, domains, enabled_by_defined)
     510
     511
     512def _gather_enabled_by_defined(item_level_interfaces: List[str],
     513                               item_cache: ItemCache) -> Dict[str, str]:
     514    enabled_by_defined = {}  # type: Dict[str, str]
     515    for uid in item_level_interfaces:
     516        for link in item_cache[uid].links_to_children():
     517            if link["role"] == "interface-placement":
     518                define = f"defined(${{{link.item.uid}:/interface-name}})"
     519                enabled_by_defined[link.item["interface-name"]] = define
     520    return enabled_by_defined
    478521
    479522
     
    485528    :param item_cache: The specification item cache containing the interfaces.
    486529    """
     530    enabled_by_defined = _gather_enabled_by_defined(
     531        config["item-level-interfaces"], item_cache)
    487532    for item in item_cache.top_level.values():
    488         _visit_header_files(item, config["interface-domains"])
     533        _visit_header_files(item, config["interface-domains"],
     534                            enabled_by_defined)
  • rtemsqual/tests/spec-interface/var.yml

    r99c6449 r0ee8226  
    22copyrights:
    33- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
    4 enabled-by: []
     4enabled-by:
     5  not: ASM
    56interface-brief: Variable brief description.
    67interface-definition:
  • rtemsqual/tests/test_interface.py

    r99c6449 r0ee8226  
    3838
    3939    interface_config = {}
     40    interface_config["item-level-interfaces"] = []
    4041    base_directory = os.path.join(tmpdir, "base")
    4142    interface_domains = {"abc": base_directory}
     
    4445    item_cache_config["paths"] = [os.path.normpath(tmpdir)]
    4546    generate(interface_config, ItemCache(item_cache_config))
     47
     48    interface_config["item-level-interfaces"] = ["/command-line"]
    4649
    4750    spec_src = os.path.join(os.path.dirname(__file__), "spec-interface")
     
    313316#endif
    314317
    315 /**
    316  * @ingroup GroupC
    317  *
    318  * @brief Variable brief description.
    319  *
    320  * Variable description.
    321  */
    322 extern struct Struct *Variable;
     318#if !defined(ASM)
     319  /**
     320   * @ingroup GroupC
     321   *
     322   * @brief Variable brief description.
     323   *
     324   * Variable description.
     325   */
     326  extern struct Struct *Variable;
     327#endif
    323328
    324329#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.