Skip to contentSkip to conversation

scripts: use build_ prefix for string not piped through cgen()

PATCH Applied Marc-André Lureau 4 participants 8 messages Jun 1, 2017 – Jul 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 scripts: use build_ prefix for string not piped through cgen()

Suggested by Markus Armbruster:

The gen_ prefix is awkward. Generated C should go through cgen() exactly once (see commit 1f9a7a1). The common way to get this wrong is passing a foo=gen_foo() keyword argument to mcgen(). I'd like us to adopt a naming convention where gen_ means "something that's been piped through cgen(), and thus must not be passed to cgen() or mcgen()". Requires renaming gen_params(), gen_marshal_proto() and gen_event_send_proto().

---
 scripts/qapi.py          |  2 +-
 scripts/qapi-commands.py |  8 ++++----
 scripts/qapi-event.py    | 12 ++++++------
 3 files changed, 11 insertions(+), 11 deletions(-)
scripts/qapi.py +1 -1
index 6c4d554165..d37a6157e0 100644
@@ -1884,7 +1884,7 @@ extern const char *const %(c_name)s_lookup[];
     return ret
 
 
-def gen_params(arg_type, boxed, extra):
+def build_params(arg_type, boxed, extra):
     if not arg_type:
         assert not boxed
         return extra
scripts/qapi-commands.py +4 -4
index 1943de4852..974d0a4a80 100644
@@ -21,7 +21,7 @@ def gen_command_decl(name, arg_type, boxed, ret_type):
 ''',
                  c_type=(ret_type and ret_type.c_type()) or 'void',
                  c_name=c_name(name),
-                 params=gen_params(arg_type, boxed, 'Error **errp'))
+                 params=build_params(arg_type, boxed, 'Error **errp'))
 
 
 def gen_call(name, arg_type, boxed, ret_type):
@@ -82,7 +82,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out,
                  c_type=ret_type.c_type(), c_name=ret_type.c_name())
 
 
-def gen_marshal_proto(name):
+def build_marshal_proto(name):
     return ('void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)'
             % c_name(name))
 
@@ -91,7 +91,7 @@ def gen_marshal_decl(name):
     return mcgen('''
 %(proto)s;
 ''',
-                 proto=gen_marshal_proto(name))
+                 proto=build_marshal_proto(name))
 
 
 def gen_marshal(name, arg_type, boxed, ret_type):
@@ -103,7 +103,7 @@ def gen_marshal(name, arg_type, boxed, ret_type):
 {
     Error *err = NULL;
 ''',
