From nobody Tue Feb 10 16:22:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506959409650347.0699895925188; Mon, 2 Oct 2017 08:50:09 -0700 (PDT) Received: from localhost ([::1]:52924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz2yl-000427-Pr for importer@patchew.org; Mon, 02 Oct 2017 11:49:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz2be-0007zn-T4 for qemu-devel@nongnu.org; Mon, 02 Oct 2017 11:26:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dz2bb-0007xp-TZ for qemu-devel@nongnu.org; Mon, 02 Oct 2017 11:26:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38700) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dz2bb-0007wU-GY for qemu-devel@nongnu.org; Mon, 02 Oct 2017 11:26:03 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84F0880472; Mon, 2 Oct 2017 15:26:02 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-91.ams2.redhat.com [10.36.116.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27BE85D722; Mon, 2 Oct 2017 15:26:02 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C038B11562E8; Mon, 2 Oct 2017 17:25:52 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 84F0880472 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Oct 2017 17:25:41 +0200 Message-Id: <20171002152552.27999-22-armbru@redhat.com> In-Reply-To: <20171002152552.27999-1-armbru@redhat.com> References: <20171002152552.27999-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 02 Oct 2017 15:26:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 21/32] qapi: Define QAPIOptionKind and QAPIOption automatically X-BeenThere: qemu-devel@gnu.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+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Enumeration type QAPIOptionKind enumerates the command line options. Flat union QAPIOption captures a single command line option. Its tag is QAPIOptionKind, and the variants are the option argument types. FIXME implement missing clash checking in QAPISchemaObjectType.check_clash() FIXME potential clash in QAPISchema._def_autos() FIXME made up info in QAPISchema._def_autos() TODO can we avoid the wrappers around non-object option argument types? Signed-off-by: Markus Armbruster --- scripts/qapi-commands.py | 2 +- scripts/qapi-event.py | 2 +- scripts/qapi-introspect.py | 2 +- scripts/qapi-types.py | 2 +- scripts/qapi-visit.py | 2 +- scripts/qapi.py | 42 ++++++++++++++++++++++++++++++= ++-- scripts/qapi2texi.py | 2 +- tests/qapi-schema/qapi-schema-test.out | 14 ++++++++++++ tests/qapi-schema/test-qapi.py | 2 +- 9 files changed, 61 insertions(+), 9 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 76cc9cc8a4..fdd3492f87 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -315,7 +315,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); prefix=3Dargs.prefix, c_prefix=3Dc_name(args.prefix, protect=3DFalse))) =20 -schema =3D QAPISchema(args.schema) +schema =3D QAPISchema(args.schema, args.prefix) gen =3D QAPISchemaGenCommandVisitor() schema.visit(gen) fdef.write(gen.defn) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index 1c61751bc0..64a4a02757 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -226,7 +226,7 @@ fdecl.write(mcgen(''' =20 event_enum_name =3D c_name(args.prefix + 'QAPIEvent', protect=3DFalse) =20 -schema =3D QAPISchema(args.schema) +schema =3D QAPISchema(args.schema, args.prefix) gen =3D QAPISchemaGenEventVisitor() schema.visit(gen) fdef.write(gen.defn) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index cc4ff01cd4..89365449b0 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -206,7 +206,7 @@ fdef.write(mcgen(''' ''', prefix=3Dargs.prefix)) =20 -schema =3D QAPISchema(args.schema) +schema =3D QAPISchema(args.schema, args.prefix) gen =3D QAPISchemaGenIntrospectVisitor(args.unmask_non_abi_names) schema.visit(gen, builtins=3DTrue) fdef.write(gen.defn) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index c058540e4d..5c53c56e45 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -276,7 +276,7 @@ else: #include "qapi/util.h" ''')) =20 -schema =3D QAPISchema(args.schema) +schema =3D QAPISchema(args.schema, args.prefix) gen =3D QAPISchemaGenTypeVisitor() schema.visit(gen, builtins=3Dnot args.schema) fdef.write(gen.defn) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index e756ef98ee..3182b860af 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -359,7 +359,7 @@ else: =20 ''')) =20 -schema =3D QAPISchema(args.schema) +schema =3D QAPISchema(args.schema, args.prefix) gen =3D QAPISchemaGenVisitVisitor() schema.visit(gen, builtins=3Dnot args.schema) fdef.write(gen.defn) diff --git a/scripts/qapi.py b/scripts/qapi.py index 1e03b62943..efc128eee0 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1235,7 +1235,12 @@ class QAPISchemaObjectType(QAPISchemaType): # and update seen to track the members seen so far. Report any errors # on behalf of info, which is not necessarily self.info def check_clash(self, info, seen): - assert not self.variants # not implemented + # check_union() ensures the following assertion holds, but + # QAPIUnion violates it. Disable it for now, so we can play + # with QAPIUnion without having to implement the missing clash + # checking first. + # FIXME implement missing clash checking + # assert not self.variants # not implemented for m in self.members: m.check_clash(info, seen) =20 @@ -1535,8 +1540,9 @@ class QAPISchemaOption(QAPISchemaEntity): =20 =20 class QAPISchema(object): - def __init__(self, file): + def __init__(self, file, prefix): try: + self.prefix =3D prefix if file: parser =3D QAPISchemaParser(file) self.exprs =3D check_exprs(parser.exprs) @@ -1545,10 +1551,14 @@ class QAPISchema(object): self.exprs =3D [] self.docs =3D [] self._entity_dict =3D {} + self._option_arg =3D {} self._predefining =3D True self._def_predefineds() self._predefining =3D False self._def_exprs() + self._predefining =3D True + self._def_autos() + self._predefining =3D False self.check() except QAPIError as err: print >>sys.stderr, err @@ -1751,6 +1761,7 @@ class QAPISchema(object): name[2:], info, doc, 'optarg', self._make_members(data, in= fo)) self._def_entity(QAPISchemaOption(name, info, doc, data, short, implied_key, boxed, help_= )) + self._option_arg[name[2:]] =3D data =20 def _def_exprs(self): for expr_elem in self.exprs: @@ -1774,6 +1785,33 @@ class QAPISchema(object): else: assert False =20 + def _def_autos(self): + info =3D {'file': None, 'line': 0, 'parent': None} # FIXME + if self._option_arg: + name =3D self.prefix + 'QAPIOption' + self._make_implicit_enum_type(name, info, + sorted(self._option_arg.keys())) + # FIXME what if these members clash with variant members? + members =3D [ + QAPISchemaObjectTypeMember('type', name + 'Kind', False), + QAPISchemaObjectTypeMember('idx', 'int32', False), + QAPISchemaObjectTypeMember('cnt', 'int32', False)] + variants =3D [] + for (key, value) in sorted(self._option_arg.items()): + if not value: + continue + typ =3D self.lookup_type(value) + if isinstance(typ, QAPISchemaObjectType): + v =3D self._make_variant(key, value) + else: + # TODO can we avoid the wrapper? + v =3D self._make_simple_variant(key, value, typ.info) + variants.append(v) + self._def_entity(QAPISchemaObjectType( + name, info, None, None, members, + QAPISchemaObjectTypeVariants('type', None, variants) + if variants else None)) + def check(self): for ent in self._entity_dict.values(): ent.check(self) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 071abc9d5d..0e099ebaa2 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -286,7 +286,7 @@ def main(argv): help=3D'QAPI schema source file') args =3D parser.parse_args() =20 - schema =3D qapi.QAPISchema(args.schema) + schema =3D qapi.QAPISchema(args.schema, '') if not qapi.doc_required: print >>sys.stderr, ("%s: need pragma 'doc-required' " "to generate documentation" % argv[0]) diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 9ee06539ac..16dc30dd99 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -79,6 +79,18 @@ object NestedEnumsOne member enum2: EnumOne optional=3DTrue member enum3: EnumOne optional=3DFalse member enum4: EnumOne optional=3DTrue +object QAPIOption + member type: QAPIOptionKind optional=3DFalse + member idx: int32 optional=3DFalse + member cnt: int32 optional=3DFalse + tag type + case opt-any: q_obj_any-wrapper + case opt-boxed: UserDefZero + case opt-enum: q_obj_EnumOne-wrapper + case opt-int: q_obj_int-wrapper + case opt-str: q_obj_str-wrapper + case opt-struct: q_obj_opt-struct-optarg +enum QAPIOptionKind ['help', 'opt-any', 'opt-boxed', 'opt-enum', 'opt-int'= , 'opt-str', 'opt-struct'] enum QEnumTwo ['value1', 'value2'] prefix QENUM_TWO object TestStruct @@ -207,6 +219,8 @@ object q_obj_EVENT_D-arg member b: str optional=3DFalse member c: str optional=3DTrue member enum3: EnumOne optional=3DTrue +object q_obj_EnumOne-wrapper + member data: EnumOne optional=3DFalse object q_obj_UserDefA-wrapper member data: UserDefA optional=3DFalse object q_obj_UserDefB-wrapper diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 2e5e7bfeb1..7de7d6dc53 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -67,7 +67,7 @@ parser.add_argument('schema', type=3Dargparse.FileType('r= '), nargs=3D'?', help=3D'QAPI schema source file') args =3D parser.parse_args() =20 -schema =3D QAPISchema(args.schema) +schema =3D QAPISchema(args.schema, '') schema.visit(QAPISchemaTestVisitor(), builtins=3Dnot args.schema) =20 for doc in schema.docs: --=20 2.13.6