[rtems-central commit] interface: Add directive constraints
Sebastian Huber
sebh at rtems.org
Wed Feb 3 05:28:01 UTC 2021
Module: rtems-central
Branch: master
Commit: bda3bd7195247162f0f6d806a2a205815293186c
Changeset: http://git.rtems.org/rtems-central/commit/?id=bda3bd7195247162f0f6d806a2a205815293186c
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Jan 22 14:36:00 2021 +0100
interface: Add directive constraints
---
rtemsspec/content.py | 6 +++++-
rtemsspec/interface.py | 20 ++++++++++++++++----
rtemsspec/tests/test_interface.py | 7 +++++++
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/rtemsspec/content.py b/rtemsspec/content.py
index e0717b4..9e4049c 100644
--- a/rtemsspec/content.py
+++ b/rtemsspec/content.py
@@ -583,6 +583,10 @@ _NOT_ALPHANUM = re.compile(r"[^a-zA-Z0-9_]")
_SPHINX_FILE_TO_DOXYGEN = re.compile(r":file:`([^`]+)`")
+def _make_str(value: Optional[str]) -> str:
+ return value if value else ""
+
+
class CContent(Content):
""" This class builds C content. """
@@ -943,7 +947,7 @@ class CContent(Content):
def add_param_description(
self,
params: Iterable[Dict[str, str]],
- substitute: Callable[[str], str] = lambda x: x) -> None:
+ substitute: Callable[[Optional[str]], str] = _make_str) -> None:
""" Adds a list of parameter descriptions. """
for param in params:
self.wrap(param["name"] + " " + substitute(param["description"]),
diff --git a/rtemsspec/interface.py b/rtemsspec/interface.py
index 84623dc..e881646 100644
--- a/rtemsspec/interface.py
+++ b/rtemsspec/interface.py
@@ -26,7 +26,7 @@
from contextlib import contextmanager
import os
-from typing import Any, Callable, Dict, Iterator, List, Union, Set
+from typing import Any, Callable, Dict, Iterator, List, Optional, Union, Set
from rtemsspec.content import CContent, CInclude, enabled_by_to_exp, \
ExpressionMapper, get_value_double_colon, get_value_doxygen_function, \
@@ -316,14 +316,16 @@ class Node:
return self.mapper.substitute(text.strip("\n"))
return text
- def substitute_text(self, text: str) -> str:
+ def substitute_text(self,
+ text: Optional[str],
+ item: Optional[Item] = None) -> str:
"""
Performs a variable substitution on a description using the item mapper
of the node.
"""
if text:
- return self.mapper.substitute(text.strip("\n"))
- return text
+ return self.mapper.substitute(text.strip("\n"), item)
+ return ""
def _get_compound_definition(self, item: Item, definition: Any) -> Lines:
content = CContent()
@@ -423,6 +425,16 @@ class Node:
content.wrap(self.substitute_text(ret["return"]),
initial_indent="@return ")
content.add_paragraph("Notes", self.substitute_text(item["notes"]))
+ constraints = [
+ self.substitute_text(parent["text"], parent)
+ for parent in item.parents("constraint")
+ ]
+ if constraints:
+ constraint_content = CContent()
+ constraint_content.add_list(
+ constraints,
+ "The following constraints apply to this directive:")
+ content.add_paragraph("Constraints", constraint_content)
return content
def _add_generic_definition(self, get_lines: GetLines) -> None:
diff --git a/rtemsspec/tests/test_interface.py b/rtemsspec/tests/test_interface.py
index 9f3cf1e..76331ad 100644
--- a/rtemsspec/tests/test_interface.py
+++ b/rtemsspec/tests/test_interface.py
@@ -223,6 +223,13 @@ typedef enum EnumB {
* these two lines
* are not wrapped
* @endcode
+ *
+ * @par Constraints
+ * @parblock
+ * The following constraints apply to this directive:
+ *
+ * * Constraint A for Function().
+ * @endparblock
*/
void Function( int Param0, const int *Param1, int *Param2, int *Param3 );
More information about the vc
mailing list