From: Amos Kong <akong@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, Amos Kong <akong@redhat.com>,
eblake@redhat.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v5 4/6] qapi: generate list struct and visit_list for enum
Date: Thu, 26 Jul 2012 12:48:59 +0800 [thread overview]
Message-ID: <1343278141-10843-5-git-send-email-akong@redhat.com> (raw)
In-Reply-To: <1343278141-10843-1-git-send-email-akong@redhat.com>
Currently, if 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 for enum.
Signed-off-by: Amos Kong <akong@redhat.com>
---
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 4a734f5..648eac7 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
@@ -265,7 +275,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"
@@ -289,6 +300,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
next prev parent reply other threads:[~2012-07-26 4:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-26 4:48 [Qemu-devel] [PATCH v5 0/6] convert sendkey to qapi Amos Kong
2012-07-26 4:48 ` [Qemu-devel] [PATCH v5 1/6] fix doc of using raw values with sendkey Amos Kong
2012-07-26 4:48 ` [Qemu-devel] [PATCH v5 2/6] monitor: rename keyname '<' to 'less' Amos Kong
2012-07-26 4:48 ` [Qemu-devel] [PATCH v5 3/6] hmp: rename arguments Amos Kong
2012-07-26 4:48 ` Amos Kong [this message]
2012-07-26 4:49 ` [Qemu-devel] [PATCH v5 5/6] ps2: output warning when event queue full Amos Kong
2012-07-27 19:24 ` Blue Swirl
2012-07-26 4:49 ` [Qemu-devel] [PATCH v5 6/6] qapi: convert sendkey Amos Kong
2012-07-26 21:22 ` Eric Blake
2012-08-02 19:57 ` Luiz Capitulino
2012-08-03 1:38 ` Amos Kong
2012-08-03 13:23 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343278141-10843-5-git-send-email-akong@redhat.com \
--to=akong@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=eblake@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).