All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com, marcandre.lureau@redhat.com,
	eblake@redhat.com
Subject: [Qemu-devel] [PATCH RFC 09/14] qapi: Pass ifcond to visitors
Date: Mon, 12 Feb 2018 08:22:02 +0100	[thread overview]
Message-ID: <20180212072207.9367-10-armbru@redhat.com> (raw)
In-Reply-To: <20180212072207.9367-1-armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/common.py                 | 15 +++++++++++++++
 tests/qapi-schema/qapi-schema-test.out |  9 +++++++++
 tests/qapi-schema/test-qapi.py         | 19 +++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 78aeec785e..692a7ec7c2 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1066,6 +1066,9 @@ class QAPISchemaVisitor(object):
     def visit_include(self, fname, info):
         pass
 
+    def visit_ifcond(self, ifcond, begin):
+        pass
+
     def visit_builtin_type(self, name, info, json_type):
         pass
 
@@ -1792,12 +1795,24 @@ class QAPISchema(object):
     def visit(self, visitor):
         visitor.visit_begin(self)
         module = None
+        ifcond = None
         for entity in self._entity_list:
             if visitor.visit_needed(entity):
                 if entity.module != module:
+                    if ifcond:
+                        visitor.visit_ifcond(ifcond, False)
+                        ifcond = None
                     module = entity.module
                     visitor.visit_module(module)
+                if entity.ifcond != ifcond:
+                    if ifcond:
+                        visitor.visit_ifcond(ifcond, False)
+                    ifcond = entity.ifcond
+                    if ifcond:
+                        visitor.visit_ifcond(ifcond, True)
                 entity.visit(visitor)
+        if ifcond:
+            visitor.visit_ifcond(ifcond, False)
         visitor.visit_end()
 
 
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index b11682314c..8fe9d7a3a8 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -232,23 +232,32 @@ command __org.qemu_x-command q_obj___org.qemu_x-command-arg -> __org.qemu_x-Unio
    gen=True success_response=True boxed=False
 object TestIfStruct
     member foo: int optional=False
+    if ['defined(TEST_IF_STRUCT)']
 enum TestIfEnum ['foo', 'bar']
+    if ['defined(TEST_IF_ENUM)']
 object q_obj_TestStruct-wrapper
     member data: TestStruct optional=False
 enum TestIfUnionKind ['foo']
+    if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']
 object TestIfUnion
     member type: TestIfUnionKind optional=False
     tag type
     case foo: q_obj_TestStruct-wrapper
+    if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']
 alternate TestIfAlternate
     tag type
     case foo: int
     case bar: TestStruct
+    if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']
 object q_obj_TestIfCmd-arg
     member foo: TestIfStruct optional=False
+    if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']
 command TestIfCmd q_obj_TestIfCmd-arg -> None
    gen=True success_response=True boxed=False
+    if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']
 object q_obj_TestIfEvent-arg
     member foo: TestIfStruct optional=False
+    if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']
 event TestIfEvent q_obj_TestIfEvent-arg
    boxed=False
+    if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']
diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
index 67e417e298..fcdbb5b1ea 100644
--- a/tests/qapi-schema/test-qapi.py
+++ b/tests/qapi-schema/test-qapi.py
@@ -17,16 +17,26 @@ from qapi.common import QAPIError, QAPISchema, QAPISchemaVisitor
 
 class QAPISchemaTestVisitor(QAPISchemaVisitor):
 
+    def __init__(self):
+        self._ifcond = None
+
     def visit_module(self, name):
         print('module %s' % name)
 
     def visit_include(self, name, info):
         print('include %s' % name)
 
+    def visit_ifcond(self, ifcond, begin):
+        if begin:
+            self._ifcond = ifcond
+        else:
+            self._ifcond = None
+
     def visit_enum_type(self, name, info, values, prefix):
         print('enum %s %s' % (name, values))
         if prefix:
             print('    prefix %s' % prefix)
