[rtems-central commit] interfacedoc: Present only one definition

Sebastian Huber sebh at rtems.org
Wed Feb 3 05:28:01 UTC 2021


Module:    rtems-central
Branch:    master
Commit:    dfe0868eca3787530826b5a326308a0c71ac1ac7
Changeset: http://git.rtems.org/rtems-central/commit/?id=dfe0868eca3787530826b5a326308a0c71ac1ac7

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jan 15 14:30:03 2021 +0100

interfacedoc: Present only one definition

Assume that all definitions of function and macro interfaces have the
same set of parameters.

---

 rtemsspec/interfacedoc.py            | 32 +++++++++-----------------------
 rtemsspec/tests/test_interfacedoc.py | 18 ++++--------------
 2 files changed, 13 insertions(+), 37 deletions(-)

diff --git a/rtemsspec/interfacedoc.py b/rtemsspec/interfacedoc.py
index caeb4cb..fcbdcf1 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 3a69572..070bf6a 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:
 



More information about the vc mailing list