All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: aliguori@us.ibm.com, eblake@redhat.com, qemu-devel@nongnu.org,
	lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum
Date: Thu, 07 Jun 2012 11:33:01 +0800	[thread overview]
Message-ID: <4FD020ED.6040101@redhat.com> (raw)
In-Reply-To: <20120607001516.GE7733@illuin>

On 07/06/12 08:15, Michael Roth wrote:
> On Sat, Jun 02, 2012 at 06:54:27AM +0800, Amos Kong wrote:
>> 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 makes qapi can generate List struct for enum.
>>
>> Signed-off-by: Amos Kong<akong@redhat.com>
>> ---
>>   scripts/qapi-types.py |   33 +++++++++++++++++++++++++++++----
>>   scripts/qapi-visit.py |   14 +++++++++-----
>>   2 files changed, 38 insertions(+), 9 deletions(-)
>>
>> diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
>> index 4a734f5..c9641fb 100644
>> --- a/scripts/qapi-types.py
>> +++ b/scripts/qapi-types.py
>> @@ -16,17 +16,36 @@ import os
>>   import getopt
>>   import errno
>>
>> -def generate_fwd_struct(name, members):
>> -    return mcgen('''
>> +def generate_fwd_struct(name, members, enum=False):
>> +    ret = ""
>> +    if not enum:
>> +        ret += mcgen('''
>>   typedef struct %(name)s %(name)s;
>>
>> +''',
>> +                     name=name)
>> +    ret += mcgen('''
>>   typedef struct %(name)sList
>>   {
>> -    %(name)s *value;
>> +''',
>> +                     name=name)
>> +    if enum:
>> +        ret += mcgen('''
>> +         %(name)s value;
>> +''',
>> +                     name=name)
>> +    else:
>> +        ret += mcgen('''
>> +         %(name)s * value;
>> +''',
>> +                     name=name)
>> +
>> +    ret += mcgen('''
>>       struct %(name)sList *next;
>>   } %(name)sList;
>>   ''',
>>                    name=name)
>> +    return ret
>>
>>   def generate_struct(structname, fieldname, members):
>>       ret = mcgen('''
>> @@ -265,7 +284,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_struct(expr['enum'], expr['data'], True)
>>           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 +309,11 @@ 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")
>
> This one is fine
>
>> +        ret += generate_type_cleanup_decl(expr['enum'])
>> +        fdef.write(generate_type_cleanup(expr['enum']) + "\n")
>
> but we don't need this one since enum types are passed around by copy.
>
> The qapi_free_X() functions are utility functions that aren't used by
> the code generators, so there should be any harm in omitting these.

Ok, will drop those two sentences.


>>       else:
>>           continue
>>       fdecl.write(ret)
>> diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
>> index 8d4e94a..e44edfa 100644
>> --- a/scripts/qapi-visit.py
>> +++ b/scripts/qapi-visit.py
>> @@ -81,7 +81,7 @@ end:
>>   ''')
>>       return ret
>>
>> -def generate_visit_list(name, members):
>> +def generate_visit_list(name, members, enum=False):
>>       return mcgen('''
>>
>
> Were there plans to add a branch for enum=True? Otherwise we can drop this
> from the patch.


redundant, will drop it.

>>   void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
>> @@ -160,12 +160,14 @@ end:
>>
>>       return ret
>>
>> -def generate_declaration(name, members, genlist=True):
>> -    ret = mcgen('''
>> +def generate_declaration(name, members, genlist=True, enum=False):
>> +    ret = ""
>> +    if not enum:
>> +        ret = mcgen('''
>>
>>   void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
>>   ''',
>> -                name=name)
>> +                    name=name)
>>
>>       if genlist:
>>           ret += mcgen('''
>> @@ -293,10 +295,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'], True)
>> +        ret += generate_visit_enum(expr['enum'], expr['data'])
>>           fdef.write(ret)
>>
>>           ret = generate_decl_enum(expr['enum'], expr['data'])
>> +        ret += generate_declaration(expr['enum'], expr['data'], enum=True)
>>           fdecl.write(ret)
>>
>>   fdecl.write('''
>> --
>> 1.7.1
>>
>>

-- 
			Amos.

  reply	other threads:[~2012-06-07  3:33 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-01 22:54 [Qemu-devel] [PATCH v2 0/6] convert sendkey to qapi Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 1/6] qerror: add QERR_OVERFLOW Amos Kong
2012-06-04  5:27   ` Anthony Liguori
2012-06-05 14:29     ` [Qemu-devel] [PATCH v2 1/6] qerror: add MAX_KEYCODES 16 Amos Kong
     [not found]       ` <4FD0326F.3010806@redhat.com>
     [not found]         ` <20120611140642.06be2ee8@doriath.home>
     [not found]           ` <4FD62827.4060900@us.ibm.com>
     [not found]             ` <20120611142546.66871522@doriath.home>
2012-06-14 10:20               ` Amos Kong
2012-06-15  7:46                 ` Amos Kong
2012-06-15  7:57                   ` Gerd Hoffmann
2012-06-15 13:35                     ` Luiz Capitulino
2012-06-18 15:30                       ` Amos Kong
2012-06-19  9:52                         ` Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 2/6] fix doc of using raw values with sendkey Amos Kong
2012-06-06 18:16   ` Luiz Capitulino
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 3/6] rename keyname '<' to 'less' Amos Kong
2012-06-06 18:22   ` Luiz Capitulino
2012-06-06 23:12     ` Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 4/6] hmp: rename arguments Amos Kong
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 5/6] qapi: generate list struct and visit_list for enum Amos Kong
2012-06-05 15:01   ` Amos Kong
2012-06-06 18:40   ` Luiz Capitulino
2012-06-07  0:26     ` Michael Roth
2012-06-07  2:52       ` Amos Kong
2012-06-11 17:00         ` Luiz Capitulino
2012-06-07  0:15   ` Michael Roth
2012-06-07  3:33     ` Amos Kong [this message]
2012-06-01 22:54 ` [Qemu-devel] [PATCH v2 6/6] qapi: convert sendkey Amos Kong
2012-06-04 17:09   ` Eric Blake
2012-06-05 14:55     ` Amos Kong
2012-06-05 15:05       ` Eric Blake
2012-06-06  7:13         ` Amos Kong
2012-06-06 11:58           ` Eric Blake
2012-06-07  4:51             ` Anthony Liguori
2012-06-07 13:08               ` Eric Blake
2012-06-01 23:03 ` [Qemu-devel] [PATCH v2 0/6] convert sendkey to qapi Amos Kong

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=4FD020ED.6040101@redhat.com \
    --to=akong@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=eblake@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.