diff options
author | Amos Kong <akong@redhat.com> | 2012-08-31 10:56:23 +0800 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2012-09-05 15:48:56 -0300 |
commit | b9c4b48d50057b6aee7c70879b240ff76f39c85b (patch) | |
tree | 350bac3ec1a13b67a2c5e289c35ccd0b60a30e76 /scripts/qapi-visit.py | |
parent | 2ef20c15b4736c9b0afc7ef2b14239182fbcd3e1 (diff) |
qapi: generate list struct and visit_list for enum
Currently, if we define an 'enum' and use it in one command's
data, list struct for enum could not be generated, but it's
used in qmp function.
For example: KeyCodesList could not be generated.
>>> qapi-schema.json:
{ 'enum': 'KeyCodes',
'data': [ 'shift', 'alt' ... ] }
{ 'command': 'sendkey',
'data': { 'keys': ['KeyCodes'], '*hold-time': 'int' } }
>>> qmp-command.h:
void qmp_sendkey(KeyCodesList * keys, bool has_hold_time, int64_t
hold_time, Error **errp);
This patch lets qapi generate list struct and visit_list for enum.
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'scripts/qapi-visit.py')
-rw-r--r-- | scripts/qapi-visit.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 04ef7c41ab..cbec24da16 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -217,6 +217,16 @@ void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, return ret +def generate_enum_declaration(name, members, genlist=True): + ret = "" + if genlist: + ret += mcgen(''' +void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp); +''', + name=name) + + return ret + def generate_decl_enum(name, members, genlist=True): return mcgen(''' @@ -335,10 +345,12 @@ for expr in exprs: ret += generate_declaration(expr['union'], expr['data']) fdecl.write(ret) elif expr.has_key('enum'): - ret = generate_visit_enum(expr['enum'], expr['data']) + ret = generate_visit_list(expr['enum'], expr['data']) + ret += generate_visit_enum(expr['enum'], expr['data']) fdef.write(ret) ret = generate_decl_enum(expr['enum'], expr['data']) + ret += generate_enum_declaration(expr['enum'], expr['data']) fdecl.write(ret) fdecl.write(''' |