+        self._print_if(self._ifcond)
 
     def visit_object_type(self, name, info, base, members, variants):
         print('object %s' % name)
@@ -36,10 +46,12 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
             print('    member %s: %s optional=%s' % \
                   (m.name, m.type.name, m.optional))
         self._print_variants(variants)
+        self._print_if(self._ifcond)
 
     def visit_alternate_type(self, name, info, variants):
         print('alternate %s' % name)
         self._print_variants(variants)
+        self._print_if(self._ifcond)
 
     def visit_command(self, name, info, arg_type, ret_type,
                       gen, success_response, boxed):
@@ -47,10 +59,12 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
               (name, arg_type and arg_type.name, ret_type and ret_type.name))
         print('   gen=%s success_response=%s boxed=%s' % \
               (gen, success_response, boxed))
+        self._print_if(self._ifcond)
 
     def visit_event(self, name, info, arg_type, boxed):
         print('event %s %s' % (name, arg_type and arg_type.name))
         print('   boxed=%s' % boxed)
+        self._print_if(self._ifcond)
 
     @staticmethod
     def _print_variants(variants):
@@ -59,6 +73,11 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
             for v in variants.variants:
                 print('    case %s: %s' % (v.name, v.type.name))
 
+    @staticmethod
+    def _print_if(ifcond, indent=4):
+        if ifcond:
+            print('%sif %s' % (' ' * indent, ifcond))
+
 
 try:
     schema = QAPISchema(sys.argv[1])
-- 
2.13.6

  parent reply	other threads:[~2018-02-12  7:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180212072207.9367-1-armbru@redhat.com>
2018-02-12  7:21 ` [Qemu-devel] [PATCH RFC 01/14] qlit: use QType instead of int Markus Armbruster
2018-02-12  7:21 ` [Qemu-devel] [PATCH RFC 02/14] qlit: add qobject_from_qlit() Markus Armbruster
2018-02-12  7:21 ` [Qemu-devel] [PATCH RFC 03/14] qapi/introspect: Simplify WIP Markus Armbruster
2018-02-12  7:21 ` [Qemu-devel] [PATCH RFC 04/14] qapi: generate a literal qobject for introspection Markus Armbruster
2018-02-12  7:21 ` [Qemu-devel] [PATCH RFC 05/14] qapi2texi: minor python code simplification Markus Armbruster
2018-02-12  7:21 ` [Qemu-devel] [PATCH RFC 06/14] qapi: add 'if' to top-level expressions Markus Armbruster
2018-02-12  7:22 ` [Qemu-devel] [PATCH RFC 07/14] qapi: pass 'if' condition into QAPISchemaEntity objects Markus Armbruster
2018-02-12  7:22 ` [Qemu-devel] [PATCH RFC 08/14] qapi: leave the ifcond attribute undefined until check() Markus Armbruster
2018-02-12  7:22 ` Markus Armbruster [this message]
2018-02-12  7:22 ` [Qemu-devel] [PATCH RFC 10/14] qapi: mcgen() shouldn't indent # lines Markus Armbruster
2018-02-12  7:22 ` [Qemu-devel] [PATCH RFC 11/14] qapi: add #if/#endif helpers Markus Armbruster
2018-02-12  7:22 ` [Qemu-devel] [PATCH RFC 12/14] qapi-introspect: modify to_qlit() to append ', ' on level > 0 Markus Armbruster
2018-02-12  7:22 ` [Qemu-devel] [PATCH RFC 13/14] qapi-introspect: Add #if conditions to introspection value Markus Armbruster
2018-02-12  7:22 ` [Qemu-devel] [PATCH RFC 14/14] qapi: Add #if conditions to commands, events, types, visitors Markus Armbruster
2018-02-14 15:28   ` Marc-Andre Lureau
2018-02-23 18:13     ` Markus Armbruster
2018-04-19 22:35       ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180212072207.9367-10-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.