ping...

>>> Lin Ma <l...@suse.com> 2016/10/20 星期四 下午 7:28 >>>
Automatically generate enum value strings that containing the acceptable values.
(Borrowed Daniel's code.)

Signed-off-by: Lin Ma <l...@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']
-- 
2.9.2



Reply via email to