qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v6 16/16] qapi: Consolidate object visitors
Date: Thu, 17 Mar 2016 16:48:41 -0600	[thread overview]
Message-ID: <1458254921-17042-17-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1458254921-17042-1-git-send-email-eblake@redhat.com>

Rather than having two separate visitor callbacks with items
already broken out, pass the actual QAPISchemaObjectType object
to the visitor.  This lets the visitor access things like
type.is_implicit() without needing another parameter, resolving
a TODO from previous patches.

For convenience and consistency, the 'name' and 'info' parameters
are still provided, even though they are now redundant with
'typ.name' and 'typ.info'.

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v6: new patch
---
 scripts/qapi.py            | 10 ++--------
 scripts/qapi-introspect.py | 10 +++++-----
 scripts/qapi-types.py      | 13 ++++++-------
 scripts/qapi-visit.py      | 12 ++++++------
 4 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index b13ae47..4dde43a 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -808,10 +808,7 @@ class QAPISchemaVisitor(object):
     def visit_array_type(self, name, info, element_type):
         pass

-    def visit_object_type(self, name, info, base, members, variants):
-        pass
-
-    def visit_object_type_flat(self, name, info, members, variants):
+    def visit_object_type(self, name, info, typ):
         pass

     def visit_alternate_type(self, name, info, variants):
@@ -1005,10 +1002,7 @@ class QAPISchemaObjectType(QAPISchemaType):
         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,
-                                       self.members, self.variants)
+        visitor.visit_object_type(self.name, self.info, self)


 class QAPISchemaMember(object):
diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index e0f926b..474eafd 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -141,11 +141,11 @@ const char %(c_name)s[] = %(c_string)s;
         element = self._use_type(element_type)
         self._gen_json('[' + element + ']', 'array', {'element-type': element})

-    def visit_object_type_flat(self, name, info, members, variants):
-        obj = {'members': [self._gen_member(m) for m in members]}
-        if variants:
-            obj.update(self._gen_variants(variants.tag_member.name,
-                                          variants.variants))
+    def visit_object_type(self, name, info, typ):
+        obj = {'members': [self._gen_member(m) for m in typ.members]}
+        if typ.variants:
+            obj.update(self._gen_variants(typ.variants.tag_member.name,
+                                          typ.variants.variants))
         self._gen_json(name, 'object', obj)

     def visit_alternate_type(self, name, info, variants):
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index e09c875..40c4c1d 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -220,17 +220,16 @@ 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):
+    def visit_object_type(self, name, info, typ):
         # Nothing to do for the special empty builtin
         if name == 'q_empty':
             return
         self._fwdecl += gen_fwd_object_or_array(name)
-        self.decl += gen_object(name, base, members, variants)
-        if base and not base.is_implicit():
-            self.decl += gen_upcast(name, base)
-        # TODO Worth changing the visitor signature, so we could
-        # directly use rather than repeat type.is_implicit()?
-        if not name.startswith('q_'):
+        self.decl += gen_object(name, typ.base, typ.local_members,
+                                typ.variants)
+        if typ.base and not typ.base.is_implicit():
+            self.decl += gen_upcast(name, typ.base)
+        if not typ.is_implicit():
             # implicit types won't be directly allocated/freed
             self._gen_type_cleanup(name)

diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index c147990..e756545 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -289,18 +289,18 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
             self.decl += decl
             self.defn += defn

-    def visit_object_type(self, name, info, base, members, variants):
+    def visit_object_type(self, name, info, typ):
         # Nothing to do for the special empty builtin
         if name == 'q_empty':
             return
         self.decl += gen_visit_members_decl(name)
-        self.defn += gen_visit_object_members(name, base, members, variants)
-        # TODO Worth changing the visitor signature, so we could
-        # directly use rather than repeat type.is_implicit()?
-        if not name.startswith('q_'):
+        self.defn += gen_visit_object_members(name, typ.base,
+                                              typ.local_members, typ.variants)
+        if not typ.is_implicit():
             # only explicit types need an allocating visit
             self.decl += gen_visit_decl(name)
-            self.defn += gen_visit_object(name, base, members, variants)
+            self.defn += gen_visit_object(name, typ.base, typ.local_members,
+                                          typ.variants)

     def visit_alternate_type(self, name, info, variants):
         self.decl += gen_visit_decl(name)
-- 
2.5.0

  parent reply	other threads:[~2016-03-17 22:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-17 22:48 [Qemu-devel] [PATCH v6 00/16] easier unboxed visits/qapi implicit types Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 01/16] qapi: Assert in places where variants are not handled Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 02/16] qapi: Fix command with named empty argument type Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 03/16] qapi: Make c_type() more OO-like Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 04/16] qapi: Adjust names of implicit types Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 05/16] qapi: Emit implicit structs in generated C Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 06/16] qapi-event: Drop qmp_output_get_qobject() null check Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 07/16] qapi-event: Utilize implicit struct visits Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 08/16] qapi-commands: " Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 09/16] qapi-commands: Inline single-use helpers of gen_marshal() Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 10/16] qapi: Inline gen_visit_members() into lone caller Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 11/16] qapi: Drop unused c_null() Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 12/16] qapi: Don't special-case simple union wrappers Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 13/16] qapi: Make BlockdevOptions doc example closer to reality Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 14/16] qapi: Allow anonymous base for flat union Eric Blake
2016-03-17 22:48 ` [Qemu-devel] [PATCH v6 15/16] qapi: Use anonymous bases in QMP flat unions Eric Blake
2016-03-17 22:48 ` Eric Blake [this message]
2016-03-18  7:47   ` [Qemu-devel] [PATCH v6 16/16] qapi: Consolidate object visitors Markus Armbruster
2016-03-18 10:01 ` [Qemu-devel] [PATCH v6 00/16] easier unboxed visits/qapi implicit types Markus Armbruster

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=1458254921-17042-17-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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).