summary refs log tree commit diff stats
path: root/scripts/qapi.py
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2013-07-10 14:34:32 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2013-07-10 14:34:32 -0500
commitc170a23ca0097a95b44fc7cc604018cd3c3b7d44 (patch)
tree804bd99545123456168886337c520707bd77ea2b /scripts/qapi.py
parent51455c59ddc370612f6e070d8eb0e594aaa7ef24 (diff)
parent5e2ac5191772dea782ff78e95edd395985273019 (diff)
downloadfocaccia-qemu-c170a23ca0097a95b44fc7cc604018cd3c3b7d44.tar.gz
focaccia-qemu-c170a23ca0097a95b44fc7cc604018cd3c3b7d44.zip
Merge remote-tracking branch 'luiz/queue/qmp' into staging
# By Kevin Wolf (4) and others
# Via Luiz Capitulino
* luiz/queue/qmp:
  add timestamp to error_report()
  qapi-schema: Use existing type for drive-backup arguments
  qapi-schema: Use BlockdevSnapshot type for blockdev-snapshot-sync
  qapi.py: Allow top-level type reference for command definitions
  qapi.py: Avoid code duplication
  qemu-char: Fix ringbuf option size

Message-id: 1373478767-20965-1-git-send-email-lcapitulino@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r--scripts/qapi.py37
1 files changed, 28 insertions, 9 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 02ad668ca3..baf13213a9 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -78,10 +78,8 @@ def parse(tokens):
 def evaluate(string):
     return parse(map(lambda x: x, tokenize(string)))[0]
 
-def parse_schema(fp):
-    exprs = []
+def get_expr(fp):
     expr = ''
-    expr_eval = None
 
     for line in fp:
         if line.startswith('#') or line == '\n':
@@ -90,27 +88,36 @@ def parse_schema(fp):
         if line.startswith(' '):
             expr += line
         elif expr:
-            expr_eval = evaluate(expr)
-            if expr_eval.has_key('enum'):
-                add_enum(expr_eval['enum'])
-            elif expr_eval.has_key('union'):
-                add_enum('%sKind' % expr_eval['union'])
-            exprs.append(expr_eval)
+            yield expr
             expr = line
         else:
             expr += line
 
     if expr:
+        yield expr
+
+def parse_schema(fp):
+    exprs = []
+
+    for expr in get_expr(fp):
         expr_eval = evaluate(expr)
+
         if expr_eval.has_key('enum'):
             add_enum(expr_eval['enum'])
         elif expr_eval.has_key('union'):
             add_enum('%sKind' % expr_eval['union'])
+        elif expr_eval.has_key('type'):
+            add_struct(expr_eval)
         exprs.append(expr_eval)
 
     return exprs
 
 def parse_args(typeinfo):
+    if isinstance(typeinfo, basestring):
+        struct = find_struct(typeinfo)
+        assert struct != None
+        typeinfo = struct['data']
+
     for member in typeinfo:
         argname = member
         argentry = typeinfo[member]
@@ -180,6 +187,18 @@ def type_name(name):
     return name
 
 enum_types = []
+struct_types = []
+
+def add_struct(definition):
+    global struct_types
+    struct_types.append(definition)
+
+def find_struct(name):
+    global struct_types
+    for struct in struct_types:
+        if struct['type'] == name:
+            return struct
+    return None
 
 def add_enum(name):
     global enum_types