218e99
From 4bd5352922b192e3442671b2015633720253a3e4 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Mon, 9 Sep 2013 14:28:04 +0200
218e99
Subject: [PATCH 13/38] qapi.py: Avoid code duplication
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1378736903-18489-14-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 54200
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 13/32] qapi.py: Avoid code duplication
218e99
Bugzilla: 1005818
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
Bugzilla: 1005818
218e99
218e99
The code that interprets the read JSON expression and appends types to
218e99
the respective global variables was duplicated. We can avoid that by
218e99
splitting off the part that reads from the file.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
218e99
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
218e99
(cherry picked from commit bd9927fee4e63b451b4ef67a4c49729070d8b05d)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 scripts/qapi.py | 18 +++++++++---------
218e99
 1 file changed, 9 insertions(+), 9 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 scripts/qapi.py |   18 +++++++++---------
218e99
 1 files changed, 9 insertions(+), 9 deletions(-)
218e99
218e99
diff --git a/scripts/qapi.py b/scripts/qapi.py
218e99
index afc5f32..daedaea 100644
218e99
--- a/scripts/qapi.py
218e99
+++ b/scripts/qapi.py
218e99
@@ -72,10 +72,8 @@ def parse(tokens):
218e99
 def evaluate(string):
218e99
     return parse(map(lambda x: x, tokenize(string)))[0]
218e99
 
218e99
-def parse_schema(fp):
218e99
-    exprs = []
218e99
+def get_expr(fp):
218e99
     expr = ''
218e99
-    expr_eval = None
218e99
 
218e99
     for line in fp:
218e99
         if line.startswith('#') or line == '\n':
218e99
@@ -84,18 +82,20 @@ def parse_schema(fp):
218e99
         if line.startswith(' '):
218e99
             expr += line
218e99
         elif expr:
218e99
-            expr_eval = evaluate(expr)
218e99
-            if expr_eval.has_key('enum'):
218e99
-                add_enum(expr_eval['enum'])
218e99
-            elif expr_eval.has_key('union'):
218e99
-                add_enum('%sKind' % expr_eval['union'])
218e99
-            exprs.append(expr_eval)
218e99
+            yield expr
218e99
             expr = line
218e99
         else:
218e99
             expr += line
218e99
 
218e99
     if expr:
218e99
+        yield expr
218e99
+
218e99
+def parse_schema(fp):
218e99
+    exprs = []
218e99
+
218e99
+    for expr in get_expr(fp):
218e99
         expr_eval = evaluate(expr)
218e99
+
218e99
         if expr_eval.has_key('enum'):
218e99
             add_enum(expr_eval['enum'])
218e99
         elif expr_eval.has_key('union'):
218e99
-- 
218e99
1.7.1
218e99