aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi/common.py59
-rw-r--r--scripts/qapi/events.py1
-rw-r--r--scripts/qapi/types.py59
3 files changed, 60 insertions, 59 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 9d5c05f6a1..306857f0c0 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -2239,65 +2239,6 @@ def _wrap_ifcond(ifcond, before, after):
return out
-def gen_enum_lookup(name, members, prefix=None):
- ret = mcgen('''
-
-const QEnumLookup %(c_name)s_lookup = {
- .array = (const char *const[]) {
-''',
- c_name=c_name(name))
- for m in members:
- ret += gen_if(m.ifcond)
- index = c_enum_const(name, m.name, prefix)
- ret += mcgen('''
- [%(index)s] = "%(name)s",
-''',
- index=index, name=m.name)
- ret += gen_endif(m.ifcond)
-
- ret += mcgen('''
- },
- .size = %(max_index)s
-};
-''',
- max_index=c_enum_const(name, '_MAX', prefix))
- return ret
-
-
-def gen_enum(name, members, prefix=None):
- # append automatically generated _MAX value
- enum_members = members + [QAPISchemaEnumMember('_MAX', None)]
-
- ret = mcgen('''
-
-typedef enum %(c_name)s {
-''',
- c_name=c_name(name))
-
- for m in enum_members:
- ret += gen_if(m.ifcond)
- ret += mcgen('''
- %(c_enum)s,
-''',
- c_enum=c_enum_const(name, m.name, prefix))
- ret += gen_endif(m.ifcond)
-
- ret += mcgen('''
-} %(c_name)s;
-''',
- c_name=c_name(name))
-
- ret += mcgen('''
-
-#define %(c_name)s_str(val) \\
- qapi_enum_lookup(&%(c_name)s_lookup, (val))
-
-extern const QEnumLookup %(c_name)s_lookup;
-''',
- c_name=c_name(name))
- return ret
-
-
def build_params(arg_type, boxed, extra=None):
ret = ''
sep = ''
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index 7308e8e589..a716a1d27f 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -13,6 +13,7 @@ See the COPYING file in the top-level directory.
"""
from qapi.common import *
+from qapi.types import gen_enum, gen_enum_lookup
def build_event_send_proto(name, arg_type, boxed):
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
index 3edd9374aa..711543147d 100644
--- a/scripts/qapi/types.py
+++ b/scripts/qapi/types.py
@@ -21,6 +21,65 @@ from qapi.common import *
objects_seen = set()
+def gen_enum_lookup(name, members, prefix=None):
+ ret = mcgen('''
+
+const QEnumLookup %(c_name)s_lookup = {
+ .array = (const char *const[]) {
+''',
+ c_name=c_name(name))
+ for m in members:
+ ret += gen_if(m.ifcond)
+ index = c_enum_const(name, m.name, prefix)
+ ret += mcgen('''
+ [%(index)s] = "%(name)s",
+''',
+ index=index, name=m.name)
+ ret += gen_endif(m.ifcond)
+
+ ret += mcgen('''
+ },
+ .size = %(max_index)s
+};
+''',
+ max_index=c_enum_const(name, '_MAX', prefix))
+ return ret
+
+
+def gen_enum(name, members, prefix=None):
+ # append automatically generated _MAX value
+ enum_members = members + [QAPISchemaEnumMember('_MAX', None)]
+
+ ret = mcgen('''
+
+typedef enum %(c_name)s {
+''',
+ c_name=c_name(name))
+
+ for m in enum_members:
+ ret += gen_if(m.ifcond)
+ ret += mcgen('''
+ %(c_enum)s,
+''',
+ c_enum=c_enum_const(name, m.name, prefix))
+ ret += gen_endif(m.ifcond)
+
+ ret += mcgen('''
+} %(c_name)s;
+''',
+ c_name=c_name(name))
+
+ ret += mcgen('''
+
+#define %(c_name)s_str(val) \\
+ qapi_enum_lookup(&%(c_name)s_lookup, (val))
+
+extern const QEnumLookup %(c_name)s_lookup;
+''',
+ c_name=c_name(name))
+ return ret
+
+
def gen_fwd_object_or_array(name):
return mcgen('''