From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 09/12] qapi: Don't use info as witness of implicit object type
Date: Thu, 15 Oct 2015 09:51:42 +0200 [thread overview]
Message-ID: <1444895505-16067-10-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1444895505-16067-1-git-send-email-armbru@redhat.com>
From: Eric Blake <eblake@redhat.com>
A future patch will enable error reporting from the various
QAPISchema*.check() methods. But to report an error related
to 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.
Instead, add an is_implicit() method to QAPISchemaEntity, and use it.
It can be overridden later for ObjectType and EnumType, when implicit
instances of those classes gain info.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1444710158-8723-8-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
scripts/qapi-types.py | 3 ++-
scripts/qapi-visit.py | 3 ++-
scripts/qapi.py | 14 ++++++++++----
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 2a29c6e..4fe618e 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -235,7 +235,8 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
def visit_needed(self, entity):
# Visit everything except implicit objects
- return not isinstance(entity, QAPISchemaObjectType) or entity.info
+ return not (entity.is_implicit() and
+ isinstance(entity, QAPISchemaObjectType))
def _gen_type_cleanup(self, name):
self.decl += gen_type_cleanup_decl(name)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index b7a6470..d0759d7 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -337,7 +337,8 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
def visit_needed(self, entity):
# Visit everything except implicit objects
- return not isinstance(entity, QAPISchemaObjectType) or entity.info
+ return not (entity.is_implicit() and
+ isinstance(entity, QAPISchemaObjectType))
def visit_enum_type(self, name, info, values, prefix):
self.decl += gen_visit_decl(name, scalar=True)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 68f97a1..d7cf0f3 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -798,6 +798,9 @@ class QAPISchemaEntity(object):
def check(self, schema):
pass
+ def is_implicit(self):
+ return not self.info
+
def visit(self, visitor):
pass
@@ -971,11 +974,11 @@ class QAPISchemaObjectType(QAPISchemaType):
self.members = members
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):
@@ -1043,7 +1046,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 (self.type.is_implicit() and
+ isinstance(self.type, QAPISchemaObjectType)):
assert len(self.type.members) == 1
assert not self.type.variants
return self.type.members[0].type
@@ -1162,11 +1166,13 @@ class QAPISchema(object):
self._def_entity(self.the_empty_object_type)
def _make_implicit_enum_type(self, name, values):
- name = name + 'Kind'
+ name = name + 'Kind' # Use namespace reserved by add_name()
self._def_entity(QAPISchemaEnumType(name, None, values, None))
return name
def _make_array_type(self, element_type):
+ # TODO fooList namespace is not reserved; user can create collisions,
+ # or abuse our type system with ['fooList'] for 2D array
name = element_type + 'List'
if not self.lookup_type(name):
self._def_entity(QAPISchemaArrayType(name, None, element_type))
--
2.4.3
next prev parent reply other threads:[~2015-10-15 7:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-15 7:51 [Qemu-devel] [PULL 00/12] QAPI patches Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 01/12] qapi: Fix regression with '-netdev help' Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 02/12] qapi: Use predicate callback to determine visit filtering Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 03/12] qapi: Prepare for errors during check() Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 04/12] qapi: Drop redundant alternate-good test Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 05/12] qapi: Move empty-enum to compile-time test Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 06/12] qapi: Drop redundant returns-int test Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 07/12] qapi: Drop redundant flat-union-reverse-define test Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 08/12] qapi: Drop redundant args-member-array test Markus Armbruster
2015-10-15 7:51 ` Markus Armbruster [this message]
2015-10-15 7:51 ` [Qemu-devel] [PULL 10/12] qapi: Lazy creation of array types Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 11/12] qapi: Create simple union type member earlier Markus Armbruster
2015-10-15 7:51 ` [Qemu-devel] [PULL 12/12] qapi: Track location that created an implicit type Markus Armbruster
2015-10-16 17:41 ` [Qemu-devel] [PULL 00/12] QAPI patches Peter Maydell
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=1444895505-16067-10-git-send-email-armbru@redhat.com \
--to=armbru@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).