summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-05-12 19:15:30 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-05-28 10:38:22 +0200
commit570e2e026c002b293fcc36b10485713e7b4cdabe (patch)
tree7d3b6b9da397bc74a398414cbba212e1c519f408
parentinterface: Allow defines without a value (diff)
downloadrtems-central-570e2e026c002b293fcc36b10485713e7b4cdabe.tar.bz2
interface: Allow macros without a value
Break line if too long.
-rw-r--r--rtemsqual/interface.py14
-rw-r--r--rtemsqual/tests/spec-interface/macro2.yml4
-rw-r--r--rtemsqual/tests/test_interface.py9
3 files changed, 20 insertions, 7 deletions
diff --git a/rtemsqual/interface.py b/rtemsqual/interface.py
index 45cea8f2..65ffd8b0 100644
--- a/rtemsqual/interface.py
+++ b/rtemsqual/interface.py
@@ -364,12 +364,18 @@ class Node:
name = item["interface-name"]
params = [param["name"] for param in item["interface-params"]]
param_line = ", ".join(params)
- line = f"#define {name}({param_line}) "
+ line = f"#define {name}({param_line})"
if len(line) > 79:
param_block = ", \\\n ".join(params)
- line = f"#define {name}( \\\n {param_block} \\\n) "
- body = self.substitute(" \\\n ".join(
- definition.strip("\n").split("\n")))
+ line = f"#define {name}( \\\n {param_block} \\\n)"
+ if not definition:
+ return line
+ body_lines = definition.strip("\n").split("\n")
+ if len(body_lines) == 1 and len(line + body_lines[0]) <= 79:
+ body = " "
+ else:
+ body = " \\\n "
+ body += self.substitute(" \\\n ".join(body_lines))
return line + body
def _get_typedef_definition(self, _item: Item, definition: Any) -> Lines:
diff --git a/rtemsqual/tests/spec-interface/macro2.yml b/rtemsqual/tests/spec-interface/macro2.yml
index 9253e090..722b381b 100644
--- a/rtemsqual/tests/spec-interface/macro2.yml
+++ b/rtemsqual/tests/spec-interface/macro2.yml
@@ -6,7 +6,9 @@ interface-brief: Short macro brief description.
interface-definition:
default: |
( ( ${.:/interface-params[0]/name} ) + 1 )
- variants: []
+ variants:
+ - definition: ""
+ enabled-by: "0"
interface-description: null
interface-name: MACRO
interface-params:
diff --git a/rtemsqual/tests/test_interface.py b/rtemsqual/tests/test_interface.py
index bafb6d81..ff9eefc4 100644
--- a/rtemsqual/tests/test_interface.py
+++ b/rtemsqual/tests/test_interface.py
@@ -248,7 +248,8 @@ static inline int VeryLongFunction(
VeryLongParam1, \\
VeryLongParam2, \\
VeryLongParam3 \\
-) do { \\
+) \\
+ do { \\
(void) VeryLongParam1; \\
(void) VeryLongParam2; \\
(void) VeryLongParam3; \\
@@ -264,7 +265,11 @@ static inline int VeryLongFunction(
*
* @return Sometimes some value.
*/
-#define MACRO(Param0) ( ( Param0 ) + 1 )
+#if 0
+ #define MACRO(Param0)
+#else
+ #define MACRO(Param0) ( ( Param0 ) + 1 )
+#endif
/**
* @ingroup GroupC