[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH RFC v4 06/29] qapi-visit: Remove redundant functions
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH RFC v4 06/29] qapi-visit: Remove redundant functions for flat union base |
Date: |
Wed, 9 Sep 2015 22:06:08 -0600 |
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.
Now that gen_visit_struct_fields() can potentially collect more
than one function into 'ret', a regular expression searching for
whether a label was used may hit a false positive within the
body of the first function. But using a regex was overkill,
since we can easily determine when we jumped to a label.
Signed-off-by: Eric Blake <address@hidden>
---
scripts/qapi-visit.py | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index f5dc257..c3e4c49 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -118,7 +118,7 @@ if (err) {
''')
pop_indent()
- if re.search('^ *goto out;', ret, re.MULTILINE):
+ if base or members:
ret += mcgen('''
out:
@@ -249,8 +249,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:
# Ugly special case for simple union TODO get rid of it
@@ -271,18 +271,19 @@ 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);
+''',
+ c_name=c_name(base.name))
+ else:
+ ret += mcgen('''
visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "%(name)s", &err);
+''',
+ c_type=variants.tag_member.type.c_name(),
+ c_name=c_name(tag_key), name=tag_key)
+ ret += mcgen('''
if (err) {
goto out_obj;
}
@@ -291,8 +292,7 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj,
const char *name, Error
}
switch ((*obj)->%(c_name)s) {
''',
- c_type=variants.tag_member.type.c_name(),
- c_name=c_name(tag_key), name=tag_key)
+ c_name=c_name(tag_key))
for var in variants.variants:
# TODO ugly special case for simple union
--
2.4.3
- [Qemu-devel] [PATCH RFC v4 00/29] qapi-ify netdev_add, and other post-introspection cleanups, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 01/29] qapi: Provide nicer array names in introspection, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 04/29] vnc: hoist allocation of VncBasicInfo to callers, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 06/29] qapi-visit: Remove redundant functions for flat union base,
Eric Blake <=
- [Qemu-devel] [PATCH RFC v4 02/29] net: use Netdev instead of NetClientOptions in client init, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 05/29] qapi: Unbox base members, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 07/29] qapi: Test use of 'number' within alternates, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 09/29] qapi: Hide tag_name data member of variants, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 08/29] qapi: Simplify visiting of alternate types, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 12/29] qapi: Use consistent generated code patterns, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 17/29] qapi: Drop useless 'data' member of unions, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 11/29] qapi: Don't pass pre-existing error to later call, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 14/29] qapi: Rework deallocation of partial struct, Eric Blake, 2015/09/10
- [Qemu-devel] [PATCH RFC v4 10/29] qapi: Fix alternates that accept 'number' but not 'int', Eric Blake, 2015/09/10