[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v4 2/5] qapi: auto generate enum value strings
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH v4 2/5] qapi: auto generate enum value strings |
Date: |
Thu, 03 Nov 2016 20:17:48 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
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.
- Re: [Qemu-devel] [PATCH v4 2/5] qapi: auto generate enum value strings,
Markus Armbruster <=