diff mbox

[RFC,13/14] qapi-introspect: Add #if conditions to introspection value

Message ID 20180212072207.9367-14-armbru@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Markus Armbruster Feb. 12, 2018, 7:22 a.m. UTC
Generated tests/test-qapi-introspect.c changes as follows:

    --- test-qapi-introspect.c.old	2018-02-11 17:36:15.039696522 +0100
    +++ tests/test-qapi-introspect.c	2018-02-11 17:36:34.455419852 +0100
    @@ -118,6 +118,9 @@ QLIT_QDICT(((QLitDictEntry[]) {
	     { "ret-type", QLIT_QSTR("14"), },
	     {}
	 })),
    +#if defined(TEST_IF_CMD)
    +#if defined(TEST_IF_STRUCT)
    +
     QLIT_QDICT(((QLitDictEntry[]) {
	     { "arg-type", QLIT_QSTR("15"), },
	     { "meta-type", QLIT_QSTR("command"), },
    @@ -125,12 +128,19 @@ QLIT_QDICT(((QLitDictEntry[]) {
	     { "ret-type", QLIT_QSTR("1"), },
	     {}
	 })),
    +#endif /* defined(TEST_IF_STRUCT) */
    +#endif /* defined(TEST_IF_CMD) */
    +
    +#if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)
    +
     QLIT_QDICT(((QLitDictEntry[]) {
	     { "arg-type", QLIT_QSTR("16"), },
	     { "meta-type", QLIT_QSTR("event"), },
	     { "name", QLIT_QSTR("TestIfEvent"), },
	     {}
	 })),
    +#endif /* defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) */
    +
     QLIT_QDICT(((QLitDictEntry[]) {
	     { "members", QLIT_QLIST(((QLitObject[]) {
		 {}

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/introspect.py | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox

Patch

diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index c02df95e72..342ae09422 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -40,6 +40,12 @@  def to_qlit(obj, level=0, suppress_first_indent=False):
         ret = 'QLIT_QDICT(((QLitDictEntry[]) {\n'
         ret += ',\n'.join(elts) + '\n'
         ret += indent(level) + '}))'
+    elif isinstance(obj, tuple):
+        # Use of tuples for conditionals is a bit of a hack
+        ifcond, begin = obj
+        if begin:
+            return gen_if(ifcond)
+        return gen_endif(ifcond)
     else:
         assert False                # not implemented
     if level > 0:
@@ -101,6 +107,9 @@  extern const QLitObject %(var)s;
         # Ignore types on first pass; visit_end() will pick up used types
         return not isinstance(entity, QAPISchemaType)
 
+    def visit_ifcond(self, ifcond, begin):
+        self._qlits.append((ifcond, begin))
+
     def _name(self, name):
         if self._unmask:
             return name