Changeset e2429ea in rtems-central


Ignore:
Timestamp:
May 8, 2020, 3:21:33 PM (5 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
21872d2
Parents:
a90371d
git-author:
Sebastian Huber <sebastian.huber@…> (05/08/20 15:21:33)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/28/20 08:38:22)
Message:

interface: Use enabled_by_to_exp()

Location:
rtemsqual
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • rtemsqual/interface.py

    ra90371d re2429ea  
    2929from typing import Any, Callable, Dict, Iterator, List, Optional, Union
    3030
    31 from rtemsqual.content import CContent
     31from rtemsqual.content import CContent, enabled_by_to_exp, ExpressionMapper
    3232from rtemsqual.items import Item, ItemCache, ItemMapper
    3333
     
    5656    target = item.map(item["interface-target"])
    5757    return target["interface-type"] + " " + target["interface-name"]
     58
     59
     60class _InterfaceMapper(ItemMapper):
     61    def __init__(self, node: "Node"):
     62        super().__init__(node.item)
     63        self._node = node
     64
     65    def __getitem__(self, identifier):
     66        item, value = self.map(identifier)
     67        if item["type"] == "interface":
     68            node = self._node
     69            header_file = node.header_file
     70            if item["interface-type"] == "enumerator":
     71                for link in item.links_to_children():
     72                    if link["role"] == "enumerator":
     73                        header_file.add_includes(link.item)
     74            else:
     75                header_file.add_includes(item)
     76            header_file.add_potential_edge(node, item)
     77        return value
     78
     79    def get_value(self, item: Item, _path: str, _value: Any, key: str,
     80                  _index: Optional[int]) -> Any:
     81        # pylint: disable=no-self-use
     82        if key == "interface-name" and item["type"] == "interface" and item[
     83                "interface-type"] == "forward-declaration":
     84            return _forward_declaration(item)
     85        raise KeyError
     86
     87
     88class _InterfaceExpressionMapper(ExpressionMapper):
     89    def __init__(self, mapper: _InterfaceMapper):
     90        super().__init__()
     91        self._mapper = mapper
     92
     93    def map(self, symbol: str) -> str:
     94        return self._mapper.substitute(symbol)
    5895
    5996
     
    67104        with node.mapper.prefix(os.path.join(prefix, "variants")):
    68105            for variant in variants:
    69                 enabled_by = variant["enabled-by"].strip()
     106                enabled_by = enabled_by_to_exp(
     107                    variant["enabled-by"],
     108                    _InterfaceExpressionMapper(node.mapper))
    70109                content.append(f"{ifelse}{enabled_by}")
    71110                with content.indent():
     
    106145
    107146
    108 class InterfaceMapper(ItemMapper):
    109     """ Interface mapper. """
    110     def __init__(self, node: "Node"):
    111         super().__init__(node.item)
    112         self._node = node
    113 
    114     def __getitem__(self, identifier):
    115         item, value = self.map(identifier)
    116         if item["type"] == "interface":
    117             node = self._node
    118             header_file = node.header_file
    119             if item["interface-type"] == "enumerator":
    120                 for link in item.links_to_children():
    121                     if link["role"] == "enumerator":
    122                         header_file.add_includes(link.item)
    123             else:
    124                 header_file.add_includes(item)
    125             header_file.add_potential_edge(node, item)
    126         return value
    127 
    128     def get_value(self, item: Item, _path: str, _value: Any, key: str,
    129                   _index: Optional[int]) -> Any:
    130         """ Gets a value by key and optional index. """
    131         # pylint: disable=no-self-use
    132         if key == "interface-name" and item["type"] == "interface" and item[
    133                 "interface-type"] == "forward-declaration":
    134             return _forward_declaration(item)
    135         raise KeyError
    136 
    137 
    138147_PARAM = {
    139148    None: "@param ",
     
    154163        self.out_edges = {}  # type: ItemMap
    155164        self.content = CContent()
    156         self.mapper = InterfaceMapper(self)
     165        self.mapper = _InterfaceMapper(self)
    157166
    158167    def __lt__(self, other: "Node") -> bool:
  • rtemsqual/tests/spec-interface/define.yml

    ra90371d re2429ea  
    1111      ((${float_t:/interface-name}) 123)
    1212  variants:
    13   - enabled-by: |
    14       defined(A) || defined(B)
    15     definition: |
    16       ((${float_t:/interface-name}) 456)
    17   - enabled-by: |
    18       defined(C) && \
    19         defined(D)
    20     definition: |
    21       ((${float_t:/interface-name}) 789)
     13  - enabled-by:
     14    - defined(${define-a:/interface-name})
     15    - (${define-b:/interface-name} > ${define-c:/interface-name})
     16    definition: ((${float_t:/interface-name}) 456)
     17  - enabled-by:
     18      and:
     19      - defined(C)
     20      - defined(D)
     21    definition: ((${float_t:/interface-name}) 789)
    2222interface-type: define
    2323links:
  • rtemsqual/tests/test_interface.py

    ra90371d re2429ea  
    9090#define _H_H
    9191
     92#include <h2.h>
    9293#include <h3.h>
    9394#include <math.h>
     
    142143 * @ingroup GroupA
    143144 */
    144 #if defined(A) || defined(B)
     145#if defined(A) || (B > C)
    145146  #define DEFINE ((float_t) 456)
    146 #elif defined(C) && \\
    147   defined(D)
     147#elif defined(C) && defined(D)
    148148  #define DEFINE ((float_t) 789)
    149149#else
Note: See TracChangeset for help on using the changeset viewer.