mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-11 05:25:32 +00:00
qapi: Move duplicate collision checks to schema check()
With the recent commit 'qapi: Detect collisions in C member names', we have two different locations for detecting clashes - one at parse time, and another at QAPISchema*.check() time. Remove all of the ad hoc parser checks, and delete associated code (for example, the global check_member_clash() method is no longer needed). Testing this showed that the test union-bad-branch wasn't adding much: union-clash-branches also exposes the error message when branches collide, and we've recently fixed things to avoid an implicit collision with max. Likewise, the error for enum-clash-member changes to report our new detection of upper case in a value name, unless we modify the test to use all lower case. The wording of several error messages has changed, but the change is generally an improvement rather than a regression. No change to generated code. Backports commit 01cfbaa4c36ecd9f1c7bcbad50c92758e1d147c4 from qemu
This commit is contained in:
parent
514226002a
commit
63f288263a
|
@ -521,21 +521,6 @@ def check_type(expr_info, source, value, allow_array=False,
|
|||
'enum'])
|
||||
|
||||
|
||||
def check_member_clash(expr_info, base_name, data, source=""):
|
||||
base = find_struct(base_name)
|
||||
assert base
|
||||
base_members = base['data']
|
||||
for key in data.keys():
|
||||
if key.startswith('*'):
|
||||
key = key[1:]
|
||||
if key in base_members or "*" + key in base_members:
|
||||
raise QAPIExprError(expr_info,
|
||||
"Member name '%s'%s clashes with base '%s'"
|
||||
% (key, source, base_name))
|
||||
if base.get('base'):
|
||||
check_member_clash(expr_info, base['base'], data, source)
|
||||
|
||||
|
||||
def check_command(expr, expr_info):
|
||||
name = expr['command']
|
||||
|
||||
|
@ -565,7 +550,6 @@ def check_union(expr, expr_info):
|
|||
base = expr.get('base')
|
||||
discriminator = expr.get('discriminator')
|
||||
members = expr['data']
|
||||
values = {}
|
||||
|
||||
# Two types of unions, determined by discriminator.
|
||||
|
||||
|
@ -612,15 +596,9 @@ def check_union(expr, expr_info):
|
|||
for (key, value) in members.items():
|
||||
check_name(expr_info, "Member of union '%s'" % name, key)
|
||||
|
||||
# Each value must name a known type; furthermore, in flat unions,
|
||||
# branches must be a struct with no overlapping member names
|
||||
# Each value must name a known type
|
||||
check_type(expr_info, "Member '%s' of union '%s'" % (key, name),
|
||||
value, allow_array=not base, allow_metas=allow_metas)
|
||||
if base:
|
||||
branch_struct = find_struct(value)
|
||||
assert branch_struct
|
||||
check_member_clash(expr_info, base, branch_struct['data'],
|
||||
" of branch '%s'" % key)
|
||||
|
||||
# If the discriminator names an enum type, then all members
|
||||
# of 'data' must also be members of the enum type.
|
||||
|
@ -631,34 +609,16 @@ def check_union(expr, expr_info):
|
|||
"enum '%s'" %
|
||||
(key, enum_define["enum_name"]))
|
||||
|
||||
# Otherwise, check for conflicts in the generated enum
|
||||
else:
|
||||
c_key = camel_to_upper(key)
|
||||
if c_key in values:
|
||||
raise QAPIExprError(expr_info,
|
||||
"Union '%s' member '%s' clashes with '%s'"
|
||||
% (name, key, values[c_key]))
|
||||
values[c_key] = key
|
||||
|
||||
|
||||
def check_alternate(expr, expr_info):
|
||||
name = expr['alternate']
|
||||
members = expr['data']
|
||||
values = {}
|
||||
types_seen = {}
|
||||
|
||||
# Check every branch
|
||||
for (key, value) in members.items():
|
||||
check_name(expr_info, "Member of alternate '%s'" % name, key)
|
||||
|
||||
# Check for conflicts in the branch names
|
||||
c_key = c_name(key)
|
||||
if c_key in values:
|
||||
raise QAPIExprError(expr_info,
|
||||
"Alternate '%s' member '%s' clashes with '%s'"
|
||||
% (name, key, values[c_key]))
|
||||
values[c_key] = key
|
||||
|
||||
# Ensure alternates have no type conflicts.
|
||||
check_type(expr_info, "Member '%s' of alternate '%s'" % (key, name),
|
||||
value,
|
||||
|
@ -677,7 +637,6 @@ def check_enum(expr, expr_info):
|
|||
name = expr['enum']
|
||||
members = expr.get('data')
|
||||
prefix = expr.get('prefix')
|
||||
values = {}
|
||||
|
||||
if not isinstance(members, list):
|
||||
raise QAPIExprError(expr_info,
|
||||
|
@ -688,12 +647,6 @@ def check_enum(expr, expr_info):
|
|||
for member in members:
|
||||
check_name(expr_info, "Member of enum '%s'" % name, member,
|
||||
enum_member=True)
|
||||
key = camel_to_upper(member)
|
||||
if key in values:
|
||||
raise QAPIExprError(expr_info,
|
||||
"Enum '%s' member '%s' clashes with '%s'"
|
||||
% (name, member, values[key]))
|
||||
values[key] = member
|
||||
|
||||
|
||||
def check_struct(expr, expr_info):
|
||||
|
@ -704,8 +657,6 @@ def check_struct(expr, expr_info):
|
|||
allow_dict=True, allow_optional=True)
|
||||
check_type(expr_info, "'base' for struct '%s'" % name, expr.get('base'),
|
||||
allow_metas=['struct'])
|
||||
if expr.get('base'):
|
||||
check_member_clash(expr_info, expr['base'], expr['data'])
|
||||
|
||||
|
||||
def check_keys(expr_elem, meta, required, optional=[]):
|
||||
|
|
Loading…
Reference in a new issue