diff mbox

[for-2.9,41/47] qapi: Factor add_name() calls out of the meta conditional

Message ID 1489385927-6735-42-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster March 13, 2017, 6:18 a.m. UTC
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi.py | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

Comments

Eric Blake March 15, 2017, 12:39 a.m. UTC | #1
On 03/13/2017 01:18 AM, Markus Armbruster wrote:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  scripts/qapi.py | 24 +++++++++---------------
>  1 file changed, 9 insertions(+), 15 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

>  def add_enum(definition, info):
>      global enum_types
> -    name = definition['enum']
> -    add_name(name, info, 'enum', 'data' not in definition)

Here, we were passing a potential True for the 'implicit' parameter...


> +        name = expr[meta]
> +        add_name(name, info, meta)

...here, we always pass False, but that's okay (an explicit enum always
has 'data'),

>          if doc and doc.symbol != name:
>              raise QAPISemError(info, "Definition of '%s' follows documentation"
>                                 " for '%s'" % (name, doc.symbol))
> @@ -974,6 +967,7 @@ def check_exprs(exprs):
>          else:
>              continue
>          add_enum({ 'enum': name }, expr_elem['info'])
> +        add_name(name, info, 'enum', implicit=True)

...and here is the only place that was getting implicit=True.  Took me a
while to see it, but the refactoring is sane.
diff mbox

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index ffd30d2..f06e3c4 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -635,8 +635,6 @@  def add_name(name, info, meta, implicit=False):
 
 def add_struct(definition, info):
     global struct_types
-    name = definition['struct']
-    add_name(name, info, 'struct')
     struct_types.append(definition)
 
 
@@ -650,8 +648,6 @@  def find_struct(name):
 
 def add_union(definition, info):
     global union_types
-    name = definition['union']
-    add_name(name, info, 'union')
     union_types.append(definition)
 
 
@@ -665,8 +661,6 @@  def find_union(name):
 
 def add_enum(definition, info):
     global enum_types
-    name = definition['enum']
-    add_name(name, info, 'enum', 'data' not in definition)
     enum_types.append(definition)
 
 
@@ -932,34 +926,33 @@  def check_exprs(exprs):
                                "Expression missing documentation comment")
 
         if 'enum' in expr:
-            name = expr['enum']
+            meta = 'enum'
             check_keys(expr_elem, 'enum', ['data'], ['prefix'])
             add_enum(expr, info)
         elif 'union' in expr:
-            name = expr['union']
+            meta = 'union'
             check_keys(expr_elem, 'union', ['data'],
                        ['base', 'discriminator'])
             add_union(expr, info)
         elif 'alternate' in expr:
-            name = expr['alternate']
+            meta = 'alternate'
             check_keys(expr_elem, 'alternate', ['data'])
-            add_name(name, info, 'alternate')
         elif 'struct' in expr:
-            name = expr['struct']
+            meta = 'struct'
             check_keys(expr_elem, 'struct', ['data'], ['base'])
             add_struct(expr, info)
         elif 'command' in expr:
-            name = expr['command']
+            meta = 'command'
             check_keys(expr_elem, 'command', [],
                        ['data', 'returns', 'gen', 'success-response', 'boxed'])
-            add_name(name, info, 'command')
         elif 'event' in expr:
-            name = expr['event']
+            meta = 'event'
             check_keys(expr_elem, 'event', [], ['data', 'boxed'])
-            add_name(name, info, 'event')
         else:
             raise QAPISemError(expr_elem['info'],
                                "Expression is missing metatype")
+        name = expr[meta]
+        add_name(name, info, meta)
         if doc and doc.symbol != name:
             raise QAPISemError(info, "Definition of '%s' follows documentation"
                                " for '%s'" % (name, doc.symbol))
@@ -974,6 +967,7 @@  def check_exprs(exprs):
         else:
             continue
         add_enum({ 'enum': name }, expr_elem['info'])
+        add_name(name, info, 'enum', implicit=True)
 
     # Validate that exprs make sense
     for expr_elem in exprs: