diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-01-15 14:30:03 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-02-01 06:59:01 +0100 |
commit | dfe0868eca3787530826b5a326308a0c71ac1ac7 (patch) | |
tree | 19b76add17f9063188834fa03a8c081bad97977a | |
parent | content: Do not warp code blocks (diff) | |
download | rtems-central-dfe0868eca3787530826b5a326308a0c71ac1ac7.tar.bz2 |
interfacedoc: Present only one definition
Assume that all definitions of function and macro interfaces have the
same set of parameters.
-rw-r--r-- | rtemsspec/interfacedoc.py | 32 | ||||
-rw-r--r-- | rtemsspec/tests/test_interfacedoc.py | 18 |
2 files changed, 13 insertions, 37 deletions
diff --git a/rtemsspec/interfacedoc.py b/rtemsspec/interfacedoc.py index caeb4cb3..fcbdcf1d 100644 --- a/rtemsspec/interfacedoc.py +++ b/rtemsspec/interfacedoc.py @@ -30,7 +30,7 @@ import functools import os from typing import Any, Dict, List, Tuple -from rtemsspec.content import CContent, enabled_by_to_exp, ExpressionMapper +from rtemsspec.content import CContent from rtemsspec.sphinxcontent import get_label, get_reference, SphinxContent, \ SphinxMapper from rtemsspec.items import Item, ItemCache, ItemGetValueContext, ItemMapper @@ -143,28 +143,14 @@ def _add_definition(content: CContent, mapper: ItemMapper, item: Item, prefix: str, value: Dict[str, Any]) -> None: # pylint: disable=too-many-arguments add_definition = _ADD_DEFINITION[item.type] - default = value["default"] - variants = value["variants"] - if variants: - ifelse = "#if " - with mapper.prefix(os.path.join(prefix, "variants")): - for variant in variants: - enabled_by = enabled_by_to_exp(variant["enabled-by"], - ExpressionMapper()) - content.append(f"{ifelse}{enabled_by}") - with content.indent(): - add_definition(content, mapper, item, - variant["definition"]) - ifelse = "#elif " - if default is not None: - content.append("#else") - with mapper.prefix(os.path.join(prefix, "default")): - with content.indent(): - add_definition(content, mapper, item, default) - content.append("#endif") - else: - with mapper.prefix(os.path.join(prefix, "default")): - add_definition(content, mapper, item, default) + key = "default" + definition = value[key] + if not definition: + # Assume that all definitions have the same interface + key = "variants" + definition = value["variants"][0]["definition"] + with mapper.prefix(os.path.join(prefix, key)): + add_definition(content, mapper, item, definition) def _generate_directive(content: SphinxContent, mapper: _Mapper, diff --git a/rtemsspec/tests/test_interfacedoc.py b/rtemsspec/tests/test_interfacedoc.py index 3a695722..070bf6ad 100644 --- a/rtemsspec/tests/test_interfacedoc.py +++ b/rtemsspec/tests/test_interfacedoc.py @@ -151,12 +151,8 @@ Function brief description with very long return type. .. code-block:: c - #if 1 - NotSoVeryLongType VeryLongTypeFunction( void ); - #else - VeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongType - VeryLongTypeFunction( void ); - #endif + VeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongType + VeryLongTypeFunction( void ); .. rubric:: RETURN VALUES: @@ -241,9 +237,7 @@ VoidFunction() .. code-block:: c - #if 1 - void VoidFunction( void ); - #endif + void VoidFunction( void ); .. Generated from spec:/macro @@ -315,11 +309,7 @@ Short macro brief description. .. code-block:: c - #if defined(0) - #define MACRO( Param0 ) - #else - #define MACRO( Param0 ) - #endif + #define MACRO( Param0 ) .. rubric:: PARAMETERS: |