[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 12/39] qapi: Prepare for catching more semantic p
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v7 12/39] qapi: Prepare for catching more semantic parse errors |
Date: |
Wed, 29 Apr 2015 07:06:27 -0600 |
This patch widens the scope of a try block (with the attending
reindentation required by Python) in preparation for a future
patch adding more instances of QAPIExprError inside the block.
It's easier to separate indentation from semantic changes, so
this patch has no real behavior change.
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
---
scripts/qapi.py | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 5f0f699..0c3459b 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -399,6 +399,7 @@ def check_exprs(schema):
check_event(expr, info)
def parse_schema(input_file):
+ # First pass: read entire file into memory
try:
schema = QAPISchema(open(input_file, "r"))
except (QAPISchemaError, QAPIExprError), e:
@@ -407,24 +408,26 @@ def parse_schema(input_file):
exprs = []
- for expr_elem in schema.exprs:
- expr = expr_elem['expr']
- if expr.has_key('enum'):
- add_enum(expr['enum'], expr.get('data'))
- elif expr.has_key('union'):
- add_union(expr)
- elif expr.has_key('type'):
- add_struct(expr)
- exprs.append(expr)
-
- # Try again for hidden UnionKind enum
- for expr_elem in schema.exprs:
- expr = expr_elem['expr']
- if expr.has_key('union'):
- if not discriminator_find_enum_define(expr):
- add_enum('%sKind' % expr['union'])
-
try:
+ # Next pass: learn the types.
+ for expr_elem in schema.exprs:
+ expr = expr_elem['expr']
+ if expr.has_key('enum'):
+ add_enum(expr['enum'], expr.get('data'))
+ elif expr.has_key('union'):
+ add_union(expr)
+ elif expr.has_key('type'):
+ add_struct(expr)
+ exprs.append(expr)
+
+ # Try again for hidden UnionKind enum
+ for expr_elem in schema.exprs:
+ expr = expr_elem['expr']
+ if expr.has_key('union'):
+ if not discriminator_find_enum_define(expr):
+ add_enum('%sKind' % expr['union'])
+
+ # Final pass - validate that exprs make sense
check_exprs(schema)
except QAPIExprError, e:
print >>sys.stderr, e
--
2.1.0
- [Qemu-devel] [PATCH v7 00/39] drop qapi nested structs, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 03/39] qapi: Simplify builtin type handling, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 06/39] qapi: Add some enum tests, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 10/39] qapi: Forbid base without discriminator in unions, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 12/39] qapi: Prepare for catching more semantic parse errors,
Eric Blake <=
- [Qemu-devel] [PATCH v7 02/39] qapi: Document type-safety considerations, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 15/39] qapi: Document new 'alternate' meta-type, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 22/39] qapi: Unify type bypass and add tests, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 27/39] qapi: More rigorous checking for type safety bypass, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 26/39] qapi: Whitelist commands that don't return dictionary, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 14/39] qapi: Rename anonymous union type in test, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 19/39] qapi: Add tests of redefined expressions, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 11/39] qapi: Tighten checking of unions, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 29/39] qapi: Document 'struct' metatype, Eric Blake, 2015/04/29
- [Qemu-devel] [PATCH v7 21/39] qapi: Allow true, false and null in schema json, Eric Blake, 2015/04/29