aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-05-07 09:53:50 +0200
committerLuiz Capitulino <lcapitulino@redhat.com>2014-05-15 14:00:46 -0400
commitbe3c771796cb5ca4e7de2e04ed3cd2e3b6b76185 (patch)
treee41b8980d739a8a5a060dfbf033a2bac45d3acdb /scripts
parent192cca60aec59eda9a36501f03fc9dabf4d66a16 (diff)
qapi: Un-inline visit of implicit struct
In preparation of error handling changes. Bonus: generates less duplicated code. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi-visit.py48
1 files changed, 34 insertions, 14 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 1e368bedbb..1ef753a9b9 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -17,6 +17,31 @@ import os
import getopt
import errno
+implicit_structs = []
+
+def generate_visit_implicit_struct(type):
+ global implicit_structs
+ if type in implicit_structs:
+ return ''
+ implicit_structs.append(type)
+ return mcgen('''
+
+static void visit_type_implicit_%(c_type)s(Visitor *m, %(c_type)s **obj, Error **errp)
+{
+ Error *err = NULL;
+
+ visit_start_implicit_struct(m, (void **)obj, sizeof(%(c_type)s), &err);
+ if (!err) {
+ visit_type_%(c_type)s_fields(m, obj, &err);
+ error_propagate(errp, err);
+ err = NULL;
+ visit_end_implicit_struct(m, &err);
+ }
+ error_propagate(errp, err);
+}
+''',
+ c_type=type_name(type))
+
def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base = None):
substructs = []
ret = ''
@@ -49,6 +74,9 @@ static void visit_type_%(full_name)s_field_%(c_name)s(Visitor *m, %(name)s **obj
}
''')
+ if base:
+ ret += generate_visit_implicit_struct(base)
+
ret += mcgen('''
static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error **errp)
@@ -60,13 +88,7 @@ static void visit_type_%(full_name)s_fields(Visitor *m, %(name)s ** obj, Error *
if base:
ret += mcgen('''
-visit_start_implicit_struct(m, (void**) &(*obj)->%(c_prefix)s%(c_name)s, sizeof(%(type)s), &err);
-if (!err) {
- visit_type_%(type)s_fields(m, &(*obj)->%(c_prefix)s%(c_name)s, &err);
- error_propagate(errp, err);
- err = NULL;
- visit_end_implicit_struct(m, &err);
-}
+visit_type_implicit_%(type)s(m, &(*obj)->%(c_prefix)s%(c_name)s, &err);
''',
c_prefix=c_var(field_prefix),
type=type_name(base), c_name=c_var('base'))
@@ -292,6 +314,10 @@ def generate_visit_union(expr):
del base_fields[discriminator]
ret += generate_visit_struct_fields(name, "", "", base_fields)
+ if discriminator:
+ for key in members:
+ ret += generate_visit_implicit_struct(members[key])
+
ret += mcgen('''
void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
@@ -330,13 +356,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
if not discriminator:
fmt = 'visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "data", &err);'
else:
- fmt = '''visit_start_implicit_struct(m, (void**) &(*obj)->%(c_name)s, sizeof(%(c_type)s), &err);
- if (!err) {
- visit_type_%(c_type)s_fields(m, &(*obj)->%(c_name)s, &err);
- error_propagate(errp, err);
- err = NULL;
- visit_end_implicit_struct(m, &err);
- }'''
+ fmt = 'visit_type_implicit_%(c_type)s(m, &(*obj)->%(c_name)s, &err);'
enum_full_value = generate_enum_full_value(disc_type, key)
ret += mcgen('''