diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2012-03-06 18:55:56 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2012-03-12 15:14:07 +0100 |
commit | dc8fb6df5a13f7231f88c78966f8a6c5306840b5 (patch) | |
tree | 61758a14593144f91c5ab01258f072e58020d786 /scripts/qapi-visit.py | |
parent | 622d241998b6a981483594712b039190ee94eff8 (diff) | |
download | qemu-dc8fb6df5a13f7231f88c78966f8a6c5306840b5.zip qemu-dc8fb6df5a13f7231f88c78966f8a6c5306840b5.tar.gz qemu-dc8fb6df5a13f7231f88c78966f8a6c5306840b5.tar.bz2 |
qapi: complete implementation of unions
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'scripts/qapi-visit.py')
-rw-r--r-- | scripts/qapi-visit.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 5160d83..54117d4 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -110,10 +110,38 @@ def generate_visit_union(name, members): void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp) { -} + Error *err = NULL; + + visit_start_struct(m, (void **)obj, "%(name)s", name, sizeof(%(name)s), &err); + visit_type_%(name)sKind(m, &(*obj)->kind, "type", &err); + if (err) { + error_propagate(errp, err); + goto end; + } + switch ((*obj)->kind) { ''', name=name) + for key in members: + ret += mcgen(''' + case %(abbrev)s_KIND_%(enum)s: + visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "data", errp); + break; +''', + abbrev = de_camel_case(name).upper(), + enum = de_camel_case(key).upper(), + c_type=members[key], + c_name=c_var(key)) + + ret += mcgen(''' + default: + abort(); + } +end: + visit_end_struct(m, errp); +} +''') + return ret def generate_declaration(name, members, genlist=True): @@ -242,6 +270,7 @@ for expr in exprs: fdecl.write(ret) elif expr.has_key('union'): ret = generate_visit_union(expr['union'], expr['data']) + ret += generate_visit_list(expr['union'], expr['data']) fdef.write(ret) ret = generate_decl_enum('%sKind' % expr['union'], expr['data'].keys()) |