[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 4/6] qapi: generate list struct and visit_list fo
From: |
Amos Kong |
Subject: |
[Qemu-devel] [PATCH v7 4/6] qapi: generate list struct and visit_list for enum |
Date: |
Mon, 20 Aug 2012 12:39:27 +0800 |
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 <address@hidden>
---
scripts/qapi-types.py | 16 +++++++++++++++-
scripts/qapi-visit.py | 14 +++++++++++++-
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index cf601ae..49ef569 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -28,6 +28,16 @@ typedef struct %(name)sList
''',
name=name)
+def generate_fwd_enum_struct(name, members):
+ return mcgen('''
+typedef struct %(name)sList
+{
+ %(name)s value;
+ struct %(name)sList *next;
+} %(name)sList;
+''',
+ name=name)
+
def generate_struct(structname, fieldname, members):
ret = mcgen('''
struct %(name)s
@@ -276,7 +286,8 @@ for expr in exprs:
if expr.has_key('type'):
ret += generate_fwd_struct(expr['type'], expr['data'])
elif expr.has_key('enum'):
- ret += generate_enum(expr['enum'], expr['data'])
+ ret += generate_enum(expr['enum'], expr['data']) + "\n"
+ ret += generate_fwd_enum_struct(expr['enum'], expr['data'])
fdef.write(generate_enum_lookup(expr['enum'], expr['data']))
elif expr.has_key('union'):
ret += generate_fwd_struct(expr['union'], expr['data']) + "\n"
@@ -300,6 +311,9 @@ for expr in exprs:
fdef.write(generate_type_cleanup(expr['union'] + "List") + "\n")
ret += generate_type_cleanup_decl(expr['union'])
fdef.write(generate_type_cleanup(expr['union']) + "\n")
+ elif expr.has_key('enum'):
+ ret += generate_type_cleanup_decl(expr['enum'] + "List")
+ fdef.write(generate_type_cleanup(expr['enum'] + "List") + "\n")
else:
continue
fdecl.write(ret)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 04ef7c4..cbec24d 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('''
--
1.7.1
- [Qemu-devel] [PATCH v7 0/6] convert sendkey to qapi, Amos Kong, 2012/08/20
- [Qemu-devel] [PATCH v7 1/6] fix doc of using raw values with sendkey, Amos Kong, 2012/08/20
- [Qemu-devel] [PATCH v7 2/6] monitor: rename keyname '<' to 'less', Amos Kong, 2012/08/20
- [Qemu-devel] [PATCH v7 5/6] add the QKeyCode enum and the key_defs table, Amos Kong, 2012/08/20
- [Qemu-devel] [PATCH v7 4/6] qapi: generate list struct and visit_list for enum,
Amos Kong <=
- [Qemu-devel] [PATCH v7 6/6] qapi: convert sendkey, Amos Kong, 2012/08/20
- [Qemu-devel] [PATCH v7 3/6] hmp: rename arguments, Amos Kong, 2012/08/20
- Re: [Qemu-devel] [PATCH v7 0/6] convert sendkey to qapi, Eric Blake, 2012/08/20