-                proto=gen_marshal_proto(name))
+                proto=build_marshal_proto(name))
 
     if ret_type:
         ret += mcgen('''
scripts/qapi-event.py +6 -6
index 0485e39145..bcbef1035f 100644
@@ -14,10 +14,10 @@
 from qapi import *
 
 
-def gen_event_send_proto(name, arg_type, boxed):
+def build_event_send_proto(name, arg_type, boxed):
     return 'void qapi_event_send_%(c_name)s(%(param)s)' % {
         'c_name': c_name(name.lower()),
-        'param': gen_params(arg_type, boxed, 'Error **errp')}
+        'param': build_params(arg_type, boxed, 'Error **errp')}
 
 
 def gen_event_send_decl(name, arg_type, boxed):
@@ -25,10 +25,10 @@ def gen_event_send_decl(name, arg_type, boxed):
 
 %(proto)s;
 ''',
-                 proto=gen_event_send_proto(name, arg_type, boxed))
+                 proto=build_event_send_proto(name, arg_type, boxed))
 
 
-# Declare and initialize an object 'qapi' using parameters from gen_params()
+# Declare and initialize an object 'qapi' using parameters from build_params()
 def gen_param_var(typ):
     assert not typ.variants
     ret = mcgen('''
@@ -42,7 +42,7 @@ def gen_param_var(typ):
         if memb.optional:
             ret += 'has_' + c_name(memb.name) + sep
         if memb.type.name == 'str':
-            # Cast away const added in gen_params()
+            # Cast away const added in build_params()
             ret += '(char *)'
         ret += c_name(memb.name)
     ret += mcgen('''
@@ -72,7 +72,7 @@ def gen_event_send(name, arg_type, boxed):
     Error *err = NULL;
     QMPEventFuncEmit emit;
 ''',
-                proto=gen_event_send_proto(name, arg_type, boxed))
+                proto=build_event_send_proto(name, arg_type, boxed))
 
     if arg_type and not arg_type.is_empty():
         ret += mcgen('''
Signature · 1 line
2.13.0.91.g00982b8dd
#1 lore raw

PATCH v2 2/2 qapi: add location comment for generated types

This may help to find where the origin of the type was declared in the json (when greping isn't easy enough).

Generates the following kind of C comment before types:

/* /home/elmarco/src/qemu/qapi/introspect.json:94 */ typedef struct SchemaInfo SchemaInfo;

---
 scripts/qapi.py       | 12 +++++++++---
 scripts/qapi-event.py |  2 +-
 scripts/qapi-types.py | 18 +++++++++---------
 3 files changed, 19 insertions(+), 13 deletions(-)
scripts/qapi.py +9 -3
index d37a6157e0..7f9935eec0 100644
@@ -1852,15 +1852,21 @@ const char *const %(c_name)s_lookup[] = {
     return ret
 
 
-def gen_enum(name, values, prefix=None):
+def build_src_loc_comment(info):
+    if info:
+        return '\n/* %s:%d */' % (info['file'], info['line'])
+    else:
+        return ''
+
+def gen_enum(info, name, values, prefix=None):
     # append automatically generated _MAX value
     enum_values = values + ['_MAX']
 
     ret = mcgen('''
-
+%(comment)s
 typedef enum %(c_name)s {
 ''',
-                c_name=c_name(name))
+                c_name=c_name(name), comment=build_src_loc_comment(info))
 
     i = 0
     for value in enum_values:
scripts/qapi-event.py +1 -1
index bcbef1035f..cf5e282011 100644
@@ -159,7 +159,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
         self._event_names = []
 
     def visit_end(self):
-        self.decl += gen_enum(event_enum_name, self._event_names)
+        self.decl += gen_enum(None, event_enum_name, self._event_names)
         self.defn += gen_enum_lookup(event_enum_name, self._event_names)
         self._event_names = None
 
scripts/qapi-types.py +9 -9
index b45e7b5634..9c8a3e277b 100644
@@ -19,12 +19,12 @@ from qapi import *
 objects_seen = set()
 
 
-def gen_fwd_object_or_array(name):
+def gen_fwd_object_or_array(info, name):
     return mcgen('''
-
+%(comment)s
 typedef struct %(c_name)s %(c_name)s;
 ''',
-                 c_name=c_name(name))
+                 c_name=c_name(name), comment=build_src_loc_comment(info))
 
 
 def gen_array(name, element_type):
@@ -199,22 +199,22 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
         # Special case for our lone builtin enum type
         # TODO use something cleaner than existence of info
         if not info:
-            self._btin += gen_enum(name, values, prefix)
+            self._btin += gen_enum(None, name, values, prefix)
             if do_builtins:
                 self.defn += gen_enum_lookup(name, values, prefix)
         else:
-            self._fwdecl += gen_enum(name, values, prefix)
+            self._fwdecl += gen_enum(info, name, values, prefix)
             self.defn += gen_enum_lookup(name, values, prefix)
 
     def visit_array_type(self, name, info, element_type):
         if isinstance(element_type, QAPISchemaBuiltinType):
-            self._btin += gen_fwd_object_or_array(name)
+            self._btin += gen_fwd_object_or_array(None, name)
             self._btin += gen_array(name, element_type)
             self._btin += gen_type_cleanup_decl(name)
             if do_builtins:
                 self.defn += gen_type_cleanup(name)
         else:
-            self._fwdecl += gen_fwd_object_or_array(name)
+            self._fwdecl += gen_fwd_object_or_array(info, name)
             self.decl += gen_array(name, element_type)
             self._gen_type_cleanup(name)
 
@@ -222,7 +222,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
         # Nothing to do for the special empty builtin
         if name == 'q_empty':
             return
-        self._fwdecl += gen_fwd_object_or_array(name)
+        self._fwdecl += gen_fwd_object_or_array(info, name)
         self.decl += gen_object(name, base, members, variants)
         if base and not base.is_implicit():
             self.decl += gen_upcast(name, base)
@@ -233,7 +233,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
             self._gen_type_cleanup(name)
 
     def visit_alternate_type(self, name, info, variants):
-        self._fwdecl += gen_fwd_object_or_array(name)
+        self._fwdecl += gen_fwd_object_or_array(info, name)
         self.decl += gen_object(name, None, [variants.tag_member], variants)
         self._gen_type_cleanup(name)
 
Signature · 1 line
2.13.0.91.g00982b8dd
Reviewed-by on v2 2/2
#2 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] qapi: add location comment for generated types

Quoted 7 lines · Marc-André Lureau

This may help to find where the origin of the type was declared in the json (when greping isn't easy enough).

Generates the following kind of C comment before types:

/* /home/elmarco/src/qemu/qapi/introspect.json:94 */ typedef struct SchemaInfo SchemaInfo;

Makes the generated code larger, but for a good cause. No real impact to the binary size (well, debug information may be slightly larger based on line numbers getting higher, but that's in the noise).

Quoted 7 lines
---
 scripts/qapi.py       | 12 +++++++++---
 scripts/qapi-event.py |  2 +-
 scripts/qapi-types.py | 18 +++++++++---------
 3 files changed, 19 insertions(+), 13 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] qapi: add location comment for generated types

In reply to Marc-André Lureau
Quoted 7 lines · Marc-André Lureau

This may help to find where the origin of the type was declared in the json (when greping isn't easy enough).

Generates the following kind of C comment before types:

/* /home/elmarco/src/qemu/qapi/introspect.json:94 */ typedef struct SchemaInfo SchemaInfo;

Can we do relative file names? I.e. just qapi/introspect.json.

Would such comments be useful for things other than typedefs?

Quoted 12 lines
---
 scripts/qapi.py       | 12 +++++++++---
 scripts/qapi-event.py |  2 +-
 scripts/qapi-types.py | 18 +++++++++---------
 3 files changed, 19 insertions(+), 13 deletions(-)
scripts/qapi.py +0 -0
index d37a6157e0..7f9935eec0 100644

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1857

Quoted 7 lines
scripts/qapi.py +3 -1
@@ -1852,15 +1852,21 @@ const char *const %(c_name)s_lookup[] = {
     return ret
 
 
-def gen_enum(name, values, prefix=None):
+def build_src_loc_comment(info):
+    if info:
+        return '\n/* %s:%d */' % (info['file'], info['line'])

Leading instead of trailing newline, hmm. Let's see how it works out.

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1859

Quoted 2 lines
scripts/qapi.py +2 -0
+    else:
+        return ''

Let's drop the else: line.

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1861

Quoted 2 lines
scripts/qapi.py +2 -0
+
+def gen_enum(info, name, values, prefix=None):

Make that name, info, values, ... for consistency with other functions taking both name and info. More of the same below.

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1866

Quoted 6 lines
scripts/qapi.py +1 -1
     # append automatically generated _MAX value
     enum_values = values + ['_MAX']
 
     ret = mcgen('''
-
+%(comment)s

Loses the blank line when not info.

Quoted 25 lines
scripts/qapi.py +1 -1
 typedef enum %(c_name)s {
 ''',
-                c_name=c_name(name))
+                c_name=c_name(name), comment=build_src_loc_comment(info))
 
     i = 0
     for value in enum_values:
scripts/qapi-event.py +1 -1
index bcbef1035f..cf5e282011 100644
@@ -159,7 +159,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
         self._event_names = []
 
     def visit_end(self):
-        self.decl += gen_enum(event_enum_name, self._event_names)
+        self.decl += gen_enum(None, event_enum_name, self._event_names)
         self.defn += gen_enum_lookup(event_enum_name, self._event_names)
         self._event_names = None
 
scripts/qapi-types.py +0 -0
index b45e7b5634..9c8a3e277b 100644

scripts/qapi-types.py from qapi import * · line 24

Quoted 8 lines
scripts/qapi-types.py +2 -2
@@ -19,12 +19,12 @@ from qapi import *
 objects_seen = set()
 
 
-def gen_fwd_object_or_array(name):
+def gen_fwd_object_or_array(info, name):
     return mcgen('''
-
+%(comment)s

Likewise.

I think we should drop the newline from build_src_loc_comment()'s value, and keep the blank line before its two uses.

Quoted 44 lines
scripts/qapi-types.py +6 -6
 typedef struct %(c_name)s %(c_name)s;
 ''',
-                 c_name=c_name(name))
+                 c_name=c_name(name), comment=build_src_loc_comment(info))
 
 
 def gen_array(name, element_type):
@@ -199,22 +199,22 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
         # Special case for our lone builtin enum type
         # TODO use something cleaner than existence of info
         if not info:
-            self._btin += gen_enum(name, values, prefix)
+            self._btin += gen_enum(None, name, values, prefix)
             if do_builtins:
                 self.defn += gen_enum_lookup(name, values, prefix)
         else:
-            self._fwdecl += gen_enum(name, values, prefix)
+            self._fwdecl += gen_enum(info, name, values, prefix)
             self.defn += gen_enum_lookup(name, values, prefix)
 
     def visit_array_type(self, name, info, element_type):
         if isinstance(element_type, QAPISchemaBuiltinType):
-            self._btin += gen_fwd_object_or_array(name)
+            self._btin += gen_fwd_object_or_array(None, name)
             self._btin += gen_array(name, element_type)
             self._btin += gen_type_cleanup_decl(name)
             if do_builtins:
                 self.defn += gen_type_cleanup(name)
         else:
-            self._fwdecl += gen_fwd_object_or_array(name)
+            self._fwdecl += gen_fwd_object_or_array(info, name)
             self.decl += gen_array(name, element_type)
             self._gen_type_cleanup(name)
 
@@ -222,7 +222,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
         # Nothing to do for the special empty builtin
         if name == 'q_empty':
             return
-        self._fwdecl += gen_fwd_object_or_array(name)
+        self._fwdecl += gen_fwd_object_or_array(info, name)
         self.decl += gen_object(name, base, members, variants)
         if base and not base.is_implicit():
             self.decl += gen_upcast(name, base)

scripts/qapi-types.py class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): · line 238

Quoted 7 lines
scripts/qapi-types.py +1 -1
@@ -233,7 +233,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
             self._gen_type_cleanup(name)
 
     def visit_alternate_type(self, name, info, variants):
-        self._fwdecl += gen_fwd_object_or_array(name)
+        self._fwdecl += gen_fwd_object_or_array(info, name)
         self.decl += gen_object(name, None, [variants.tag_member], variants)
         self._gen_type_cleanup(name)

No comment gets generated before built-in types such as QType and anyList. That's okay, but perhaps the commit message could be a bit more precise.

#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] qapi: add location comment for generated types

Hi

Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Marc-André Lureau

This may help to find where the origin of the type was declared in the json (when greping isn't easy enough).

Quoted 7 lines
Quoted 4 lines

Generates the following kind of C comment before types:

/* /home/elmarco/src/qemu/qapi/introspect.json:94 */ typedef struct SchemaInfo SchemaInfo;

Can we do relative file names? I.e. just qapi/introspect.json.

We could, but relative to $srcdir or $builddir? I think absolute path avoids some potential confusion.

Quoted 3 lines

Would such comments be useful for things other than typedefs?

Certainly it could, however I just needed it for typedef, didn't bother adding it for the rest.

Quoted 23 lines
Quoted 13 lines
---
 scripts/qapi.py       | 12 +++++++++---
 scripts/qapi-event.py |  2 +-
 scripts/qapi-types.py | 18 +++++++++---------
 3 files changed, 19 insertions(+), 13 deletions(-)
scripts/qapi.py +0 -0
index d37a6157e0..7f9935eec0 100644

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1857

Quoted 7 lines
scripts/qapi.py +3 -1
@@ -1852,15 +1852,21 @@ const char *const %(c_name)s_lookup[] = {
     return ret
 
 
-def gen_enum(name, values, prefix=None):
+def build_src_loc_comment(info):
+    if info:
+        return '\n/* %s:%d */' % (info['file'], info['line'])

Leading instead of trailing newline, hmm. Let's see how it works out.

Quoted 5 lines

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1859

Quoted 2 lines
scripts/qapi.py +2 -0
+    else:
+        return ''

Let's drop the else: line.

ok

Quoted 8 lines

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1861

Quoted 3 lines
scripts/qapi.py +2 -0
+
+def gen_enum(info, name, values, prefix=None):

Make that name, info, values, ... for consistency with other functions taking both name and info. More of the same below.

ok

Quoted 47 lines

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1866

Quoted 6 lines
scripts/qapi.py +1 -1
     # append automatically generated _MAX value
     enum_values = values + ['_MAX']
 
     ret = mcgen('''
-
+%(comment)s

Loses the blank line when not info.

scripts/qapi.py const char *const %(c_name)s_lookup[] = {

Quoted 4 lines
scripts/qapi.py +1 -1
 typedef enum %(c_name)s {
 ''',
-                c_name=c_name(name))
+                c_name=c_name(name), comment=build_src_loc_comment(

info))

Quoted 8 lines
scripts/qapi.py +0 -0
     i = 0
     for value in enum_values:
scripts/qapi-event.py +0 -0
index bcbef1035f..cf5e282011 100644

scripts/qapi-event.py class QAPISchemaGenEventVisitor(QAPISchemaVisitor): · line 163

Quoted 6 lines
scripts/qapi-event.py +1 -1
@@ -159,7 +159,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
         self._event_names = []
 
     def visit_end(self):
-        self.decl += gen_enum(event_enum_name, self._event_names)
+        self.decl += gen_enum(None, event_enum_name, self._event_names)
         self.defn += gen_enum_lookup(event_enum_name,

self._event_names)

Quoted 7 lines
scripts/qapi-event.py +0 -0
         self._event_names = None
 
scripts/qapi-types.py +0 -0
index b45e7b5634..9c8a3e277b 100644

scripts/qapi-types.py from qapi import * · line 24

Quoted 8 lines
scripts/qapi-types.py +2 -2
@@ -19,12 +19,12 @@ from qapi import *
 objects_seen = set()
 
 
-def gen_fwd_object_or_array(name):
+def gen_fwd_object_or_array(info, name):
     return mcgen('''
-
+%(comment)s

Likewise.

Quoted 4 lines

I think we should drop the newline from build_src_loc_comment()'s value, and keep the blank line before its two uses.

And you get an extra empty line if info is None. I don't mind. Other option is to just add \n in the else case in build_src_loc_comment()

Quoted 52 lines

scripts/qapi-types.py from qapi import *

Quoted 4 lines
scripts/qapi-types.py +1 -1
 typedef struct %(c_name)s %(c_name)s;
 ''',
-                 c_name=c_name(name))
+                 c_name=c_name(name), comment=build_src_loc_comment(

info))

Quoted 40 lines
scripts/qapi-types.py +5 -5
 def gen_array(name, element_type):
@@ -199,22 +199,22 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
         # Special case for our lone builtin enum type
         # TODO use something cleaner than existence of info
         if not info:
-            self._btin += gen_enum(name, values, prefix)
+            self._btin += gen_enum(None, name, values, prefix)
             if do_builtins:
                 self.defn += gen_enum_lookup(name, values, prefix)
         else:
-            self._fwdecl += gen_enum(name, values, prefix)
+            self._fwdecl += gen_enum(info, name, values, prefix)
             self.defn += gen_enum_lookup(name, values, prefix)
 
     def visit_array_type(self, name, info, element_type):
         if isinstance(element_type, QAPISchemaBuiltinType):
-            self._btin += gen_fwd_object_or_array(name)
+            self._btin += gen_fwd_object_or_array(None, name)
             self._btin += gen_array(name, element_type)
             self._btin += gen_type_cleanup_decl(name)
             if do_builtins:
                 self.defn += gen_type_cleanup(name)
         else:
-            self._fwdecl += gen_fwd_object_or_array(name)
+            self._fwdecl += gen_fwd_object_or_array(info, name)
             self.decl += gen_array(name, element_type)
             self._gen_type_cleanup(name)
 
@@ -222,7 +222,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
         # Nothing to do for the special empty builtin
         if name == 'q_empty':
             return
-        self._fwdecl += gen_fwd_object_or_array(name)
+        self._fwdecl += gen_fwd_object_or_array(info, name)
         self.decl += gen_object(name, base, members, variants)
         if base and not base.is_implicit():
             self.decl += gen_upcast(name, base)

scripts/qapi-types.py class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): · line 237

