qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] 答复: Re: [PATCH v4 2/5] qapi: auto generate enum value stri


From: Lin Ma
Subject: [Qemu-devel] 答复: Re: [PATCH v4 2/5] qapi: auto generate enum value strings
Date: Mon, 07 Nov 2016 08:41:59 -0700


>>> Markus Armbruster <address@hidden> 2016/11/4 星期五 上午 3:17 >>>
>Lin Ma <address@hidden> writes:
>
>> Automatically generate enum value strings that containing the acceptable 
>> values.
>> (Borrowed Daniel's code.)
>>
>> Signed-off-by: Lin Ma <address@hidden>
>> ---
>>  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 via email to

[Prev in Thread] Current Thread [Next in Thread]