From 25a0d9c977c2f5db914b0a1619759fd77d97b016 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 12 Oct 2015 22:22:21 -0600 Subject: qapi: Use predicate callback to determine visit filtering Previously, qapi-types and qapi-visit filtered out implicit objects during visit_object_type() by using 'info' (works since implicit objects do not [yet] have associated info); meanwhile qapi-introspect filtered out all schema types on the first pass by returning a python type from visit_begin(), which was then used at a distance in QAPISchema.visit() to do the filtering. Rather than keeping these ad hoc approaches, add a new visitor callback visit_needed() which returns False to skip a given entity, and which defaults to True unless overridden. Use the new mechanism to simplify all three filtering visitors. No change to the generated code. Suggested-by: Markus Armbruster Signed-off-by: Eric Blake Message-Id: <1444710158-8723-2-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index d405f8d670..2a29c6e106 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -233,6 +233,10 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl = self._btin + self.decl self._btin = None + def visit_needed(self, entity): + # Visit everything except implicit objects + return not isinstance(entity, QAPISchemaObjectType) or entity.info + def _gen_type_cleanup(self, name): self.decl += gen_type_cleanup_decl(name) self.defn += gen_type_cleanup(name) @@ -254,14 +258,13 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self._gen_type_cleanup(name) def visit_object_type(self, name, info, base, members, variants): - if info: - self._fwdecl += gen_fwd_object_or_array(name) - if variants: - assert not members # not implemented - self.decl += gen_union(name, base, variants) - else: - self.decl += gen_struct(name, base, members) - self._gen_type_cleanup(name) + self._fwdecl += gen_fwd_object_or_array(name) + if variants: + assert not members # not implemented + self.decl += gen_union(name, base, variants) + else: + self.decl += gen_struct(name, base, members) + self._gen_type_cleanup(name) def visit_alternate_type(self, name, info, variants): self._fwdecl += gen_fwd_object_or_array(name) -- cgit v1.2.3 From 49823c4b4304a3e4aa5d67e089946b12d6a52d64 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 12 Oct 2015 22:22:27 -0600 Subject: qapi: Don't use info as witness of implicit object type 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 Message-Id: <1444710158-8723-8-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 2a29c6e106..4fe618ef3c 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) -- cgit v1.2.3