Quoted 6 lines
scripts/qapi-types.py +1 -1
@@ -233,7 +233,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
             self._gen_type_cleanup(name)
 
     def visit_alternate_type(self, name, info, variants):
-        self._fwdecl += gen_fwd_object_or_array(name)
+        self._fwdecl += gen_fwd_object_or_array(info, name)
         self.decl += gen_object(name, None, [variants.tag_member],

variants)

Quoted 7 lines

scripts/qapi-types.py class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): · line 238

Quoted 1 line
scripts/qapi-types.py +0 -0
         self._gen_type_cleanup(name)

No comment gets generated before built-in types such as QType and anyList. That's okay, but perhaps the commit message could be a bit more precise.

ok

#5 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] qapi: add location comment for generated types

Quoted 11 lines · Marc-André Lureau

Hi

Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Marc-André Lureau

This may help to find where the origin of the type was declared in the json (when greping isn't easy enough).

Generates the following kind of C comment before types:

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

/* /home/elmarco/src/qemu/qapi/introspect.json:94 */ typedef struct SchemaInfo SchemaInfo;

Can we do relative file names? I.e. just qapi/introspect.json.

We could, but relative to $srcdir or $builddir? I think absolute path avoids some potential confusion.

Source files are always relative to $srcdir.

Absolute paths are a total pain when you diff files generated in separate trees.

Quoted 5 lines
Quoted 2 lines

Would such comments be useful for things other than typedefs?

Certainly it could, however I just needed it for typedef, didn't bother adding it for the rest.

Fair enough.

Quoted 87 lines
Quoted 22 lines
Quoted 12 lines
---
 scripts/qapi.py       | 12 +++++++++---
 scripts/qapi-event.py |  2 +-
 scripts/qapi-types.py | 18 +++++++++---------
 3 files changed, 19 insertions(+), 13 deletions(-)
scripts/qapi.py +0 -0
index d37a6157e0..7f9935eec0 100644

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1857

Quoted 7 lines
scripts/qapi.py +3 -1
@@ -1852,15 +1852,21 @@ const char *const %(c_name)s_lookup[] = {
     return ret
 
 
-def gen_enum(name, values, prefix=None):
+def build_src_loc_comment(info):
+    if info:
+        return '\n/* %s:%d */' % (info['file'], info['line'])

Leading instead of trailing newline, hmm. Let's see how it works out.

Quoted 5 lines

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1859

Quoted 2 lines
scripts/qapi.py +2 -0
+    else:
+        return ''

Let's drop the else: line.

ok

Quoted 8 lines

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1861

Quoted 3 lines
scripts/qapi.py +2 -0
+
+def gen_enum(info, name, values, prefix=None):

Make that name, info, values, ... for consistency with other functions taking both name and info. More of the same below.

ok

Quoted 45 lines

scripts/qapi.py const char *const %(c_name)s_lookup[] = { · line 1866

Quoted 6 lines
scripts/qapi.py +1 -1
     # append automatically generated _MAX value
     enum_values = values + ['_MAX']
 
     ret = mcgen('''
-
+%(comment)s

Loses the blank line when not info.

Quoted 25 lines
scripts/qapi.py +1 -1
 typedef enum %(c_name)s {
 ''',
-                c_name=c_name(name))
+                c_name=c_name(name), comment=build_src_loc_comment(info))
 
     i = 0
     for value in enum_values:
scripts/qapi-event.py +1 -1
index bcbef1035f..cf5e282011 100644
@@ -159,7 +159,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
         self._event_names = []
 
     def visit_end(self):
-        self.decl += gen_enum(event_enum_name, self._event_names)
+        self.decl += gen_enum(None, event_enum_name, self._event_names)
         self.defn += gen_enum_lookup(event_enum_name, self._event_names)
         self._event_names = None
 
scripts/qapi-types.py +0 -0
index b45e7b5634..9c8a3e277b 100644

scripts/qapi-types.py from qapi import * · line 24

Quoted 8 lines
scripts/qapi-types.py +2 -2
@@ -19,12 +19,12 @@ from qapi import *
 objects_seen = set()
 
 
-def gen_fwd_object_or_array(name):
+def gen_fwd_object_or_array(info, name):
     return mcgen('''
-
+%(comment)s

Likewise.

Quoted 5 lines
Quoted 4 lines

I think we should drop the newline from build_src_loc_comment()'s value, and keep the blank line before its two uses.

And you get an extra empty line if info is None. I don't mind.

I misread your code. The leading '\n' is kind of weird, but it works.

Quoted 2 lines

Other option
is to just add \n in the else case in build_src_loc_comment()

Could work, too. Perhaps even something like '/* built-in */\n'.

[...]

Reviewed-by on v2 1/2
#6 lore raw
In reply to Marc-André Lureau

On 06/01/2017 07:41 AM, Marc-André Lureau wrote:

No 0/2 cover letter?

Quoted 10 lines

Suggested by Markus Armbruster:

The gen_ prefix is awkward. Generated C should go through cgen() exactly once (see commit 1f9a7a1). The common way to get this wrong is passing a foo=gen_foo() keyword argument to mcgen(). I'd like us to adopt a naming convention where gen_ means "something that's been piped through cgen(), and thus must not be passed to cgen() or mcgen()". Requires renaming gen_params(), gen_marshal_proto() and gen_event_send_proto().

Quoted 7 lines
---
 scripts/qapi.py          |  2 +-
 scripts/qapi-commands.py |  8 ++++----
 scripts/qapi-event.py    | 12 ++++++------
 3 files changed, 11 insertions(+), 11 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#7 lore raw
In reply to Marc-André Lureau
Quoted 1 line · Marc-André Lureau

Suggested by Markus Armbruster:

Replacing the line above with ...

Quoted 7 lines

The gen_ prefix is awkward. Generated C should go through cgen() exactly once (see commit 1f9a7a1). The common way to get this wrong is passing a foo=gen_foo() keyword argument to mcgen(). I'd like us to adopt a naming convention where gen_ means "something that's been piped through cgen(), and thus must not be passed to cgen() or mcgen()". Requires renaming gen_params(), gen_marshal_proto() and gen_event_send_proto().

Quoted 1 line

Applied, thanks!