From patchwork Mon Sep 21 21:57:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 520618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0427014012C for ; Tue, 22 Sep 2015 08:09:53 +1000 (AEST) Received: from localhost ([::1]:34272 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze9HT-0001JU-46 for incoming@patchwork.ozlabs.org; Mon, 21 Sep 2015 18:09:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze96F-0007Yi-O0 for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ze96E-0000oJ-EM for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46753) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze96E-0000o8-5O for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:14 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id C88A42EAAA8; Mon, 21 Sep 2015 21:58:13 +0000 (UTC) Received: from red.redhat.com (ovpn-113-166.phx2.redhat.com [10.3.113.166]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8LLw4bX027229; Mon, 21 Sep 2015 17:58:13 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 21 Sep 2015 15:57:27 -0600 Message-Id: <1442872682-6523-12-git-send-email-eblake@redhat.com> In-Reply-To: <1442872682-6523-1-git-send-email-eblake@redhat.com> References: <1442872682-6523-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Michael Roth , marcandre.lureau@redhat.com, DirtY.iCE.hu@gmail.com, armbru@redhat.com, ehabkost@redhat.com Subject: [Qemu-devel] [PATCH v5 11/46] qapi: Don't use info as witness of implicit object type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A future patch will enable error reporting from the various check() methods. But to report an error on an implicit type, we'll need to associate a location with the type (the same location as the top-level entity that is causing the creation of the implicit type), and once we do that, keying off of whether foo.info exists is no longer a viable way to determine if foo is an implicit type. Rename the info member to _info (so that sub-classes can still use it, but external code should not), add an is_implicit() method to QAPISchemaObjectType, and adjust the visitor to pass another parameter about whether the type is implicit. Signed-off-by: Eric Blake --- scripts/qapi-types.py | 4 ++-- scripts/qapi-visit.py | 4 ++-- scripts/qapi.py | 33 +++++++++++++++++++-------------- tests/qapi-schema/test-qapi.py | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index b292682..aa25e03 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -253,8 +253,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl += gen_array(name, element_type) self._gen_type_cleanup(name) - def visit_object_type(self, name, info, base, members, variants): - if info: + def visit_object_type(self, name, info, base, members, variants, implicit): + if not implicit: self._fwdecl += gen_fwd_object_or_array(name) if variants: assert not members # not implemented diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 1f287ba..62a47fa 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -348,8 +348,8 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl += decl self.defn += defn - def visit_object_type(self, name, info, base, members, variants): - if info: + def visit_object_type(self, name, info, base, members, variants, implicit): + if not implicit: self.decl += gen_visit_decl(name) if variants: assert not members # not implemented diff --git a/scripts/qapi.py b/scripts/qapi.py index 7275daa..1dc7641 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -786,7 +786,7 @@ class QAPISchemaEntity(object): def __init__(self, name, info): assert isinstance(name, str) self.name = name - self.info = info + self._info = info def c_name(self): return c_name(self.name) @@ -814,7 +814,7 @@ class QAPISchemaVisitor(object): def visit_array_type(self, name, info, element_type): pass - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, implicit): pass def visit_object_type_flat(self, name, info, members, variants): @@ -877,7 +877,7 @@ class QAPISchemaBuiltinType(QAPISchemaType): return self._json_type_name def visit(self, visitor): - visitor.visit_builtin_type(self.name, self.info, self.json_type()) + visitor.visit_builtin_type(self.name, self._info, self.json_type()) class QAPISchemaEnumType(QAPISchemaType): @@ -903,7 +903,7 @@ class QAPISchemaEnumType(QAPISchemaType): return 'string' def visit(self, visitor): - visitor.visit_enum_type(self.name, self.info, + visitor.visit_enum_type(self.name, self._info, self.values, self.prefix) @@ -922,7 +922,7 @@ class QAPISchemaArrayType(QAPISchemaType): return 'array' def visit(self, visitor): - visitor.visit_array_type(self.name, self.info, self.element_type) + visitor.visit_array_type(self.name, self._info, self.element_type) class QAPISchemaObjectType(QAPISchemaType): @@ -961,21 +961,25 @@ class QAPISchemaObjectType(QAPISchemaType): self.variants.check(schema, members, seen) self.members = members + def is_implicit(self): + return self.name[0] == ':' + def c_name(self): - assert self.info + assert not self.is_implicit() return QAPISchemaType.c_name(self) def c_type(self, is_param=False): - assert self.info + assert not self.is_implicit() return QAPISchemaType.c_type(self) def json_type(self): return 'object' def visit(self, visitor): - visitor.visit_object_type(self.name, self.info, - self.base, self.local_members, self.variants) - visitor.visit_object_type_flat(self.name, self.info, + visitor.visit_object_type(self.name, self._info, + self.base, self.local_members, self.variants, + self.is_implicit()) + visitor.visit_object_type_flat(self.name, self._info, self.members, self.variants) @@ -1034,7 +1038,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): # This function exists to support ugly simple union special cases # TODO get rid of them, and drop the function def simple_union_type(self): - if isinstance(self.type, QAPISchemaObjectType) and not self.type.info: + if isinstance(self.type, QAPISchemaObjectType) and \ + self.type.is_implicit(): assert len(self.type.members) == 1 assert not self.type.variants return self.type.members[0].type @@ -1055,7 +1060,7 @@ class QAPISchemaAlternateType(QAPISchemaType): return 'value' def visit(self, visitor): - visitor.visit_alternate_type(self.name, self.info, self.variants) + visitor.visit_alternate_type(self.name, self._info, self.variants) class QAPISchemaCommand(QAPISchemaEntity): @@ -1080,7 +1085,7 @@ class QAPISchemaCommand(QAPISchemaEntity): assert isinstance(self.ret_type, QAPISchemaType) def visit(self, visitor): - visitor.visit_command(self.name, self.info, + visitor.visit_command(self.name, self._info, self.arg_type, self.ret_type, self.gen, self.success_response) @@ -1099,7 +1104,7 @@ class QAPISchemaEvent(QAPISchemaEntity): assert not self.arg_type.variants # not implemented def visit(self, visitor): - visitor.visit_event(self.name, self.info, self.arg_type) + visitor.visit_event(self.name, self._info, self.arg_type) class QAPISchema(object): diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 649677e..f2cce64 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -22,7 +22,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): if prefix: print ' prefix %s' % prefix - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, implicit): print 'object %s' % name if base: print ' base %s' % base.name