aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi.py
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2015-05-04 09:05:13 -0600
committerMarkus Armbruster <armbru@redhat.com>2015-05-05 18:39:00 +0200
commitab916faddd16f0165e9cc2551f90699be8efde53 (patch)
treea1bb9e4b8cb26b9a76e67de714ce4d3ad1f9fd52 /scripts/qapi.py
parent7b1b98c420355ccea98d8bd55c9193ee6b7cef97 (diff)
qapi: Use 'alternate' to replace anonymous union
Previous patches have led up to the point where I create the new meta-type "'alternate':'Foo'". See the previous patches for documentation; I intentionally split as much work into earlier patches to minimize the size of this patch, but a lot of it is churn due to testsuite fallout after updating to the new type. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r--scripts/qapi.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 0b88325abd..05c38c5b00 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -281,7 +281,6 @@ def check_union(expr, expr_info):
"along with base" %name)
# Two types of unions, determined by discriminator.
- assert discriminator != {}
# With no discriminator it is a simple union.
if discriminator is None:
@@ -344,17 +343,14 @@ def check_union(expr, expr_info):
values[c_key] = key
def check_alternate(expr, expr_info):
- name = expr['union']
- base = expr.get('base')
- discriminator = expr.get('discriminator')
+ name = expr['alternate']
members = expr['data']
values = { 'MAX': '(automatic)' }
types_seen = {}
- assert discriminator == {}
- if base is not None:
+ if expr.get('base') is not None:
raise QAPIExprError(expr_info,
- "Anonymous union '%s' must not have a base"
+ "Alternate '%s' must not have a base"
% name)
# Check every branch
@@ -363,23 +359,23 @@ def check_alternate(expr, expr_info):
c_key = _generate_enum_string(key)
if c_key in values:
raise QAPIExprError(expr_info,
- "Anonymous union '%s' member '%s' clashes "
- "with '%s'" % (name, key, values[c_key]))
+ "Alternate '%s' member '%s' clashes with '%s'"
+ % (name, key, values[c_key]))
values[c_key] = key
# Ensure alternates have no type conflicts.
if isinstance(value, list):
raise QAPIExprError(expr_info,
- "Anonymous union '%s' member '%s' must "
+ "Alternate '%s' member '%s' must "
"not be array type" % (name, key))
qtype = find_alternate_member_qtype(value)
if not qtype:
raise QAPIExprError(expr_info,
- "Anonymous union '%s' member '%s' has "
+ "Alternate '%s' member '%s' has "
"invalid type '%s'" % (name, key, value))
if qtype in types_seen:
raise QAPIExprError(expr_info,
- "Anonymous union '%s' member '%s' can't "
+ "Alternate '%s' member '%s' can't "
"be distinguished from member '%s'"
% (name, key, types_seen[qtype]))
types_seen[qtype] = key
@@ -412,10 +408,9 @@ def check_exprs(schema):
if expr.has_key('enum'):
check_enum(expr, info)
elif expr.has_key('union'):
- if expr.get('discriminator') == {}:
- check_alternate(expr, info)
- else:
- check_union(expr, info)
+ check_union(expr, info)
+ elif expr.has_key('alternate'):
+ check_alternate(expr, info)
elif expr.has_key('event'):
check_event(expr, info)
@@ -447,6 +442,8 @@ def parse_schema(input_file):
if expr.has_key('union'):
if not discriminator_find_enum_define(expr):
add_enum('%sKind' % expr['union'])
+ elif expr.has_key('alternate'):
+ add_enum('%sKind' % expr['alternate'])
# Final pass - validate that exprs make sense
check_exprs(schema)
@@ -557,8 +554,7 @@ def find_struct(name):
def add_union(definition):
global union_types
- if definition.get('discriminator') != {}:
- union_types.append(definition)
+ union_types.append(definition)
def find_union(name):
global union_types