From patchwork Mon Feb 12 07:22:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 10211913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 58A07602CB for ; Mon, 12 Feb 2018 07:34:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34D63288A1 for ; Mon, 12 Feb 2018 07:34:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2435028BAC; Mon, 12 Feb 2018 07:34:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F3CB288A1 for ; Mon, 12 Feb 2018 07:34:32 +0000 (UTC) Received: from localhost ([::1]:49647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1el8dD-0003UM-SH for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Feb 2018 02:34:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1el8RN-0000j8-B4 for qemu-devel@nongnu.org; Mon, 12 Feb 2018 02:22:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1el8RK-0005vw-M4 for qemu-devel@nongnu.org; Mon, 12 Feb 2018 02:22:17 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43056 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1el8RK-0005tq-AJ for qemu-devel@nongnu.org; Mon, 12 Feb 2018 02:22:14 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF4098182D20; Mon, 12 Feb 2018 07:22:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-43.ams2.redhat.com [10.36.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB9382026612; Mon, 12 Feb 2018 07:22:12 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 02B351138657; Mon, 12 Feb 2018 08:22:08 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 12 Feb 2018 08:22:02 +0100 Message-Id: <20180212072207.9367-10-armbru@redhat.com> In-Reply-To: <20180212072207.9367-1-armbru@redhat.com> References: <20180212072207.9367-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 12 Feb 2018 07:22:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 12 Feb 2018 07:22:13 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH RFC 09/14] qapi: Pass ifcond to visitors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Markus Armbruster --- 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])