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] [RFC PATCH v2 04/12] qapi-visit: Remove redundant functions for flat union base
Date: Thu,  6 Aug 2015 21:52:33 -0600	[thread overview]
Message-ID: <1438919561-27750-5-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1438919561-27750-1-git-send-email-eblake@redhat.com>

The code for visiting the base class of a child struct created
visit_type_Base_fields(); the code for visiting the base class
of a flat union created visit_type_Union_fields(). If the same
type is shared between a struct and a union, the two functions
differed only by whether they visited the discriminator used by
the union. But if the base class always visits all its fields,
then we don't need to revisit the discriminator specially for
a union.  By consistently visiting the base class fields under
the name of the base class, we can eliminate some redundant
code.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi-visit.py | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index ef96345..b131c0d 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -115,7 +115,7 @@ if (err) {
 ''')

     pop_indent()
-    if re.search('^ *goto out;', ret, re.MULTILINE):
+    if base or members:
         ret += mcgen('''

 out:
@@ -241,8 +241,8 @@ def gen_visit_union(name, base, variants):
     ret = ''

     if base:
-        members = [m for m in base.members if m != variants.tag_member]
-        ret += gen_visit_struct_fields(name, None, members)
+        ret += gen_visit_struct_fields(base.name, base.base,
+                                       base.local_members)

     for var in variants.variants:
         # TODO ugly special case for simple union
@@ -263,29 +263,31 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error
 ''',
                  c_name=c_name(name), name=name)

-    if base:
-        ret += mcgen('''
-        visit_type_%(c_name)s_fields(m, obj, &err);
-        if (err) {
-            goto out_obj;
-        }
-''',
-                     c_name=c_name(name))
-
     tag_key = variants.tag_member.name
-    ret += mcgen('''
+    if base:
+        ret += mcgen('''
+        visit_type_%(c_name)s_fields(m, (%(c_name)s **)obj, &err);
+        if (err) {
+            goto out_obj;
+        }
+''',
+                     c_name=c_name(base.name))
+    else:
+        ret += mcgen('''
         visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "%(name)s", &err);
         if (err) {
             goto out_obj;
         }
+''',
+                     c_type=variants.tag_member.type.c_name(),
+                     c_name=c_name(tag_key), name=tag_key)
+    ret += mcgen('''
         if (!visit_start_union(m, !!(*obj)->data, &err) || err) {
             goto out_obj;
         }
         switch ((*obj)->%(c_name)s) {
 ''',
-                 c_type=variants.tag_member.type.c_name(),
-                 c_name=c_name(variants.tag_member.name),
-                 name=tag_key)
+                 c_name=c_name(tag_key))

     for var in variants.variants:
         # TODO ugly special case for simple union
-- 
2.4.3

  parent reply	other threads:[~2015-08-07  3:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-07  3:52 [Qemu-devel] [RFC PATCH v2 00/12] post-introspection qapi cleanups Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 01/12] qapi: use 'type' in generated C code to match QMP union wire form Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 02/12] vnc: hoist allocation of VncBasicInfo to callers Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 03/12] qapi: Unbox base members Eric Blake
2015-08-07  3:52 ` Eric Blake [this message]
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 05/12] qapi: Test use of 'number' within alternates Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 06/12] qapi: Simplify visiting of alternate types Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 07/12] qapi: Fix alternates that accept 'number' but not 'int' Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 08/12] qapi: Add tests for empty unions Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 09/12] qapi: Rework deallocation of partial struct Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 10/12] qapi: Avoid use of 'data' member of qapi unions Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 11/12] qapi: Forbid empty unions and useless alternates Eric Blake
2015-08-07  3:52 ` [Qemu-devel] [RFC PATCH v2 12/12] qapi: Drop useless 'data' member of unions Eric Blake
2015-08-07 22:07 ` [Qemu-devel] [RFC PATCH v2 13/12] qapi: Remove dead visitor code Eric Blake
2015-08-07 22:07 ` [Qemu-devel] [RFC PATCH v2 14/12] qapi: Document visitor interfaces Eric Blake

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=1438919561-27750-5-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).