[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 39/40] qapi: Move duplicate collision checks to schem
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 39/40] qapi: Move duplicate collision checks to schema check() |
Date: |
Thu, 17 Dec 2015 09:33:44 +0100 |
From: Eric Blake <address@hidden>
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.
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/qapi.py | 51 +--------------------------
tests/Makefile | 1 -
tests/qapi-schema/alternate-clash.err | 2 +-
tests/qapi-schema/enum-clash-member.err | 2 +-
tests/qapi-schema/enum-clash-member.json | 2 +-
tests/qapi-schema/flat-union-clash-member.err | 2 +-
tests/qapi-schema/struct-base-clash-deep.err | 2 +-
tests/qapi-schema/struct-base-clash.err | 2 +-
tests/qapi-schema/union-bad-branch.err | 1 -
tests/qapi-schema/union-bad-branch.exit | 1 -
tests/qapi-schema/union-bad-branch.json | 8 -----
tests/qapi-schema/union-bad-branch.out | 0
tests/qapi-schema/union-clash-branches.err | 2 +-
tests/qapi-schema/union-clash-branches.json | 2 +-
14 files changed, 9 insertions(+), 69 deletions(-)
delete mode 100644 tests/qapi-schema/union-bad-branch.err
delete mode 100644 tests/qapi-schema/union-bad-branch.exit
delete mode 100644 tests/qapi-schema/union-bad-branch.json
delete mode 100644 tests/qapi-schema/union-bad-branch.out
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 74a561a..8edfd79 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -519,21 +519,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']
@@ -563,7 +548,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.
@@ -610,15 +594,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.
@@ -629,34 +607,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,
@@ -675,7 +635,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,
@@ -686,12 +645,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):
@@ -702,8 +655,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=[]):
diff --git a/tests/Makefile b/tests/Makefile
index 6b8b112..69cef77 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -341,7 +341,6 @@ qapi-schema += unclosed-list.json
qapi-schema += unclosed-object.json
qapi-schema += unclosed-string.json
qapi-schema += unicode-str.json
-qapi-schema += union-bad-branch.json
qapi-schema += union-base-no-discriminator.json
qapi-schema += union-branch-case.json
qapi-schema += union-clash-branches.json
diff --git a/tests/qapi-schema/alternate-clash.err
b/tests/qapi-schema/alternate-clash.err
index a475ab6..604d849 100644
--- a/tests/qapi-schema/alternate-clash.err
+++ b/tests/qapi-schema/alternate-clash.err
@@ -1 +1 @@
-tests/qapi-schema/alternate-clash.json:7: Alternate 'Alt1' member 'a_b'
clashes with 'a-b'
+tests/qapi-schema/alternate-clash.json:7: 'a_b' (branch of Alt1) collides with
'a-b' (branch of Alt1)
diff --git a/tests/qapi-schema/enum-clash-member.err
b/tests/qapi-schema/enum-clash-member.err
index 48bd136..5403c78 100644
--- a/tests/qapi-schema/enum-clash-member.err
+++ b/tests/qapi-schema/enum-clash-member.err
@@ -1 +1 @@
-tests/qapi-schema/enum-clash-member.json:2: Enum 'MyEnum' member 'ONE' clashes
with 'one'
+tests/qapi-schema/enum-clash-member.json:2: 'one_two' (member of MyEnum)
collides with 'one-two' (member of MyEnum)
diff --git a/tests/qapi-schema/enum-clash-member.json
b/tests/qapi-schema/enum-clash-member.json
index b7dc02a..b6928b8 100644
--- a/tests/qapi-schema/enum-clash-member.json
+++ b/tests/qapi-schema/enum-clash-member.json
@@ -1,2 +1,2 @@
# we reject enums where members will clash when mapped to C enum
-{ 'enum': 'MyEnum', 'data': [ 'one', 'ONE' ] }
+{ 'enum': 'MyEnum', 'data': [ 'one-two', 'one_two' ] }
diff --git a/tests/qapi-schema/flat-union-clash-member.err
b/tests/qapi-schema/flat-union-clash-member.err
index 2f0397a..2adf697 100644
--- a/tests/qapi-schema/flat-union-clash-member.err
+++ b/tests/qapi-schema/flat-union-clash-member.err
@@ -1 +1 @@
-tests/qapi-schema/flat-union-clash-member.json:11: Member name 'name' of
branch 'value1' clashes with base 'Base'
+tests/qapi-schema/flat-union-clash-member.json:11: 'name' (member of Branch1)
collides with 'name' (member of Base)
diff --git a/tests/qapi-schema/struct-base-clash-deep.err
b/tests/qapi-schema/struct-base-clash-deep.err
index f7a25a3..e2d7943 100644
--- a/tests/qapi-schema/struct-base-clash-deep.err
+++ b/tests/qapi-schema/struct-base-clash-deep.err
@@ -1 +1 @@
-tests/qapi-schema/struct-base-clash-deep.json:10: Member name 'name' clashes
with base 'Base'
+tests/qapi-schema/struct-base-clash-deep.json:10: 'name' (member of Sub)
collides with 'name' (member of Base)
diff --git a/tests/qapi-schema/struct-base-clash.err
b/tests/qapi-schema/struct-base-clash.err
index 3a9f66b..c52f33d 100644
--- a/tests/qapi-schema/struct-base-clash.err
+++ b/tests/qapi-schema/struct-base-clash.err
@@ -1 +1 @@
-tests/qapi-schema/struct-base-clash.json:5: Member name 'name' clashes with
base 'Base'
+tests/qapi-schema/struct-base-clash.json:5: 'name' (member of Sub) collides
with 'name' (member of Base)
diff --git a/tests/qapi-schema/union-bad-branch.err
b/tests/qapi-schema/union-bad-branch.err
deleted file mode 100644
index 8822735..0000000
--- a/tests/qapi-schema/union-bad-branch.err
+++ /dev/null
@@ -1 +0,0 @@
-tests/qapi-schema/union-bad-branch.json:6: Union 'MyUnion' member 'ONE'
clashes with 'one'
diff --git a/tests/qapi-schema/union-bad-branch.exit
b/tests/qapi-schema/union-bad-branch.exit
deleted file mode 100644
index d00491f..0000000
--- a/tests/qapi-schema/union-bad-branch.exit
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/tests/qapi-schema/union-bad-branch.json
b/tests/qapi-schema/union-bad-branch.json
deleted file mode 100644
index 913aa38..0000000
--- a/tests/qapi-schema/union-bad-branch.json
+++ /dev/null
@@ -1,8 +0,0 @@
-# we reject normal unions where branches would collide in C
-{ 'struct': 'One',
- 'data': { 'string': 'str' } }
-{ 'struct': 'Two',
- 'data': { 'number': 'int' } }
-{ 'union': 'MyUnion',
- 'data': { 'one': 'One',
- 'ONE': 'Two' } }
diff --git a/tests/qapi-schema/union-bad-branch.out
b/tests/qapi-schema/union-bad-branch.out
deleted file mode 100644
index e69de29..0000000
diff --git a/tests/qapi-schema/union-clash-branches.err
b/tests/qapi-schema/union-clash-branches.err
index 005c48d..e5b2113 100644
--- a/tests/qapi-schema/union-clash-branches.err
+++ b/tests/qapi-schema/union-clash-branches.err
@@ -1 +1 @@
-tests/qapi-schema/union-clash-branches.json:4: Union 'TestUnion' member 'a_b'
clashes with 'a-b'
+tests/qapi-schema/union-clash-branches.json:4: 'a_b' (branch of TestUnion)
collides with 'a-b' (branch of TestUnion)
diff --git a/tests/qapi-schema/union-clash-branches.json
b/tests/qapi-schema/union-clash-branches.json
index 31d135f..3bece8c 100644
--- a/tests/qapi-schema/union-clash-branches.json
+++ b/tests/qapi-schema/union-clash-branches.json
@@ -1,5 +1,5 @@
# Union branch name collision
# Reject a union that would result in a collision in generated C names (this
-# would try to generate two enum values 'TEST_UNION_KIND_A_B').
+# would try to generate two members 'a_b').
{ 'union': 'TestUnion',
'data': { 'a-b': 'int', 'a_b': 'str' } }
--
2.4.3
- [Qemu-devel] [PULL 23/40] qapi: Remove obsolete tests for MAX collision, (continued)
- [Qemu-devel] [PULL 23/40] qapi: Remove obsolete tests for MAX collision, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 31/40] qapi-types: Drop unnedeed ._fwdefn, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 11/40] qapi: Check for QAPI collisions involving variant members, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 20/40] blkdebug: Avoid '.' in enum values, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 16/40] qapi: Detect collisions in C member names, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 15/40] qapi: Track owner of each object member, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 28/40] qobject: Rename qtype_code to QType, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 35/40] qapi: Shorter visits of optional fields, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 34/40] qapi: Simplify visits of optional fields, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 27/40] qobject: Simplify QObject, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 39/40] qapi: Move duplicate collision checks to schema check(),
Markus Armbruster <=
- [Qemu-devel] [PULL 29/40] qapi: Convert QType into QAPI built-in enum type, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 37/40] qapi: Track enum values by QAPISchemaMember, not string, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 40/40] qapi: Detect base class loops, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 33/40] qapi: Fix alternates that accept 'number' but not 'int', Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 38/40] qapi: Enforce (or whitelist) case conventions on qapi members, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 22/40] qapi: Don't let implicit enum MAX member collide, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 26/40] qapi: Change munging of CamelCase enum values, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 36/40] qapi: Prepare new QAPISchemaMember base class, Markus Armbruster, 2015/12/17
- [Qemu-devel] [PULL 30/40] qapi: Simplify visiting of alternate types, Markus Armbruster, 2015/12/17
- Re: [Qemu-devel] [PULL 00/40] QAPI patches for 2015-12-17, Peter Maydell, 2015/12/17