diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-09-30 13:20:46 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-10-04 08:05:34 +0200 |
commit | 5e39be78999abc23715236aef1afa7c22446de74 (patch) | |
tree | 07ba2e0541fb4a4bb3fda7798387573c5c57691e /rtemsspec | |
parent | modules: Update rtems (diff) | |
download | rtems-central-5e39be78999abc23715236aef1afa7c22446de74.tar.bz2 |
spec: Unify interface functions and macros
Diffstat (limited to 'rtemsspec')
-rw-r--r-- | rtemsspec/interface.py | 5 | ||||
-rw-r--r-- | rtemsspec/interfacedoc.py | 19 | ||||
-rw-r--r-- | rtemsspec/tests/spec-interface/macro.yml | 22 | ||||
-rw-r--r-- | rtemsspec/tests/spec-interface/macro2.yml | 16 | ||||
-rw-r--r-- | rtemsspec/tests/spec-interface/macro3.yml | 6 | ||||
-rw-r--r-- | rtemsspec/tests/test_interfacedoc.py | 8 |
6 files changed, 47 insertions, 29 deletions
diff --git a/rtemsspec/interface.py b/rtemsspec/interface.py index f5bb7edc..87fb3662 100644 --- a/rtemsspec/interface.py +++ b/rtemsspec/interface.py @@ -547,9 +547,10 @@ class Node: if len(line) > 79: param_block = ", \\\n ".join(params) line = f"#define {name}( \\\n {param_block} \\\n)" - if not definition: + body = definition["body"] + if not body: return line - body_lines = self.substitute_code(definition).split("\n") + body_lines = self.substitute_code(body).split("\n") if len(body_lines) == 1 and len(line + body_lines[0]) <= 79: body = " " else: diff --git a/rtemsspec/interfacedoc.py b/rtemsspec/interfacedoc.py index 72f07492..d0666c25 100644 --- a/rtemsspec/interfacedoc.py +++ b/rtemsspec/interfacedoc.py @@ -49,6 +49,10 @@ def _get_reference(name: str) -> str: return get_reference(get_label(f"{INTERFACE} {name}")) +def _get_code_param(ctx: ItemGetValueContext) -> Any: + return _sanitize_name(ctx.value[ctx.key]) + + class _CodeMapper(ItemMapper): def __init__(self, item: Item): super().__init__(item) @@ -56,6 +60,7 @@ class _CodeMapper(ItemMapper): get_value_forward_declaration) self.add_get_value("interface/struct:/name", get_value_compound) self.add_get_value("interface/union:/name", get_value_compound) + self.add_get_value("interface/macro:/params/name", _get_code_param) def _get_param(ctx: ItemGetValueContext) -> Any: @@ -125,23 +130,13 @@ def _add_function_definition(content: CContent, mapper: ItemMapper, item: Item, value: Dict[str, Any]) -> None: ret = mapper.substitute(value["return"]) name = item["name"] - params = [ - mapper.substitute(_sanitize_name(param)) for param in value["params"] - ] + params = [mapper.substitute(param) for param in value["params"]] content.declare_function(ret, name, params) -def _add_macro_definition(content: CContent, _mapper: ItemMapper, item: Item, - _value: Dict[str, Any]) -> None: - ret = "#define" - name = item["name"] - params = [_sanitize_name(param["name"]) for param in item["params"]] - content.call_function(ret, name, params, semicolon="") - - _ADD_DEFINITION = { "interface/function": _add_function_definition, - "interface/macro": _add_macro_definition, + "interface/macro": _add_function_definition, } diff --git a/rtemsspec/tests/spec-interface/macro.yml b/rtemsspec/tests/spec-interface/macro.yml index 1de4b429..449576c2 100644 --- a/rtemsspec/tests/spec-interface/macro.yml +++ b/rtemsspec/tests/spec-interface/macro.yml @@ -3,13 +3,21 @@ brief: Very long macro brief description. copyrights: - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) definition: - default: | - do { - (void) ${.:/params[1]/name}; - (void) ${.:/params[2]/name}; - (void) ${.:/params[3]/name}; - } while ( 0 ); - ${.:/params[0]/name} + 1; + default: + attributes: null + body: | + do { + (void) ${.:/params[1]/name}; + (void) ${.:/params[2]/name}; + (void) ${.:/params[3]/name}; + } while ( 0 ); + ${.:/params[0]/name} + 1; + params: + - ${.:/params[0]/name} + - ${.:/params[1]/name} + - ${.:/params[2]/name} + - ${.:/params[3]/name} + return: null variants: [] description: null enabled-by: true diff --git a/rtemsspec/tests/spec-interface/macro2.yml b/rtemsspec/tests/spec-interface/macro2.yml index 00fbd89e..fdae338f 100644 --- a/rtemsspec/tests/spec-interface/macro2.yml +++ b/rtemsspec/tests/spec-interface/macro2.yml @@ -3,10 +3,20 @@ brief: Short macro brief description. copyrights: - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) definition: - default: | - ( ( ${.:/params[0]/name} ) + 1 ) + default: + attributes: null + body: | + ( ( ${.:/params[0]/name} ) + 1 ) + params: + - ${.:/params[0]/name} + return: null variants: - - definition: '' + - definition: + attributes: null + body: '' + params: + - ${.:/params[0]/name} + return: null enabled-by: '0' description: null enabled-by: true diff --git a/rtemsspec/tests/spec-interface/macro3.yml b/rtemsspec/tests/spec-interface/macro3.yml index eed7e52b..be93887a 100644 --- a/rtemsspec/tests/spec-interface/macro3.yml +++ b/rtemsspec/tests/spec-interface/macro3.yml @@ -3,7 +3,11 @@ brief: Macro without parameters. copyrights: - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) definition: - default: '0' + default: + attributes: null + body: '0' + params: [] + return: null variants: [] description: null enabled-by: true diff --git a/rtemsspec/tests/test_interfacedoc.py b/rtemsspec/tests/test_interfacedoc.py index 99ecdeef..3d5eb523 100644 --- a/rtemsspec/tests/test_interfacedoc.py +++ b/rtemsspec/tests/test_interfacedoc.py @@ -263,12 +263,12 @@ Very long macro brief description. .. code-block:: c - #define VERY_LONG_MACRO( + VERY_LONG_MACRO( VeryLongParam0, VeryLongParam1, VeryLongParam2, VeryLongParam3 - ) + ); .. rubric:: PARAMETERS: @@ -314,7 +314,7 @@ Short macro brief description. .. code-block:: c - #define MACRO( Param0 ) + MACRO( Param0 ); .. rubric:: PARAMETERS: @@ -344,7 +344,7 @@ Macro without parameters. .. code-block:: c - #define MACRO() + MACRO( void ); """ assert content == src.read() |