diff mbox series

[RFC,11/14] qapi: add #if/#endif helpers

Message ID 20180212072207.9367-12-armbru@redhat.com
State New
Headers show
Series None | expand

Commit Message

Markus Armbruster Feb. 12, 2018, 7:22 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Add helpers to wrap generated code with #if/#endif lines.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qapi/common.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 1b254d5b32..1a78dfaf3f 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1973,6 +1973,24 @@  def guardend(name):
                  name=guardname(name))
 
 
+def gen_if(ifcond):
+    ret = ''
+    for ifc in ifcond:
+        ret += mcgen('''
+#if %(cond)s
+''', cond=ifc)
+    return ret
+
+
+def gen_endif(ifcond):
+    ret = ''
+    for ifc in reversed(ifcond):
+        ret += mcgen('''
+#endif /* %(cond)s */
+''', cond=ifc)
+    return ret
+
+
 def gen_enum_lookup(name, values, prefix=None):
     ret = mcgen('''