[rtems-central commit] rtemsspec: Fix interface formatting

Sebastian Huber sebh at rtems.org
Fri Sep 25 10:56:34 UTC 2020


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Sep 25 09:02:50 2020 +0200

rtemsspec: Fix interface formatting

---

 rtemsspec/applconfig.py              | 41 -----------------------------------
 rtemsspec/interface.py               |  2 ++
 rtemsspec/sphinxcontent.py           | 42 ++++++++++++++++++++++++++++++++++++
 rtemsspec/tests/test_interfacedoc.py |  3 ++-
 4 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/rtemsspec/applconfig.py b/rtemsspec/applconfig.py
index 830b322..81ea099 100644
--- a/rtemsspec/applconfig.py
+++ b/rtemsspec/applconfig.py
@@ -351,34 +351,6 @@ def _get_value_sphinx_reference(ctx: ItemGetValueContext) -> Any:
     return _SPHINX_DOC_REFS[ctx.key]
 
 
-def _get_value_sphinx_define(ctx: ItemGetValueContext) -> Any:
-    return f":c:macro:`{ctx.value[ctx.key]}`"
-
-
-def _get_value_sphinx_function(ctx: ItemGetValueContext) -> Any:
-    return f":c:func:`{ctx.value[ctx.key]}`"
-
-
-def _get_value_sphinx_type(ctx: ItemGetValueContext) -> Any:
-    return f":c:type:`{ctx.value[ctx.key]}`"
-
-
-def _get_value_sphinx_url(ctx: ItemGetValueContext) -> Any:
-    return f"`{ctx.value[ctx.key]} <{ctx.item['reference']}>`_"
-
-
-def _get_value_sphinx_unspecified_define(ctx: ItemGetValueContext) -> Any:
-    if ctx.item["reference"]:
-        return _get_value_sphinx_url(ctx)
-    return _get_value_sphinx_define(ctx)
-
-
-def _get_value_sphinx_unspecified_type(ctx: ItemGetValueContext) -> Any:
-    if ctx.item["reference"]:
-        return _get_value_sphinx_url(ctx)
-    return _get_value_sphinx_type(ctx)
-
-
 def _add_sphinx_get_values(mapper: ItemMapper) -> None:
     for key in _SPHINX_DOC_REFS:
         for opt in ["feature-enable", "feature", "initializer", "integer"]:
@@ -386,19 +358,6 @@ def _add_sphinx_get_values(mapper: ItemMapper) -> None:
             mapper.add_get_value(doc_ref, _get_value_none)
             mapper.add_get_value(f"{doc_ref}/{key}",
                                  _get_value_sphinx_reference)
-    mapper.add_get_value("interface/define:/name", _get_value_sphinx_define)
-    mapper.add_get_value("interface/function:/name",
-                         _get_value_sphinx_function)
-    mapper.add_get_value("interface/macro:/name", _get_value_sphinx_function)
-    mapper.add_get_value("interface/struct:/name", _get_value_sphinx_type)
-    mapper.add_get_value("interface/typedef:/name", _get_value_sphinx_type)
-    mapper.add_get_value("interface/union:/name", _get_value_sphinx_type)
-    mapper.add_get_value("interface/unspecified-define:/name",
-                         _get_value_sphinx_unspecified_define)
-    mapper.add_get_value("interface/unspecified-function:/name",
-                         _get_value_sphinx_function)
-    mapper.add_get_value("interface/unspecified-type:/name",
-                         _get_value_sphinx_unspecified_type)
 
 
 def _c_user_ref(ref: str, name: str) -> str:
diff --git a/rtemsspec/interface.py b/rtemsspec/interface.py
index 9bca070..30d16d6 100644
--- a/rtemsspec/interface.py
+++ b/rtemsspec/interface.py
@@ -82,6 +82,8 @@ class _InterfaceMapper(ItemMapper):
         for opt in ["feature-enable", "feature", "initializer", "integer"]:
             name = f"interface/appl-config-option/{opt}:doc:/name"
             self.add_get_value(name, get_value_hash)
