mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 12:23:53 -06:00
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 <armbru@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1444710158-8723-2-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
d08ac81a45
commit
25a0d9c977
4 changed files with 33 additions and 20 deletions
|
@ -811,6 +811,10 @@ class QAPISchemaVisitor(object):
|
|||
def visit_end(self):
|
||||
pass
|
||||
|
||||
def visit_needed(self, entity):
|
||||
# Default to visiting everything
|
||||
return True
|
||||
|
||||
def visit_builtin_type(self, name, info, json_type):
|
||||
pass
|
||||
|
||||
|
@ -1304,10 +1308,10 @@ class QAPISchema(object):
|
|||
ent.check(self)
|
||||
|
||||
def visit(self, visitor):
|
||||
ignore = visitor.visit_begin(self)
|
||||
for name in sorted(self._entity_dict.keys()):
|
||||
if not ignore or not isinstance(self._entity_dict[name], ignore):
|
||||
self._entity_dict[name].visit(visitor)
|
||||
visitor.visit_begin(self)
|
||||
for (name, entity) in sorted(self._entity_dict.items()):
|
||||
if visitor.visit_needed(entity):
|
||||
entity.visit(visitor)
|
||||
visitor.visit_end()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue