All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lin Ma" <lma@suse.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, afaerber@suse.de
Subject: [Qemu-devel] 答复: Re:  [PATCH v4 2/5] qapi: auto generate enum value strings
Date: Mon, 07 Nov 2016 08:41:59 -0700	[thread overview]
Message-ID: <5821114702000062000ADF9D@prv-mh.provo.novell.com> (raw)
In-Reply-To: <8760o4wexv.fsf@dusky.pond.sub.org>



>>> Markus Armbruster <armbru@redhat.com> 2016/11/4 星期五 上午 3:17 >>>
>Lin Ma <lma@suse.com> writes:
>
>> Automatically generate enum value strings that containing the acceptable values.
>> (Borrowed Daniel's code.)
>>
>> Signed-off-by: Lin Ma <lma@suse.com>
>> ---
>>  scripts/qapi-types.py | 2 ++
>>  scripts/qapi.py       | 9 +++++++++
>>  2 files changed, 11 insertions(+)
>>
>> diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
>> index dabc42e..0446839 100644
>> --- a/scripts/qapi-types.py
>> +++ b/scripts/qapi-types.py
>> @@ -202,9 +202,11 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
>>			  self._btin += gen_enum(name, values, prefix)
>>			  if do_builtins:
>>				  self.defn += gen_enum_lookup(name, values, prefix)
>> +			    self._btin += gen_enum_value_str(name, values)
>>		  else:
>>			  self._fwdecl += gen_enum(name, values, prefix)
>>			  self.defn += gen_enum_lookup(name, values, prefix)
>> +		    self._fwdecl += gen_enum_value_str(name, values)
>>  
>>	  def visit_array_type(self, name, info, element_type):
>>		  if isinstance(element_type, QAPISchemaBuiltinType):
>> diff --git a/scripts/qapi.py b/scripts/qapi.py
>> index 21bc32f..d11c414 100644
>> --- a/scripts/qapi.py
>> +++ b/scripts/qapi.py
>> @@ -1649,6 +1649,15 @@ const char *const %(c_name)s_lookup[] = {
>>	  return ret
>>  
>>  
>> +def gen_enum_value_str(name, values):
>> +    return mcgen('''
>> +
>> +#define %(c_name)s_value_str "%(value_str)s"
>> +''',
>> +			    c_name=c_name(name),
>> +			    value_str=", ".join(["'%s'" % c for c in values]))
>> +
>> +
>>  def gen_enum(name, values, prefix=None):
>>	  # append automatically generated _MAX value
>>	  enum_values = values + ['_MAX']
>
>This function is generating a macro definition, not a string.  We could
>call it gen_enum_values_define().  But I'd simply fold it into
>gen_enum().
>
>Adds another 9KiB to qapi-types.h, which is included widely.  Instead of
>defining these macros, we could also iterate over FOO_lookup[] at
>run-time.  But let's first review how the macro is used.
Sorry, I'm not familiar with writing qemu test code. I didn't understand it.
What's the meaning of 'Adds another 9KiB to qapi-types.h'? What is '9KiB'?
 
Thanks,
Lin
 

 

  reply	other threads:[~2016-11-07 15:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-20 11:28 [Qemu-devel] [PATCH v4 0/5] object: Add 'help' option for all available backends and properties Lin Ma
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 1/5] qom: Add interface check in object_class_is_abstract Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-11-03 18:18   ` [Qemu-devel] " Markus Armbruster
2016-11-07  9:19     ` [Qemu-devel] 答复: " Lin Ma
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 2/5] qapi: auto generate enum value strings Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-11-03 19:17   ` [Qemu-devel] " Markus Armbruster
2016-11-07 15:41     ` Lin Ma [this message]
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 3/5] qapi: add test case for the generated enum value str Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 4/5] backends: add description for enum class properties Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-11-03 19:58   ` [Qemu-devel] " Markus Armbruster
2016-11-07 15:54     ` [Qemu-devel] 答复: " Lin Ma
2016-11-07 16:09     ` [Qemu-devel] " Daniel P. Berrange
2016-10-20 11:28 ` [Qemu-devel] [PATCH v4 5/5] object: Add 'help' option for all available backends and properties Lin Ma
2016-11-03  5:19   ` [Qemu-devel] 答复: " Lin Ma
2016-11-03 19:50   ` [Qemu-devel] " Markus Armbruster
2016-11-07 16:17     ` [Qemu-devel] 答复: " Lin Ma
2016-11-03  5:19 ` [Qemu-devel] 答复: [PATCH v4 0/5] " Lin Ma

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=5821114702000062000ADF9D@prv-mh.provo.novell.com \
    --to=lma@suse.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=pbonzini@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 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.