+        self.add_get_value("interface/unspecified-function:doc:/name",
+                           get_value_doxygen_function)
 
     @contextmanager
     def code(self) -> Iterator[None]:
diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py
index 914e243..f9bafa7 100644
--- a/rtemsspec/sphinxcontent.py
+++ b/rtemsspec/sphinxcontent.py
@@ -221,6 +221,34 @@ def _get_appl_config_option(ctx: ItemGetValueContext) -> Any:
     return f":ref:`{ctx.value[ctx.key]}`"
 
 
+def _get_value_sphinx_macro(ctx: ItemGetValueContext) -> Any:
+    return f":c:macro:`{ctx.value[ctx.key]}`"
+
+
+def _get_value_sphinx_function(ctx: ItemGetValueContext) -> Any:
+    return f":c:func:`{ctx.value[ctx.key]}`"
+
+
+def _get_value_sphinx_type(ctx: ItemGetValueContext) -> Any:
+    return f":c:type:`{ctx.value[ctx.key]}`"
+
+
+def _get_value_sphinx_url(ctx: ItemGetValueContext) -> Any:
+    return f"`{ctx.value[ctx.key]} <{ctx.item['reference']}>`_"
+
+
+def _get_value_sphinx_unspecified_define(ctx: ItemGetValueContext) -> Any:
+    if ctx.item["reference"]:
+        return _get_value_sphinx_url(ctx)
+    return _get_value_sphinx_macro(ctx)
+
+
+def _get_value_sphinx_unspecified_type(ctx: ItemGetValueContext) -> Any:
+    if ctx.item["reference"]:
+        return _get_value_sphinx_url(ctx)
+    return _get_value_sphinx_type(ctx)
+
+
 class SphinxMapper(ItemMapper):
     """ Sphinx item mapper. """
     def __init__(self, item: Item):
@@ -235,3 +263,17 @@ class SphinxMapper(ItemMapper):
                            _get_appl_config_option)
         self.add_get_value("interface/appl-config-option/integer:/name",
                            _get_appl_config_option)
+        self.add_get_value("interface/define:/name", _get_value_sphinx_macro)
+        self.add_get_value("interface/enum:/name", _get_value_sphinx_type)
+        self.add_get_value("interface/function:/name",
+                           _get_value_sphinx_function)
+        self.add_get_value("interface/macro:/name", _get_value_sphinx_function)
+        self.add_get_value("interface/struct:/name", _get_value_sphinx_type)
+        self.add_get_value("interface/typedef:/name", _get_value_sphinx_type)
+        self.add_get_value("interface/union:/name", _get_value_sphinx_type)
+        self.add_get_value("interface/unspecified-define:/name",
+                           _get_value_sphinx_unspecified_define)
+        self.add_get_value("interface/unspecified-function:/name",
+                           _get_value_sphinx_function)
+        self.add_get_value("interface/unspecified-type:/name",
+                           _get_value_sphinx_unspecified_type)
diff --git a/rtemsspec/tests/test_interfacedoc.py b/rtemsspec/tests/test_interfacedoc.py
index 911fc42..07dc8b1 100644
--- a/rtemsspec/tests/test_interfacedoc.py
+++ b/rtemsspec/tests/test_interfacedoc.py
@@ -217,7 +217,8 @@ DIRECTIVE PARAMETERS:
 
 DESCRIPTION:
     Function description.  References to :ref:`InterfaceVeryLongFunction`,
-    Integer, Enum, DEFINE, VERY_LONG_MACRO, Variable, ENUMERATOR_0, Struct,
+    :c:type:`Integer`, :c:type:`Enum`, :c:macro:`DEFINE`,
+    :c:func:`VERY_LONG_MACRO`, Variable, ENUMERATOR_0, :c:type:`Struct`,
     :ref:`a`, and interface.
 """
         assert content == src.read()



More information about the vc mailing list