All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [PATCH v2 5/7] qapi: Move gen_enum(), gen_enum_lookup() back to qapi/types.py
Date: Fri, 18 Oct 2019 09:43:43 +0200	[thread overview]
Message-ID: <20191018074345.24034-6-armbru@redhat.com> (raw)
In-Reply-To: <20191018074345.24034-1-armbru@redhat.com>

The next commit will split up qapi/common.py.  gen_enum() needs
QAPISchemaEnumMember, and that's in the way.  Move it to qapi/types.py
along with its buddy gen_enum_lookup().

Permit me a short a digression on history: how did gen_enum() end up
in qapi/common.py?  Commit 21cd70dfc1 "qapi script: add event support"
duplicated qapi-types.py's gen_enum() and gen_enum_lookup() in
qapi-event.py.  Simply importing them would have been cleaner, but
wasn't possible as qapi-types.py was a program, not a module.  Commit
efd2eaa6c2 "qapi: De-duplicate enum code generation" de-duplicated by
moving them to qapi.py, which was a module.

Since then, program qapi-types.py has morphed into module types.py.
It's where gen_enum() and gen_enum_lookup() started, and where they
belong.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi/common.py | 59 ------------------------------------------
 scripts/qapi/events.py |  1 +
 scripts/qapi/types.py  | 59 ++++++++++++++++++++++++++++++++++++++++++
 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('''
 
-- 
2.21.0



  parent reply	other threads:[~2019-10-18  7:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18  7:43 [PATCH v2 0/7] qapi: Cleanups and test speedup Markus Armbruster
2019-10-18  7:43 ` [PATCH v2 1/7] qapi: Don't suppress doc generation without pragma doc-required Markus Armbruster
2019-10-18  7:43 ` [PATCH v2 2/7] qapi: Store pragma state in QAPISourceInfo, not global state Markus Armbruster
2019-10-18  7:43 ` [PATCH v2 3/7] qapi: Eliminate accidental global frontend state Markus Armbruster
2019-10-18  7:43 ` [PATCH v2 4/7] qapi: Speed up frontend tests Markus Armbruster
2019-10-18  7:43 ` Markus Armbruster [this message]
2019-10-18  7:43 ` [PATCH v2 6/7] qapi: Split up scripts/qapi/common.py Markus Armbruster
2019-10-18  7:43 ` [PATCH v2 7/7] qapi: Clear scripts/qapi/doc.py executable bits again Markus Armbruster

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=20191018074345.24034-6-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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.