qapi: Pay back some frontend technical debt
cover qapi: Pay back some frontend technical debt
When we introduced the QAPISchema intermediate representation (commit ac88219a6c7), we took a shortcut: we left check_exprs() & friends alone instead of moving the semantic checks to their proper place. Time to finish this job. Topped off with error message gardening.
Based-on: <[email protected]>
Markus Armbruster (25):
qapi: Tighten QAPISchemaFOO.check() assertions
qapi: Rename .owner to .defined_in
qapi: New QAPISourceInfo, replacing dict
qapi: Prefix frontend errors with an "in definition" line
qapi: Clean up member name case checking
qapi: Change frontend error messages to start with lower case
qapi: Improve reporting of member name clashes
qapi: Reorder check_FOO() parameters for consistency
qapi: Improve reporting of invalid name errors
qapi: Use check_name_str() where it suffices
qapi: Report invalid '*' prefix like any other invalid name
qapi: Move check for reserved names out of add_name()
qapi: Make check_type()'s array case a bit more obvious
qapi: Plumb info to the QAPISchemaMember
qapi: Inline check_name() into check_union()
qapi: Move context-sensitive checking to the proper place
qapi: Move context-free checking to the proper place
qapi: Improve reporting of invalid 'if' errors
qapi: Improve reporting of invalid flags
qapi: Improve reporting of missing / unknown definition keys
qapi: Avoid redundant definition references in error messages
qapi: Eliminate check_keys(), rename check_known_keys()
qapi: Improve reporting of missing documentation comment
qapi: Improve reporting of redefinition
qapi: Improve source file read error handling
qapi/qapi-schema.json | 2 +- scripts/qapi/common.py | 1017 +++++++++-------- scripts/qapi/events.py | 2 +- tests/qapi-schema/allow-preconfig-test.err | 3 +- tests/qapi-schema/alternate-any.err | 3 +- tests/qapi-schema/alternate-array.err | 3 +- tests/qapi-schema/alternate-base.err | 3 +- .../alternate-branch-if-invalid.err | 1 + tests/qapi-schema/alternate-clash.err | 3 +- .../alternate-conflict-bool-string.err | 3 +- tests/qapi-schema/alternate-conflict-dict.err | 3 +- .../alternate-conflict-enum-bool.err | 3 +- .../alternate-conflict-enum-int.err | 3 +- .../alternate-conflict-num-string.err | 3 +- .../qapi-schema/alternate-conflict-string.err | 3 +- tests/qapi-schema/alternate-empty.err | 3 +- tests/qapi-schema/alternate-invalid-dict.err | 3 +- tests/qapi-schema/alternate-nested.err | 3 +- tests/qapi-schema/alternate-unknown.err | 3 +- tests/qapi-schema/args-alternate.err | 3 +- tests/qapi-schema/args-any.err | 3 +- tests/qapi-schema/args-array-empty.err | 3 +- tests/qapi-schema/args-array-unknown.err | 3 +- tests/qapi-schema/args-bad-boxed.err | 3 +- tests/qapi-schema/args-boxed-anon.err | 3 +- tests/qapi-schema/args-boxed-string.err | 3 +- tests/qapi-schema/args-int.err | 3 +- tests/qapi-schema/args-invalid.err | 3 +- tests/qapi-schema/args-member-array-bad.err | 3 +- tests/qapi-schema/args-member-case.err | 3 +- tests/qapi-schema/args-member-case.json | 2 +- tests/qapi-schema/args-member-unknown.err | 3 +- tests/qapi-schema/args-name-clash.err | 3 +- tests/qapi-schema/args-union.err | 3 +- tests/qapi-schema/args-unknown.err | 3 +- tests/qapi-schema/bad-base.err | 3 +- tests/qapi-schema/bad-data.err | 3 +- tests/qapi-schema/bad-ident.err | 3 +- tests/qapi-schema/bad-if-empty-list.err | 1 + tests/qapi-schema/bad-if-empty.err | 1 + tests/qapi-schema/bad-if-list.err | 1 + tests/qapi-schema/bad-if.err | 1 + tests/qapi-schema/bad-type-bool.err | 2 +- tests/qapi-schema/bad-type-dict.err | 2 +- tests/qapi-schema/bad-type-int.err | 2 +- tests/qapi-schema/base-cycle-direct.err | 3 +- tests/qapi-schema/base-cycle-indirect.err | 3 +- tests/qapi-schema/command-int.err | 3 +- .../qapi-schema/doc-bad-alternate-member.err | 2 +- tests/qapi-schema/doc-bad-command-arg.err | 2 +- tests/qapi-schema/doc-bad-symbol.err | 3 +- tests/qapi-schema/doc-bad-union-member.err | 2 +- tests/qapi-schema/doc-before-include.err | 2 +- tests/qapi-schema/doc-before-pragma.err | 2 +- tests/qapi-schema/doc-duplicated-return.err | 2 +- tests/qapi-schema/doc-duplicated-since.err | 2 +- tests/qapi-schema/doc-empty-arg.err | 2 +- tests/qapi-schema/doc-empty-section.err | 2 +- tests/qapi-schema/doc-empty-symbol.err | 2 +- tests/qapi-schema/doc-invalid-end.err | 2 +- tests/qapi-schema/doc-invalid-end2.err | 2 +- tests/qapi-schema/doc-invalid-start.err | 2 +- tests/qapi-schema/doc-missing-colon.err | 2 +- tests/qapi-schema/doc-missing-expr.err | 2 +- tests/qapi-schema/doc-missing-space.err | 2 +- tests/qapi-schema/doc-missing.err | 3 +- tests/qapi-schema/doc-no-symbol.err | 2 +- tests/qapi-schema/double-type.err | 3 +- tests/qapi-schema/duplicate-key.err | 2 +- tests/qapi-schema/enum-bad-member.err | 3 +- tests/qapi-schema/enum-bad-name.err | 3 +- tests/qapi-schema/enum-bad-prefix.err | 3 +- tests/qapi-schema/enum-clash-member.err | 3 +- .../qapi-schema/enum-dict-member-unknown.err | 3 +- tests/qapi-schema/enum-if-invalid.err | 1 + tests/qapi-schema/enum-int-member.err | 2 +- tests/qapi-schema/enum-member-case.err | 3 +- tests/qapi-schema/enum-missing-data.err | 3 +- tests/qapi-schema/enum-wrong-data.err | 3 +- tests/qapi-schema/escape-outside-string.err | 2 +- tests/qapi-schema/escape-too-big.err | 1 + tests/qapi-schema/event-boxed-empty.err | 3 +- .../qapi-schema/event-member-invalid-dict.err | 3 +- tests/qapi-schema/event-nest-struct.err | 3 +- tests/qapi-schema/features-bad-type.err | 3 +- tests/qapi-schema/features-duplicate-name.err | 3 +- tests/qapi-schema/features-if-invalid.err | 1 + tests/qapi-schema/features-missing-name.err | 3 +- tests/qapi-schema/features-name-bad-type.err | 3 +- tests/qapi-schema/features-no-list.err | 3 +- tests/qapi-schema/features-unknown-key.err | 3 +- tests/qapi-schema/flat-union-array-branch.err | 3 +- tests/qapi-schema/flat-union-bad-base.err | 3 +- .../flat-union-bad-discriminator.err | 3 +- tests/qapi-schema/flat-union-base-any.err | 3 +- tests/qapi-schema/flat-union-base-union.err | 3 +- tests/qapi-schema/flat-union-clash-member.err | 3 +- .../flat-union-discriminator-bad-name.err | 3 +- .../flat-union-discriminator-bad-name.json | 1 - tests/qapi-schema/flat-union-empty.err | 3 +- .../flat-union-inline-invalid-dict.err | 3 +- tests/qapi-schema/flat-union-inline.err | 3 +- tests/qapi-schema/flat-union-int-branch.err | 3 +- .../flat-union-invalid-branch-key.err | 3 +- .../flat-union-invalid-discriminator.err | 3 +- .../flat-union-invalid-if-discriminator.err | 3 +- tests/qapi-schema/flat-union-no-base.err | 3 +- .../flat-union-optional-discriminator.err | 3 +- .../flat-union-optional-discriminator.json | 1 - .../flat-union-string-discriminator.err | 3 +- tests/qapi-schema/funny-char.err | 2 +- tests/qapi-schema/funny-word.err | 2 +- tests/qapi-schema/ident-with-escape.err | 2 +- tests/qapi-schema/include-before-err.err | 2 +- tests/qapi-schema/include-cycle.err | 2 +- tests/qapi-schema/include-extra-junk.err | 2 +- tests/qapi-schema/include-nested-err.err | 2 +- tests/qapi-schema/include-no-file.err | 2 +- tests/qapi-schema/include-non-file.err | 2 +- tests/qapi-schema/include-self-cycle.err | 2 +- tests/qapi-schema/leading-comma-list.err | 2 +- tests/qapi-schema/leading-comma-object.err | 2 +- tests/qapi-schema/missing-colon.err | 2 +- tests/qapi-schema/missing-comma-list.err | 2 +- tests/qapi-schema/missing-comma-object.err | 2 +- tests/qapi-schema/missing-type.err | 2 +- .../nested-struct-data-invalid-dict.err | 3 +- tests/qapi-schema/nested-struct-data.err | 3 +- tests/qapi-schema/non-objects.err | 2 +- tests/qapi-schema/oob-test.err | 3 +- .../qapi-schema/pragma-doc-required-crap.err | 2 +- tests/qapi-schema/pragma-extra-junk.err | 2 +- .../pragma-name-case-whitelist-crap.err | 2 +- tests/qapi-schema/pragma-non-dict.err | 2 +- .../pragma-returns-whitelist-crap.err | 2 +- tests/qapi-schema/pragma-unknown.err | 2 +- tests/qapi-schema/quoted-structural-chars.err | 2 +- tests/qapi-schema/redefined-builtin.err | 3 +- tests/qapi-schema/redefined-command.err | 5 +- tests/qapi-schema/redefined-event.err | 5 +- tests/qapi-schema/redefined-type.err | 5 +- tests/qapi-schema/reserved-command-q.err | 3 +- tests/qapi-schema/reserved-enum-q.err | 3 +- tests/qapi-schema/reserved-member-has.err | 3 +- tests/qapi-schema/reserved-member-q.err | 3 +- tests/qapi-schema/reserved-member-u.err | 3 +- .../reserved-member-underscore.err | 3 +- tests/qapi-schema/reserved-type-kind.err | 3 +- tests/qapi-schema/reserved-type-list.err | 3 +- tests/qapi-schema/returns-alternate.err | 3 +- tests/qapi-schema/returns-array-bad.err | 3 +- tests/qapi-schema/returns-dict.err | 3 +- tests/qapi-schema/returns-unknown.err | 3 +- tests/qapi-schema/returns-whitelist.err | 3 +- tests/qapi-schema/string-code-point-127.err | 2 +- tests/qapi-schema/string-code-point-31.err | 2 +- tests/qapi-schema/string-control.err | 1 + tests/qapi-schema/string-unclosed.err | 1 + tests/qapi-schema/string-unicode.err | 1 + tests/qapi-schema/struct-base-clash-deep.err | 3 +- tests/qapi-schema/struct-base-clash.err | 3 +- tests/qapi-schema/struct-data-invalid.err | 3 +- .../qapi-schema/struct-member-if-invalid.err | 1 + .../struct-member-invalid-dict.err | 3 +- tests/qapi-schema/struct-member-invalid.err | 3 +- tests/qapi-schema/trailing-comma-list.err | 2 +- tests/qapi-schema/trailing-comma-object.err | 2 +- tests/qapi-schema/type-bypass-bad-gen.err | 3 +- tests/qapi-schema/unclosed-list.err | 2 +- tests/qapi-schema/unclosed-object.err | 2 +- tests/qapi-schema/unclosed-string.err | 2 +- tests/qapi-schema/union-base-empty.err | 3 +- .../union-base-no-discriminator.err | 3 +- tests/qapi-schema/union-branch-case.err | 3 +- tests/qapi-schema/union-branch-case.json | 4 +- tests/qapi-schema/union-branch-if-invalid.err | 1 + .../qapi-schema/union-branch-invalid-dict.err | 3 +- tests/qapi-schema/union-clash-branches.err | 3 +- tests/qapi-schema/union-empty.err | 3 +- tests/qapi-schema/union-invalid-base.err | 3 +- tests/qapi-schema/union-optional-branch.err | 3 +- tests/qapi-schema/union-unknown.err | 3 +- tests/qapi-schema/union-unknown.json | 2 +- tests/qapi-schema/unknown-escape.err | 2 +- tests/qapi-schema/unknown-expr-key.err | 3 +- 185 files changed, 814 insertions(+), 673 deletions(-) create mode 100644 tests/qapi-schema/escape-too-big.err create mode 100644 tests/qapi-schema/string-control.err create mode 100644 tests/qapi-schema/string-unclosed.err create mode 100644 tests/qapi-schema/string-unicode.err
Signature · 1 line
2.21.0
PATCH 1/25 qapi: Tighten QAPISchemaFOO.check() assertions
When we introduced the QAPISchema intermediate representation (commit ac88219a6c7), we took a shortcut: we left check_exprs() & friends alone instead of moving semantic checks into the QAPISchemaFOO.check(). check_exprs() still checks and reports errors, and the .check() assert check_exprs() did the job. There are a few gaps, though.
QAPISchemaArrayType.check() neglects to assert the element type is not an array. Add the assertion.
QAPISchemaObjectTypeVariants.check() neglects to assert the tag member is not optional. Add the assertion.
It neglects to assert the tag member is not conditional. Add the assertion.
It neglects to assert we actually have variants. Add the assertion.
It asserts the variants are object types, but neglects to assert they don't have variants. Tighten the assertion.
QAPISchemaObjectTypeVariants.check_clash() has the same issue. However, it can run only after .check(). Delete the assertion instead of tightening it.
QAPISchemaAlternateType.check() neglects to assert the branch types don't conflict. Fixing that isn't trivial, so add just a TODO comment for now. It'll be resolved later in this series.
--- scripts/qapi/common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
scripts/qapi/common.py +7 -2
@@ -1362,6 +1362,7 @@ class QAPISchemaArrayType(QAPISchemaType): QAPISchemaType.check(self, schema) self.element_type = schema.lookup_type(self._element_type_name) assert self.element_type + assert not isinstance(self.element_type, QAPISchemaArrayType) @property def ifcond(self):
@@ -1606,6 +1607,8 @@ class QAPISchemaObjectTypeVariants(object): self.tag_member = seen[c_name(self._tag_name)] assert self._tag_name == self.tag_member.name assert isinstance(self.tag_member.type, QAPISchemaEnumType) + assert not self.tag_member.optional + assert self.tag_member.ifcond == [] if self._tag_name: # flat union # branches that are not explicitly covered get an empty type cases = set([v.name for v in self.variants])
@@ -1615,20 +1618,21 @@ class QAPISchemaObjectTypeVariants(object): m.ifcond) v.set_owner(self.tag_member.owner) self.variants.append(v) + assert self.variants for v in self.variants: v.check(schema) # Union names must match enum values; alternate names are # checked separately. Use 'seen' to tell the two apart. if seen: assert v.name in self.tag_member.type.member_names() - assert isinstance(v.type, QAPISchemaObjectType) + assert (isinstance(v.type, QAPISchemaObjectType) + and not v.type.variants) v.type.check(schema) def check_clash(self, info, seen): for v in self.variants: # Reset seen map for each variant, since qapi names from one # branch do not affect another branch - assert isinstance(v.type, QAPISchemaObjectType) v.type.check_clash(info, dict(seen))
@@ -1659,6 +1663,7 @@ class QAPISchemaAlternateType(QAPISchemaType): seen = {} for v in self.variants.variants: v.check_clash(self.info, seen) + # TODO check conflicting qtypes if self.doc: self.doc.connect_member(v) if self.doc:
Signature · 1 line
2.21.0
Re: [PATCH 01/25] qapi: Tighten QAPISchemaFOO.check() assertions
Quoted 21 lines · Markus Armbruster
When we introduced the QAPISchema intermediate representation (commit
ac88219a6c7), we took a shortcut: we leftcheck_exprs()& friends alone instead of moving semantic checks into theQAPISchemaFOO.check().check_exprs()still checks and reports errors, and the .check() assertcheck_exprs()did the job. There are a few gaps, though.
QAPISchemaArrayType.check()neglects to assert the element type is not an array. Add the assertion.
QAPISchemaObjectTypeVariants.check()neglects to assert the tag member is not optional. Add the assertion.It neglects to assert the tag member is not conditional. Add the assertion.
It neglects to assert we actually have variants. Add the assertion.
It asserts the variants are object types, but neglects to assert they don't have variants. Tighten the assertion.
Quoted 7 lines
QAPISchemaObjectTypeVariants.check_clash()has the same issue. However, it can run only after .check(). Delete the assertion instead of tightening it.
QAPISchemaAlternateType.check()neglects to assert the branch types don't conflict. Fixing that isn't trivial, so add just a TODO comment for now. It'll be resolved later in this series.
I'm guessing you found these by deleting check_exprs() and seeing what failed due to inadequate .check()
Quoted 5 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 01/25] qapi: Tighten QAPISchemaFOO.check() assertions
Quoted 26 lines · Eric Blake
Quoted 25 lines · Markus Armbruster
When we introduced the QAPISchema intermediate representation (commit
ac88219a6c7), we took a shortcut: we leftcheck_exprs()& friends alone instead of moving semantic checks into theQAPISchemaFOO.check().check_exprs()still checks and reports errors, and the .check() assertcheck_exprs()did the job. There are a few gaps, though.
QAPISchemaArrayType.check()neglects to assert the element type is not an array. Add the assertion.
QAPISchemaObjectTypeVariants.check()neglects to assert the tag member is not optional. Add the assertion.It neglects to assert the tag member is not conditional. Add the assertion.
It neglects to assert we actually have variants. Add the assertion.
It asserts the variants are object types, but neglects to assert they don't have variants. Tighten the assertion.
QAPISchemaObjectTypeVariants.check_clash()has the same issue. However, it can run only after .check(). Delete the assertion instead of tightening it.
Quoted 6 lines
Quoted 3 lines
QAPISchemaAlternateType.check()neglects to assert the branch types don't conflict. Fixing that isn't trivial, so add just a TODO comment for now. It'll be resolved later in this series.I'm guessing you found these by deleting
check_exprs()and seeing what failed due to inadequate .check()
The first two or three I found by staring at the code. The remainder I found when I moved checks from check_exprs() to .check() [PATCH 16]: any check that doesn't replace an assertion means the assertion was missing.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)Reviewed-by Eric Blake <[email protected]>
Thanks!
PATCH 2/25 qapi: Rename .owner to .defined_in
In reply to Markus ArmbrusterQAPISchemaMember.owner is the name of the defining entity. That's a confusing name when an object type inherits members from a base type. Rename it to .defined_in. Rename .set_owner() and ._pretty_owner() to match.
--- scripts/qapi/common.py | 61 +++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 30 deletions(-)
scripts/qapi/common.py +31 -30
@@ -1319,7 +1319,7 @@ class QAPISchemaEnumType(QAPISchemaType): QAPISchemaType.__init__(self, name, info, doc, ifcond) for m in members: assert isinstance(m, QAPISchemaEnumMember) - m.set_owner(name) + m.set_defined_in(name) assert prefix is None or isinstance(prefix, str) self.members = members self.prefix = prefix
@@ -1405,13 +1405,13 @@ class QAPISchemaObjectType(QAPISchemaType): assert base is None or isinstance(base, str) for m in local_members: assert isinstance(m, QAPISchemaObjectTypeMember) - m.set_owner(name) + m.set_defined_in(name) if variants is not None: assert isinstance(variants, QAPISchemaObjectTypeVariants) - variants.set_owner(name) + variants.set_defined_in(name) for f in features: assert isinstance(f, QAPISchemaFeature) - f.set_owner(name) + f.set_defined_in(name) self._base_name = base self.base = None self.local_members = local_members
@@ -1521,15 +1521,16 @@ class QAPISchemaMember(object): assert isinstance(name, str) self.name = name self.ifcond = ifcond or [] - self.owner = None + self.defined_in = None - def set_owner(self, name): - assert not self.owner - self.owner = name + def set_defined_in(self, name): + assert not self.defined_in + self.defined_in = name def check_clash(self, info, seen): cname = c_name(self.name) - if cname.lower() != cname and self.owner not in name_case_whitelist: + if (cname.lower() != cname + and self.defined_in not in name_case_whitelist): raise QAPISemError(info, "%s should not use uppercase" % self.describe()) if cname in seen:
@@ -1537,27 +1538,27 @@ class QAPISchemaMember(object): (self.describe(), seen[cname].describe())) seen[cname] = self - def _pretty_owner(self): - owner = self.owner - if owner.startswith('q_obj_'): + def _pretty_defined_in(self): + defined_in = self.defined_in + if defined_in.startswith('q_obj_'): # See QAPISchema._make_implicit_object_type() - reverse the # mapping there to create a nice human-readable description - owner = owner[6:] - if owner.endswith('-arg'): - return '(parameter of %s)' % owner[:-4] - elif owner.endswith('-base'): - return '(base of %s)' % owner[:-5] + defined_in = defined_in[6:] + if defined_in.endswith('-arg'): + return '(parameter of %s)' % defined_in[:-4] + elif defined_in.endswith('-base'): + return '(base of %s)' % defined_in[:-5] else: - assert owner.endswith('-wrapper') + assert defined_in.endswith('-wrapper') # Unreachable and not implemented assert False - if owner.endswith('Kind'): + if defined_in.endswith('Kind'): # See QAPISchema._make_implicit_enum_type() - return '(branch of %s)' % owner[:-4] - return '(%s of %s)' % (self.role, owner) + return '(branch of %s)' % defined_in[:-4] + return '(%s of %s)' % (self.role, defined_in) def describe(self): - return "'%s' %s" % (self.name, self._pretty_owner()) + return "'%s' %s" % (self.name, self._pretty_defined_in()) class QAPISchemaEnumMember(QAPISchemaMember):
@@ -1578,7 +1579,7 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): self.optional = optional def check(self, schema): - assert self.owner + assert self.defined_in self.type = schema.lookup_type(self._type_name) assert self.type
@@ -1598,9 +1599,9 @@ class QAPISchemaObjectTypeVariants(object): self.tag_member = tag_member self.variants = variants - def set_owner(self, name): + def set_defined_in(self, name): for v in self.variants: - v.set_owner(name) + v.set_defined_in(name) def check(self, schema, seen): if not self.tag_member: # flat union
@@ -1616,7 +1617,7 @@ class QAPISchemaObjectTypeVariants(object): if m.name not in cases: v = QAPISchemaObjectTypeVariant(m.name, 'q_empty', m.ifcond) - v.set_owner(self.tag_member.owner) + v.set_defined_in(self.tag_member.defined_in) self.variants.append(v) assert self.variants for v in self.variants:
@@ -1648,8 +1649,8 @@ class QAPISchemaAlternateType(QAPISchemaType): QAPISchemaType.__init__(self, name, info, doc, ifcond) assert isinstance(variants, QAPISchemaObjectTypeVariants) assert variants.tag_member - variants.set_owner(name) - variants.tag_member.set_owner(self.name) + variants.set_defined_in(name) + variants.tag_member.set_defined_in(self.name) self.variants = variants def check(self, schema):
@@ -1829,7 +1830,7 @@ class QAPISchema(object): for v in values] def _make_implicit_enum_type(self, name, info, ifcond, values): - # See also QAPISchemaObjectTypeMember._pretty_owner() + # See also QAPISchemaObjectTypeMember._pretty_defined_in() name = name + 'Kind' # Use namespace reserved by add_name() self._def_entity(QAPISchemaEnumType( name, info, None, ifcond, self._make_enum_members(values), None))
@@ -1845,7 +1846,7 @@ class QAPISchema(object): role, members): if not members: return None - # See also QAPISchemaObjectTypeMember._pretty_owner() + # See also QAPISchemaObjectTypeMember._pretty_defined_in() name = 'q_obj_%s-%s' % (name, role) typ = self.lookup_entity(name, QAPISchemaObjectType) if typ:
Signature · 1 line
2.21.0
Re: [PATCH 02/25] qapi: Rename .owner to .defined_in
Quoted 9 lines · Markus Armbruster
QAPISchemaMember.owner is the name of the defining entity. That's a confusing name when an object type inherits members from a base type. Rename it to .defined_in. Rename .set_owner() and ._pretty_owner() to match.
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 61 +++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 30 deletions(-)
Mechanical, and more legible.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 3/25 qapi: New QAPISourceInfo, replacing dict
In reply to Markus ArmbrusterWe track source locations with a dict of the form
{'file': FNAME, 'line': LINENO, parent': PARENT}where PARENT is None for the main file, and the include directive's source location for included files.
This is servicable enough, but the next commit will add information, and that's going to come out cleaner if we turn this into a class. So do that.
--- scripts/qapi/common.py | 69 +++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 28 deletions(-)
scripts/qapi/common.py +41 -28
@@ -13,6 +13,7 @@ from __future__ import print_function from contextlib import contextmanager +import copy import errno import os import re
@@ -53,34 +54,50 @@ struct_types = {} union_types = {} all_names = {} + # # Parsing the schema into expressions # +class QAPISourceInfo(object): + def __init__(self, fname, line, parent): + self.fname = fname + self.line = line + self.parent = parent -def error_path(parent): - res = '' - while parent: - res = ('In file included from %s:%d:\n' % (parent['file'], - parent['line'])) + res - parent = parent['parent'] - return res + def next_line(self): + info = copy.copy(self) + info.line += 1 + return info + + def loc(self): + return '%s:%d' % (self.fname, self.line) + + def include_path(self): + ret = '' + parent = self.parent + while parent: + ret = 'In file included from %s:\n' % parent.loc() + ret + parent = parent.parent + return ret + + def __str__(self): + return self.include_path() + self.loc() class QAPIError(Exception): - def __init__(self, fname, line, col, incl_info, msg): + def __init__(self, info, col, msg): Exception.__init__(self) - self.fname = fname - self.line = line + self.info = info self.col = col - self.info = incl_info self.msg = msg def __str__(self): - loc = '%s:%d' % (self.fname, self.line) + loc = str(self.info) if self.col is not None: + assert self.info.line is not None loc += ':%s' % self.col - return error_path(self.info) + '%s: %s' % (loc, self.msg) + return loc + ': ' + self.msg class QAPIParseError(QAPIError):
@@ -91,14 +108,12 @@ class QAPIParseError(QAPIError): col = (col + 7) % 8 + 1 else: col += 1 - QAPIError.__init__(self, parser.fname, parser.line, col, - parser.incl_info, msg) + QAPIError.__init__(self, parser.info, col, msg) class QAPISemError(QAPIError): def __init__(self, info, msg): - QAPIError.__init__(self, info['file'], info['line'], None, - info['parent'], msg) + QAPIError.__init__(self, info, None, msg) class QAPIDoc(object):
@@ -382,12 +397,11 @@ class QAPISchemaParser(object): def __init__(self, fp, previously_included=[], incl_info=None): self.fname = fp.name previously_included.append(os.path.abspath(fp.name)) - self.incl_info = incl_info self.src = fp.read() if self.src == '' or self.src[-1] != '\n': self.src += '\n' self.cursor = 0 - self.line = 1 + self.info = QAPISourceInfo(self.fname, 1, incl_info) self.line_pos = 0 self.exprs = [] self.docs = []
@@ -395,8 +409,7 @@ class QAPISchemaParser(object): cur_doc = None while self.tok is not None: - info = {'file': self.fname, 'line': self.line, - 'parent': self.incl_info} + info = self.info if self.tok == '#': self.reject_expr_doc(cur_doc) cur_doc = self.get_doc(info)
@@ -456,9 +469,9 @@ class QAPISchemaParser(object): # catch inclusion cycle inf = info while inf: - if incl_abs_fname == os.path.abspath(inf['file']): + if incl_abs_fname == os.path.abspath(inf.fname): raise QAPISemError(info, "Inclusion loop for %s" % include) - inf = inf['parent'] + inf = inf.parent # skip multiple include of the same file if incl_abs_fname in previously_included:
@@ -552,7 +565,7 @@ class QAPISchemaParser(object): if self.cursor == len(self.src): self.tok = None return - self.line += 1 + self.info = self.info.next_line() self.line_pos = self.cursor elif not self.tok.isspace(): # Show up to next structural, whitespace or quote
@@ -1172,7 +1185,7 @@ class QAPISchemaEntity(object): def check(self, schema): assert not self._checked if self.info: - self._module = os.path.relpath(self.info['file'], + self._module = os.path.relpath(self.info.fname, os.path.dirname(schema.fname)) self._checked = True
@@ -1781,9 +1794,9 @@ class QAPISchema(object): include = expr['include'] assert doc is None main_info = info - while main_info['parent']: - main_info = main_info['parent'] - fname = os.path.relpath(include, os.path.dirname(main_info['file'])) + while main_info.parent: + main_info = main_info.parent + fname = os.path.relpath(include, os.path.dirname(main_info.fname)) self._def_entity(QAPISchemaInclude(fname, info)) def _def_builtin_type(self, name, json_type, c_type):
Signature · 1 line
2.21.0
Re: [PATCH 03/25] qapi: New QAPISourceInfo, replacing dict
Quoted 3 lines · Markus Armbruster
We track source locations with a dict of the form
{'file': FNAME, 'line': LINENO, parent': PARENT}
Missing ' on parent
Quoted 5 lines
where PARENT is None for the main file, and the include directive's source location for included files.
This is servicable enough, but the next commit will add information,
serviceable
Quoted 8 lines
and that's going to come out cleaner if we turn this into a class. So do that.
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 69 +++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 28 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 03/25] qapi: New QAPISourceInfo, replacing dict
Quoted 8 lines · Eric Blake
Quoted 3 lines · Markus Armbruster
We track source locations with a dict of the form
{'file': FNAME, 'line': LINENO, parent': PARENT}Missing ' on parent
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
where PARENT is None for the main file, and the include directive's source location for included files.
This is servicable enough, but the next commit will add information,
serviceable
Will fix both.
Quoted 9 lines
Quoted 8 lines
and that's going to come out cleaner if we turn this into a class. So do that.
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 69 +++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 28 deletions(-)Reviewed-by Eric Blake <[email protected]>
Thanks!
Re: [PATCH 03/25] qapi: New QAPISourceInfo, replacing dict
In reply to Markus ArmbrusterQuoted 15 lines · Markus Armbruster
We track source locations with a dict of the form
{'file': FNAME, 'line': LINENO, parent': PARENT}where PARENT is None for the main file, and the include directive's source location for included files.
This is servicable enough, but the next commit will add information, and that's going to come out cleaner if we turn this into a class. So do that.
Signed-off-by Markus Armbruster <[email protected]>---
class QAPIError(Exception):
scripts/qapi/common.py struct_types = {} · line 90
Quoted 3 lines
scripts/qapi/common.py +1
-1- def __init__(self, fname, line, col, incl_info, msg): + def __init__(self, info, col, msg): Exception.__init__(self)
Unrelated to this patch, but I just noticed
https://docs.quantifiedcode.com/python-anti-patterns/ today (in part based on my question on another patch about using 'list.get(key, False)' rather than 'key in list and list[key]'). In particular, I found
https://docs.quantifiedcode.com/python-anti-patterns/correctness/missing_argument_to_super.html
which recommends using:
def __init__(...):
super(QAPIError, self).__init__()
(because of Python 2), while other sits state that with python 3, you can further get away with:
def __init__(...):
super().__init(...)
Should we be switching our code base to use super() in more places, rather than hard-coding the parent class name?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 03/25] qapi: New QAPISourceInfo, replacing dict
Quoted 30 lines · Eric Blake
Quoted 15 lines · Markus Armbruster
We track source locations with a dict of the form
{'file': FNAME, 'line': LINENO, parent': PARENT}where PARENT is None for the main file, and the include directive's source location for included files.
This is servicable enough, but the next commit will add information, and that's going to come out cleaner if we turn this into a class. So do that.
Signed-off-by Markus Armbruster <[email protected]>---
class QAPIError(Exception):
scripts/qapi/common.py struct_types = {} · line 90
Quoted 3 lines
scripts/qapi/common.py +1
-1- def __init__(self, fname, line, col, incl_info, msg): + def __init__(self, info, col, msg): Exception.__init__(self)Unrelated to this patch, but I just noticed
https://docs.quantifiedcode.com/python-anti-patterns/ today (in part based on my question on another patch about using 'list.get(key, False)' rather than 'key in list and list[key]'). In particular, I found
https://docs.quantifiedcode.com/python-anti-patterns/correctness/missing_argument_to_super.html
which recommends using:def
__init__(...):super(QAPIError, self).__init__()
Quoted 8 lines
(because of Python 2), while other sits state that with python 3, you can further get away with:
def
__init__(...):super().__init(...)Should we be switching our code base to use
super()in more places, rather than hard-coding the parent class name?
I intend to switch to super() in a future 'bye Python 2' series.
PATCH 4/25 qapi: Prefix frontend errors with an "in definition" line
In reply to Markus ArmbrusterWe take pains to include the offending expression in error messages, e.g.
tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any'
But not always:
tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a list of strings
Instead of improving them one by one, report the offending expression whenever it is known, like this:
tests/qapi-schema/enum-if-invalid.json: In enum 'TestIfEnum':
tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a list of strings
Error messages that mention the offending expression become a bit redundant, e.g.
tests/qapi-schema/alternate-any.json: In alternate 'Alt':
tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any'
I'll take care of that later in this series.
--- scripts/qapi/common.py | 15 ++++++++++++++- tests/qapi-schema/alternate-any.err | 1 + tests/qapi-schema/alternate-array.err | 1 + tests/qapi-schema/alternate-branch-if-invalid.err | 1 + tests/qapi-schema/alternate-clash.err | 1 + .../alternate-conflict-bool-string.err | 1 + tests/qapi-schema/alternate-conflict-dict.err | 1 + .../qapi-schema/alternate-conflict-enum-bool.err | 1 + tests/qapi-schema/alternate-conflict-enum-int.err | 1 + .../qapi-schema/alternate-conflict-num-string.err | 1 + tests/qapi-schema/alternate-conflict-string.err | 1 + tests/qapi-schema/alternate-empty.err | 1 + tests/qapi-schema/alternate-invalid-dict.err | 1 + tests/qapi-schema/alternate-nested.err | 1 + tests/qapi-schema/alternate-unknown.err | 1 + tests/qapi-schema/args-alternate.err | 1 + tests/qapi-schema/args-any.err | 1 + tests/qapi-schema/args-array-empty.err | 1 + tests/qapi-schema/args-array-unknown.err | 1 + tests/qapi-schema/args-boxed-anon.err | 1 + tests/qapi-schema/args-boxed-string.err | 1 + tests/qapi-schema/args-int.err | 1 + tests/qapi-schema/args-invalid.err | 1 + tests/qapi-schema/args-member-array-bad.err | 1 + tests/qapi-schema/args-member-case.err | 1 + tests/qapi-schema/args-member-unknown.err | 1 + tests/qapi-schema/args-name-clash.err | 1 + tests/qapi-schema/args-union.err | 1 + tests/qapi-schema/args-unknown.err | 1 + tests/qapi-schema/bad-base.err | 1 + tests/qapi-schema/bad-data.err | 1 + tests/qapi-schema/base-cycle-direct.err | 1 + tests/qapi-schema/base-cycle-indirect.err | 1 + tests/qapi-schema/doc-bad-symbol.err | 1 + tests/qapi-schema/enum-bad-member.err | 1 + tests/qapi-schema/enum-bad-name.err | 1 + tests/qapi-schema/enum-bad-prefix.err | 1 + tests/qapi-schema/enum-clash-member.err | 1 + tests/qapi-schema/enum-dict-member-unknown.err | 1 + tests/qapi-schema/enum-if-invalid.err | 1 + tests/qapi-schema/enum-member-case.err | 1 + tests/qapi-schema/enum-wrong-data.err | 1 + tests/qapi-schema/event-boxed-empty.err | 1 + tests/qapi-schema/event-member-invalid-dict.err | 1 + tests/qapi-schema/event-nest-struct.err | 1 + tests/qapi-schema/features-bad-type.err | 1 + tests/qapi-schema/features-duplicate-name.err | 1 + tests/qapi-schema/features-if-invalid.err | 1 + tests/qapi-schema/features-missing-name.err | 1 + tests/qapi-schema/features-name-bad-type.err | 1 + tests/qapi-schema/features-no-list.err | 1 + tests/qapi-schema/features-unknown-key.err | 1 + tests/qapi-schema/flat-union-array-branch.err | 1 + tests/qapi-schema/flat-union-bad-base.err | 1 + .../qapi-schema/flat-union-bad-discriminator.err | 1 + tests/qapi-schema/flat-union-base-any.err | 1 + tests/qapi-schema/flat-union-base-union.err | 1 + tests/qapi-schema/flat-union-clash-member.err | 1 + .../flat-union-discriminator-bad-name.err | 1 + tests/qapi-schema/flat-union-empty.err | 1 + .../flat-union-inline-invalid-dict.err | 1 + tests/qapi-schema/flat-union-inline.err | 1 + tests/qapi-schema/flat-union-int-branch.err | 1 + .../qapi-schema/flat-union-invalid-branch-key.err | 1 + .../flat-union-invalid-discriminator.err | 1 + .../flat-union-invalid-if-discriminator.err | 1 + tests/qapi-schema/flat-union-no-base.err | 1 + .../flat-union-optional-discriminator.err | 1 + .../flat-union-string-discriminator.err | 1 + .../nested-struct-data-invalid-dict.err | 1 + tests/qapi-schema/nested-struct-data.err | 1 + tests/qapi-schema/reserved-enum-q.err | 1 + tests/qapi-schema/reserved-member-has.err | 1 + tests/qapi-schema/reserved-member-q.err | 1 + tests/qapi-schema/reserved-member-u.err | 1 + tests/qapi-schema/reserved-member-underscore.err | 1 + tests/qapi-schema/returns-alternate.err | 1 + tests/qapi-schema/returns-array-bad.err | 1 + tests/qapi-schema/returns-dict.err | 1 + tests/qapi-schema/returns-unknown.err | 1 + tests/qapi-schema/returns-whitelist.err | 1 + tests/qapi-schema/struct-base-clash-deep.err | 1 + tests/qapi-schema/struct-base-clash.err | 1 + tests/qapi-schema/struct-data-invalid.err | 1 + tests/qapi-schema/struct-member-if-invalid.err | 1 + tests/qapi-schema/struct-member-invalid-dict.err | 1 + tests/qapi-schema/struct-member-invalid.err | 1 + tests/qapi-schema/union-base-empty.err | 1 + tests/qapi-schema/union-base-no-discriminator.err | 1 + tests/qapi-schema/union-branch-case.err | 1 + tests/qapi-schema/union-branch-if-invalid.err | 1 + tests/qapi-schema/union-branch-invalid-dict.err | 1 + tests/qapi-schema/union-clash-branches.err | 1 + tests/qapi-schema/union-empty.err | 1 + tests/qapi-schema/union-invalid-base.err | 1 + tests/qapi-schema/union-optional-branch.err | 1 + tests/qapi-schema/union-unknown.err | 1 + 97 files changed, 110 insertions(+), 1 deletion(-)
scripts/qapi/common.py +14 -1
@@ -64,6 +64,12 @@ class QAPISourceInfo(object): self.fname = fname self.line = line self.parent = parent + self.defn_meta = None + self.defn_name = None + + def set_defn(self, meta, name): + self.defn_meta = meta + self.defn_name = name def next_line(self): info = copy.copy(self)
@@ -73,6 +79,12 @@ class QAPISourceInfo(object): def loc(self): return '%s:%d' % (self.fname, self.line) + def in_defn(self): + if self.defn_name: + return "%s: In %s '%s':\n" % (self.fname, + self.defn_meta, self.defn_name) + return '' + def include_path(self): ret = '' parent = self.parent
@@ -82,7 +94,7 @@ class QAPISourceInfo(object): return ret def __str__(self): - return self.include_path() + self.loc() + return self.include_path() + self.in_defn() + self.loc() class QAPIError(Exception):
@@ -1127,6 +1139,7 @@ def check_exprs(exprs): normalize_if(expr) name = expr[meta] add_name(name, info, meta) + info.set_defn(meta, name) if doc and doc.symbol != name: raise QAPISemError(info, "Definition of '%s' follows documentation" " for '%s'" % (name, doc.symbol))
tests/qapi-schema/alternate-any.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-any.json: In alternate 'Alt': tests/qapi-schema/alternate-any.json:2: Alternate 'Alt' member 'one' cannot use type 'any'
tests/qapi-schema/alternate-array.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-array.json: In alternate 'Alt': tests/qapi-schema/alternate-array.json:5: Member 'two' of alternate 'Alt' cannot be an array
tests/qapi-schema/alternate-branch-if-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-branch-if-invalid.json: In alternate 'Alt': tests/qapi-schema/alternate-branch-if-invalid.json:2: 'if' condition ' ' makes no sense
tests/qapi-schema/alternate-clash.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-clash.json: In alternate 'Alt1': tests/qapi-schema/alternate-clash.json:7: 'a_b' (branch of Alt1) collides with 'a-b' (branch of Alt1)
tests/qapi-schema/alternate-conflict-bool-string.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-conflict-bool-string.json: In alternate 'Alt': tests/qapi-schema/alternate-conflict-bool-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-conflict-dict.json: In alternate 'Alt': tests/qapi-schema/alternate-conflict-dict.json:6: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-enum-bool.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-conflict-enum-bool.json: In alternate 'Alt': tests/qapi-schema/alternate-conflict-enum-bool.json:4: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-enum-int.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-conflict-enum-int.json: In alternate 'Alt': tests/qapi-schema/alternate-conflict-enum-int.json:4: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-num-string.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-conflict-num-string.json: In alternate 'Alt': tests/qapi-schema/alternate-conflict-num-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-string.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-conflict-string.json: In alternate 'Alt': tests/qapi-schema/alternate-conflict-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-empty.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-empty.json: In alternate 'Alt': tests/qapi-schema/alternate-empty.json:2: Alternate 'Alt' cannot have empty 'data'
tests/qapi-schema/alternate-invalid-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-invalid-dict.json: In alternate 'Alt': tests/qapi-schema/alternate-invalid-dict.json:2: Key 'type' is missing from member 'two' of alternate 'Alt'
tests/qapi-schema/alternate-nested.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-nested.json: In alternate 'Alt2': tests/qapi-schema/alternate-nested.json:4: Member 'nested' of alternate 'Alt2' cannot use alternate type 'Alt1'
tests/qapi-schema/alternate-unknown.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/alternate-unknown.json: In alternate 'Alt': tests/qapi-schema/alternate-unknown.json:2: Member 'unknown' of alternate 'Alt' uses unknown type 'MissingType'
tests/qapi-schema/args-alternate.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-alternate.json: In command 'oops': tests/qapi-schema/args-alternate.json:3: 'data' for command 'oops' cannot use alternate type 'Alt'
tests/qapi-schema/args-any.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-any.json: In command 'oops': tests/qapi-schema/args-any.json:2: 'data' for command 'oops' cannot use built-in type 'any'
tests/qapi-schema/args-array-empty.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-array-empty.json: In command 'oops': tests/qapi-schema/args-array-empty.json:2: Member 'empty' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-array-unknown.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-array-unknown.json: In command 'oops': tests/qapi-schema/args-array-unknown.json:2: Member 'array' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-boxed-anon.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-boxed-anon.json: In command 'foo': tests/qapi-schema/args-boxed-anon.json:2: 'data' for command 'foo' should be a type name
tests/qapi-schema/args-boxed-string.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-boxed-string.json: In command 'foo': tests/qapi-schema/args-boxed-string.json:2: 'data' for command 'foo' cannot use built-in type 'str'
tests/qapi-schema/args-int.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-int.json: In command 'oops': tests/qapi-schema/args-int.json:2: 'data' for command 'oops' cannot use built-in type 'int'
tests/qapi-schema/args-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-invalid.json: In command 'foo': tests/qapi-schema/args-invalid.json:1: 'data' for command 'foo' should be an object or type name
tests/qapi-schema/args-member-array-bad.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-member-array-bad.json: In command 'oops': tests/qapi-schema/args-member-array-bad.json:2: Member 'member' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-member-case.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-member-case.json: In command 'no-way-this-will-get-whitelisted': tests/qapi-schema/args-member-case.json:2: 'Arg' (parameter of no-way-this-will-get-whitelisted) should not use uppercase
tests/qapi-schema/args-member-unknown.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-member-unknown.json: In command 'oops': tests/qapi-schema/args-member-unknown.json:2: Member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-name-clash.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-name-clash.json: In command 'oops': tests/qapi-schema/args-name-clash.json:4: 'a_b' (parameter of oops) collides with 'a-b' (parameter of oops)
tests/qapi-schema/args-union.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-union.json: In command 'oops': tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni'
tests/qapi-schema/args-unknown.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/args-unknown.json: In command 'oops': tests/qapi-schema/args-unknown.json:2: 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/bad-base.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/bad-base.json: In struct 'MyType': tests/qapi-schema/bad-base.json:3: 'base' for struct 'MyType' cannot use union type 'Union'
tests/qapi-schema/bad-data.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/bad-data.json: In command 'oops': tests/qapi-schema/bad-data.json:2: 'data' for command 'oops' cannot be an array
tests/qapi-schema/base-cycle-direct.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/base-cycle-direct.json: In struct 'Loopy': tests/qapi-schema/base-cycle-direct.json:2: Object Loopy contains itself
tests/qapi-schema/base-cycle-indirect.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/base-cycle-indirect.json: In struct 'Base1': tests/qapi-schema/base-cycle-indirect.json:2: Object Base1 contains itself
tests/qapi-schema/doc-bad-symbol.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/doc-bad-symbol.json: In command 'foo': tests/qapi-schema/doc-bad-symbol.json:6: Definition of 'foo' follows documentation for 'food'
tests/qapi-schema/enum-bad-member.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-bad-member.json: In enum 'MyEnum': tests/qapi-schema/enum-bad-member.json:2: Member of enum 'MyEnum' requires a string name
tests/qapi-schema/enum-bad-name.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-bad-name.json: In enum 'MyEnum': tests/qapi-schema/enum-bad-name.json:3: Member of enum 'MyEnum' uses invalid name 'not\possible'
tests/qapi-schema/enum-bad-prefix.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-bad-prefix.json: In enum 'MyEnum': tests/qapi-schema/enum-bad-prefix.json:2: Enum 'MyEnum' requires a string for 'prefix'
tests/qapi-schema/enum-clash-member.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-clash-member.json: In enum 'MyEnum': tests/qapi-schema/enum-clash-member.json:2: 'one_two' (value of MyEnum) collides with 'one-two' (value of MyEnum)
tests/qapi-schema/enum-dict-member-unknown.err +1 -0
@@ -1,2 +1,3 @@ +tests/qapi-schema/enum-dict-member-unknown.json: In enum 'MyEnum': tests/qapi-schema/enum-dict-member-unknown.json:2: Unknown key 'bad-key' in member of enum 'MyEnum' Valid keys are 'if', 'name'.
tests/qapi-schema/enum-if-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-if-invalid.json: In enum 'TestIfEnum': tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a list of strings
tests/qapi-schema/enum-member-case.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-member-case.json: In enum 'NoWayThisWillGetWhitelisted': tests/qapi-schema/enum-member-case.json:4: 'Value' (value of NoWayThisWillGetWhitelisted) should not use uppercase
tests/qapi-schema/enum-wrong-data.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-wrong-data.json: In enum 'MyEnum': tests/qapi-schema/enum-wrong-data.json:2: Enum 'MyEnum' requires an array for 'data'
tests/qapi-schema/event-boxed-empty.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/event-boxed-empty.json: In event 'FOO': tests/qapi-schema/event-boxed-empty.json:2: Use of 'boxed' requires 'data'
tests/qapi-schema/event-member-invalid-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/event-member-invalid-dict.json: In event 'EVENT_A': tests/qapi-schema/event-member-invalid-dict.json:1: Key 'type' is missing from member 'a' of 'data' for event 'EVENT_A'
tests/qapi-schema/event-nest-struct.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/event-nest-struct.json: In event 'EVENT_A': tests/qapi-schema/event-nest-struct.json:1: Member 'a' of 'data' for event 'EVENT_A' should be a type name
tests/qapi-schema/features-bad-type.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/features-bad-type.json: In struct 'FeatureStruct0': tests/qapi-schema/features-bad-type.json:1: Feature of struct FeatureStruct0 requires a string name
tests/qapi-schema/features-duplicate-name.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/features-duplicate-name.json: In struct 'FeatureStruct0': tests/qapi-schema/features-duplicate-name.json:1: 'foo' (feature of FeatureStruct0) collides with 'foo' (feature of FeatureStruct0)
tests/qapi-schema/features-if-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/features-if-invalid.json: In struct 'Stru': tests/qapi-schema/features-if-invalid.json:2: 'if' condition must be a string or a list of strings
tests/qapi-schema/features-missing-name.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/features-missing-name.json: In struct 'FeatureStruct0': tests/qapi-schema/features-missing-name.json:1: Key 'name' is missing from feature of struct FeatureStruct0
tests/qapi-schema/features-name-bad-type.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/features-name-bad-type.json: In struct 'FeatureStruct0': tests/qapi-schema/features-name-bad-type.json:1: Feature of struct FeatureStruct0 requires a string name
tests/qapi-schema/features-no-list.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/features-no-list.json: In struct 'FeatureStruct0': tests/qapi-schema/features-no-list.json:1: Struct 'FeatureStruct0' requires an array for 'features'
tests/qapi-schema/features-unknown-key.err +1 -0
@@ -1,2 +1,3 @@ +tests/qapi-schema/features-unknown-key.json: In struct 'FeatureStruct0': tests/qapi-schema/features-unknown-key.json:1: Unknown key 'colour' in feature of struct FeatureStruct0 Valid keys are 'if', 'name'.
tests/qapi-schema/flat-union-array-branch.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-array-branch.json: In union 'TestUnion': tests/qapi-schema/flat-union-array-branch.json:8: Member 'value1' of union 'TestUnion' cannot be an array
tests/qapi-schema/flat-union-bad-base.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-bad-base.json: In union 'TestUnion': tests/qapi-schema/flat-union-bad-base.json:8: 'string' (member of TestTypeA) collides with 'string' (base of TestUnion)
tests/qapi-schema/flat-union-bad-discriminator.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-bad-discriminator.json: In union 'TestUnion': tests/qapi-schema/flat-union-bad-discriminator.json:11: Discriminator of flat union 'TestUnion' requires a string name
tests/qapi-schema/flat-union-base-any.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-base-any.json: In union 'TestUnion': tests/qapi-schema/flat-union-base-any.json:8: 'base' for union 'TestUnion' cannot use built-in type 'any'
tests/qapi-schema/flat-union-base-union.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-base-union.json: In union 'TestUnion': tests/qapi-schema/flat-union-base-union.json:14: 'base' for union 'TestUnion' cannot use union type 'UnionBase'
tests/qapi-schema/flat-union-clash-member.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-clash-member.json: In union 'TestUnion': tests/qapi-schema/flat-union-clash-member.json:11: 'name' (member of Branch1) collides with 'name' (member of Base)
tests/qapi-schema/flat-union-discriminator-bad-name.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-discriminator-bad-name.json: In union 'MyUnion': tests/qapi-schema/flat-union-discriminator-bad-name.json:7: Discriminator of flat union 'MyUnion' does not allow optional name '*switch'
tests/qapi-schema/flat-union-empty.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-empty.json: In union 'Union': tests/qapi-schema/flat-union-empty.json:4: Union 'Union' has no branches
tests/qapi-schema/flat-union-inline-invalid-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-inline-invalid-dict.json: In union 'TestUnion': tests/qapi-schema/flat-union-inline-invalid-dict.json:7: Key 'type' is missing from member 'value1' of union 'TestUnion'
tests/qapi-schema/flat-union-inline.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-inline.json: In union 'TestUnion': tests/qapi-schema/flat-union-inline.json:7: Member 'value1' of union 'TestUnion' should be a type name
tests/qapi-schema/flat-union-int-branch.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-int-branch.json: In union 'TestUnion': tests/qapi-schema/flat-union-int-branch.json:8: Member 'value1' of union 'TestUnion' cannot use built-in type 'int'
tests/qapi-schema/flat-union-invalid-branch-key.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-invalid-branch-key.json: In union 'TestUnion': tests/qapi-schema/flat-union-invalid-branch-key.json:13: Discriminator value 'value_wrong' is not found in enum 'TestEnum'
tests/qapi-schema/flat-union-invalid-discriminator.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-invalid-discriminator.json: In union 'TestUnion': tests/qapi-schema/flat-union-invalid-discriminator.json:10: Discriminator 'enum_wrong' is not a member of 'base'
tests/qapi-schema/flat-union-invalid-if-discriminator.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-invalid-if-discriminator.json: In union 'TestUnion': tests/qapi-schema/flat-union-invalid-if-discriminator.json:10: The discriminator 'enum1' for union TestUnion must not be conditional
tests/qapi-schema/flat-union-no-base.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-no-base.json: In union 'TestUnion': tests/qapi-schema/flat-union-no-base.json:9: Flat union 'TestUnion' must have a base
tests/qapi-schema/flat-union-optional-discriminator.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-optional-discriminator.json: In union 'MyUnion': tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator 'switch' is not a member of 'base'
tests/qapi-schema/flat-union-string-discriminator.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/flat-union-string-discriminator.json: In union 'TestUnion': tests/qapi-schema/flat-union-string-discriminator.json:13: Discriminator 'kind' must be of enumeration type
tests/qapi-schema/nested-struct-data-invalid-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/nested-struct-data-invalid-dict.json: In command 'foo': tests/qapi-schema/nested-struct-data-invalid-dict.json:2: Key 'type' is missing from member 'a' of 'data' for command 'foo'
tests/qapi-schema/nested-struct-data.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/nested-struct-data.json: In command 'foo': tests/qapi-schema/nested-struct-data.json:2: Member 'a' of 'data' for command 'foo' should be a type name
tests/qapi-schema/reserved-enum-q.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-enum-q.json: In enum 'Foo': tests/qapi-schema/reserved-enum-q.json:4: Member of enum 'Foo' uses invalid name 'q-Unix'
tests/qapi-schema/reserved-member-has.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-member-has.json: In command 'oops': tests/qapi-schema/reserved-member-has.json:5: Member of 'data' for command 'oops' uses reserved name 'has-a'
tests/qapi-schema/reserved-member-q.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-member-q.json: In struct 'Foo': tests/qapi-schema/reserved-member-q.json:4: Member of 'data' for struct 'Foo' uses invalid name 'q-unix'
tests/qapi-schema/reserved-member-u.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-member-u.json: In struct 'Oops': tests/qapi-schema/reserved-member-u.json:7: Member of 'data' for struct 'Oops' uses reserved name 'u'
tests/qapi-schema/reserved-member-underscore.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-member-underscore.json: In struct 'Oops': tests/qapi-schema/reserved-member-underscore.json:4: Member of 'data' for struct 'Oops' uses invalid name '_oops'
tests/qapi-schema/returns-alternate.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/returns-alternate.json: In command 'oops': tests/qapi-schema/returns-alternate.json:3: 'returns' for command 'oops' cannot use alternate type 'Alt'
tests/qapi-schema/returns-array-bad.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/returns-array-bad.json: In command 'oops': tests/qapi-schema/returns-array-bad.json:2: 'returns' for command 'oops': array type must contain single type name
tests/qapi-schema/returns-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/returns-dict.json: In command 'oops': tests/qapi-schema/returns-dict.json:2: 'returns' for command 'oops' should be a type name
tests/qapi-schema/returns-unknown.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/returns-unknown.json: In command 'oops': tests/qapi-schema/returns-unknown.json:2: 'returns' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/returns-whitelist.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/returns-whitelist.json: In command 'no-way-this-will-get-whitelisted': tests/qapi-schema/returns-whitelist.json:14: 'returns' for command 'no-way-this-will-get-whitelisted' cannot use built-in type 'int'
tests/qapi-schema/struct-base-clash-deep.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/struct-base-clash-deep.json: In struct 'Sub': tests/qapi-schema/struct-base-clash-deep.json:10: 'name' (member of Sub) collides with 'name' (member of Base)
tests/qapi-schema/struct-base-clash.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/struct-base-clash.json: In struct 'Sub': tests/qapi-schema/struct-base-clash.json:5: 'name' (member of Sub) collides with 'name' (member of Base)
tests/qapi-schema/struct-data-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/struct-data-invalid.json: In struct 'foo': tests/qapi-schema/struct-data-invalid.json:1: 'data' for struct 'foo' should be an object or type name
tests/qapi-schema/struct-member-if-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/struct-member-if-invalid.json: In struct 'Stru': tests/qapi-schema/struct-member-if-invalid.json:2: 'if' condition must be a string or a list of strings
tests/qapi-schema/struct-member-invalid-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/struct-member-invalid-dict.json: In struct 'foo': tests/qapi-schema/struct-member-invalid-dict.json:2: Key 'type' is missing from member '*a' of 'data' for struct 'foo'
tests/qapi-schema/struct-member-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/struct-member-invalid.json: In struct 'foo': tests/qapi-schema/struct-member-invalid.json:1: Member 'a' of 'data' for struct 'foo' should be a type name
tests/qapi-schema/union-base-empty.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-base-empty.json: In union 'TestUnion': tests/qapi-schema/union-base-empty.json:5: Discriminator 'type' is not a member of 'base'
tests/qapi-schema/union-base-no-discriminator.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-base-no-discriminator.json: In union 'TestUnion': tests/qapi-schema/union-base-no-discriminator.json:11: Simple union 'TestUnion' must not have a base
tests/qapi-schema/union-branch-case.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-branch-case.json: In union 'NoWayThisWillGetWhitelisted': tests/qapi-schema/union-branch-case.json:2: 'Branch' (branch of NoWayThisWillGetWhitelisted) should not use uppercase
tests/qapi-schema/union-branch-if-invalid.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-branch-if-invalid.json: In union 'Uni': tests/qapi-schema/union-branch-if-invalid.json:4: 'if' condition '' makes no sense
tests/qapi-schema/union-branch-invalid-dict.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-branch-invalid-dict.json: In union 'UnionInvalidBranch': tests/qapi-schema/union-branch-invalid-dict.json:2: Key 'type' is missing from member 'integer' of union 'UnionInvalidBranch'
tests/qapi-schema/union-clash-branches.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-clash-branches.json: In union 'TestUnion': tests/qapi-schema/union-clash-branches.json:4: 'a_b' (branch of TestUnion) collides with 'a-b' (branch of TestUnion)
tests/qapi-schema/union-empty.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-empty.json: In union 'Union': tests/qapi-schema/union-empty.json:2: Union 'Union' has no branches
tests/qapi-schema/union-invalid-base.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-invalid-base.json: In union 'TestUnion': tests/qapi-schema/union-invalid-base.json:8: 'base' for union 'TestUnion' cannot use built-in type 'int'
tests/qapi-schema/union-optional-branch.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-optional-branch.json: In union 'Union': tests/qapi-schema/union-optional-branch.json:2: Member of union 'Union' does not allow optional name '*a'
tests/qapi-schema/union-unknown.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/union-unknown.json: In union 'Union': tests/qapi-schema/union-unknown.json:2: Member 'unknown' of union 'Union' uses unknown type 'MissingType'
Signature · 1 line
2.21.0
Re: [PATCH 04/25] qapi: Prefix frontend errors with an "in definition" line
Quoted 7 lines · Markus Armbruster
We take pains to include the offending expression in error messages, e.g.
tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any'But not always:
Quoted 7 lines
tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a list of stringsInstead of improving them one by one, report the offending expression whenever it is known, like this:
tests/qapi-schema/enum-if-invalid.json: In enum 'TestIfEnum':
tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a list of strings
Works for me.
Quoted 8 lines
Error messages that mention the offending expression become a bit redundant, e.g.
tests/qapi-schema/alternate-any.json: In alternate 'Alt':
tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any'I'll take care of that later in this series.
Temporary verboseness is not a problem.
Quoted 6 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 15 ++++++++++++++- tests/qapi-schema/alternate-any.err | 1 + tests/qapi-schema/alternate-array.err | 1 +
Touches a lot. But such is refactoring life.
Quoted 37 lines
+++
b/scripts/qapi/common.pyscripts/qapi/common.py +13
-1@@ -64,6 +64,12 @@ class QAPISourceInfo(object): self.fname = fname self.line = line self.parent = parent + self.defn_meta = None + self.defn_name = None + + def set_defn(self, meta, name): + self.defn_meta = meta + self.defn_name = name def next_line(self): info = copy.copy(self)@@ -73,6 +79,12 @@ class QAPISourceInfo(object): def loc(self): return '%s:%d' % (self.fname, self.line) + def in_defn(self): + if self.defn_name: + return "%s: In %s '%s':\n" % (self.fname, + self.defn_meta, self.defn_name) + return '' + def include_path(self): ret = '' parent = self.parent@@ -82,7 +94,7 @@ class QAPISourceInfo(object): return ret def __str__(self): - return self.include_path() + self.loc() + return self.include_path() + self.in_defn() + self.loc() class QAPIError(Exception):
scripts/qapi/common.py def check_exprs(exprs): · line 1143
Quoted 5 lines
scripts/qapi/common.py +1
-0@@ -1127,6 +1139,7 @@ def check_exprs(exprs): normalize_if(expr) name = expr[meta] add_name(name, info, meta) + info.set_defn(meta, name) if doc and doc.symbol != name:
Rather simple addition. Everything else in the patch is fallout.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 5/25 qapi: Clean up member name case checking
In reply to Markus ArmbrusterQAPISchemaMember.check_clash() checks for member names that map to the same c_name(). Takes care of rejecting duplicate names.
It also checks a naming rule: no uppercase in member names. That's a rather odd place to do it. Enforcing naming rules is check_name_str()'s job.
qapi-code-gen.txt specifies the name case rule applies to the name as it appears in the schema. check_clash() checks c_name(name) instead. No difference, as c_name() leaves alone case, but unclean.
Move the name case check into check_name_str(), less the c_name(). New argument @permit_upper suppresses it. Pass permit_upper=True for definitions (which are not members), and when the member's owner is whitelisted with pragma name-case-whitelist.
Bonus: name-case-whitelist now applies to a union's inline base, too. Update qapi/qapi-schema.json pragma to whitelist union CpuInfo instead of CpuInfo's implicit base type's name q_obj_CpuInfo-base.
--- qapi/qapi-schema.json | 2 +- scripts/qapi/common.py | 25 +++++++++++++----------- tests/qapi-schema/args-member-case.err | 2 +- tests/qapi-schema/args-member-case.json | 2 +- tests/qapi-schema/enum-member-case.err | 2 +- tests/qapi-schema/union-branch-case.err | 4 ++-- tests/qapi-schema/union-branch-case.json | 4 ++-- 7 files changed, 22 insertions(+), 19 deletions(-)
qapi/qapi-schema.json +1 -1
@@ -71,7 +71,7 @@ 'QapiErrorClass', # all members, visible through errors 'UuidInfo', # UUID, visible through query-uuid 'X86CPURegister32', # all members, visible indirectly through qom-get - 'q_obj_CpuInfo-base' # CPU, visible through query-cpu + 'CpuInfo' # CPU, visible through query-cpu ] } } # Documentation generated with qapi-gen.py is in source order, with
scripts/qapi/common.py +14 -11
@@ -704,8 +704,8 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(info, source, name, allow_optional=False, - enum_member=False): +def check_name(info, source, name, + allow_optional=False, enum_member=False, permit_upper=False): global valid_name membername = name
@@ -725,11 +725,14 @@ def check_name(info, source, name, allow_optional=False, if not valid_name.match(membername) or \ c_name(membername, False).startswith('q_'): raise QAPISemError(info, "%s uses invalid name '%s'" % (source, name)) + if not permit_upper and name.lower() != name: + raise QAPISemError( + info, "%s uses uppercase in name '%s'" % (source, name)) def add_name(name, info, meta): global all_names - check_name(info, "'%s'" % meta, name) + check_name(info, "'%s'" % meta, name, permit_upper=True) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:
@@ -797,10 +800,12 @@ def check_type(info, source, value, raise QAPISemError(info, "%s should be an object or type name" % source) + permit_upper = allow_dict in name_case_whitelist + # value is a dictionary, check that each member is okay for (key, arg) in value.items(): check_name(info, "Member of %s" % source, key, - allow_optional=True) + allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key))
@@ -870,7 +875,7 @@ def check_union(expr, info): else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=True, + base, allow_dict=name, allow_metas=['struct']) if not base: raise QAPISemError(info, "Flat union '%s' must have a base"
@@ -982,13 +987,15 @@ def check_enum(expr, info): raise QAPISemError(info, "Enum '%s' requires a string for 'prefix'" % name) + permit_upper = name in name_case_whitelist + for member in members: check_known_keys(info, "member of enum '%s'" % name, member, ['name'], ['if']) check_if(member, info) normalize_if(member) check_name(info, "Member of enum '%s'" % name, member['name'], - enum_member=True) + enum_member=True, permit_upper=permit_upper) def check_struct(expr, info):
@@ -997,7 +1004,7 @@ def check_struct(expr, info): features = expr.get('features') check_type(info, "'data' for struct '%s'" % name, members, - allow_dict=True) + allow_dict=name) check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=['struct'])
@@ -1555,10 +1562,6 @@ class QAPISchemaMember(object): def check_clash(self, info, seen): cname = c_name(self.name) - if (cname.lower() != cname - and self.defined_in not in name_case_whitelist): - raise QAPISemError(info, - "%s should not use uppercase" % self.describe()) if cname in seen: raise QAPISemError(info, "%s collides with %s" % (self.describe(), seen[cname].describe()))
tests/qapi-schema/args-member-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-case.json: In command 'no-way-this-will-get-whitelisted': -tests/qapi-schema/args-member-case.json:2: 'Arg' (parameter of no-way-this-will-get-whitelisted) should not use uppercase +tests/qapi-schema/args-member-case.json:2: Member of 'data' for command 'no-way-this-will-get-whitelisted' uses uppercase in name 'Arg'
tests/qapi-schema/args-member-case.json +1 -1
@@ -1,2 +1,2 @@ -# Member names should be 'lower-case' unless the struct/command is whitelisted +# Member names should be 'lower-case' unless the struct is whitelisted { 'command': 'no-way-this-will-get-whitelisted', 'data': { 'Arg': 'int' } }
tests/qapi-schema/enum-member-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-member-case.json: In enum 'NoWayThisWillGetWhitelisted': -tests/qapi-schema/enum-member-case.json:4: 'Value' (value of NoWayThisWillGetWhitelisted) should not use uppercase +tests/qapi-schema/enum-member-case.json:4: Member of enum 'NoWayThisWillGetWhitelisted' uses uppercase in name 'Value'
tests/qapi-schema/union-branch-case.err +2 -2
@@ -1,2 +1,2 @@ -tests/qapi-schema/union-branch-case.json: In union 'NoWayThisWillGetWhitelisted': -tests/qapi-schema/union-branch-case.json:2: 'Branch' (branch of NoWayThisWillGetWhitelisted) should not use uppercase +tests/qapi-schema/union-branch-case.json: In union 'Uni': +tests/qapi-schema/union-branch-case.json:2: Member of union 'Uni' uses uppercase in name 'Branch'
tests/qapi-schema/union-branch-case.json +2 -2
@@ -1,2 +1,2 @@ -# Branch names should be 'lower-case' unless the union is whitelisted -{ 'union': 'NoWayThisWillGetWhitelisted', 'data': { 'Branch': 'int' } } +# Branch names should be 'lower-case' +{ 'union': 'Uni', 'data': { 'Branch': 'int' } }
Signature · 1 line
2.21.0
Re: [PATCH 05/25] qapi: Clean up member name case checking
Quoted 25 lines · Markus Armbruster
QAPISchemaMember.check_clash()checks for member names that map to the samec_name(). Takes care of rejecting duplicate names.It also checks a naming rule: no uppercase in member names. That's a rather odd place to do it. Enforcing naming rules is check_name_str()'s job.
qapi-code-gen.txt specifies the name case rule applies to the name as it appears in the schema.
check_clash()checksc_name(name)instead. No difference, asc_name()leaves alone case, but unclean.Move the name case check into
check_name_str(), less thec_name(). New argument @permit_upper suppresses it. Pass permit_upper=True for definitions (which are not members), and when the member's owner is whitelisted with pragma name-case-whitelist.Bonus: name-case-whitelist now applies to a union's inline base, too. Update
qapi/qapi-schema.jsonpragma to whitelist union CpuInfo instead of CpuInfo's implicit base type's name q_obj_CpuInfo-base.Signed-off-by Markus Armbruster <[email protected]>---
+++
b/qapi/qapi-schema.json
qapi/qapi-schema.json line 74
Quoted 5 lines
qapi/qapi-schema.json +1
-1@@ -71,7 +71,7 @@ 'QapiErrorClass', # all members, visible through errors 'UuidInfo', # UUID, visible through query-uuid 'X86CPURegister32', # all members, visible indirectly through qom-get - 'q_obj_CpuInfo-base' # CPU, visible through query-cpu + 'CpuInfo' # CPU, visible through query-cpu
Yes, much nicer.
Quoted 35 lines
qapi/qapi-schema.json +0
-0] } } # Documentation generated with qapi-gen.py is in source order, withscripts/qapi/common.py +6
-3@@ -704,8 +704,8 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(info, source, name, allow_optional=False, - enum_member=False): +def check_name(info, source, name, + allow_optional=False, enum_member=False, permit_upper=False): global valid_name membername = name@@ -725,11 +725,14 @@ def check_name(info, source, name, allow_optional=False, if not valid_name.match(membername) or \ c_name(membername, False).startswith('q_'): raise QAPISemError(info, "%s uses invalid name '%s'" % (source, name)) + if not permit_upper and name.lower() != name: + raise QAPISemError( + info, "%s uses uppercase in name '%s'" % (source, name)) def add_name(name, info, meta): global all_names - check_name(info, "'%s'" % meta, name) + check_name(info, "'%s'" % meta, name, permit_upper=True) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:
scripts/qapi/common.py def check_type(info, source, value, · line 804
Quoted 5 lines
scripts/qapi/common.py +2
-0@@ -797,10 +800,12 @@ def check_type(info, source, value, raise QAPISemError(info, "%s should be an object or type name" % source) + permit_upper = allow_dict in name_case_whitelist +
so allow_dict changes from a bool to a string to be looked up...
Quoted 9 lines
scripts/qapi/common.py +1
-1# value is a dictionary, check that each member is okay for (key, arg) in value.items(): check_name(info, "Member of %s" % source, key, - allow_optional=True) + allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key))
scripts/qapi/common.py def check_union(expr, info): · line 878
Quoted 5 lines
scripts/qapi/common.py +1
-1@@ -870,7 +875,7 @@ def check_union(expr, info): else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=True, + base, allow_dict=name,
...and this is an example client affected by the change. That threw me for a bit, but seems to work.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 05/25] qapi: Clean up member name case checking
Quoted 86 lines · Eric Blake
Quoted 25 lines · Markus Armbruster
QAPISchemaMember.check_clash()checks for member names that map to the samec_name(). Takes care of rejecting duplicate names.It also checks a naming rule: no uppercase in member names. That's a rather odd place to do it. Enforcing naming rules is check_name_str()'s job.
qapi-code-gen.txt specifies the name case rule applies to the name as it appears in the schema.
check_clash()checksc_name(name)instead. No difference, asc_name()leaves alone case, but unclean.Move the name case check into
check_name_str(), less thec_name(). New argument @permit_upper suppresses it. Pass permit_upper=True for definitions (which are not members), and when the member's owner is whitelisted with pragma name-case-whitelist.Bonus: name-case-whitelist now applies to a union's inline base, too. Update
qapi/qapi-schema.jsonpragma to whitelist union CpuInfo instead of CpuInfo's implicit base type's name q_obj_CpuInfo-base.Signed-off-by Markus Armbruster <[email protected]>---
+++
b/qapi/qapi-schema.jsonqapi/qapi-schema.json line 74
Quoted 5 lines
qapi/qapi-schema.json +1
-1@@ -71,7 +71,7 @@ 'QapiErrorClass', # all members, visible through errors 'UuidInfo', # UUID, visible through query-uuid 'X86CPURegister32', # all members, visible indirectly through qom-get - 'q_obj_CpuInfo-base' # CPU, visible through query-cpu + 'CpuInfo' # CPU, visible through query-cpuYes, much nicer.
Quoted 35 lines
qapi/qapi-schema.json +0
-0] } } # Documentation generated with qapi-gen.py is in source order, withscripts/qapi/common.py +6
-3@@ -704,8 +704,8 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(info, source, name, allow_optional=False, - enum_member=False): +def check_name(info, source, name, + allow_optional=False, enum_member=False, permit_upper=False): global valid_name membername = name@@ -725,11 +725,14 @@ def check_name(info, source, name, allow_optional=False, if not valid_name.match(membername) or \ c_name(membername, False).startswith('q_'): raise QAPISemError(info, "%s uses invalid name '%s'" % (source, name)) + if not permit_upper and name.lower() != name: + raise QAPISemError( + info, "%s uses uppercase in name '%s'" % (source, name)) def add_name(name, info, meta): global all_names - check_name(info, "'%s'" % meta, name) + check_name(info, "'%s'" % meta, name, permit_upper=True) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:scripts/qapi/common.py def check_type(info, source, value, · line 804
Quoted 5 lines
scripts/qapi/common.py +2
-0@@ -797,10 +800,12 @@ def check_type(info, source, value, raise QAPISemError(info, "%s should be an object or type name" % source) + permit_upper = allow_dict in name_case_whitelist +so
allow_dictchanges from a bool to a string to be looked up...Quoted 9 lines
scripts/qapi/common.py +1
-1# value is a dictionary, check that each member is okay for (key, arg) in value.items(): check_name(info, "Member of %s" % source, key, - allow_optional=True) + allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key))@@ -870,7 +875,7 @@ def check_union(expr, info):
Quoted 8 lines
scripts/qapi/common.py def check_union(expr, info): · line 878
Quoted 5 lines
scripts/qapi/common.py +1
-1else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=True, + base, allow_dict=name,...and this is an example client affected by the change. That threw me for a bit, but seems to work.
I'm not proud of this interface, but I couldn't think of anything better.
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks!
PATCH 6/25 qapi: Change frontend error messages to start with lower case
In reply to Markus ArmbrusterStarting error messages with a capital letter complicates things when text can get interpolated both at the beginning and in the middle of an error message. The next patch will do that. Switch to lower case to keep it simpler.
For what it's worth, the GNU Coding Standards advise the message "should not begin with a capital letter when it follows a program name and/or file name, because that isn’t the beginning of a sentence. (The sentence conceptually starts at the beginning of the line.)"
--- scripts/qapi/common.py | 175 +++++++++--------- tests/qapi-schema/alternate-any.err | 2 +- tests/qapi-schema/alternate-array.err | 2 +- tests/qapi-schema/alternate-base.err | 2 +- .../alternate-conflict-bool-string.err | 2 +- tests/qapi-schema/alternate-conflict-dict.err | 2 +- .../alternate-conflict-enum-bool.err | 2 +- .../alternate-conflict-enum-int.err | 2 +- .../alternate-conflict-num-string.err | 2 +- .../qapi-schema/alternate-conflict-string.err | 2 +- tests/qapi-schema/alternate-empty.err | 2 +- tests/qapi-schema/alternate-invalid-dict.err | 2 +- tests/qapi-schema/alternate-nested.err | 2 +- tests/qapi-schema/alternate-unknown.err | 2 +- tests/qapi-schema/args-array-empty.err | 2 +- tests/qapi-schema/args-array-unknown.err | 2 +- tests/qapi-schema/args-member-array-bad.err | 2 +- tests/qapi-schema/args-member-case.err | 2 +- tests/qapi-schema/args-member-unknown.err | 2 +- tests/qapi-schema/bad-type-int.err | 2 +- tests/qapi-schema/base-cycle-direct.err | 2 +- tests/qapi-schema/base-cycle-indirect.err | 2 +- .../qapi-schema/doc-bad-alternate-member.err | 2 +- tests/qapi-schema/doc-bad-command-arg.err | 2 +- tests/qapi-schema/doc-bad-symbol.err | 2 +- tests/qapi-schema/doc-bad-union-member.err | 2 +- tests/qapi-schema/doc-before-include.err | 2 +- tests/qapi-schema/doc-before-pragma.err | 2 +- tests/qapi-schema/doc-duplicated-return.err | 2 +- tests/qapi-schema/doc-duplicated-since.err | 2 +- tests/qapi-schema/doc-empty-arg.err | 2 +- tests/qapi-schema/doc-empty-section.err | 2 +- tests/qapi-schema/doc-empty-symbol.err | 2 +- tests/qapi-schema/doc-invalid-end.err | 2 +- tests/qapi-schema/doc-invalid-end2.err | 2 +- tests/qapi-schema/doc-invalid-start.err | 2 +- tests/qapi-schema/doc-missing-colon.err | 2 +- tests/qapi-schema/doc-missing-expr.err | 2 +- tests/qapi-schema/doc-missing-space.err | 2 +- tests/qapi-schema/doc-missing.err | 2 +- tests/qapi-schema/doc-no-symbol.err | 2 +- tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/duplicate-key.err | 2 +- tests/qapi-schema/enum-bad-member.err | 2 +- tests/qapi-schema/enum-bad-name.err | 2 +- tests/qapi-schema/enum-bad-prefix.err | 2 +- .../qapi-schema/enum-dict-member-unknown.err | 2 +- tests/qapi-schema/enum-int-member.err | 2 +- tests/qapi-schema/enum-member-case.err | 2 +- tests/qapi-schema/enum-missing-data.err | 2 +- tests/qapi-schema/enum-wrong-data.err | 2 +- tests/qapi-schema/escape-outside-string.err | 2 +- tests/qapi-schema/escape-too-big.err | 1 + tests/qapi-schema/event-boxed-empty.err | 2 +- .../qapi-schema/event-member-invalid-dict.err | 2 +- tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/features-bad-type.err | 2 +- tests/qapi-schema/features-missing-name.err | 2 +- tests/qapi-schema/features-name-bad-type.err | 2 +- tests/qapi-schema/features-no-list.err | 2 +- tests/qapi-schema/features-unknown-key.err | 2 +- tests/qapi-schema/flat-union-array-branch.err | 2 +- .../flat-union-bad-discriminator.err | 2 +- .../flat-union-discriminator-bad-name.err | 2 +- tests/qapi-schema/flat-union-empty.err | 2 +- .../flat-union-inline-invalid-dict.err | 2 +- tests/qapi-schema/flat-union-inline.err | 2 +- tests/qapi-schema/flat-union-int-branch.err | 2 +- .../flat-union-invalid-branch-key.err | 2 +- .../flat-union-invalid-discriminator.err | 2 +- .../flat-union-invalid-if-discriminator.err | 2 +- tests/qapi-schema/flat-union-no-base.err | 2 +- .../flat-union-optional-discriminator.err | 2 +- .../flat-union-string-discriminator.err | 2 +- tests/qapi-schema/funny-char.err | 2 +- tests/qapi-schema/funny-word.err | 2 +- tests/qapi-schema/ident-with-escape.err | 2 +- tests/qapi-schema/include-before-err.err | 2 +- tests/qapi-schema/include-cycle.err | 2 +- tests/qapi-schema/include-extra-junk.err | 2 +- tests/qapi-schema/include-nested-err.err | 2 +- tests/qapi-schema/include-non-file.err | 2 +- tests/qapi-schema/include-self-cycle.err | 2 +- tests/qapi-schema/leading-comma-list.err | 2 +- tests/qapi-schema/leading-comma-object.err | 2 +- tests/qapi-schema/missing-colon.err | 2 +- tests/qapi-schema/missing-comma-list.err | 2 +- tests/qapi-schema/missing-comma-object.err | 2 +- tests/qapi-schema/missing-type.err | 2 +- .../nested-struct-data-invalid-dict.err | 2 +- tests/qapi-schema/nested-struct-data.err | 2 +- tests/qapi-schema/non-objects.err | 2 +- .../qapi-schema/pragma-doc-required-crap.err | 2 +- tests/qapi-schema/pragma-extra-junk.err | 2 +- .../pragma-name-case-whitelist-crap.err | 2 +- tests/qapi-schema/pragma-non-dict.err | 2 +- .../pragma-returns-whitelist-crap.err | 2 +- tests/qapi-schema/pragma-unknown.err | 2 +- tests/qapi-schema/quoted-structural-chars.err | 2 +- tests/qapi-schema/reserved-enum-q.err | 2 +- tests/qapi-schema/reserved-member-has.err | 2 +- tests/qapi-schema/reserved-member-q.err | 2 +- tests/qapi-schema/reserved-member-u.err | 2 +- .../reserved-member-underscore.err | 2 +- tests/qapi-schema/string-code-point-127.err | 2 +- tests/qapi-schema/string-code-point-31.err | 2 +- tests/qapi-schema/string-control.err | 1 + tests/qapi-schema/string-unclosed.err | 1 + tests/qapi-schema/string-unicode.err | 1 + .../struct-member-invalid-dict.err | 2 +- tests/qapi-schema/struct-member-invalid.err | 2 +- tests/qapi-schema/trailing-comma-list.err | 2 +- tests/qapi-schema/trailing-comma-object.err | 2 +- tests/qapi-schema/unclosed-list.err | 2 +- tests/qapi-schema/unclosed-object.err | 2 +- tests/qapi-schema/unclosed-string.err | 2 +- tests/qapi-schema/union-base-empty.err | 2 +- .../union-base-no-discriminator.err | 2 +- tests/qapi-schema/union-branch-case.err | 2 +- .../qapi-schema/union-branch-invalid-dict.err | 2 +- tests/qapi-schema/union-empty.err | 2 +- tests/qapi-schema/union-optional-branch.err | 2 +- tests/qapi-schema/union-unknown.err | 2 +- tests/qapi-schema/unknown-escape.err | 2 +- tests/qapi-schema/unknown-expr-key.err | 2 +- 125 files changed, 215 insertions(+), 204 deletions(-) create mode 100644 tests/qapi-schema/escape-too-big.err create mode 100644 tests/qapi-schema/string-control.err create mode 100644 tests/qapi-schema/string-unclosed.err create mode 100644 tests/qapi-schema/string-unicode.err
scripts/qapi/common.py +91 -84
@@ -207,7 +207,7 @@ class QAPIDoc(object): return if line[0] != ' ': - raise QAPIParseError(self._parser, "Missing space after #") + raise QAPIParseError(self._parser, "missing space after #") line = line[1:] self._append_line(line)
@@ -241,11 +241,11 @@ class QAPIDoc(object): # recognized, and get silently treated as ordinary text if not self.symbol and not self.body.text and line.startswith('@'): if not line.endswith(':'): - raise QAPIParseError(self._parser, "Line should end with ':'") + raise QAPIParseError(self._parser, "line should end with ':'") self.symbol = line[1:-1] # FIXME invalid names other than the empty string aren't flagged if not self.symbol: - raise QAPIParseError(self._parser, "Invalid name") + raise QAPIParseError(self._parser, "invalid name") elif self.symbol: # This is a definition documentation block if name.startswith('@') and name.endswith(':'):
@@ -344,7 +344,7 @@ class QAPIDoc(object): def _start_symbol_section(self, symbols_dict, name): # FIXME invalid names other than the empty string aren't flagged if not name: - raise QAPIParseError(self._parser, "Invalid parameter name") + raise QAPIParseError(self._parser, "invalid parameter name") if name in symbols_dict: raise QAPIParseError(self._parser, "'%s' parameter name duplicated" % name)
@@ -362,7 +362,7 @@ class QAPIDoc(object): def _start_section(self, name=None): if name in ('Returns', 'Since') and self.has_section(name): raise QAPIParseError(self._parser, - "Duplicated '%s' section" % name) + "duplicated '%s' section" % name) self._end_section() self._section = QAPIDoc.Section(name) self.sections.append(self._section)
@@ -371,7 +371,7 @@ class QAPIDoc(object): if self._section: text = self._section.text = self._section.text.strip() if self._section.name and (not text or text.isspace()): - raise QAPIParseError(self._parser, "Empty doc section '%s'" + raise QAPIParseError(self._parser, "empty doc section '%s'" % self._section.name) self._section = None
@@ -400,7 +400,7 @@ class QAPIDoc(object): if bogus: raise QAPISemError( self.info, - "The following documented members are not in " + "the following documented members are not in " "the declaration: %s" % ", ".join(bogus))
@@ -432,11 +432,11 @@ class QAPISchemaParser(object): if 'include' in expr: self.reject_expr_doc(cur_doc) if len(expr) != 1: - raise QAPISemError(info, "Invalid 'include' directive") + raise QAPISemError(info, "invalid 'include' directive") include = expr['include'] if not isinstance(include, str): raise QAPISemError(info, - "Value of 'include' must be a string") + "value of 'include' must be a string") incl_fname = os.path.join(os.path.dirname(self.fname), include) self.exprs.append({'expr': {'include': incl_fname},
@@ -449,11 +449,11 @@ class QAPISchemaParser(object): elif "pragma" in expr: self.reject_expr_doc(cur_doc) if len(expr) != 1: - raise QAPISemError(info, "Invalid 'pragma' directive") + raise QAPISemError(info, "invalid 'pragma' directive") pragma = expr['pragma'] if not isinstance(pragma, dict): raise QAPISemError( - info, "Value of 'pragma' must be an object") + info, "value of 'pragma' must be an object") for name, value in pragma.items(): self._pragma(name, value, info) else:
@@ -462,7 +462,7 @@ class QAPISchemaParser(object): if cur_doc: if not cur_doc.symbol: raise QAPISemError( - cur_doc.info, "Definition documentation required") + cur_doc.info, "definition documentation required") expr_elem['doc'] = cur_doc self.exprs.append(expr_elem) cur_doc = None
@@ -473,7 +473,7 @@ class QAPISchemaParser(object): if doc and doc.symbol: raise QAPISemError( doc.info, - "Documentation for '%s' is not followed by the definition" + "documentation for '%s' is not followed by the definition" % doc.symbol) def _include(self, include, info, incl_fname, previously_included):
@@ -482,7 +482,7 @@ class QAPISchemaParser(object): inf = info while inf: if incl_abs_fname == os.path.abspath(inf.fname): - raise QAPISemError(info, "Inclusion loop for %s" % include) + raise QAPISemError(info, "inclusion loop for %s" % include) inf = inf.parent # skip multiple include of the same file
@@ -503,24 +503,24 @@ class QAPISchemaParser(object): if name == 'doc-required': if not isinstance(value, bool): raise QAPISemError(info, - "Pragma 'doc-required' must be boolean") + "pragma 'doc-required' must be boolean") doc_required = value elif name == 'returns-whitelist': if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): - raise QAPISemError(info, - "Pragma returns-whitelist must be" - " a list of strings") + raise QAPISemError( + info, + "pragma returns-whitelist must be a list of strings") returns_whitelist = value elif name == 'name-case-whitelist': if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): - raise QAPISemError(info, - "Pragma name-case-whitelist must be" - " a list of strings") + raise QAPISemError( + info, + "pragma name-case-whitelist must be a list of strings") name_case_whitelist = value else: - raise QAPISemError(info, "Unknown pragma '%s'" % name) + raise QAPISemError(info, "unknown pragma '%s'" % name) def accept(self, skip_comment=True): while True:
@@ -547,13 +547,13 @@ class QAPISchemaParser(object): ch = self.src[self.cursor] self.cursor += 1 if ch == '\n': - raise QAPIParseError(self, "Missing terminating \"'\"") + raise QAPIParseError(self, "missing terminating \"'\"") if esc: # Note: we recognize only \\ because we have # no use for funny characters in strings if ch != '\\': raise QAPIParseError(self, - "Unknown escape \\%s" % ch) + "unknown escape \\%s" % ch) esc = False elif ch == '\\': esc = True
@@ -563,7 +563,7 @@ class QAPISchemaParser(object): return if ord(ch) < 32 or ord(ch) >= 127: raise QAPIParseError( - self, "Funny character in string") + self, "funny character in string") string += ch elif self.src.startswith('true', self.pos): self.val = True
@@ -584,7 +584,7 @@ class QAPISchemaParser(object): # character match = re.match('[^[\\]{}:,\\s\'"]+', self.src[self.cursor-1:]) - raise QAPIParseError(self, "Stray '%s'" % match.group(0)) + raise QAPIParseError(self, "stray '%s'" % match.group(0)) def get_members(self): expr = OrderedDict()
@@ -592,24 +592,24 @@ class QAPISchemaParser(object): self.accept() return expr if self.tok != "'": - raise QAPIParseError(self, "Expected string or '}'") + raise QAPIParseError(self, "expected string or '}'") while True: key = self.val self.accept() if self.tok != ':': - raise QAPIParseError(self, "Expected ':'") + raise QAPIParseError(self, "expected ':'") self.accept() if key in expr: - raise QAPIParseError(self, "Duplicate key '%s'" % key) + raise QAPIParseError(self, "duplicate key '%s'" % key) expr[key] = self.get_expr(True) if self.tok == '}': self.accept() return expr if self.tok != ',': - raise QAPIParseError(self, "Expected ',' or '}'") + raise QAPIParseError(self, "expected ',' or '}'") self.accept() if self.tok != "'": - raise QAPIParseError(self, "Expected string") + raise QAPIParseError(self, "expected string") def get_values(self): expr = []
@@ -618,19 +618,19 @@ class QAPISchemaParser(object): return expr if self.tok not in "{['tfn": raise QAPIParseError( - self, "Expected '{', '[', ']', string, boolean or 'null'") + self, "expected '{', '[', ']', string, boolean or 'null'") while True: expr.append(self.get_expr(True)) if self.tok == ']': self.accept() return expr if self.tok != ',': - raise QAPIParseError(self, "Expected ',' or ']'") + raise QAPIParseError(self, "expected ',' or ']'") self.accept() def get_expr(self, nested): if self.tok != '{' and not nested: - raise QAPIParseError(self, "Expected '{'") + raise QAPIParseError(self, "expected '{'") if self.tok == '{': self.accept() expr = self.get_members()
@@ -642,13 +642,13 @@ class QAPISchemaParser(object): self.accept() else: raise QAPIParseError( - self, "Expected '{', '[', string, boolean or 'null'") + self, "expected '{', '[', string, boolean or 'null'") return expr def get_doc(self, info): if self.val != '##': - raise QAPIParseError(self, "Junk after '##' at start of " - "documentation comment") + raise QAPIParseError( + self, "junk after '##' at start of documentation comment") doc = QAPIDoc(self, info) self.accept(False)
@@ -656,8 +656,9 @@ class QAPISchemaParser(object): if self.val.startswith('##'): # End of doc comment if self.val != '##': - raise QAPIParseError(self, "Junk after '##' at end of " - "documentation comment") + raise QAPIParseError( + self, + "junk after '##' at end of documentation comment") doc.end_comment() self.accept() return doc
@@ -665,7 +666,7 @@ class QAPISchemaParser(object): doc.append(self.val) self.accept(False) - raise QAPIParseError(self, "Documentation comment must end with '##'") + raise QAPIParseError(self, "documentation comment must end with '##'") #
@@ -804,18 +805,18 @@ def check_type(info, source, value, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name(info, "Member of %s" % source, key, + check_name(info, "member of %s" % source, key, allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): - raise QAPISemError(info, "Member of %s uses reserved name '%s'" - % (source, key)) + raise QAPISemError( + info, "member of %s uses reserved name '%s'" % (source, key)) # Todo: allow dictionaries to represent default values of # an optional argument. check_known_keys(info, "member '%s' of %s" % (key, source), arg, ['type'], ['if']) check_if(arg, info) normalize_if(arg) - check_type(info, "Member '%s' of %s" % (key, source), + check_type(info, "member '%s' of %s" % (key, source), arg['type'], allow_array=True, allow_metas=['built-in', 'union', 'alternate', 'struct', 'enum'])
@@ -868,8 +869,8 @@ def check_union(expr, info): enum_values = members.keys() allow_metas = ['built-in', 'union', 'alternate', 'struct', 'enum'] if base is not None: - raise QAPISemError(info, "Simple union '%s' must not have a base" % - name) + raise QAPISemError( + info, "simple union '%s' must not have a base" % name) # Else, it's a flat union. else:
@@ -878,46 +879,47 @@ def check_union(expr, info): base, allow_dict=name, allow_metas=['struct']) if not base: - raise QAPISemError(info, "Flat union '%s' must have a base" + raise QAPISemError(info, "flat union '%s' must have a base" % name) base_members = find_base_members(base) assert base_members is not None # The value of member 'discriminator' must name a non-optional # member of the base struct. - check_name(info, "Discriminator of flat union '%s'" % name, + check_name(info, "discriminator of flat union '%s'" % name, discriminator) discriminator_value = base_members.get(discriminator) if not discriminator_value: raise QAPISemError(info, - "Discriminator '%s' is not a member of 'base'" + "discriminator '%s' is not a member of 'base'" % discriminator) if discriminator_value.get('if'): raise QAPISemError( info, - "The discriminator '%s' for union %s must not be conditional" + "the discriminator '%s' for union %s must not be conditional" % (discriminator, name)) enum_define = enum_types.get(discriminator_value['type']) # Do not allow string discriminator if not enum_define: - raise QAPISemError(info, - "Discriminator '%s' must be of enumeration " - "type" % discriminator) + raise QAPISemError( + info, + "discriminator '%s' must be of enumeration type" + % discriminator) enum_values = enum_get_names(enum_define) allow_metas = ['struct'] if (len(enum_values) == 0): - raise QAPISemError(info, "Union '%s' has no branches" % name) + raise QAPISemError(info, "union '%s' has no branches" % name) for (key, value) in members.items(): - check_name(info, "Member of union '%s'" % name, key) + check_name(info, "member of union '%s'" % name, key) check_known_keys(info, "member '%s' of union '%s'" % (key, name), value, ['type'], ['if']) check_if(value, info) normalize_if(value) # Each value must name a known type - check_type(info, "Member '%s' of union '%s'" % (key, name), + check_type(info, "member '%s' of union '%s'" % (key, name), value['type'], allow_array=not base, allow_metas=allow_metas)
@@ -925,10 +927,10 @@ def check_union(expr, info): # of 'data' must also be members of the enum type. if discriminator is not None: if key not in enum_values: - raise QAPISemError(info, - "Discriminator value '%s' is not found in " - "enum '%s'" - % (key, enum_define['enum'])) + raise QAPISemError( + info, + "discriminator value '%s' is not found in enum '%s'" + % (key, enum_define['enum'])) def check_alternate(expr, info):
@@ -938,9 +940,9 @@ def check_alternate(expr, info): if len(members) == 0: raise QAPISemError(info, - "Alternate '%s' cannot have empty 'data'" % name) + "alternate '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): - check_name(info, "Member of alternate '%s'" % name, key) + check_name(info, "member of alternate '%s'" % name, key) check_known_keys(info, "member '%s' of alternate '%s'" % (key, name), value, ['type'], ['if'])
@@ -949,12 +951,14 @@ def check_alternate(expr, info): typ = value['type'] # Ensure alternates have no type conflicts. - check_type(info, "Member '%s' of alternate '%s'" % (key, name), typ, + check_type(info, "member '%s' of alternate '%s'" % (key, name), typ, allow_metas=['built-in', 'union', 'struct', 'enum']) qtype = find_alternate_member_qtype(typ) if not qtype: - raise QAPISemError(info, "Alternate '%s' member '%s' cannot use " - "type '%s'" % (name, key, typ)) + raise QAPISemError( + info, + "alternate '%s' member '%s' cannot use type '%s'" + % (name, key, typ)) conflicting = set([qtype]) if qtype == 'QTYPE_QSTRING': enum_expr = enum_types.get(typ)
@@ -969,9 +973,11 @@ def check_alternate(expr, info): conflicting.add('QTYPE_QBOOL') for qt in conflicting: if qt in types_seen: - raise QAPISemError(info, "Alternate '%s' member '%s' can't " - "be distinguished from member '%s'" - % (name, key, types_seen[qt])) + raise QAPISemError( + info, + "alternate '%s' member '%s' can't be distinguished " + "from member '%s'" + % (name, key, types_seen[qt])) types_seen[qt] = key
@@ -982,10 +988,10 @@ def check_enum(expr, info): if not isinstance(members, list): raise QAPISemError(info, - "Enum '%s' requires an array for 'data'" % name) + "enum '%s' requires an array for 'data'" % name) if prefix is not None and not isinstance(prefix, str): raise QAPISemError(info, - "Enum '%s' requires a string for 'prefix'" % name) + "enum '%s' requires a string for 'prefix'" % name) permit_upper = name in name_case_whitelist
@@ -994,7 +1000,7 @@ def check_enum(expr, info): ['name'], ['if']) check_if(member, info) normalize_if(member) - check_name(info, "Member of enum '%s'" % name, member['name'], + check_name(info, "member of enum '%s'" % name, member['name'], enum_member=True, permit_upper=permit_upper)
@@ -1010,9 +1016,8 @@ def check_struct(expr, info): if features: if not isinstance(features, list): - raise QAPISemError(info, - "Struct '%s' requires an array for 'features'" % - name) + raise QAPISemError( + info, "struct '%s' requires an array for 'features'" % name) for f in features: assert isinstance(f, dict) check_known_keys(info, "feature of struct %s" % name, f,
@@ -1020,7 +1025,7 @@ def check_struct(expr, info): check_if(f, info) normalize_if(f) - check_name(info, "Feature of struct %s" % name, f['name']) + check_name(info, "feature of struct %s" % name, f['name']) def check_known_keys(info, source, value, required, optional):
@@ -1030,13 +1035,13 @@ def check_known_keys(info, source, value, required, optional): missing = set(required) - set(value) if missing: - raise QAPISemError(info, "Key%s %s %s missing from %s" + raise QAPISemError(info, "key%s %s %s missing from %s" % ('s' if len(missing) > 1 else '', pprint(missing), 'are' if len(missing) > 1 else 'is', source)) allowed = set(required + optional) unknown = set(value) - allowed if unknown: - raise QAPISemError(info, "Unknown key%s %s in %s\nValid keys are %s." + raise QAPISemError(info, "unknown key%s %s in %s\nValid keys are %s." % ('s' if len(unknown) > 1 else '', pprint(unknown), source, pprint(allowed)))
@@ -1106,7 +1111,7 @@ def check_exprs(exprs): if not doc and doc_required: raise QAPISemError(info, - "Definition missing documentation comment") + "definition missing documentation comment") if 'enum' in expr: meta = 'enum'
@@ -1142,14 +1147,16 @@ def check_exprs(exprs): check_keys(expr, info, 'event', [], ['data', 'boxed', 'if']) normalize_members(expr.get('data')) else: - raise QAPISemError(info, "Expression is missing metatype") + raise QAPISemError(info, "expression is missing metatype") normalize_if(expr) name = expr[meta] add_name(name, info, meta) info.set_defn(meta, name) if doc and doc.symbol != name: - raise QAPISemError(info, "Definition of '%s' follows documentation" - " for '%s'" % (name, doc.symbol)) + raise QAPISemError( + info, + "definition of '%s' follows documentation for '%s'" + % (name, doc.symbol)) # Validate that exprs make sense for expr_elem in exprs:
@@ -1462,7 +1469,7 @@ class QAPISchemaObjectType(QAPISchemaType): if self._checked: # Recursed: C struct contains itself raise QAPISemError(self.info, - "Object %s contains itself" % self.name) + "object %s contains itself" % self.name) QAPISchemaType.check(self, schema) assert self._checked and self.members is None
@@ -1734,7 +1741,7 @@ class QAPISchemaCommand(QAPISchemaEntity): assert isinstance(self.arg_type, QAPISchemaObjectType) assert not self.arg_type.variants or self.boxed elif self.boxed: - raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") + raise QAPISemError(self.info, "use of 'boxed' requires 'data'") if self._ret_type_name: self.ret_type = schema.lookup_type(self._ret_type_name) assert isinstance(self.ret_type, QAPISchemaType)
@@ -1763,7 +1770,7 @@ class QAPISchemaEvent(QAPISchemaEntity): assert isinstance(self.arg_type, QAPISchemaObjectType) assert not self.arg_type.variants or self.boxed elif self.boxed: - raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") + raise QAPISemError(self.info, "use of 'boxed' requires 'data'") def visit(self, visitor): QAPISchemaEntity.visit(self, visitor)
tests/qapi-schema/alternate-any.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-any.json: In alternate 'Alt': -tests/qapi-schema/alternate-any.json:2: Alternate 'Alt' member 'one' cannot use type 'any' +tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any'
tests/qapi-schema/alternate-array.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-array.json: In alternate 'Alt': -tests/qapi-schema/alternate-array.json:5: Member 'two' of alternate 'Alt' cannot be an array +tests/qapi-schema/alternate-array.json:5: member 'two' of alternate 'Alt' cannot be an array
tests/qapi-schema/alternate-base.err +1 -1
@@ -1,2 +1,2 @@ -tests/qapi-schema/alternate-base.json:4: Unknown key 'base' in alternate 'Alt' +tests/qapi-schema/alternate-base.json:4: unknown key 'base' in alternate 'Alt' Valid keys are 'alternate', 'data', 'if'.
tests/qapi-schema/alternate-conflict-bool-string.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-bool-string.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-bool-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-bool-string.json:2: alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-dict.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-dict.json:6: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-dict.json:6: alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-enum-bool.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-enum-bool.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-enum-bool.json:4: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-enum-bool.json:4: alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-enum-int.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-enum-int.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-enum-int.json:4: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-enum-int.json:4: alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-num-string.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-num-string.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-num-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-num-string.json:2: alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-conflict-string.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-string.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-string.json:2: alternate 'Alt' member 'two' can't be distinguished from member 'one'
tests/qapi-schema/alternate-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-empty.json: In alternate 'Alt': -tests/qapi-schema/alternate-empty.json:2: Alternate 'Alt' cannot have empty 'data' +tests/qapi-schema/alternate-empty.json:2: alternate 'Alt' cannot have empty 'data'
tests/qapi-schema/alternate-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-invalid-dict.json: In alternate 'Alt': -tests/qapi-schema/alternate-invalid-dict.json:2: Key 'type' is missing from member 'two' of alternate 'Alt' +tests/qapi-schema/alternate-invalid-dict.json:2: key 'type' is missing from member 'two' of alternate 'Alt'
tests/qapi-schema/alternate-nested.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-nested.json: In alternate 'Alt2': -tests/qapi-schema/alternate-nested.json:4: Member 'nested' of alternate 'Alt2' cannot use alternate type 'Alt1' +tests/qapi-schema/alternate-nested.json:4: member 'nested' of alternate 'Alt2' cannot use alternate type 'Alt1'
tests/qapi-schema/alternate-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-unknown.json: In alternate 'Alt': -tests/qapi-schema/alternate-unknown.json:2: Member 'unknown' of alternate 'Alt' uses unknown type 'MissingType' +tests/qapi-schema/alternate-unknown.json:2: member 'unknown' of alternate 'Alt' uses unknown type 'MissingType'
tests/qapi-schema/args-array-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-array-empty.json: In command 'oops': -tests/qapi-schema/args-array-empty.json:2: Member 'empty' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-array-empty.json:2: member 'empty' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-array-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-array-unknown.json: In command 'oops': -tests/qapi-schema/args-array-unknown.json:2: Member 'array' of 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-array-unknown.json:2: member 'array' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/args-member-array-bad.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-array-bad.json: In command 'oops': -tests/qapi-schema/args-member-array-bad.json:2: Member 'member' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-member-array-bad.json:2: member 'member' of 'data' for command 'oops': array type must contain single type name
tests/qapi-schema/args-member-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-case.json: In command 'no-way-this-will-get-whitelisted': -tests/qapi-schema/args-member-case.json:2: Member of 'data' for command 'no-way-this-will-get-whitelisted' uses uppercase in name 'Arg' +tests/qapi-schema/args-member-case.json:2: member of 'data' for command 'no-way-this-will-get-whitelisted' uses uppercase in name 'Arg'
tests/qapi-schema/args-member-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-unknown.json: In command 'oops': -tests/qapi-schema/args-member-unknown.json:2: Member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-member-unknown.json:2: member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType'
tests/qapi-schema/bad-type-int.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-type-int.json:3:13: Stray '123' +tests/qapi-schema/bad-type-int.json:3:13: stray '123'
tests/qapi-schema/base-cycle-direct.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/base-cycle-direct.json: In struct 'Loopy': -tests/qapi-schema/base-cycle-direct.json:2: Object Loopy contains itself +tests/qapi-schema/base-cycle-direct.json:2: object Loopy contains itself
tests/qapi-schema/base-cycle-indirect.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/base-cycle-indirect.json: In struct 'Base1': -tests/qapi-schema/base-cycle-indirect.json:2: Object Base1 contains itself +tests/qapi-schema/base-cycle-indirect.json:2: object Base1 contains itself
tests/qapi-schema/doc-bad-alternate-member.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-bad-alternate-member.json:3: The following documented members are not in the declaration: aa, bb +tests/qapi-schema/doc-bad-alternate-member.json:3: the following documented members are not in the declaration: aa, bb
tests/qapi-schema/doc-bad-command-arg.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-bad-command-arg.json:3: The following documented members are not in the declaration: b +tests/qapi-schema/doc-bad-command-arg.json:3: the following documented members are not in the declaration: b
tests/qapi-schema/doc-bad-symbol.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/doc-bad-symbol.json: In command 'foo': -tests/qapi-schema/doc-bad-symbol.json:6: Definition of 'foo' follows documentation for 'food' +tests/qapi-schema/doc-bad-symbol.json:6: definition of 'foo' follows documentation for 'food'
tests/qapi-schema/doc-bad-union-member.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-bad-union-member.json:3: The following documented members are not in the declaration: a, b +tests/qapi-schema/doc-bad-union-member.json:3: the following documented members are not in the declaration: a, b
tests/qapi-schema/doc-before-include.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-before-include.json:3: Documentation for 'foo' is not followed by the definition +tests/qapi-schema/doc-before-include.json:3: documentation for 'foo' is not followed by the definition
tests/qapi-schema/doc-before-pragma.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-before-pragma.json:3: Documentation for 'foo' is not followed by the definition +tests/qapi-schema/doc-before-pragma.json:3: documentation for 'foo' is not followed by the definition
tests/qapi-schema/doc-duplicated-return.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-duplicated-return.json:7:1: Duplicated 'Returns' section +tests/qapi-schema/doc-duplicated-return.json:7:1: duplicated 'Returns' section
tests/qapi-schema/doc-duplicated-since.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-duplicated-since.json:7:1: Duplicated 'Since' section +tests/qapi-schema/doc-duplicated-since.json:7:1: duplicated 'Since' section
tests/qapi-schema/doc-empty-arg.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-empty-arg.json:5:1: Invalid parameter name +tests/qapi-schema/doc-empty-arg.json:5:1: invalid parameter name
tests/qapi-schema/doc-empty-section.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-empty-section.json:7:1: Empty doc section 'Note' +tests/qapi-schema/doc-empty-section.json:7:1: empty doc section 'Note'
tests/qapi-schema/doc-empty-symbol.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-empty-symbol.json:4:1: Invalid name +tests/qapi-schema/doc-empty-symbol.json:4:1: invalid name
tests/qapi-schema/doc-invalid-end.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-invalid-end.json:5:2: Documentation comment must end with '##' +tests/qapi-schema/doc-invalid-end.json:5:2: documentation comment must end with '##'
tests/qapi-schema/doc-invalid-end2.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-invalid-end2.json:5:1: Junk after '##' at end of documentation comment +tests/qapi-schema/doc-invalid-end2.json:5:1: junk after '##' at end of documentation comment
tests/qapi-schema/doc-invalid-start.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-invalid-start.json:3:1: Junk after '##' at start of documentation comment +tests/qapi-schema/doc-invalid-start.json:3:1: junk after '##' at start of documentation comment
tests/qapi-schema/doc-missing-colon.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-missing-colon.json:4:1: Line should end with ':' +tests/qapi-schema/doc-missing-colon.json:4:1: line should end with ':'
tests/qapi-schema/doc-missing-expr.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-missing-expr.json:3: Documentation for 'bar' is not followed by the definition +tests/qapi-schema/doc-missing-expr.json:3: documentation for 'bar' is not followed by the definition
tests/qapi-schema/doc-missing-space.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-missing-space.json:5:1: Missing space after # +tests/qapi-schema/doc-missing-space.json:5:1: missing space after #
tests/qapi-schema/doc-missing.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-missing.json:5: Definition missing documentation comment +tests/qapi-schema/doc-missing.json:5: definition missing documentation comment
tests/qapi-schema/doc-no-symbol.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/doc-no-symbol.json:3: Definition documentation required +tests/qapi-schema/doc-no-symbol.json:3: definition documentation required
tests/qapi-schema/double-type.err +1 -1
@@ -1,2 +1,2 @@ -tests/qapi-schema/double-type.json:2: Unknown key 'command' in struct 'bar' +tests/qapi-schema/double-type.json:2: unknown key 'command' in struct 'bar' Valid keys are 'base', 'data', 'features', 'if', 'struct'.
tests/qapi-schema/duplicate-key.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/duplicate-key.json:3:10: Duplicate key 'key' +tests/qapi-schema/duplicate-key.json:3:10: duplicate key 'key'
tests/qapi-schema/enum-bad-member.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-bad-member.json: In enum 'MyEnum': -tests/qapi-schema/enum-bad-member.json:2: Member of enum 'MyEnum' requires a string name +tests/qapi-schema/enum-bad-member.json:2: member of enum 'MyEnum' requires a string name
tests/qapi-schema/enum-bad-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-bad-name.json: In enum 'MyEnum': -tests/qapi-schema/enum-bad-name.json:3: Member of enum 'MyEnum' uses invalid name 'not\possible' +tests/qapi-schema/enum-bad-name.json:3: member of enum 'MyEnum' uses invalid name 'not\possible'
tests/qapi-schema/enum-bad-prefix.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-bad-prefix.json: In enum 'MyEnum': -tests/qapi-schema/enum-bad-prefix.json:2: Enum 'MyEnum' requires a string for 'prefix' +tests/qapi-schema/enum-bad-prefix.json:2: enum 'MyEnum' requires a string for 'prefix'
tests/qapi-schema/enum-dict-member-unknown.err +1 -1
@@ -1,3 +1,3 @@ tests/qapi-schema/enum-dict-member-unknown.json: In enum 'MyEnum': -tests/qapi-schema/enum-dict-member-unknown.json:2: Unknown key 'bad-key' in member of enum 'MyEnum' +tests/qapi-schema/enum-dict-member-unknown.json:2: unknown key 'bad-key' in member of enum 'MyEnum' Valid keys are 'if', 'name'.
tests/qapi-schema/enum-int-member.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-int-member.json:3:31: Stray '1' +tests/qapi-schema/enum-int-member.json:3:31: stray '1'
tests/qapi-schema/enum-member-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-member-case.json: In enum 'NoWayThisWillGetWhitelisted': -tests/qapi-schema/enum-member-case.json:4: Member of enum 'NoWayThisWillGetWhitelisted' uses uppercase in name 'Value' +tests/qapi-schema/enum-member-case.json:4: member of enum 'NoWayThisWillGetWhitelisted' uses uppercase in name 'Value'
tests/qapi-schema/enum-missing-data.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/enum-missing-data.json:2: Key 'data' is missing from enum 'MyEnum' +tests/qapi-schema/enum-missing-data.json:2: key 'data' is missing from enum 'MyEnum'
tests/qapi-schema/enum-wrong-data.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-wrong-data.json: In enum 'MyEnum': -tests/qapi-schema/enum-wrong-data.json:2: Enum 'MyEnum' requires an array for 'data' +tests/qapi-schema/enum-wrong-data.json:2: enum 'MyEnum' requires an array for 'data'
tests/qapi-schema/escape-outside-string.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/escape-outside-string.json:3:27: Stray '\' +tests/qapi-schema/escape-outside-string.json:3:27: stray '\'
tests/qapi-schema/escape-too-big.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/escape-too-big.json:3:14: for now, \u escape only supports non-zero values up to \u007f
tests/qapi-schema/event-boxed-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/event-boxed-empty.json: In event 'FOO': -tests/qapi-schema/event-boxed-empty.json:2: Use of 'boxed' requires 'data' +tests/qapi-schema/event-boxed-empty.json:2: use of 'boxed' requires 'data'
tests/qapi-schema/event-member-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/event-member-invalid-dict.json: In event 'EVENT_A': -tests/qapi-schema/event-member-invalid-dict.json:1: Key 'type' is missing from member 'a' of 'data' for event 'EVENT_A' +tests/qapi-schema/event-member-invalid-dict.json:1: key 'type' is missing from member 'a' of 'data' for event 'EVENT_A'
tests/qapi-schema/event-nest-struct.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/event-nest-struct.json: In event 'EVENT_A': -tests/qapi-schema/event-nest-struct.json:1: Member 'a' of 'data' for event 'EVENT_A' should be a type name +tests/qapi-schema/event-nest-struct.json:1: member 'a' of 'data' for event 'EVENT_A' should be a type name
tests/qapi-schema/features-bad-type.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-bad-type.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-bad-type.json:1: Feature of struct FeatureStruct0 requires a string name +tests/qapi-schema/features-bad-type.json:1: feature of struct FeatureStruct0 requires a string name
tests/qapi-schema/features-missing-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-missing-name.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-missing-name.json:1: Key 'name' is missing from feature of struct FeatureStruct0 +tests/qapi-schema/features-missing-name.json:1: key 'name' is missing from feature of struct FeatureStruct0
tests/qapi-schema/features-name-bad-type.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-name-bad-type.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-name-bad-type.json:1: Feature of struct FeatureStruct0 requires a string name +tests/qapi-schema/features-name-bad-type.json:1: feature of struct FeatureStruct0 requires a string name
tests/qapi-schema/features-no-list.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-no-list.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-no-list.json:1: Struct 'FeatureStruct0' requires an array for 'features' +tests/qapi-schema/features-no-list.json:1: struct 'FeatureStruct0' requires an array for 'features'
tests/qapi-schema/features-unknown-key.err +1 -1
@@ -1,3 +1,3 @@ tests/qapi-schema/features-unknown-key.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-unknown-key.json:1: Unknown key 'colour' in feature of struct FeatureStruct0 +tests/qapi-schema/features-unknown-key.json:1: unknown key 'colour' in feature of struct FeatureStruct0 Valid keys are 'if', 'name'.
tests/qapi-schema/flat-union-array-branch.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-array-branch.json: In union 'TestUnion': -tests/qapi-schema/flat-union-array-branch.json:8: Member 'value1' of union 'TestUnion' cannot be an array +tests/qapi-schema/flat-union-array-branch.json:8: member 'value1' of union 'TestUnion' cannot be an array
tests/qapi-schema/flat-union-bad-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-bad-discriminator.json: In union 'TestUnion': -tests/qapi-schema/flat-union-bad-discriminator.json:11: Discriminator of flat union 'TestUnion' requires a string name +tests/qapi-schema/flat-union-bad-discriminator.json:11: discriminator of flat union 'TestUnion' requires a string name
tests/qapi-schema/flat-union-discriminator-bad-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-discriminator-bad-name.json: In union 'MyUnion': -tests/qapi-schema/flat-union-discriminator-bad-name.json:7: Discriminator of flat union 'MyUnion' does not allow optional name '*switch' +tests/qapi-schema/flat-union-discriminator-bad-name.json:7: discriminator of flat union 'MyUnion' does not allow optional name '*switch'
tests/qapi-schema/flat-union-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-empty.json: In union 'Union': -tests/qapi-schema/flat-union-empty.json:4: Union 'Union' has no branches +tests/qapi-schema/flat-union-empty.json:4: union 'Union' has no branches
tests/qapi-schema/flat-union-inline-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-inline-invalid-dict.json: In union 'TestUnion': -tests/qapi-schema/flat-union-inline-invalid-dict.json:7: Key 'type' is missing from member 'value1' of union 'TestUnion' +tests/qapi-schema/flat-union-inline-invalid-dict.json:7: key 'type' is missing from member 'value1' of union 'TestUnion'
tests/qapi-schema/flat-union-inline.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-inline.json: In union 'TestUnion': -tests/qapi-schema/flat-union-inline.json:7: Member 'value1' of union 'TestUnion' should be a type name +tests/qapi-schema/flat-union-inline.json:7: member 'value1' of union 'TestUnion' should be a type name
tests/qapi-schema/flat-union-int-branch.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-int-branch.json: In union 'TestUnion': -tests/qapi-schema/flat-union-int-branch.json:8: Member 'value1' of union 'TestUnion' cannot use built-in type 'int' +tests/qapi-schema/flat-union-int-branch.json:8: member 'value1' of union 'TestUnion' cannot use built-in type 'int'
tests/qapi-schema/flat-union-invalid-branch-key.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-invalid-branch-key.json: In union 'TestUnion': -tests/qapi-schema/flat-union-invalid-branch-key.json:13: Discriminator value 'value_wrong' is not found in enum 'TestEnum' +tests/qapi-schema/flat-union-invalid-branch-key.json:13: discriminator value 'value_wrong' is not found in enum 'TestEnum'
tests/qapi-schema/flat-union-invalid-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-invalid-discriminator.json: In union 'TestUnion': -tests/qapi-schema/flat-union-invalid-discriminator.json:10: Discriminator 'enum_wrong' is not a member of 'base' +tests/qapi-schema/flat-union-invalid-discriminator.json:10: discriminator 'enum_wrong' is not a member of 'base'
tests/qapi-schema/flat-union-invalid-if-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-invalid-if-discriminator.json: In union 'TestUnion': -tests/qapi-schema/flat-union-invalid-if-discriminator.json:10: The discriminator 'enum1' for union TestUnion must not be conditional +tests/qapi-schema/flat-union-invalid-if-discriminator.json:10: the discriminator 'enum1' for union TestUnion must not be conditional
tests/qapi-schema/flat-union-no-base.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-no-base.json: In union 'TestUnion': -tests/qapi-schema/flat-union-no-base.json:9: Flat union 'TestUnion' must have a base +tests/qapi-schema/flat-union-no-base.json:9: flat union 'TestUnion' must have a base
tests/qapi-schema/flat-union-optional-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-optional-discriminator.json: In union 'MyUnion': -tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator 'switch' is not a member of 'base' +tests/qapi-schema/flat-union-optional-discriminator.json:7: discriminator 'switch' is not a member of 'base'
tests/qapi-schema/flat-union-string-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-string-discriminator.json: In union 'TestUnion': -tests/qapi-schema/flat-union-string-discriminator.json:13: Discriminator 'kind' must be of enumeration type +tests/qapi-schema/flat-union-string-discriminator.json:13: discriminator 'kind' must be of enumeration type
tests/qapi-schema/funny-char.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/funny-char.json:2:36: Stray ';' +tests/qapi-schema/funny-char.json:2:36: stray ';'
tests/qapi-schema/funny-word.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/funny-word.json:1:3: Stray 'command' +tests/qapi-schema/funny-word.json:1:3: stray 'command'
tests/qapi-schema/ident-with-escape.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/ident-with-escape.json:3:3: Unknown escape \u +tests/qapi-schema/ident-with-escape.json:3:3: unknown escape \u
tests/qapi-schema/include-before-err.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/include-before-err.json:2:13: Expected ':' +tests/qapi-schema/include-before-err.json:2:13: expected ':'
tests/qapi-schema/include-cycle.err +1 -1
@@ -1,3 +1,3 @@ In file included from tests/qapi-schema/include-cycle.json:1: In file included from tests/qapi-schema/include-cycle-b.json:1: -tests/qapi-schema/include-cycle-c.json:1: Inclusion loop for include-cycle.json +tests/qapi-schema/include-cycle-c.json:1: inclusion loop for include-cycle.json
tests/qapi-schema/include-extra-junk.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/include-extra-junk.json:3: Invalid 'include' directive +tests/qapi-schema/include-extra-junk.json:3: invalid 'include' directive
tests/qapi-schema/include-nested-err.err +1 -1
@@ -1,2 +1,2 @@ In file included from tests/qapi-schema/include-nested-err.json:1: -tests/qapi-schema/missing-colon.json:1:10: Expected ':' +tests/qapi-schema/missing-colon.json:1:10: expected ':'
tests/qapi-schema/include-non-file.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/include-non-file.json:1: Value of 'include' must be a string +tests/qapi-schema/include-non-file.json:1: value of 'include' must be a string
tests/qapi-schema/include-self-cycle.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/include-self-cycle.json:1: Inclusion loop for include-self-cycle.json +tests/qapi-schema/include-self-cycle.json:1: inclusion loop for include-self-cycle.json
tests/qapi-schema/leading-comma-list.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/leading-comma-list.json:2:13: Expected '{', '[', ']', string, boolean or 'null' +tests/qapi-schema/leading-comma-list.json:2:13: expected '{', '[', ']', string, boolean or 'null'
tests/qapi-schema/leading-comma-object.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/leading-comma-object.json:1:3: Expected string or '}' +tests/qapi-schema/leading-comma-object.json:1:3: expected string or '}'
tests/qapi-schema/missing-colon.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/missing-colon.json:1:10: Expected ':' +tests/qapi-schema/missing-colon.json:1:10: expected ':'
tests/qapi-schema/missing-comma-list.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/missing-comma-list.json:2:20: Expected ',' or ']' +tests/qapi-schema/missing-comma-list.json:2:20: expected ',' or ']'
tests/qapi-schema/missing-comma-object.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/missing-comma-object.json:2:3: Expected ',' or '}' +tests/qapi-schema/missing-comma-object.json:2:3: expected ',' or '}'
tests/qapi-schema/missing-type.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/missing-type.json:2: Expression is missing metatype +tests/qapi-schema/missing-type.json:2: expression is missing metatype
tests/qapi-schema/nested-struct-data-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/nested-struct-data-invalid-dict.json: In command 'foo': -tests/qapi-schema/nested-struct-data-invalid-dict.json:2: Key 'type' is missing from member 'a' of 'data' for command 'foo' +tests/qapi-schema/nested-struct-data-invalid-dict.json:2: key 'type' is missing from member 'a' of 'data' for command 'foo'
tests/qapi-schema/nested-struct-data.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/nested-struct-data.json: In command 'foo': -tests/qapi-schema/nested-struct-data.json:2: Member 'a' of 'data' for command 'foo' should be a type name +tests/qapi-schema/nested-struct-data.json:2: member 'a' of 'data' for command 'foo' should be a type name
tests/qapi-schema/non-objects.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/non-objects.json:1:1: Expected '{' +tests/qapi-schema/non-objects.json:1:1: expected '{'
tests/qapi-schema/pragma-doc-required-crap.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/pragma-doc-required-crap.json:3: Pragma 'doc-required' must be boolean +tests/qapi-schema/pragma-doc-required-crap.json:3: pragma 'doc-required' must be boolean
tests/qapi-schema/pragma-extra-junk.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/pragma-extra-junk.json:3: Invalid 'pragma' directive +tests/qapi-schema/pragma-extra-junk.json:3: invalid 'pragma' directive
tests/qapi-schema/pragma-name-case-whitelist-crap.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/pragma-name-case-whitelist-crap.json:3: Pragma name-case-whitelist must be a list of strings +tests/qapi-schema/pragma-name-case-whitelist-crap.json:3: pragma name-case-whitelist must be a list of strings
tests/qapi-schema/pragma-non-dict.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/pragma-non-dict.json:3: Value of 'pragma' must be an object +tests/qapi-schema/pragma-non-dict.json:3: value of 'pragma' must be an object
tests/qapi-schema/pragma-returns-whitelist-crap.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/pragma-returns-whitelist-crap.json:3: Pragma returns-whitelist must be a list of strings +tests/qapi-schema/pragma-returns-whitelist-crap.json:3: pragma returns-whitelist must be a list of strings
tests/qapi-schema/pragma-unknown.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/pragma-unknown.json:1: Unknown pragma 'no-such-pragma' +tests/qapi-schema/pragma-unknown.json:1: unknown pragma 'no-such-pragma'
tests/qapi-schema/quoted-structural-chars.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/quoted-structural-chars.json:1:1: Expected '{' +tests/qapi-schema/quoted-structural-chars.json:1:1: expected '{'
tests/qapi-schema/reserved-enum-q.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-enum-q.json: In enum 'Foo': -tests/qapi-schema/reserved-enum-q.json:4: Member of enum 'Foo' uses invalid name 'q-Unix' +tests/qapi-schema/reserved-enum-q.json:4: member of enum 'Foo' uses invalid name 'q-Unix'
tests/qapi-schema/reserved-member-has.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-has.json: In command 'oops': -tests/qapi-schema/reserved-member-has.json:5: Member of 'data' for command 'oops' uses reserved name 'has-a' +tests/qapi-schema/reserved-member-has.json:5: member of 'data' for command 'oops' uses reserved name 'has-a'
tests/qapi-schema/reserved-member-q.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-q.json: In struct 'Foo': -tests/qapi-schema/reserved-member-q.json:4: Member of 'data' for struct 'Foo' uses invalid name 'q-unix' +tests/qapi-schema/reserved-member-q.json:4: member of 'data' for struct 'Foo' uses invalid name 'q-unix'
tests/qapi-schema/reserved-member-u.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-u.json: In struct 'Oops': -tests/qapi-schema/reserved-member-u.json:7: Member of 'data' for struct 'Oops' uses reserved name 'u' +tests/qapi-schema/reserved-member-u.json:7: member of 'data' for struct 'Oops' uses reserved name 'u'
tests/qapi-schema/reserved-member-underscore.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-underscore.json: In struct 'Oops': -tests/qapi-schema/reserved-member-underscore.json:4: Member of 'data' for struct 'Oops' uses invalid name '_oops' +tests/qapi-schema/reserved-member-underscore.json:4: member of 'data' for struct 'Oops' uses invalid name '_oops'
tests/qapi-schema/string-code-point-127.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/string-code-point-127.json:2:14: Funny character in string +tests/qapi-schema/string-code-point-127.json:2:14: funny character in string
tests/qapi-schema/string-code-point-31.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/string-code-point-31.json:2:14: Funny character in string +tests/qapi-schema/string-code-point-31.json:2:14: funny character in string
tests/qapi-schema/string-control.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/string-control.json:2:14: control character \u007f in string
tests/qapi-schema/string-unclosed.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/string-unclosed.json:1:11: missing terminating "'"
tests/qapi-schema/string-unicode.err new file +1 -0
@@ -0,0 +1 @@ +tests/qapi-schema/string-unicode.json:2:14: non-ASCII character in string
tests/qapi-schema/struct-member-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/struct-member-invalid-dict.json: In struct 'foo': -tests/qapi-schema/struct-member-invalid-dict.json:2: Key 'type' is missing from member '*a' of 'data' for struct 'foo' +tests/qapi-schema/struct-member-invalid-dict.json:2: key 'type' is missing from member '*a' of 'data' for struct 'foo'
tests/qapi-schema/struct-member-invalid.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/struct-member-invalid.json: In struct 'foo': -tests/qapi-schema/struct-member-invalid.json:1: Member 'a' of 'data' for struct 'foo' should be a type name +tests/qapi-schema/struct-member-invalid.json:1: member 'a' of 'data' for struct 'foo' should be a type name
tests/qapi-schema/trailing-comma-list.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/trailing-comma-list.json:2:36: Expected '{', '[', string, boolean or 'null' +tests/qapi-schema/trailing-comma-list.json:2:36: expected '{', '[', string, boolean or 'null'
tests/qapi-schema/trailing-comma-object.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/trailing-comma-object.json:2:38: Expected string +tests/qapi-schema/trailing-comma-object.json:2:38: expected string
tests/qapi-schema/unclosed-list.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/unclosed-list.json:1:20: Expected ',' or ']' +tests/qapi-schema/unclosed-list.json:1:20: expected ',' or ']'
tests/qapi-schema/unclosed-object.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/unclosed-object.json:1:21: Expected ',' or '}' +tests/qapi-schema/unclosed-object.json:1:21: expected ',' or '}'
tests/qapi-schema/unclosed-string.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/unclosed-string.json:1:11: Missing terminating "'" +tests/qapi-schema/unclosed-string.json:1:11: missing terminating "'"
tests/qapi-schema/union-base-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-base-empty.json: In union 'TestUnion': -tests/qapi-schema/union-base-empty.json:5: Discriminator 'type' is not a member of 'base' +tests/qapi-schema/union-base-empty.json:5: discriminator 'type' is not a member of 'base'
tests/qapi-schema/union-base-no-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-base-no-discriminator.json: In union 'TestUnion': -tests/qapi-schema/union-base-no-discriminator.json:11: Simple union 'TestUnion' must not have a base +tests/qapi-schema/union-base-no-discriminator.json:11: simple union 'TestUnion' must not have a base
tests/qapi-schema/union-branch-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-branch-case.json: In union 'Uni': -tests/qapi-schema/union-branch-case.json:2: Member of union 'Uni' uses uppercase in name 'Branch' +tests/qapi-schema/union-branch-case.json:2: member of union 'Uni' uses uppercase in name 'Branch'
tests/qapi-schema/union-branch-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-branch-invalid-dict.json: In union 'UnionInvalidBranch': -tests/qapi-schema/union-branch-invalid-dict.json:2: Key 'type' is missing from member 'integer' of union 'UnionInvalidBranch' +tests/qapi-schema/union-branch-invalid-dict.json:2: key 'type' is missing from member 'integer' of union 'UnionInvalidBranch'
tests/qapi-schema/union-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-empty.json: In union 'Union': -tests/qapi-schema/union-empty.json:2: Union 'Union' has no branches +tests/qapi-schema/union-empty.json:2: union 'Union' has no branches
tests/qapi-schema/union-optional-branch.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-optional-branch.json: In union 'Union': -tests/qapi-schema/union-optional-branch.json:2: Member of union 'Union' does not allow optional name '*a' +tests/qapi-schema/union-optional-branch.json:2: member of union 'Union' does not allow optional name '*a'
tests/qapi-schema/union-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-unknown.json: In union 'Union': -tests/qapi-schema/union-unknown.json:2: Member 'unknown' of union 'Union' uses unknown type 'MissingType' +tests/qapi-schema/union-unknown.json:2: member 'unknown' of union 'Union' uses unknown type 'MissingType'
tests/qapi-schema/unknown-escape.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/unknown-escape.json:3:21: Unknown escape \x +tests/qapi-schema/unknown-escape.json:3:21: unknown escape \x
tests/qapi-schema/unknown-expr-key.err +1 -1
@@ -1,2 +1,2 @@ -tests/qapi-schema/unknown-expr-key.json:2: Unknown keys 'bogus', 'phony' in struct 'bar' +tests/qapi-schema/unknown-expr-key.json:2: unknown keys 'bogus', 'phony' in struct 'bar' Valid keys are 'base', 'data', 'features', 'if', 'struct'.
Signature · 1 line
2.21.0
Re: [PATCH 06/25] qapi: Change frontend error messages to start with lower case
Quoted 9 lines · Markus Armbruster
Starting error messages with a capital letter complicates things when text can get interpolated both at the beginning and in the middle of an error message. The next patch will do that. Switch to lower case to keep it simpler.
For what it's worth, the GNU Coding Standards advise the message "should not begin with a capital letter when it follows a program name and/or file name, because that isn’t the beginning of a sentence. (The sentence conceptually starts at the beginning of the line.)"
We're inconsistent throughout the code base, but this is one place where I like the GCS rationale. Fixing it everywhere may not be worth the churn, but fixing it within the subset of the qapi generator is worthwhile.
Quoted 6 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 175 +++++++++--------- tests/qapi-schema/alternate-any.err | 2 +-
Quoted 6 lines
tests/qapi-schema/unknown-expr-key.err | 2 +- 125 files changed, 215 insertions(+), 204 deletions(-) create mode 100644 tests/qapi-schema/escape-too-big.err create mode 100644 tests/qapi-schema/string-control.err create mode 100644 tests/qapi-schema/string-unclosed.err create mode 100644 tests/qapi-schema/string-unicode.err
Umm, what's going on here?
You'll want to either drop these files (if they were leftovers in your working directory from previous points in time), or defer their addition to when the corresponding actual tests exist.
scripts/qapi/common.py class QAPISchemaParser(object): · line 651
Quoted 6 lines
def
get_doc(self, info):
if self.val != '##':scripts/qapi/common.py +2
-2- raise QAPIParseError(self, "Junk after '##' at start of " - "documentation comment") + raise QAPIParseError( + self, "junk after '##' at start of documentation comment")
Reformatting like this also makes grepping for a particular message easier.
scripts/qapi/common.py def check_union(expr, info): · line 874
Quoted 9 lines
scripts/qapi/common.py +2
-2@@ -868,8 +869,8 @@ def check_union(expr, info): enum_values = members.keys() allow_metas = ['built-in', 'union', 'alternate', 'struct', 'enum'] if base is not None: - raise QAPISemError(info, "Simple union '%s' must not have a base" % - name) + raise QAPISemError( + info, "simple union '%s' must not have a base" % name)
A bit odd that you reformat here to get the second argument all on one line...
scripts/qapi/common.py def check_union(expr, info): · line 883
Quoted 9 lines
scripts/qapi/common.py +1
-1# Else, it's a flat union. else:@@ -878,46 +879,47 @@ def check_union(expr, info): base, allow_dict=name, allow_metas=['struct']) if not base: - raise QAPISemError(info, "Flat union '%s' must have a base" + raise QAPISemError(info, "flat union '%s' must have a base" % name)
...but not here. The reformatting is not the primary focus of the patch, and doesn't hurt semantically whether or not you do it, but maybe it is worth calling out in the commit message the criteria you used for deciding when to reformat, and/or make the patch strive for more consistency. I'll leave that up to you; fixing the spurious new files, and making your choice of where to place the linebreaks, doesn't affect my ability to offer:
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 06/25] qapi: Change frontend error messages to start with lower case
Quoted 21 lines · Eric Blake
Quoted 9 lines · Markus Armbruster
Starting error messages with a capital letter complicates things when text can get interpolated both at the beginning and in the middle of an error message. The next patch will do that. Switch to lower case to keep it simpler.
For what it's worth, the GNU Coding Standards advise the message "should not begin with a capital letter when it follows a program name and/or file name, because that isn’t the beginning of a sentence. (The sentence conceptually starts at the beginning of the line.)"
We're inconsistent throughout the code base, but this is one place where I like the GCS rationale. Fixing it everywhere may not be worth the churn, but fixing it within the subset of the qapi generator is worthwhile.
Quoted 5 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 175 +++++++++--------- tests/qapi-schema/alternate-any.err | 2 +-
Quoted 8 lines
Quoted 6 lines
tests/qapi-schema/unknown-expr-key.err | 2 +- 125 files changed, 215 insertions(+), 204 deletions(-) create mode 100644 tests/qapi-schema/escape-too-big.err create mode 100644 tests/qapi-schema/string-control.err create mode 100644 tests/qapi-schema/string-unclosed.err create mode 100644 tests/qapi-schema/string-unicode.errUmm, what's going on here?
Accident.
Quoted 3 lines
You'll want to either drop these files (if they were leftovers in your working directory from previous points in time), or defer their addition to when the corresponding actual tests exist.
I'll drop them,
Quoted 23 lines
scripts/qapi/common.py class QAPISchemaParser(object): · line 651
Quoted 6 lines
def
get_doc(self, info):
if self.val != '##':scripts/qapi/common.py +2
-2- raise QAPIParseError(self, "Junk after '##' at start of " - "documentation comment") + raise QAPIParseError( + self, "junk after '##' at start of documentation comment")Reformatting like this also makes grepping for a particular message easier.
scripts/qapi/common.py def check_union(expr, info): · line 874
Quoted 9 lines
scripts/qapi/common.py +2
-2@@ -868,8 +869,8 @@ def check_union(expr, info): enum_values = members.keys() allow_metas = ['built-in', 'union', 'alternate', 'struct', 'enum'] if base is not None: - raise QAPISemError(info, "Simple union '%s' must not have a base" % - name) + raise QAPISemError( + info, "simple union '%s' must not have a base" % name)A bit odd that you reformat here to get the second argument all on one line...
Quoted 15 lines
scripts/qapi/common.py def check_union(expr, info): · line 883
Quoted 9 lines
scripts/qapi/common.py +1
-1# Else, it's a flat union. else:@@ -878,46 +879,47 @@ def check_union(expr, info): base, allow_dict=name, allow_metas=['struct']) if not base: - raise QAPISemError(info, "Flat union '%s' must have a base" + raise QAPISemError(info, "flat union '%s' must have a base" % name)...but not here. The reformatting is not the primary focus of the patch, and doesn't hurt semantically whether or not you do it, but maybe it is worth calling out in the commit message the criteria you used for deciding when to reformat, and/or make the patch strive for more consistency.
I admit I wobble between
raise QAPISemError(info, "some lengthy error message text with %s"
% argument)
and
raise QAPISemError(info,
"some lengthy error message text with %s" % argument)
and
raise QAPISemError(
info, "some lengthy error message text with %s" % argument)
The first looks okay, but as a rule, lines should be broken at an operator with lowest precedence.
The second tends to produce long lines.
I'm still getting used to the third.
Quoted 5 lines
I'll leave that up to you; fixing the spurious new files,
and making your choice of where to place the linebreaks, doesn't affect my ability to offer:Reviewed-by Eric Blake <[email protected]>
I'll have another look.
Thanks!
PATCH 7/25 qapi: Improve reporting of member name clashes
In reply to Markus ArmbrusterWe report name clashes like this:
struct-base-clash.json: In struct 'Sub':
struct-base-clash.json:5: 'name' (member of Sub) collides with 'name' (member of Base)
The "(member of Sub)" is redundant with "In struct 'Sub'". Comes from QAPISchemaMember.describe(). Pass info to it, so it can detect the redundancy and avoid it. Result:
struct-base-clash.json: In struct 'Sub':
struct-base-clash.json:5: member 'name' collides with member 'name' of type 'Base'
--- scripts/qapi/common.py | 35 ++++++++++++------- tests/qapi-schema/alternate-clash.err | 2 +- tests/qapi-schema/args-name-clash.err | 2 +- tests/qapi-schema/enum-clash-member.err | 2 +- tests/qapi-schema/features-duplicate-name.err | 2 +- tests/qapi-schema/flat-union-bad-base.err | 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-clash-branches.err | 2 +- 10 files changed, 31 insertions(+), 22 deletions(-)
scripts/qapi/common.py +22 -13
@@ -1570,31 +1570,40 @@ class QAPISchemaMember(object): def check_clash(self, info, seen): cname = c_name(self.name) if cname in seen: - raise QAPISemError(info, "%s collides with %s" % - (self.describe(), seen[cname].describe())) + raise QAPISemError( + info, "%s collides with %s" + % (self.describe(info), seen[cname].describe(info))) seen[cname] = self - def _pretty_defined_in(self): + def describe(self, info): + role = self.role defined_in = self.defined_in + assert defined_in + if defined_in.startswith('q_obj_'): # See QAPISchema._make_implicit_object_type() - reverse the # mapping there to create a nice human-readable description defined_in = defined_in[6:] if defined_in.endswith('-arg'): - return '(parameter of %s)' % defined_in[:-4] + # Implicit type created for a command's dict 'data' + assert role == 'member' + role = 'parameter' elif defined_in.endswith('-base'): - return '(base of %s)' % defined_in[:-5] + # Implicit type created for a flat union's dict 'base' + role = 'base ' + role else: + # Implicit type created for a simple union's branch assert defined_in.endswith('-wrapper') # Unreachable and not implemented assert False - if defined_in.endswith('Kind'): + elif defined_in.endswith('Kind'): # See QAPISchema._make_implicit_enum_type() - return '(branch of %s)' % defined_in[:-4] - return '(%s of %s)' % (self.role, defined_in) - - def describe(self): - return "'%s' %s" % (self.name, self._pretty_defined_in()) + # Implicit enum created for simple union's branches + assert role == 'value' + role = 'branch' + elif defined_in != info.defn_name: + return "%s '%s' of type '%s'" % (role, self.name, defined_in) + return "%s '%s'" % (role, self.name) class QAPISchemaEnumMember(QAPISchemaMember):
@@ -1866,7 +1875,7 @@ class QAPISchema(object): for v in values] def _make_implicit_enum_type(self, name, info, ifcond, values): - # See also QAPISchemaObjectTypeMember._pretty_defined_in() + # See also QAPISchemaObjectTypeMember.describe() name = name + 'Kind' # Use namespace reserved by add_name() self._def_entity(QAPISchemaEnumType( name, info, None, ifcond, self._make_enum_members(values), None))
@@ -1882,7 +1891,7 @@ class QAPISchema(object): role, members): if not members: return None - # See also QAPISchemaObjectTypeMember._pretty_defined_in() + # See also QAPISchemaObjectTypeMember.describe() name = 'q_obj_%s-%s' % (name, role) typ = self.lookup_entity(name, QAPISchemaObjectType) if typ:
tests/qapi-schema/alternate-clash.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-clash.json: In alternate 'Alt1': -tests/qapi-schema/alternate-clash.json:7: 'a_b' (branch of Alt1) collides with 'a-b' (branch of Alt1) +tests/qapi-schema/alternate-clash.json:7: branch 'a_b' collides with branch 'a-b'
tests/qapi-schema/args-name-clash.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-name-clash.json: In command 'oops': -tests/qapi-schema/args-name-clash.json:4: 'a_b' (parameter of oops) collides with 'a-b' (parameter of oops) +tests/qapi-schema/args-name-clash.json:4: parameter 'a_b' collides with parameter 'a-b'
tests/qapi-schema/enum-clash-member.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-clash-member.json: In enum 'MyEnum': -tests/qapi-schema/enum-clash-member.json:2: 'one_two' (value of MyEnum) collides with 'one-two' (value of MyEnum) +tests/qapi-schema/enum-clash-member.json:2: value 'one_two' collides with value 'one-two'
tests/qapi-schema/features-duplicate-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-duplicate-name.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-duplicate-name.json:1: 'foo' (feature of FeatureStruct0) collides with 'foo' (feature of FeatureStruct0) +tests/qapi-schema/features-duplicate-name.json:1: feature 'foo' collides with feature 'foo'
tests/qapi-schema/flat-union-bad-base.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-bad-base.json: In union 'TestUnion': -tests/qapi-schema/flat-union-bad-base.json:8: 'string' (member of TestTypeA) collides with 'string' (base of TestUnion) +tests/qapi-schema/flat-union-bad-base.json:8: member 'string' of type 'TestTypeA' collides with base member 'string'
tests/qapi-schema/flat-union-clash-member.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-clash-member.json: In union 'TestUnion': -tests/qapi-schema/flat-union-clash-member.json:11: 'name' (member of Branch1) collides with 'name' (member of Base) +tests/qapi-schema/flat-union-clash-member.json:11: member 'name' of type 'Branch1' collides with member 'name' of type 'Base'
tests/qapi-schema/struct-base-clash-deep.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/struct-base-clash-deep.json: In struct 'Sub': -tests/qapi-schema/struct-base-clash-deep.json:10: 'name' (member of Sub) collides with 'name' (member of Base) +tests/qapi-schema/struct-base-clash-deep.json:10: member 'name' collides with member 'name' of type 'Base'
tests/qapi-schema/struct-base-clash.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/struct-base-clash.json: In struct 'Sub': -tests/qapi-schema/struct-base-clash.json:5: 'name' (member of Sub) collides with 'name' (member of Base) +tests/qapi-schema/struct-base-clash.json:5: member 'name' collides with member 'name' of type 'Base'
tests/qapi-schema/union-clash-branches.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-clash-branches.json: In union 'TestUnion': -tests/qapi-schema/union-clash-branches.json:4: 'a_b' (branch of TestUnion) collides with 'a-b' (branch of TestUnion) +tests/qapi-schema/union-clash-branches.json:4: branch 'a_b' collides with branch 'a-b'
Signature · 1 line
2.21.0
Re: [PATCH 07/25] qapi: Improve reporting of member name clashes
Quoted 9 lines · Markus Armbruster
We report name clashes like this:
struct-base-clash.json: In struct 'Sub':
struct-base-clash.json:5: 'name' (member of Sub) collides with 'name' (member of Base)The "(member of Sub)" is redundant with "In struct 'Sub'". Comes from
QAPISchemaMember.describe(). Pass info to it, so it can detect the redundancy and avoid it. Result:
Quoted 5 lines
struct-base-clash.json: In struct 'Sub':
struct-base-clash.json:5: member 'name' collides with member 'name' of type 'Base'Signed-off-by Markus Armbruster <[email protected]>---
The resulting error messages are indeed nicer.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 8/25 qapi: Reorder check_FOO() parameters for consistency
In reply to Markus ArmbrusterMost check_FOO() take the thing being checked as first argument. check_name(), check_type(), check_known_keys() don't. Clean that up.
While there, drop a "Todo" comment that should have been dropped in commit 87adbbffd4 "qapi: add a dictionary form for TYPE".
--- scripts/qapi/common.py | 80 ++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 41 deletions(-)
scripts/qapi/common.py +39 -41
@@ -705,7 +705,7 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') -def check_name(info, source, name, +def check_name(name, info, source, allow_optional=False, enum_member=False, permit_upper=False): global valid_name membername = name
@@ -733,7 +733,7 @@ def check_name(info, source, name, def add_name(name, info, meta): global all_names - check_name(info, "'%s'" % meta, name, permit_upper=True) + check_name(name, info, "'%s'" % meta, permit_upper=True) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:
@@ -767,7 +767,7 @@ def check_if(expr, info): check_if_str(ifcond, info) -def check_type(info, source, value, +def check_type(value, info, source, allow_array=False, allow_dict=False, allow_metas=[]): global all_names
@@ -805,19 +805,17 @@ def check_type(info, source, value, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name(info, "member of %s" % source, key, + check_name(key, info, "member of %s" % source, allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError( info, "member of %s uses reserved name '%s'" % (source, key)) - # Todo: allow dictionaries to represent default values of - # an optional argument. - check_known_keys(info, "member '%s' of %s" % (key, source), - arg, ['type'], ['if']) + check_known_keys(arg, info, "member '%s' of %s" % (key, source), + ['type'], ['if']) check_if(arg, info) normalize_if(arg) - check_type(info, "member '%s' of %s" % (key, source), - arg['type'], allow_array=True, + check_type(arg['type'], info, "member '%s' of %s" % (key, source), + allow_array=True, allow_metas=['built-in', 'union', 'alternate', 'struct', 'enum'])
@@ -829,15 +827,15 @@ def check_command(expr, info): args_meta = ['struct'] if boxed: args_meta += ['union'] - check_type(info, "'data' for command '%s'" % name, - expr.get('data'), allow_dict=not boxed, - allow_metas=args_meta) + check_type(expr.get('data'), info, + "'data' for command '%s'" % name, + allow_dict=not boxed, allow_metas=args_meta) returns_meta = ['union', 'struct'] if name in returns_whitelist: returns_meta += ['built-in', 'alternate', 'enum'] - check_type(info, "'returns' for command '%s'" % name, - expr.get('returns'), allow_array=True, - allow_metas=returns_meta) + check_type(expr.get('returns'), info, + "'returns' for command '%s'" % name, + allow_array=True, allow_metas=returns_meta) def check_event(expr, info):
@@ -847,9 +845,9 @@ def check_event(expr, info): meta = ['struct'] if boxed: meta += ['union'] - check_type(info, "'data' for event '%s'" % name, - expr.get('data'), allow_dict=not boxed, - allow_metas=meta) + check_type(expr.get('data'), info, + "'data' for event '%s'" % name, + allow_dict=not boxed, allow_metas=meta) def enum_get_names(expr):
@@ -875,9 +873,8 @@ def check_union(expr, info): # Else, it's a flat union. else: # The object must have a string or dictionary 'base'. - check_type(info, "'base' for union '%s'" % name, - base, allow_dict=name, - allow_metas=['struct']) + check_type(base, info, "'base' for union '%s'" % name, + allow_dict=name, allow_metas=['struct']) if not base: raise QAPISemError(info, "flat union '%s' must have a base" % name)
@@ -886,8 +883,8 @@ def check_union(expr, info): # The value of member 'discriminator' must name a non-optional # member of the base struct. - check_name(info, "discriminator of flat union '%s'" % name, - discriminator) + check_name(discriminator, info, + "discriminator of flat union '%s'" % name) discriminator_value = base_members.get(discriminator) if not discriminator_value: raise QAPISemError(info,
@@ -912,15 +909,16 @@ def check_union(expr, info): raise QAPISemError(info, "union '%s' has no branches" % name) for (key, value) in members.items(): - check_name(info, "member of union '%s'" % name, key) + check_name(key, info, "member of union '%s'" % name) - check_known_keys(info, "member '%s' of union '%s'" % (key, name), - value, ['type'], ['if']) + check_known_keys(value, info, + "member '%s' of union '%s'" % (key, name), + ['type'], ['if']) check_if(value, info) normalize_if(value) # Each value must name a known type - check_type(info, "member '%s' of union '%s'" % (key, name), - value['type'], + check_type(value['type'], info, + "member '%s' of union '%s'" % (key, name), allow_array=not base, allow_metas=allow_metas) # If the discriminator names an enum type, then all members
@@ -942,16 +940,16 @@ def check_alternate(expr, info): raise QAPISemError(info, "alternate '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): - check_name(info, "member of alternate '%s'" % name, key) - check_known_keys(info, + check_name(key, info, "member of alternate '%s'" % name) + check_known_keys(value, info, "member '%s' of alternate '%s'" % (key, name), - value, ['type'], ['if']) + ['type'], ['if']) check_if(value, info) normalize_if(value) typ = value['type'] # Ensure alternates have no type conflicts. - check_type(info, "member '%s' of alternate '%s'" % (key, name), typ, + check_type(typ, info, "member '%s' of alternate '%s'" % (key, name), allow_metas=['built-in', 'union', 'struct', 'enum']) qtype = find_alternate_member_qtype(typ) if not qtype:
@@ -996,11 +994,11 @@ def check_enum(expr, info): permit_upper = name in name_case_whitelist for member in members: - check_known_keys(info, "member of enum '%s'" % name, member, + check_known_keys(member, info, "member of enum '%s'" % name, ['name'], ['if']) check_if(member, info) normalize_if(member) - check_name(info, "member of enum '%s'" % name, member['name'], + check_name(member['name'], info, "member of enum '%s'" % name, enum_member=True, permit_upper=permit_upper)
@@ -1009,9 +1007,9 @@ def check_struct(expr, info): members = expr['data'] features = expr.get('features') - check_type(info, "'data' for struct '%s'" % name, members, + check_type(members, info, "'data' for struct '%s'" % name, allow_dict=name) - check_type(info, "'base' for struct '%s'" % name, expr.get('base'), + check_type(expr.get('base'), info, "'base' for struct '%s'" % name, allow_metas=['struct']) if features:
@@ -1020,15 +1018,15 @@ def check_struct(expr, info): info, "struct '%s' requires an array for 'features'" % name) for f in features: assert isinstance(f, dict) - check_known_keys(info, "feature of struct %s" % name, f, + check_known_keys(f, info, "feature of struct %s" % name, ['name'], ['if']) check_if(f, info) normalize_if(f) - check_name(info, "feature of struct %s" % name, f['name']) + check_name(f['name'], info, "feature of struct %s" % name) -def check_known_keys(info, source, value, required, optional): +def check_known_keys(value, info, source, required, optional): def pprint(elems): return ', '.join("'" + e + "'" for e in sorted(elems))
@@ -1052,7 +1050,7 @@ def check_keys(expr, info, meta, required, optional=[]): raise QAPISemError(info, "'%s' key must have a string value" % meta) required = required + [meta] source = "%s '%s'" % (meta, name) - check_known_keys(info, source, expr, required, optional) + check_known_keys(expr, info, source, required, optional) for (key, value) in expr.items(): if key in ['gen', 'success-response'] and value is not False: raise QAPISemError(info,
Signature · 1 line
2.21.0
Re: [PATCH 08/25] qapi: Reorder check_FOO() parameters for consistency
Quoted 11 lines · Markus Armbruster
Most
check_FOO()take the thing being checked as first argument.check_name(),check_type(),check_known_keys()don't. Clean that up.While there, drop a "Todo" comment that should have been dropped in commit
87adbbffd4"qapi: add a dictionary form for TYPE".Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 80 ++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 41 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 9/25 qapi: Improve reporting of invalid name errors
In reply to Markus ArmbrusterSplit check_name() into check_name_is_str() and check_name_str(), keep check_name() as a wrapper.
Move add_name()'s call into its caller check_exprs(), and inline.
This permits delaying check_name_str() there, so its error message gains an "in definition" line.
--- scripts/qapi/common.py | 20 ++++++++++++++++---- tests/qapi-schema/bad-ident.err | 1 + tests/qapi-schema/command-int.err | 1 + tests/qapi-schema/redefined-builtin.err | 1 + tests/qapi-schema/redefined-command.err | 1 + tests/qapi-schema/redefined-event.err | 1 + tests/qapi-schema/redefined-type.err | 1 + tests/qapi-schema/reserved-command-q.err | 1 + tests/qapi-schema/reserved-type-kind.err | 1 + tests/qapi-schema/reserved-type-list.err | 1 + 10 files changed, 25 insertions(+), 4 deletions(-)
scripts/qapi/common.py +16 -4
@@ -707,11 +707,22 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' def check_name(name, info, source, allow_optional=False, enum_member=False, permit_upper=False): + check_name_is_str(name, info, source) + check_name_str(name, info, source, + allow_optional, enum_member, permit_upper) + + +def check_name_is_str(name, info, source): + if not isinstance(name, str): + raise QAPISemError(info, "%s requires a string name" % source) + + +def check_name_str(name, info, source, + allow_optional=False, enum_member=False, + permit_upper=False): global valid_name membername = name - if not isinstance(name, str): - raise QAPISemError(info, "%s requires a string name" % source) if name.startswith('*'): membername = name[1:] if not allow_optional:
@@ -733,7 +744,6 @@ def check_name(name, info, source, def add_name(name, info, meta): global all_names - check_name(name, info, "'%s'" % meta, permit_upper=True) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names:
@@ -1148,8 +1158,10 @@ def check_exprs(exprs): raise QAPISemError(info, "expression is missing metatype") normalize_if(expr) name = expr[meta] - add_name(name, info, meta) + check_name_is_str(name, info, "'%s'" % meta) info.set_defn(meta, name) + check_name_str(name, info, "'%s'" % meta, permit_upper=True) + add_name(name, info, meta) if doc and doc.symbol != name: raise QAPISemError( info,
tests/qapi-schema/bad-ident.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/bad-ident.json: In struct '*oops': tests/qapi-schema/bad-ident.json:2: 'struct' does not allow optional name '*oops'
tests/qapi-schema/command-int.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/command-int.json: In command 'int': tests/qapi-schema/command-int.json:2: built-in 'int' is already defined
tests/qapi-schema/redefined-builtin.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/redefined-builtin.json: In struct 'size': tests/qapi-schema/redefined-builtin.json:2: built-in 'size' is already defined
tests/qapi-schema/redefined-command.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/redefined-command.json: In command 'foo': tests/qapi-schema/redefined-command.json:3: command 'foo' is already defined
tests/qapi-schema/redefined-event.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/redefined-event.json: In event 'EVENT_A': tests/qapi-schema/redefined-event.json:3: event 'EVENT_A' is already defined
tests/qapi-schema/redefined-type.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/redefined-type.json: In enum 'foo': tests/qapi-schema/redefined-type.json:3: struct 'foo' is already defined
tests/qapi-schema/reserved-command-q.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-command-q.json: In command 'q-unix': tests/qapi-schema/reserved-command-q.json:5: 'command' uses invalid name 'q-unix'
tests/qapi-schema/reserved-type-kind.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-type-kind.json: In enum 'UnionKind': tests/qapi-schema/reserved-type-kind.json:2: enum 'UnionKind' should not end in 'Kind'
tests/qapi-schema/reserved-type-list.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/reserved-type-list.json: In struct 'FooList': tests/qapi-schema/reserved-type-list.json:5: struct 'FooList' should not end in 'List'
Signature · 1 line
2.21.0
Re: [PATCH 09/25] qapi: Improve reporting of invalid name errors
Quoted 10 lines · Markus Armbruster
Split
check_name()intocheck_name_is_str()andcheck_name_str(), keepcheck_name()as a wrapper.Move add_name()'s call into its caller
check_exprs(), and inline.This permits delaying
check_name_str()there, so its error message gains an "in definition" line.Signed-off-by Markus Armbruster <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 10/25 qapi: Use check_name_str() where it suffices
In reply to Markus ArmbrusterReplace check_name() by check_name_str() where the name is known to be a string.
--- scripts/qapi/common.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
scripts/qapi/common.py +4 -5
@@ -815,8 +815,8 @@ def check_type(value, info, source, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name(key, info, "member of %s" % source, - allow_optional=True, permit_upper=permit_upper) + check_name_str(key, info, "member of %s" % source, + allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError( info, "member of %s uses reserved name '%s'" % (source, key))
@@ -919,8 +919,7 @@ def check_union(expr, info): raise QAPISemError(info, "union '%s' has no branches" % name) for (key, value) in members.items(): - check_name(key, info, "member of union '%s'" % name) - + check_name_str(key, info, "member of union '%s'" % name) check_known_keys(value, info, "member '%s' of union '%s'" % (key, name), ['type'], ['if'])
@@ -950,7 +949,7 @@ def check_alternate(expr, info): raise QAPISemError(info, "alternate '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): - check_name(key, info, "member of alternate '%s'" % name) + check_name_str(key, info, "member of alternate '%s'" % name) check_known_keys(value, info, "member '%s' of alternate '%s'" % (key, name), ['type'], ['if'])
Signature · 1 line
2.21.0
Re: [PATCH 10/25] qapi: Use check_name_str() where it suffices
Quoted 8 lines · Markus Armbruster
Replace
check_name()bycheck_name_str()where the name is known to be a string.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 11/25 qapi: Report invalid '*' prefix like any other invalid name
In reply to Markus ArmbrusterThe special "does not allow optional name" error is well meant, but confusing in practice. Drop it.
--- scripts/qapi/common.py | 6 ++---- tests/qapi-schema/bad-ident.err | 2 +- tests/qapi-schema/flat-union-discriminator-bad-name.err | 2 +- tests/qapi-schema/flat-union-discriminator-bad-name.json | 2 +- tests/qapi-schema/union-optional-branch.err | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-)
scripts/qapi/common.py +2 -4
@@ -723,11 +723,8 @@ def check_name_str(name, info, source, global valid_name membername = name - if name.startswith('*'): + if allow_optional and name.startswith('*'): membername = name[1:] - if not allow_optional: - raise QAPISemError(info, "%s does not allow optional name '%s'" - % (source, name)) # Enum members can start with a digit, because the generated C # code always prefixes it with the enum name if enum_member and membername[0].isdigit():
@@ -740,6 +737,7 @@ def check_name_str(name, info, source, if not permit_upper and name.lower() != name: raise QAPISemError( info, "%s uses uppercase in name '%s'" % (source, name)) + assert not membername.startswith('*') def add_name(name, info, meta):
tests/qapi-schema/bad-ident.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/bad-ident.json: In struct '*oops': -tests/qapi-schema/bad-ident.json:2: 'struct' does not allow optional name '*oops' +tests/qapi-schema/bad-ident.json:2: 'struct' uses invalid name '*oops'
tests/qapi-schema/flat-union-discriminator-bad-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-discriminator-bad-name.json: In union 'MyUnion': -tests/qapi-schema/flat-union-discriminator-bad-name.json:7: discriminator of flat union 'MyUnion' does not allow optional name '*switch' +tests/qapi-schema/flat-union-discriminator-bad-name.json:7: discriminator of flat union 'MyUnion' uses invalid name '*switch'
tests/qapi-schema/flat-union-discriminator-bad-name.json +1 -1
@@ -1,5 +1,5 @@ # discriminator '*switch' isn't a member of base, 'switch' is -# reports "does not allow optional name", which is good enough +# reports "uses invalid name", which is good enough { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } }
tests/qapi-schema/union-optional-branch.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-optional-branch.json: In union 'Union': -tests/qapi-schema/union-optional-branch.json:2: member of union 'Union' does not allow optional name '*a' +tests/qapi-schema/union-optional-branch.json:2: member of union 'Union' uses invalid name '*a'
Signature · 1 line
2.21.0
Re: [PATCH 11/25] qapi: Report invalid '*' prefix like any other invalid name
Quoted 5 lines · Markus Armbruster
The special "does not allow optional name" error is well meant, but confusing in practice. Drop it.
Signed-off-by Markus Armbruster <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 12/25 qapi: Move check for reserved names out of add_name()
In reply to Markus ArmbrusterThe checks for reserved names are spread far and wide. Move one from add_name() to new check_defn_name_str(). This is a first step towards collecting them all in dedicated name checking functions next to check_name().
While there, drop the quotes around the meta-type in check_name_str()'s error messages: "'command' uses ... name 'NAME'" becomes "command uses ... name 'NAME'".
--- scripts/qapi/common.py | 16 ++++++++++------ tests/qapi-schema/bad-ident.err | 2 +- tests/qapi-schema/reserved-command-q.err | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-)
scripts/qapi/common.py +10 -6
@@ -740,6 +740,13 @@ def check_name_str(name, info, source, assert not membername.startswith('*') +def check_defn_name_str(name, info, meta): + check_name_str(name, info, meta, permit_upper=True) + if name.endswith('Kind') or name.endswith('List'): + raise QAPISemError(info, "%s '%s' should not end in '%s'" + % (meta, name, name[-4:])) + + def add_name(name, info, meta): global all_names # FIXME should reject names that differ only in '_' vs. '.'
@@ -747,9 +754,6 @@ def add_name(name, info, meta): if name in all_names: raise QAPISemError(info, "%s '%s' is already defined" % (all_names[name], name)) - if name.endswith('Kind') or name.endswith('List'): - raise QAPISemError(info, "%s '%s' should not end in '%s'" - % (meta, name, name[-4:])) all_names[name] = meta
@@ -1157,7 +1161,7 @@ def check_exprs(exprs): name = expr[meta] check_name_is_str(name, info, "'%s'" % meta) info.set_defn(meta, name) - check_name_str(name, info, "'%s'" % meta, permit_upper=True) + check_defn_name_str(name, info, meta) add_name(name, info, meta) if doc and doc.symbol != name: raise QAPISemError(
@@ -1883,13 +1887,13 @@ class QAPISchema(object): def _make_implicit_enum_type(self, name, info, ifcond, values): # See also QAPISchemaObjectTypeMember.describe() - name = name + 'Kind' # Use namespace reserved by add_name() + name = name + 'Kind' # reserved by check_defn_name_str() self._def_entity(QAPISchemaEnumType( name, info, None, ifcond, self._make_enum_members(values), None)) return name def _make_array_type(self, element_type, info): - name = element_type + 'List' # Use namespace reserved by add_name() + name = element_type + 'List' # reserved by check_defn_name_str() if not self.lookup_type(name): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name
tests/qapi-schema/bad-ident.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/bad-ident.json: In struct '*oops': -tests/qapi-schema/bad-ident.json:2: 'struct' uses invalid name '*oops' +tests/qapi-schema/bad-ident.json:2: struct uses invalid name '*oops'
tests/qapi-schema/reserved-command-q.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-command-q.json: In command 'q-unix': -tests/qapi-schema/reserved-command-q.json:5: 'command' uses invalid name 'q-unix' +tests/qapi-schema/reserved-command-q.json:5: command uses invalid name 'q-unix'
Signature · 1 line
2.21.0
Re: [PATCH 12/25] qapi: Move check for reserved names out of add_name()
Quoted 11 lines · Markus Armbruster
The checks for reserved names are spread far and wide. Move one from
add_name()to newcheck_defn_name_str(). This is a first step towards collecting them all in dedicated name checking functions next tocheck_name().While there, drop the quotes around the meta-type in check_name_str()'s error messages: "'command' uses ... name 'NAME'" becomes "command uses ... name 'NAME'".
Signed-off-by Markus Armbruster <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 13/25 qapi: Make check_type()'s array case a bit more obvious
In reply to Markus Armbrustercheck_type() checks the array's contents, then peels off the array and falls through to the "not array" code without resetting allow_array and allow_dict to False. Works because the peeled value is a string, and allow_array and allow_dict aren't used then. Tidy up anyway:
recurse instead, defaulting allow_array and allow_dict to False.
--- scripts/qapi/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/qapi/common.py +2 -1
@@ -794,7 +794,8 @@ def check_type(value, info, source, raise QAPISemError(info, "%s: array type must contain single type name" % source) - value = value[0] + check_type(value[0], info, source, allow_metas=allow_metas) + return # Check if type name for value is okay if isinstance(value, str):
Signature · 1 line
2.21.0
Re: [PATCH 13/25] qapi: Make check_type()'s array case a bit more obvious
Quoted 10 lines · Markus Armbruster
check_type()checks the array's contents, then peels off the array and falls through to the "not array" code without resettingallow_arrayandallow_dictto False. Works because the peeled value is a string, andallow_arrayandallow_dictaren't used then. Tidy up anyway:
recurse instead, defaultingallow_arrayandallow_dictto False.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 16 lines
scripts/qapi/common.py +2
-1@@ -794,7 +794,8 @@ def check_type(value, info, source, raise QAPISemError(info, "%s: array type must contain single type name" % source) - value = value[0] + check_type(value[0], info, source, allow_metas=allow_metas) + return # Check if type name for value is okay if isinstance(value, str):
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 14/25 qapi: Plumb info to the QAPISchemaMember
In reply to Markus ArmbrusterFuture commits will need info in the .check() methods of QAPISchemaMember and its descendants. Get it there.
--- scripts/qapi/common.py | 76 +++++++++++++++++++++++------------------- scripts/qapi/events.py | 2 +- 2 files changed, 43 insertions(+), 35 deletions(-)
scripts/qapi/common.py +42 -34
@@ -1569,9 +1569,10 @@ class QAPISchemaMember(object): """ Represents object members, enum members and features """ role = 'member' - def __init__(self, name, ifcond=None): + def __init__(self, name, info, ifcond=None): assert isinstance(name, str) self.name = name + self.info = info self.ifcond = ifcond or [] self.defined_in = None
@@ -1627,8 +1628,8 @@ class QAPISchemaFeature(QAPISchemaMember): class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, typ, optional, ifcond=None): - QAPISchemaMember.__init__(self, name, ifcond) + def __init__(self, name, info, typ, optional, ifcond=None): + QAPISchemaMember.__init__(self, name, info, ifcond) assert isinstance(typ, str) assert isinstance(optional, bool) self._type_name = typ
@@ -1642,7 +1643,7 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): class QAPISchemaObjectTypeVariants(object): - def __init__(self, tag_name, tag_member, variants): + def __init__(self, tag_name, info, tag_member, variants): # Flat unions pass tag_name but not tag_member. # Simple unions and alternates pass tag_member but not tag_name. # After check(), tag_member is always set, and tag_name remains
@@ -1653,6 +1654,7 @@ class QAPISchemaObjectTypeVariants(object): for v in variants: assert isinstance(v, QAPISchemaObjectTypeVariant) self._tag_name = tag_name + self.info = info self.tag_member = tag_member self.variants = variants
@@ -1672,8 +1674,8 @@ class QAPISchemaObjectTypeVariants(object): cases = set([v.name for v in self.variants]) for m in self.tag_member.type.members: if m.name not in cases: - v = QAPISchemaObjectTypeVariant(m.name, 'q_empty', - m.ifcond) + v = QAPISchemaObjectTypeVariant(m.name, self.info, + 'q_empty', m.ifcond) v.set_defined_in(self.tag_member.defined_in) self.variants.append(v) assert self.variants
@@ -1697,8 +1699,9 @@ class QAPISchemaObjectTypeVariants(object): class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): role = 'branch' - def __init__(self, name, typ, ifcond=None): - QAPISchemaObjectTypeMember.__init__(self, name, typ, False, ifcond) + def __init__(self, name, info, typ, ifcond=None): + QAPISchemaObjectTypeMember.__init__(self, name, info, typ, + False, ifcond) class QAPISchemaAlternateType(QAPISchemaType):
@@ -1874,23 +1877,26 @@ class QAPISchema(object): qtypes = ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] - qtype_values = self._make_enum_members([{'name': n} for n in qtypes]) + qtype_values = self._make_enum_members( + [{'name': n} for n in qtypes], None) self._def_entity(QAPISchemaEnumType('QType', None, None, None, qtype_values, 'QTYPE')) - def _make_features(self, features): - return [QAPISchemaFeature(f['name'], f.get('if')) for f in features] + def _make_features(self, features, info): + return [QAPISchemaFeature(f['name'], info, f.get('if')) + for f in features] - def _make_enum_members(self, values): - return [QAPISchemaEnumMember(v['name'], v.get('if')) + def _make_enum_members(self, values, info): + return [QAPISchemaEnumMember(v['name'], info, v.get('if')) for v in values] def _make_implicit_enum_type(self, name, info, ifcond, values): # See also QAPISchemaObjectTypeMember.describe() name = name + 'Kind' # reserved by check_defn_name_str() self._def_entity(QAPISchemaEnumType( - name, info, None, ifcond, self._make_enum_members(values), None)) + name, info, None, ifcond, self._make_enum_members(values, info), + None)) return name def _make_array_type(self, element_type, info):
@@ -1929,7 +1935,7 @@ class QAPISchema(object): ifcond = expr.get('if') self._def_entity(QAPISchemaEnumType( name, info, doc, ifcond, - self._make_enum_members(data), prefix)) + self._make_enum_members(data, info), prefix)) def _make_member(self, name, typ, ifcond, info): optional = False
@@ -1939,7 +1945,7 @@ class QAPISchema(object): if isinstance(typ, list): assert len(typ) == 1 typ = self._make_array_type(typ[0], info) - return QAPISchemaObjectTypeMember(name, typ, optional, ifcond) + return QAPISchemaObjectTypeMember(name, info, typ, optional, ifcond) def _make_members(self, data, info): return [self._make_member(key, value['type'], value.get('if'), info)
@@ -1951,13 +1957,14 @@ class QAPISchema(object): data = expr['data'] ifcond = expr.get('if') features = expr.get('features', []) - self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, base, - self._make_members(data, info), - None, - self._make_features(features))) + self._def_entity(QAPISchemaObjectType( + name, info, doc, ifcond, base, + self._make_members(data, info), + None, + self._make_features(features, info))) - def _make_variant(self, case, typ, ifcond): - return QAPISchemaObjectTypeVariant(case, typ, ifcond) + def _make_variant(self, case, typ, ifcond, info): + return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) def _make_simple_variant(self, case, typ, ifcond, info): if isinstance(typ, list):
@@ -1966,7 +1973,7 @@ class QAPISchema(object): typ = self._make_implicit_object_type( typ, info, None, self.lookup_type(typ), 'wrapper', [self._make_member('data', typ, None, info)]) - return QAPISchemaObjectTypeVariant(case, typ, ifcond) + return QAPISchemaObjectTypeVariant(case, info, typ, ifcond) def _def_union_type(self, expr, info, doc): name = expr['union']
@@ -1980,7 +1987,8 @@ class QAPISchema(object): name, info, doc, ifcond, 'base', self._make_members(base, info)) if tag_name: - variants = [self._make_variant(key, value['type'], value.get('if')) + variants = [self._make_variant(key, value['type'], + value.get('if'), info) for (key, value) in data.items()] members = [] else:
@@ -1989,26 +1997,26 @@ class QAPISchema(object): for (key, value) in data.items()] enum = [{'name': v.name, 'if': v.ifcond} for v in variants] typ = self._make_implicit_enum_type(name, info, ifcond, enum) - tag_member = QAPISchemaObjectTypeMember('type', typ, False) + tag_member = QAPISchemaObjectTypeMember('type', info, typ, False) members = [tag_member] self._def_entity( QAPISchemaObjectType(name, info, doc, ifcond, base, members, - QAPISchemaObjectTypeVariants(tag_name, - tag_member, - variants), [])) + QAPISchemaObjectTypeVariants( + tag_name, info, tag_member, variants), + [])) def _def_alternate_type(self, expr, info, doc): name = expr['alternate'] data = expr['data'] ifcond = expr.get('if') - variants = [self._make_variant(key, value['type'], value.get('if')) + variants = [self._make_variant(key, value['type'], value.get('if'), + info) for (key, value) in data.items()] - tag_member = QAPISchemaObjectTypeMember('type', 'QType', False) + tag_member = QAPISchemaObjectTypeMember('type', info, 'QType', False) self._def_entity( QAPISchemaAlternateType(name, info, doc, ifcond, - QAPISchemaObjectTypeVariants(None, - tag_member, - variants))) + QAPISchemaObjectTypeVariants( + None, info, tag_member, variants))) def _def_command(self, expr, info, doc): name = expr['command']
@@ -2300,7 +2308,7 @@ const QEnumLookup %(c_name)s_lookup = { def gen_enum(name, members, prefix=None): # append automatically generated _MAX value - enum_members = members + [QAPISchemaEnumMember('_MAX')] + enum_members = members + [QAPISchemaEnumMember('_MAX', None)] ret = mcgen('''
scripts/qapi/events.py +1 -1
@@ -194,7 +194,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); self._event_emit_name)) # Note: we generate the enum member regardless of @ifcond, to # keep the enumeration usable in target-independent code. - self._event_enum_members.append(QAPISchemaEnumMember(name)) + self._event_enum_members.append(QAPISchemaEnumMember(name, None)) def gen_events(schema, output_dir, prefix):
Signature · 1 line
2.21.0
Re: [PATCH 14/25] qapi: Plumb info to the QAPISchemaMember
Quoted 9 lines · Markus Armbruster
Future commits will need info in the .check() methods of QAPISchemaMember and its descendants. Get it there.
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 76 +++++++++++++++++++++++------------------- scripts/qapi/events.py | 2 +- 2 files changed, 43 insertions(+), 35 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 15/25 qapi: Inline check_name() into check_union()
In reply to Markus Armbrustercheck_name() consists of check_name_is_str() and check_name_str(). check_union() relies on the latter to catch optional discriminators. The next commit will replace that by a more straightforward check. Inlining check_name() into check_union() now should make that easier to review.
--- scripts/qapi/common.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/qapi/common.py +4 -2
@@ -896,8 +896,10 @@ def check_union(expr, info): # The value of member 'discriminator' must name a non-optional # member of the base struct. - check_name(discriminator, info, - "discriminator of flat union '%s'" % name) + check_name_is_str(discriminator, info, + "discriminator of flat union '%s'" % name) + check_name_str(discriminator, info, + "discriminator of flat union '%s'" % name) discriminator_value = base_members.get(discriminator) if not discriminator_value: raise QAPISemError(info,
Signature · 1 line
2.21.0
Re: [PATCH 15/25] qapi: Inline check_name() into check_union()
Quoted 11 lines · Markus Armbruster
check_name()consists ofcheck_name_is_str()andcheck_name_str().check_union()relies on the latter to catch optional discriminators. The next commit will replace that by a more straightforward check. Inliningcheck_name()intocheck_union()now should make that easier to review.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 16/25 qapi: Move context-sensitive checking to the proper place
In reply to Markus ArmbrusterWhen we introduced the QAPISchema intermediate representation (commit ac88219a6c7), we took a shortcut: we left check_exprs() & friends alone instead of moving semantic checks into the QAPISchemaFOO.check(). The .check() assert check_exprs() did its job.
Time to finish the conversion job. Move exactly the context-sensitive checks to the .check(). They replace assertions there. Context-free checks stay put.
Fixes the misleading optional tag error demonstrated by test flat-union-optional-discriminator.
A few other error message improve.
--- scripts/qapi/common.py | 422 ++++++++---------- tests/qapi-schema/alternate-any.err | 2 +- .../alternate-conflict-bool-string.err | 2 +- tests/qapi-schema/alternate-conflict-dict.err | 2 +- .../alternate-conflict-enum-bool.err | 2 +- .../alternate-conflict-enum-int.err | 2 +- .../alternate-conflict-num-string.err | 2 +- .../qapi-schema/alternate-conflict-string.err | 2 +- tests/qapi-schema/alternate-nested.err | 2 +- tests/qapi-schema/alternate-unknown.err | 2 +- tests/qapi-schema/args-alternate.err | 2 +- tests/qapi-schema/args-any.err | 2 +- tests/qapi-schema/args-array-unknown.err | 2 +- tests/qapi-schema/args-boxed-string.err | 2 +- tests/qapi-schema/args-int.err | 2 +- tests/qapi-schema/args-member-unknown.err | 2 +- tests/qapi-schema/args-union.err | 2 +- tests/qapi-schema/args-unknown.err | 2 +- tests/qapi-schema/bad-base.err | 2 +- tests/qapi-schema/command-int.err | 2 +- tests/qapi-schema/flat-union-base-any.err | 2 +- tests/qapi-schema/flat-union-base-union.err | 2 +- .../flat-union-discriminator-bad-name.err | 2 +- .../flat-union-discriminator-bad-name.json | 1 - tests/qapi-schema/flat-union-empty.err | 2 +- tests/qapi-schema/flat-union-int-branch.err | 2 +- .../flat-union-invalid-branch-key.err | 2 +- .../flat-union-invalid-if-discriminator.err | 2 +- .../flat-union-optional-discriminator.err | 2 +- .../flat-union-optional-discriminator.json | 1 - .../flat-union-string-discriminator.err | 2 +- tests/qapi-schema/redefined-builtin.err | 2 +- tests/qapi-schema/redefined-type.err | 2 +- tests/qapi-schema/returns-alternate.err | 2 +- tests/qapi-schema/returns-unknown.err | 2 +- tests/qapi-schema/returns-whitelist.err | 2 +- tests/qapi-schema/union-empty.err | 2 +- tests/qapi-schema/union-invalid-base.err | 2 +- tests/qapi-schema/union-unknown.err | 2 +- tests/qapi-schema/union-unknown.json | 2 +- 40 files changed, 228 insertions(+), 270 deletions(-)
scripts/qapi/common.py +191 -231
@@ -21,25 +21,6 @@ import string import sys from collections import OrderedDict -builtin_types = { - 'null': 'QTYPE_QNULL', - 'str': 'QTYPE_QSTRING', - 'int': 'QTYPE_QNUM', - 'number': 'QTYPE_QNUM', - 'bool': 'QTYPE_QBOOL', - 'int8': 'QTYPE_QNUM', - 'int16': 'QTYPE_QNUM', - 'int32': 'QTYPE_QNUM', - 'int64': 'QTYPE_QNUM', - 'uint8': 'QTYPE_QNUM', - 'uint16': 'QTYPE_QNUM', - 'uint32': 'QTYPE_QNUM', - 'uint64': 'QTYPE_QNUM', - 'size': 'QTYPE_QNUM', - 'any': None, # any QType possible, actually - 'QType': 'QTYPE_QSTRING', -} - # Are documentation comments required? doc_required = False
@@ -49,11 +30,6 @@ returns_whitelist = [] # Whitelist of entities allowed to violate case conventions name_case_whitelist = [] -enum_types = {} -struct_types = {} -union_types = {} -all_names = {} - # # Parsing the schema into expressions
@@ -670,34 +646,9 @@ class QAPISchemaParser(object): # -# Semantic analysis of schema expressions -# TODO fold into QAPISchema -# TODO catching name collisions in generated code would be nice +# Check (context-free) schema expression structure # - -def find_base_members(base): - if isinstance(base, dict): - return base - base_struct_define = struct_types.get(base) - if not base_struct_define: - return None - return base_struct_define['data'] - - -# Return the qtype of an alternate branch, or None on error. -def find_alternate_member_qtype(qapi_type): - if qapi_type in builtin_types: - return builtin_types[qapi_type] - elif qapi_type in struct_types: - return 'QTYPE_QDICT' - elif qapi_type in enum_types: - return 'QTYPE_QSTRING' - elif qapi_type in union_types: - return 'QTYPE_QDICT' - return None - - # Names must be letters, numbers, -, and _. They must start with letter, # except for downstream extensions which must start with __RFQDN_. # Dots are only valid in the downstream extension prefix.
@@ -747,16 +698,6 @@ def check_defn_name_str(name, info, meta): % (meta, name, name[-4:])) -def add_name(name, info, meta): - global all_names - # FIXME should reject names that differ only in '_' vs. '.' - # vs. '-', because they're liable to clash in generated C. - if name in all_names: - raise QAPISemError(info, "%s '%s' is already defined" - % (all_names[name], name)) - all_names[name] = meta - - def check_if(expr, info): def check_if_str(ifcond, info):
@@ -780,13 +721,11 @@ def check_if(expr, info): def check_type(value, info, source, - allow_array=False, allow_dict=False, allow_metas=[]): - global all_names - + allow_array=False, allow_dict=False): if value is None: return - # Check if array type for value is okay + # Array type if isinstance(value, list): if not allow_array: raise QAPISemError(info, "%s cannot be an array" % source)
@@ -794,19 +733,14 @@ def check_type(value, info, source, raise QAPISemError(info, "%s: array type must contain single type name" % source) - check_type(value[0], info, source, allow_metas=allow_metas) return - # Check if type name for value is okay + # Type name if isinstance(value, str): - if value not in all_names: - raise QAPISemError(info, "%s uses unknown type '%s'" - % (source, value)) - if not all_names[value] in allow_metas: - raise QAPISemError(info, "%s cannot use %s type '%s'" % - (source, all_names[value], value)) return + # Anonymous type + if not allow_dict: raise QAPISemError(info, "%s should be a type name" % source)
@@ -828,43 +762,28 @@ def check_type(value, info, source, check_if(arg, info) normalize_if(arg) check_type(arg['type'], info, "member '%s' of %s" % (key, source), - allow_array=True, - allow_metas=['built-in', 'union', 'alternate', 'struct', - 'enum']) + allow_array=True) def check_command(expr, info): name = expr['command'] boxed = expr.get('boxed', False) - args_meta = ['struct'] - if boxed: - args_meta += ['union'] check_type(expr.get('data'), info, "'data' for command '%s'" % name, - allow_dict=not boxed, allow_metas=args_meta) - returns_meta = ['union', 'struct'] - if name in returns_whitelist: - returns_meta += ['built-in', 'alternate', 'enum'] + allow_dict=not boxed) check_type(expr.get('returns'), info, "'returns' for command '%s'" % name, - allow_array=True, allow_metas=returns_meta) + allow_array=True) def check_event(expr, info): name = expr['event'] boxed = expr.get('boxed', False) - meta = ['struct'] - if boxed: - meta += ['union'] check_type(expr.get('data'), info, "'data' for event '%s'" % name, - allow_dict=not boxed, allow_metas=meta) - - -def enum_get_names(expr): - return [e['name'] for e in expr['data']] + allow_dict=not boxed) def check_union(expr, info):
@@ -873,55 +792,18 @@ def check_union(expr, info): discriminator = expr.get('discriminator') members = expr['data'] - # Two types of unions, determined by discriminator. - - # With no discriminator it is a simple union. - if discriminator is None: - enum_values = members.keys() - allow_metas = ['built-in', 'union', 'alternate', 'struct', 'enum'] + if discriminator is None: # simple union if base is not None: raise QAPISemError( info, "simple union '%s' must not have a base" % name) - - # Else, it's a flat union. - else: - # The object must have a string or dictionary 'base'. + else: # flat union check_type(base, info, "'base' for union '%s'" % name, - allow_dict=name, allow_metas=['struct']) + allow_dict=name) if not base: raise QAPISemError(info, "flat union '%s' must have a base" % name) - base_members = find_base_members(base) - assert base_members is not None - - # The value of member 'discriminator' must name a non-optional - # member of the base struct. check_name_is_str(discriminator, info, "discriminator of flat union '%s'" % name) - check_name_str(discriminator, info, - "discriminator of flat union '%s'" % name) - discriminator_value = base_members.get(discriminator) - if not discriminator_value: - raise QAPISemError(info, - "discriminator '%s' is not a member of 'base'" - % discriminator) - if discriminator_value.get('if'): - raise QAPISemError( - info, - "the discriminator '%s' for union %s must not be conditional" - % (discriminator, name)) - enum_define = enum_types.get(discriminator_value['type']) - # Do not allow string discriminator - if not enum_define: - raise QAPISemError( - info, - "discriminator '%s' must be of enumeration type" - % discriminator) - enum_values = enum_get_names(enum_define) - allow_metas = ['struct'] - - if (len(enum_values) == 0): - raise QAPISemError(info, "union '%s' has no branches" % name) for (key, value) in members.items(): check_name_str(key, info, "member of union '%s'" % name)
@@ -930,25 +812,14 @@ def check_union(expr, info): ['type'], ['if']) check_if(value, info) normalize_if(value) - # Each value must name a known type check_type(value['type'], info, "member '%s' of union '%s'" % (key, name), - allow_array=not base, allow_metas=allow_metas) - - # If the discriminator names an enum type, then all members - # of 'data' must also be members of the enum type. - if discriminator is not None: - if key not in enum_values: - raise QAPISemError( - info, - "discriminator value '%s' is not found in enum '%s'" - % (key, enum_define['enum'])) + allow_array=not base) def check_alternate(expr, info): name = expr['alternate'] members = expr['data'] - types_seen = {} if len(members) == 0: raise QAPISemError(info,
@@ -960,37 +831,8 @@ def check_alternate(expr, info): ['type'], ['if']) check_if(value, info) normalize_if(value) - typ = value['type'] - - # Ensure alternates have no type conflicts. - check_type(typ, info, "member '%s' of alternate '%s'" % (key, name), - allow_metas=['built-in', 'union', 'struct', 'enum']) - qtype = find_alternate_member_qtype(typ) - if not qtype: - raise QAPISemError( - info, - "alternate '%s' member '%s' cannot use type '%s'" - % (name, key, typ)) - conflicting = set([qtype]) - if qtype == 'QTYPE_QSTRING': - enum_expr = enum_types.get(typ) - if enum_expr: - for v in enum_get_names(enum_expr): - if v in ['on', 'off']: - conflicting.add('QTYPE_QBOOL') - if re.match(r'[-+0-9.]', v): # lazy, could be tightened - conflicting.add('QTYPE_QNUM') - else: - conflicting.add('QTYPE_QNUM') - conflicting.add('QTYPE_QBOOL') - for qt in conflicting: - if qt in types_seen: - raise QAPISemError( - info, - "alternate '%s' member '%s' can't be distinguished " - "from member '%s'" - % (name, key, types_seen[qt])) - types_seen[qt] = key + check_type(value['type'], info, + "member '%s' of alternate '%s'" % (key, name)) def check_enum(expr, info):
@@ -1023,8 +865,7 @@ def check_struct(expr, info): check_type(members, info, "'data' for struct '%s'" % name, allow_dict=name) - check_type(expr.get('base'), info, "'base' for struct '%s'" % name, - allow_metas=['struct']) + check_type(expr.get('base'), info, "'base' for struct '%s'" % name) if features: if not isinstance(features, list):
@@ -1106,13 +947,6 @@ def normalize_if(expr): def check_exprs(exprs): - global all_names - - # Populate name table with names of built-in types - for builtin in builtin_types.keys(): - all_names[builtin] = 'built-in' - - # Learn the types and check for valid expression keys for expr_elem in exprs: expr = expr_elem['expr'] info = expr_elem['info']
@@ -1129,14 +963,12 @@ def check_exprs(exprs): meta = 'enum' check_keys(expr, info, 'enum', ['data'], ['if', 'prefix']) normalize_enum(expr) - enum_types[expr[meta]] = expr elif 'union' in expr: meta = 'union' check_keys(expr, info, 'union', ['data'], ['base', 'discriminator', 'if']) normalize_members(expr.get('base')) normalize_members(expr['data']) - union_types[expr[meta]] = expr elif 'alternate' in expr: meta = 'alternate' check_keys(expr, info, 'alternate', ['data'], ['if'])
@@ -1147,7 +979,6 @@ def check_exprs(exprs): ['base', 'if', 'features']) normalize_members(expr['data']) normalize_features(expr.get('features')) - struct_types[expr[meta]] = expr elif 'command' in expr: meta = 'command' check_keys(expr, info, 'command', [],
@@ -1161,36 +992,29 @@ def check_exprs(exprs): else: raise QAPISemError(info, "expression is missing metatype") normalize_if(expr) + name = expr[meta] check_name_is_str(name, info, "'%s'" % meta) info.set_defn(meta, name) check_defn_name_str(name, info, meta) - add_name(name, info, meta) + if doc and doc.symbol != name: raise QAPISemError( info, "definition of '%s' follows documentation for '%s'" % (name, doc.symbol)) - # Validate that exprs make sense - for expr_elem in exprs: - expr = expr_elem['expr'] - info = expr_elem['info'] - doc = expr_elem.get('doc') - - if 'include' in expr: - continue - if 'enum' in expr: + if meta == 'enum': check_enum(expr, info) - elif 'union' in expr: + elif meta == 'union': check_union(expr, info) - elif 'alternate' in expr: + elif meta == 'alternate': check_alternate(expr, info) - elif 'struct' in expr: + elif meta == 'struct': check_struct(expr, info) - elif 'command' in expr: + elif meta == 'command': check_command(expr, info) - elif 'event' in expr: + elif meta == 'event': check_event(expr, info) else: assert False, 'unexpected meta type'
@@ -1203,9 +1027,12 @@ def check_exprs(exprs): # # Schema compiler frontend +# TODO catching name collisions in generated code would be nice # class QAPISchemaEntity(object): + meta = None + def __init__(self, name, info, doc, ifcond=None): assert name is None or isinstance(name, str) self.name = name
@@ -1246,6 +1073,10 @@ class QAPISchemaEntity(object): def visit(self, visitor): assert self._checked + def describe(self): + assert self.meta + return "%s '%s'" % (self.meta, self.name) + class QAPISchemaVisitor(object): def visit_begin(self, schema):
@@ -1336,8 +1167,14 @@ class QAPISchemaType(QAPISchemaEntity): return None return self.name + def describe(self): + assert self.meta + return "%s type '%s'" % (self.meta, self.name) + class QAPISchemaBuiltinType(QAPISchemaType): + meta = 'built-in' + def __init__(self, name, json_type, c_type): QAPISchemaType.__init__(self, name, None, None) assert not c_type or isinstance(c_type, str)
@@ -1369,6 +1206,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): class QAPISchemaEnumType(QAPISchemaType): + meta = 'enum' + def __init__(self, name, info, doc, ifcond, members, prefix): QAPISchemaType.__init__(self, name, info, doc, ifcond) for m in members:
@@ -1406,6 +1245,8 @@ class QAPISchemaEnumType(QAPISchemaType): class QAPISchemaArrayType(QAPISchemaType): + meta = 'array' + def __init__(self, name, info, element_type): QAPISchemaType.__init__(self, name, info, None, None) assert isinstance(element_type, str)
@@ -1414,8 +1255,9 @@ class QAPISchemaArrayType(QAPISchemaType): def check(self, schema): QAPISchemaType.check(self, schema) - self.element_type = schema.lookup_type(self._element_type_name) - assert self.element_type + self.element_type = schema.resolve_type( + self._element_type_name, self.info, + self.info and self.info.defn_meta) assert not isinstance(self.element_type, QAPISchemaArrayType) @property
@@ -1448,6 +1290,10 @@ class QAPISchemaArrayType(QAPISchemaType): visitor.visit_array_type(self.name, self.info, self.ifcond, self.element_type) + def describe(self): + assert self.meta + return "%s type ['%s']" % (self.meta, self._element_type_name) + class QAPISchemaObjectType(QAPISchemaType): def __init__(self, name, info, doc, ifcond,
@@ -1456,6 +1302,7 @@ class QAPISchemaObjectType(QAPISchemaType): # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base QAPISchemaType.__init__(self, name, info, doc, ifcond) + self.meta = 'union' if variants else 'struct' assert base is None or isinstance(base, str) for m in local_members: assert isinstance(m, QAPISchemaObjectTypeMember)
@@ -1490,8 +1337,14 @@ class QAPISchemaObjectType(QAPISchemaType): seen = OrderedDict() if self._base_name: - self.base = schema.lookup_type(self._base_name) - assert isinstance(self.base, QAPISchemaObjectType) + self.base = schema.resolve_type(self._base_name, self.info, + "'base'") + if (not isinstance(self.base, QAPISchemaObjectType) + or self.base.variants): + raise QAPISemError( + self.info, + "'base' requires a struct type, %s isn't" + % self.base.describe()) self.base.check(schema) self.base.check_clash(self.info, seen) for m in self.local_members:
@@ -1503,7 +1356,6 @@ class QAPISchemaObjectType(QAPISchemaType): if self.variants: self.variants.check(schema, seen) - assert self.variants.tag_member in members self.variants.check_clash(self.info, seen) # Features are in a name space separate from members
@@ -1640,8 +1492,8 @@ class QAPISchemaObjectTypeMember(QAPISchemaMember): def check(self, schema): assert self.defined_in - self.type = schema.lookup_type(self._type_name) - assert self.type + self.type = schema.resolve_type(self._type_name, self.info, + self.describe) class QAPISchemaObjectTypeVariants(object):
@@ -1665,12 +1517,40 @@ class QAPISchemaObjectTypeVariants(object): v.set_defined_in(name) def check(self, schema, seen): - if not self.tag_member: # flat union - self.tag_member = seen[c_name(self._tag_name)] - assert self._tag_name == self.tag_member.name - assert isinstance(self.tag_member.type, QAPISchemaEnumType) - assert not self.tag_member.optional - assert self.tag_member.ifcond == [] + if not self.tag_member: # flat union + self.tag_member = seen.get(c_name(self._tag_name)) + base = "'base'" + # Pointing to the base type when not implicit would be + # nice, but we don't know it here + if not self.tag_member or self._tag_name != self.tag_member.name: + raise QAPISemError( + self.info, + "discriminator '%s' is not a member of %s" + % (self._tag_name, base)) + # Here we do: + base_type = schema.lookup_type(self.tag_member.defined_in) + assert base_type + if not base_type.is_implicit(): + base = "base type '%s'" % self.tag_member.defined_in + if not isinstance(self.tag_member.type, QAPISchemaEnumType): + raise QAPISemError( + self.info, + "discriminator member '%s' of %s must be of enum type" + % (self._tag_name, base)) + if self.tag_member.optional: + raise QAPISemError( + self.info, + "discriminator member '%s' of %s must not be optional" + % (self._tag_name, base)) + if self.tag_member.ifcond: + raise QAPISemError( + self.info, + "discriminator member '%s' of %s must not be conditional" + % (self._tag_name, base)) + else: # simple union + assert isinstance(self.tag_member.type, QAPISchemaEnumType) + assert not self.tag_member.optional + assert self.tag_member.ifcond == [] if self._tag_name: # flat union # branches that are not explicitly covered get an empty type cases = set([v.name for v in self.variants])
@@ -1680,15 +1560,23 @@ class QAPISchemaObjectTypeVariants(object): 'q_empty', m.ifcond) v.set_defined_in(self.tag_member.defined_in) self.variants.append(v) - assert self.variants + if not self.variants: + raise QAPISemError(self.info, "union has no branches") for v in self.variants: v.check(schema) # Union names must match enum values; alternate names are # checked separately. Use 'seen' to tell the two apart. if seen: - assert v.name in self.tag_member.type.member_names() - assert (isinstance(v.type, QAPISchemaObjectType) - and not v.type.variants) + if v.name not in self.tag_member.type.member_names(): + raise QAPISemError( + self.info, + "branch '%s' is not a value of %s" + % (v.name, self.tag_member.type.describe())) + if (not isinstance(v.type, QAPISchemaObjectType) + or v.type.variants): + raise QAPISemError( + self.info, "%s cannot use %s" + % (v.describe(self.info), v.type.describe())) v.type.check(schema) def check_clash(self, info, seen):
@@ -1707,6 +1595,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): class QAPISchemaAlternateType(QAPISchemaType): + meta = 'alternate' + def __init__(self, name, info, doc, ifcond, variants): QAPISchemaType.__init__(self, name, info, doc, ifcond) assert isinstance(variants, QAPISchemaObjectTypeVariants)
@@ -1724,9 +1614,33 @@ class QAPISchemaAlternateType(QAPISchemaType): # Alternate branch names have no relation to the tag enum values; # so we have to check for potential name collisions ourselves. seen = {} + types_seen = {} for v in self.variants.variants: v.check_clash(self.info, seen) - # TODO check conflicting qtypes + qtype = v.type.alternate_qtype() + if not qtype: + raise QAPISemError( + self.info, "%s cannot use %s" + % (v.describe(self.info), v.type.describe())) + conflicting = set([qtype]) + if qtype == 'QTYPE_QSTRING': + if isinstance(v.type, QAPISchemaEnumType): + for m in v.type.members: + if m.name in ['on', 'off']: + conflicting.add('QTYPE_QBOOL') + if re.match(r'[-+0-9.]', m.name): + # lazy, could be tightened + conflicting.add('QTYPE_QNUM') + else: + conflicting.add('QTYPE_QNUM') + conflicting.add('QTYPE_QBOOL') + for qt in conflicting: + if qt in types_seen: + raise QAPISemError( + self.info, + "%s can't be distinguished from '%s'" + % (v.describe(self.info), types_seen[qt])) + types_seen[qt] = v.name if self.doc: self.doc.connect_member(v) if self.doc:
@@ -1745,6 +1659,8 @@ class QAPISchemaAlternateType(QAPISchemaType): class QAPISchemaCommand(QAPISchemaEntity): + meta = 'command' + def __init__(self, name, info, doc, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig): QAPISchemaEntity.__init__(self, name, info, doc, ifcond)
@@ -1763,14 +1679,32 @@ class QAPISchemaCommand(QAPISchemaEntity): def check(self, schema): QAPISchemaEntity.check(self, schema) if self._arg_type_name: - self.arg_type = schema.lookup_type(self._arg_type_name) - assert isinstance(self.arg_type, QAPISchemaObjectType) - assert not self.arg_type.variants or self.boxed + self.arg_type = schema.resolve_type( + self._arg_type_name, self.info, "command's 'data'") + if not isinstance(self.arg_type, QAPISchemaObjectType): + raise QAPISemError( + self.info, + "command's 'data' cannot take %s" + % self.arg_type.describe()) + if self.arg_type.variants and not self.boxed: + raise QAPISemError( + self.info, + "command's 'data' can take %s only with 'boxed': true" + % self.arg_type.describe()) elif self.boxed: raise QAPISemError(self.info, "use of 'boxed' requires 'data'") if self._ret_type_name: - self.ret_type = schema.lookup_type(self._ret_type_name) - assert isinstance(self.ret_type, QAPISchemaType) + self.ret_type = schema.resolve_type( + self._ret_type_name, self.info, "command's 'returns'") + if self.name not in returns_whitelist: + if not (isinstance(self.ret_type, QAPISchemaObjectType) + or (isinstance(self.ret_type, QAPISchemaArrayType) + and isinstance(self.ret_type.element_type, + QAPISchemaObjectType))): + raise QAPISemError( + self.info, + "command's 'returns' cannot take %s" + % self.ret_type.describe()) def visit(self, visitor): QAPISchemaEntity.visit(self, visitor)
@@ -1782,6 +1716,8 @@ class QAPISchemaCommand(QAPISchemaEntity): class QAPISchemaEvent(QAPISchemaEntity): + meta = 'event' + def __init__(self, name, info, doc, ifcond, arg_type, boxed): QAPISchemaEntity.__init__(self, name, info, doc, ifcond) assert not arg_type or isinstance(arg_type, str)
@@ -1792,9 +1728,18 @@ class QAPISchemaEvent(QAPISchemaEntity): def check(self, schema): QAPISchemaEntity.check(self, schema) if self._arg_type_name: - self.arg_type = schema.lookup_type(self._arg_type_name) - assert isinstance(self.arg_type, QAPISchemaObjectType) - assert not self.arg_type.variants or self.boxed + self.arg_type = schema.resolve_type( + self._arg_type_name, self.info, "event's 'data'") + if not isinstance(self.arg_type, QAPISchemaObjectType): + raise QAPISemError( + self.info, + "event's 'data' cannot take %s" + % self.arg_type.describe()) + if self.arg_type.variants and not self.boxed: + raise QAPISemError( + self.info, + "event's 'data' can take %s only with 'boxed': true" + % self.arg_type.describe()) elif self.boxed: raise QAPISemError(self.info, "use of 'boxed' requires 'data'")
@@ -1825,10 +1770,16 @@ class QAPISchema(object): def _def_entity(self, ent): # Only the predefined types are allowed to not have info assert ent.info or self._predefining - assert ent.name is None or ent.name not in self._entity_dict self._entity_list.append(ent) - if ent.name is not None: - self._entity_dict[ent.name] = ent + if ent.name is None: + return + # TODO reject names that differ only in '_' vs. '.' vs. '-', + # because they're liable to clash in generated C. + other_ent = self._entity_dict.get(ent.name) + if other_ent: + raise QAPISemError( + ent.info, "%s is already defined" % other_ent.describe()) + self._entity_dict[ent.name] = ent def lookup_entity(self, name, typ=None): ent = self._entity_dict.get(name)
@@ -1839,6 +1790,15 @@ class QAPISchema(object): def lookup_type(self, name): return self.lookup_entity(name, QAPISchemaType) + def resolve_type(self, name, info, what): + typ = self.lookup_type(name) + if not typ: + if callable(what): + what = what(info) + raise QAPISemError( + info, "%s uses unknown type '%s'" % (what, name)) + return typ + def _def_include(self, expr, info, doc): include = expr['include'] assert doc is None
@@ -1924,7 +1884,7 @@ class QAPISchema(object): # But it's not tight: the disjunction need not imply it. We # may end up compiling useless wrapper types. # TODO kill simple unions or implement the disjunction - assert ifcond == typ._ifcond # pylint: disable=protected-access + assert (ifcond or []) == typ._ifcond # pylint: disable=protected-access else: self._def_entity(QAPISchemaObjectType(name, info, doc, ifcond, None, members, None, []))
tests/qapi-schema/alternate-any.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-any.json: In alternate 'Alt': -tests/qapi-schema/alternate-any.json:2: alternate 'Alt' member 'one' cannot use type 'any' +tests/qapi-schema/alternate-any.json:2: branch 'one' cannot use built-in type 'any'
tests/qapi-schema/alternate-conflict-bool-string.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-bool-string.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-bool-string.json:2: alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-bool-string.json:2: branch 'two' can't be distinguished from 'one'
tests/qapi-schema/alternate-conflict-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-dict.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-dict.json:6: alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-dict.json:6: branch 'two' can't be distinguished from 'one'
tests/qapi-schema/alternate-conflict-enum-bool.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-enum-bool.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-enum-bool.json:4: alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-enum-bool.json:4: branch 'two' can't be distinguished from 'one'
tests/qapi-schema/alternate-conflict-enum-int.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-enum-int.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-enum-int.json:4: alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-enum-int.json:4: branch 'two' can't be distinguished from 'one'
tests/qapi-schema/alternate-conflict-num-string.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-num-string.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-num-string.json:2: alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-num-string.json:2: branch 'two' can't be distinguished from 'one'
tests/qapi-schema/alternate-conflict-string.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-conflict-string.json: In alternate 'Alt': -tests/qapi-schema/alternate-conflict-string.json:2: alternate 'Alt' member 'two' can't be distinguished from member 'one' +tests/qapi-schema/alternate-conflict-string.json:2: branch 'two' can't be distinguished from 'one'
tests/qapi-schema/alternate-nested.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-nested.json: In alternate 'Alt2': -tests/qapi-schema/alternate-nested.json:4: member 'nested' of alternate 'Alt2' cannot use alternate type 'Alt1' +tests/qapi-schema/alternate-nested.json:4: branch 'nested' cannot use alternate type 'Alt1'
tests/qapi-schema/alternate-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-unknown.json: In alternate 'Alt': -tests/qapi-schema/alternate-unknown.json:2: member 'unknown' of alternate 'Alt' uses unknown type 'MissingType' +tests/qapi-schema/alternate-unknown.json:2: branch 'unknown' uses unknown type 'MissingType'
tests/qapi-schema/args-alternate.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-alternate.json: In command 'oops': -tests/qapi-schema/args-alternate.json:3: 'data' for command 'oops' cannot use alternate type 'Alt' +tests/qapi-schema/args-alternate.json:3: command's 'data' cannot take alternate type 'Alt'
tests/qapi-schema/args-any.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-any.json: In command 'oops': -tests/qapi-schema/args-any.json:2: 'data' for command 'oops' cannot use built-in type 'any' +tests/qapi-schema/args-any.json:2: command's 'data' cannot take built-in type 'any'
tests/qapi-schema/args-array-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-array-unknown.json: In command 'oops': -tests/qapi-schema/args-array-unknown.json:2: member 'array' of 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-array-unknown.json:2: command uses unknown type 'NoSuchType'
tests/qapi-schema/args-boxed-string.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-boxed-string.json: In command 'foo': -tests/qapi-schema/args-boxed-string.json:2: 'data' for command 'foo' cannot use built-in type 'str' +tests/qapi-schema/args-boxed-string.json:2: command's 'data' cannot take built-in type 'str'
tests/qapi-schema/args-int.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-int.json: In command 'oops': -tests/qapi-schema/args-int.json:2: 'data' for command 'oops' cannot use built-in type 'int' +tests/qapi-schema/args-int.json:2: command's 'data' cannot take built-in type 'int'
tests/qapi-schema/args-member-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-unknown.json: In command 'oops': -tests/qapi-schema/args-member-unknown.json:2: member 'member' of 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-member-unknown.json:2: parameter 'member' uses unknown type 'NoSuchType'
tests/qapi-schema/args-union.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-union.json: In command 'oops': -tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni' +tests/qapi-schema/args-union.json:3: command's 'data' can take union type 'Uni' only with 'boxed': true
tests/qapi-schema/args-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-unknown.json: In command 'oops': -tests/qapi-schema/args-unknown.json:2: 'data' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/args-unknown.json:2: command's 'data' uses unknown type 'NoSuchType'
tests/qapi-schema/bad-base.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/bad-base.json: In struct 'MyType': -tests/qapi-schema/bad-base.json:3: 'base' for struct 'MyType' cannot use union type 'Union' +tests/qapi-schema/bad-base.json:3: 'base' requires a struct type, union type 'Union' isn't
tests/qapi-schema/command-int.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/command-int.json: In command 'int': -tests/qapi-schema/command-int.json:2: built-in 'int' is already defined +tests/qapi-schema/command-int.json:2: built-in type 'int' is already defined
tests/qapi-schema/flat-union-base-any.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-base-any.json: In union 'TestUnion': -tests/qapi-schema/flat-union-base-any.json:8: 'base' for union 'TestUnion' cannot use built-in type 'any' +tests/qapi-schema/flat-union-base-any.json:8: 'base' requires a struct type, built-in type 'any' isn't
tests/qapi-schema/flat-union-base-union.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-base-union.json: In union 'TestUnion': -tests/qapi-schema/flat-union-base-union.json:14: 'base' for union 'TestUnion' cannot use union type 'UnionBase' +tests/qapi-schema/flat-union-base-union.json:14: 'base' requires a struct type, union type 'UnionBase' isn't
tests/qapi-schema/flat-union-discriminator-bad-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-discriminator-bad-name.json: In union 'MyUnion': -tests/qapi-schema/flat-union-discriminator-bad-name.json:7: discriminator of flat union 'MyUnion' uses invalid name '*switch' +tests/qapi-schema/flat-union-discriminator-bad-name.json:6: discriminator '*switch' is not a member of 'base'
tests/qapi-schema/flat-union-discriminator-bad-name.json +0 -1
@@ -1,5 +1,4 @@ # discriminator '*switch' isn't a member of base, 'switch' is -# reports "uses invalid name", which is good enough { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } }
tests/qapi-schema/flat-union-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-empty.json: In union 'Union': -tests/qapi-schema/flat-union-empty.json:4: union 'Union' has no branches +tests/qapi-schema/flat-union-empty.json:4: union has no branches
tests/qapi-schema/flat-union-int-branch.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-int-branch.json: In union 'TestUnion': -tests/qapi-schema/flat-union-int-branch.json:8: member 'value1' of union 'TestUnion' cannot use built-in type 'int' +tests/qapi-schema/flat-union-int-branch.json:8: branch 'value1' cannot use built-in type 'int'
tests/qapi-schema/flat-union-invalid-branch-key.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-invalid-branch-key.json: In union 'TestUnion': -tests/qapi-schema/flat-union-invalid-branch-key.json:13: discriminator value 'value_wrong' is not found in enum 'TestEnum' +tests/qapi-schema/flat-union-invalid-branch-key.json:13: branch 'value_wrong' is not a value of enum type 'TestEnum'
tests/qapi-schema/flat-union-invalid-if-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-invalid-if-discriminator.json: In union 'TestUnion': -tests/qapi-schema/flat-union-invalid-if-discriminator.json:10: the discriminator 'enum1' for union TestUnion must not be conditional +tests/qapi-schema/flat-union-invalid-if-discriminator.json:10: discriminator member 'enum1' of 'base' must not be conditional
tests/qapi-schema/flat-union-optional-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-optional-discriminator.json: In union 'MyUnion': -tests/qapi-schema/flat-union-optional-discriminator.json:7: discriminator 'switch' is not a member of 'base' +tests/qapi-schema/flat-union-optional-discriminator.json:6: discriminator member 'switch' of base type 'Base' must not be optional
tests/qapi-schema/flat-union-optional-discriminator.json +0 -1
@@ -1,5 +1,4 @@ # we require the discriminator to be non-optional -# FIXME reports "discriminator 'switch' is not a member of base struct 'Base'" { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } }
tests/qapi-schema/flat-union-string-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-string-discriminator.json: In union 'TestUnion': -tests/qapi-schema/flat-union-string-discriminator.json:13: discriminator 'kind' must be of enumeration type +tests/qapi-schema/flat-union-string-discriminator.json:13: discriminator member 'kind' of base type 'TestBase' must be of enum type
tests/qapi-schema/redefined-builtin.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/redefined-builtin.json: In struct 'size': -tests/qapi-schema/redefined-builtin.json:2: built-in 'size' is already defined +tests/qapi-schema/redefined-builtin.json:2: built-in type 'size' is already defined
tests/qapi-schema/redefined-type.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/redefined-type.json: In enum 'foo': -tests/qapi-schema/redefined-type.json:3: struct 'foo' is already defined +tests/qapi-schema/redefined-type.json:3: struct type 'foo' is already defined
tests/qapi-schema/returns-alternate.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/returns-alternate.json: In command 'oops': -tests/qapi-schema/returns-alternate.json:3: 'returns' for command 'oops' cannot use alternate type 'Alt' +tests/qapi-schema/returns-alternate.json:3: command's 'returns' cannot take alternate type 'Alt'
tests/qapi-schema/returns-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/returns-unknown.json: In command 'oops': -tests/qapi-schema/returns-unknown.json:2: 'returns' for command 'oops' uses unknown type 'NoSuchType' +tests/qapi-schema/returns-unknown.json:2: command's 'returns' uses unknown type 'NoSuchType'
tests/qapi-schema/returns-whitelist.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/returns-whitelist.json: In command 'no-way-this-will-get-whitelisted': -tests/qapi-schema/returns-whitelist.json:14: 'returns' for command 'no-way-this-will-get-whitelisted' cannot use built-in type 'int' +tests/qapi-schema/returns-whitelist.json:14: command's 'returns' cannot take array type ['int']
tests/qapi-schema/union-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-empty.json: In union 'Union': -tests/qapi-schema/union-empty.json:2: union 'Union' has no branches +tests/qapi-schema/union-empty.json:2: union has no branches
tests/qapi-schema/union-invalid-base.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-invalid-base.json: In union 'TestUnion': -tests/qapi-schema/union-invalid-base.json:8: 'base' for union 'TestUnion' cannot use built-in type 'int' +tests/qapi-schema/union-invalid-base.json:8: 'base' requires a struct type, built-in type 'int' isn't
tests/qapi-schema/union-unknown.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-unknown.json: In union 'Union': -tests/qapi-schema/union-unknown.json:2: member 'unknown' of union 'Union' uses unknown type 'MissingType' +tests/qapi-schema/union-unknown.json:2: union uses unknown type 'MissingType'
tests/qapi-schema/union-unknown.json +1 -1
@@ -1,3 +1,3 @@ # we reject a union with unknown type in branch { 'union': 'Union', - 'data': { 'unknown': 'MissingType' } } + 'data': { 'unknown': ['MissingType'] } }
Signature · 1 line
2.21.0
Re: [PATCH 16/25] qapi: Move context-sensitive checking to the proper place
Quoted 19 lines · Markus Armbruster
When we introduced the QAPISchema intermediate representation (commit
ac88219a6c7), we took a shortcut: we leftcheck_exprs()& friends alone instead of moving semantic checks into theQAPISchemaFOO.check(). The .check() assertcheck_exprs()did its job.Time to finish the conversion job. Move exactly the context-sensitive checks to the .check(). They replace assertions there. Context-free checks stay put.
Fixes the misleading optional tag error demonstrated by test flat-union-optional-discriminator.
A few other error message improve.
Signed-off-by Markus Armbruster <[email protected]>---
scripts/qapi/common.py +0
-0
scripts/qapi/common.py
Quoted 1 line
scripts/qapi/common.py +0
-1--- a/scripts/qapi/common.py
Thankfully, our large coverage of tests goes a long way to show that the conversion is correct. I didn't notice anything obvious that might have been overlooked (we may still find things down the road, but I'm not going to hold up this patch trying to find those things). Meanwhile, the conversion from assert to conditionals inside .check() looks complete.
scripts/qapi/common.py line 2
Quoted 5 lines
+++ b/tests/qapi-schema/args-union.err
scripts/qapi/common.py +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/args-union.json: In command 'oops': -tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni' +tests/qapi-schema/args-union.json:3: command's 'data' can take union type 'Uni' only with 'boxed': true
This one is definitely nicer.
Quoted 10 lines
+++ b/tests/qapi-schema/flat-union-discriminator-bad-name.err
scripts/qapi/common.py +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-discriminator-bad-name.json: In union 'MyUnion': -tests/qapi-schema/flat-union-discriminator-bad-name.json:7: discriminator of flat union 'MyUnion' uses invalid name '*switch' +tests/qapi-schema/flat-union-discriminator-bad-name.json:6: discriminator '*switch' is not a member of 'base'tests/qapi-schema/flat-union-discriminator-bad-name.json +0
-0
tests/qapi-schema/flat-union-discriminator-bad-name.json line 4
Quoted 5 lines
tests/qapi-schema/flat-union-discriminator-bad-name.json +0
-1@@ -1,5 +1,4 @@ # discriminator '*switch' isn't a member of base, 'switch' is -# reports "uses invalid name", which is good enough { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } }
I find this one to be borderline in quality (if we have '*switch' in the base, claiming that '*switch' is not a member of base is confusing until you realize that base actually has an optional member named 'switch') - but anyone that actually stumbles into this one will probably quickly figure out their problem, and we may be revisiting it later anyways when we finally include patches for a default discriminator.
Quoted 10 lines
+++ b/tests/qapi-schema/flat-union-optional-discriminator.err
tests/qapi-schema/flat-union-discriminator-bad-name.json +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-optional-discriminator.json: In union 'MyUnion': -tests/qapi-schema/flat-union-optional-discriminator.json:7: discriminator 'switch' is not a member of 'base' +tests/qapi-schema/flat-union-optional-discriminator.json:6: discriminator member 'switch' of base type 'Base' must not be optionaltests/qapi-schema/flat-union-optional-discriminator.json +0
-0
tests/qapi-schema/flat-union-optional-discriminator.json line 4
Quoted 5 lines
tests/qapi-schema/flat-union-optional-discriminator.json +0
-1@@ -1,5 +1,4 @@ # we require the discriminator to be non-optional -# FIXME reports "discriminator 'switch' is not a member of base struct 'Base'" { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } }
And while the other one is borderline, I agree that this one is better.
Quoted 11 lines
+++ b/tests/qapi-schema/union-unknown.err
tests/qapi-schema/flat-union-optional-discriminator.json +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/union-unknown.json: In union 'Union': -tests/qapi-schema/union-unknown.json:2: member 'unknown' of union 'Union' uses unknown type 'MissingType' +tests/qapi-schema/union-unknown.json:2: union uses unknown type 'MissingType'tests/qapi-schema/union-unknown.json +0
-0
tests/qapi-schema/union-unknown.json line 3
Quoted 4 lines
tests/qapi-schema/union-unknown.json +1
-1@@ -1,3 +1,3 @@ # we reject a union with unknown type in branch { 'union': 'Union', - 'data': { 'unknown': 'MissingType' } } + 'data': { 'unknown': ['MissingType'] } }
And here you covered one more code path by going through an array type.
Overall looks good.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 16/25] qapi: Move context-sensitive checking to the proper place
Quoted 18 lines · Eric Blake
Quoted 16 lines · Markus Armbruster
When we introduced the QAPISchema intermediate representation (commit
ac88219a6c7), we took a shortcut: we leftcheck_exprs()& friends alone instead of moving semantic checks into theQAPISchemaFOO.check(). The .check() assertcheck_exprs()did its job.Time to finish the conversion job. Move exactly the context-sensitive checks to the .check(). They replace assertions there. Context-free checks stay put.
Fixes the misleading optional tag error demonstrated by test flat-union-optional-discriminator.
A few other error message improve.
Signed-off-by Markus Armbruster <[email protected]>---
Quoted 9 lines
scripts/qapi/common.py
Quoted 3 lines
scripts/qapi/common.py +0
-1--- a/scripts/qapi/common.pyThankfully, our large coverage of tests goes a long way to show that the conversion is correct. I didn't notice anything obvious that might have been overlooked (we may still find things down the road, but I'm not going to hold up this patch trying to find those things). Meanwhile, the conversion from assert to conditionals inside .check() looks complete.
Additional arguments supporting correctness:
* Every deleted check gets added back.
* Every added check replaces an assertion.
Quoted 67 lines
scripts/qapi/common.py line 2
Quoted 5 lines
+++ b/tests/qapi-schema/args-union.err
scripts/qapi/common.py +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/args-union.json: In command 'oops': -tests/qapi-schema/args-union.json:3: 'data' for command 'oops' cannot use union type 'Uni' +tests/qapi-schema/args-union.json:3: command's 'data' can take union type 'Uni' only with 'boxed': trueThis one is definitely nicer.
Quoted 10 lines
+++ b/tests/qapi-schema/flat-union-discriminator-bad-name.err
scripts/qapi/common.py +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-discriminator-bad-name.json: In union 'MyUnion': -tests/qapi-schema/flat-union-discriminator-bad-name.json:7: discriminator of flat union 'MyUnion' uses invalid name '*switch' +tests/qapi-schema/flat-union-discriminator-bad-name.json:6: discriminator '*switch' is not a member of 'base'tests/qapi-schema/flat-union-discriminator-bad-name.json +0
-0tests/qapi-schema/flat-union-discriminator-bad-name.json line 4
Quoted 5 lines
tests/qapi-schema/flat-union-discriminator-bad-name.json +0
-1@@ -1,5 +1,4 @@ # discriminator '*switch' isn't a member of base, 'switch' is -# reports "uses invalid name", which is good enough { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } }I find this one to be borderline in quality (if we have '*switch' in the base, claiming that '*switch' is not a member of base is confusing until you realize that base actually has an optional member named 'switch') - but anyone that actually stumbles into this one will probably quickly figure out their problem, and we may be revisiting it later anyways when we finally include patches for a default discriminator.
Quoted 10 lines
+++ b/tests/qapi-schema/flat-union-optional-discriminator.err
tests/qapi-schema/flat-union-discriminator-bad-name.json +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-optional-discriminator.json: In union 'MyUnion': -tests/qapi-schema/flat-union-optional-discriminator.json:7: discriminator 'switch' is not a member of 'base' +tests/qapi-schema/flat-union-optional-discriminator.json:6: discriminator member 'switch' of base type 'Base' must not be optionaltests/qapi-schema/flat-union-optional-discriminator.json +0
-0tests/qapi-schema/flat-union-optional-discriminator.json line 4
Quoted 5 lines
tests/qapi-schema/flat-union-optional-discriminator.json +0
-1@@ -1,5 +1,4 @@ # we require the discriminator to be non-optional -# FIXME reports "discriminator 'switch' is not a member of base struct 'Base'" { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } }And while the other one is borderline, I agree that this one is better.
Quoted 11 lines
+++ b/tests/qapi-schema/union-unknown.err
tests/qapi-schema/flat-union-optional-discriminator.json +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/union-unknown.json: In union 'Union': -tests/qapi-schema/union-unknown.json:2: member 'unknown' of union 'Union' uses unknown type 'MissingType' +tests/qapi-schema/union-unknown.json:2: union uses unknown type 'MissingType'tests/qapi-schema/union-unknown.json +0
-0tests/qapi-schema/union-unknown.json line 3
Quoted 4 lines
tests/qapi-schema/union-unknown.json +1
-1@@ -1,3 +1,3 @@ # we reject a union with unknown type in branch { 'union': 'Union', - 'data': { 'unknown': 'MissingType' } } + 'data': { 'unknown': ['MissingType'] } }And here you covered one more code path by going through an array type.
Quoted 3 lines
Overall looks good.
Reviewed-by Eric Blake <[email protected]>
Thanks!
PATCH 17/25 qapi: Move context-free checking to the proper place
In reply to Markus ArmbrusterQAPISchemaCommand.check() and QAPISchemaEvent().check() check 'data' is present when 'boxed': true. That's context-free. Move to check_command() and check_event().
Tweak the error message while there.
check_exprs() & friends now check exactly what qapi-code-gen.txt calls the second layer of syntax.
--- scripts/qapi/common.py | 16 ++++++++-------- tests/qapi-schema/event-boxed-empty.err | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-)
scripts/qapi/common.py +8 -8
@@ -767,10 +767,12 @@ def check_type(value, info, source, def check_command(expr, info): name = expr['command'] + args = expr.get('data') boxed = expr.get('boxed', False) - check_type(expr.get('data'), info, - "'data' for command '%s'" % name, + if boxed and args is None: + raise QAPISemError(info, "'boxed': true requires 'data'") + check_type(args, info, "'data' for command '%s'" % name, allow_dict=not boxed) check_type(expr.get('returns'), info, "'returns' for command '%s'" % name,
@@ -779,10 +781,12 @@ def check_command(expr, info): def check_event(expr, info): name = expr['event'] + args = expr.get('data') boxed = expr.get('boxed', False) - check_type(expr.get('data'), info, - "'data' for event '%s'" % name, + if boxed and args is None: + raise QAPISemError(info, "'boxed': true requires 'data'") + check_type(args, info, "'data' for event '%s'" % name, allow_dict=not boxed)
@@ -1691,8 +1695,6 @@ class QAPISchemaCommand(QAPISchemaEntity): self.info, "command's 'data' can take %s only with 'boxed': true" % self.arg_type.describe()) - elif self.boxed: - raise QAPISemError(self.info, "use of 'boxed' requires 'data'") if self._ret_type_name: self.ret_type = schema.resolve_type( self._ret_type_name, self.info, "command's 'returns'")
@@ -1740,8 +1742,6 @@ class QAPISchemaEvent(QAPISchemaEntity): self.info, "event's 'data' can take %s only with 'boxed': true" % self.arg_type.describe()) - elif self.boxed: - raise QAPISemError(self.info, "use of 'boxed' requires 'data'") def visit(self, visitor): QAPISchemaEntity.visit(self, visitor)
tests/qapi-schema/event-boxed-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/event-boxed-empty.json: In event 'FOO': -tests/qapi-schema/event-boxed-empty.json:2: use of 'boxed' requires 'data' +tests/qapi-schema/event-boxed-empty.json:2: 'boxed': true requires 'data'
Signature · 1 line
2.21.0
Re: [PATCH 17/25] qapi: Move context-free checking to the proper place
Quoted 6 lines · Markus Armbruster
QAPISchemaCommand.check()and QAPISchemaEvent().check() check 'data' is present when 'boxed': true. That's context-free. Move tocheck_command()andcheck_event().Tweak the error message while there.
Quoted 9 lines
check_exprs()& friends now check exactly what qapi-code-gen.txt calls the second layer of syntax.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 16 ++++++++-------- tests/qapi-schema/event-boxed-empty.err | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 18/25 qapi: Improve reporting of invalid 'if' errors
In reply to Markus ArmbrusterMove check_if() from check_keys() to check_exprs() and call it later, so its error messages gain an "in definition" line.
Checking values in a function named check_keys() is unclean anyway. The original sin was commit 0545f6b887 "qapi: Better error messages for bad expressions", which checks the value of key 'name'. More sinning in commit 2cbf09925a "qapi: More rigorous checking for type safety bypass", commit c818408e44 "qapi: Implement boxed types for commands/events", and commit 967c885108 "qapi: add 'if' to top-level expressions". This commit does penance for the latter. The next commits will do penance for the others.
--- scripts/qapi/common.py | 4 ++-- tests/qapi-schema/bad-if-empty-list.err | 1 + tests/qapi-schema/bad-if-empty.err | 1 + tests/qapi-schema/bad-if-list.err | 1 + tests/qapi-schema/bad-if.err | 1 + 5 files changed, 6 insertions(+), 2 deletions(-)
scripts/qapi/common.py +2 -2
@@ -920,8 +920,6 @@ def check_keys(expr, info, meta, required, optional=[]): raise QAPISemError(info, "'%s' of %s '%s' should only use true value" % (key, meta, name)) - if key == 'if': - check_if(expr, info) def normalize_enum(expr):
@@ -1023,6 +1021,8 @@ def check_exprs(exprs): else: assert False, 'unexpected meta type' + check_if(expr, info) + if doc: doc.check_expr(expr)
tests/qapi-schema/bad-if-empty-list.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/bad-if-empty-list.json: In struct 'TestIfStruct': tests/qapi-schema/bad-if-empty-list.json:2: 'if' condition [] is useless
tests/qapi-schema/bad-if-empty.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/bad-if-empty.json: In struct 'TestIfStruct': tests/qapi-schema/bad-if-empty.json:2: 'if' condition '' makes no sense
tests/qapi-schema/bad-if-list.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/bad-if-list.json: In struct 'TestIfStruct': tests/qapi-schema/bad-if-list.json:2: 'if' condition ' ' makes no sense
tests/qapi-schema/bad-if.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/bad-if.json: In struct 'TestIfStruct': tests/qapi-schema/bad-if.json:2: 'if' condition must be a string or a list of strings
Signature · 1 line
2.21.0
Re: [PATCH 18/25] qapi: Improve reporting of invalid 'if' errors
Quoted 12 lines · Markus Armbruster
Move
check_if()fromcheck_keys()tocheck_exprs()and call it later, so its error messages gain an "in definition" line.Checking values in a function named
check_keys()is unclean anyway. The original sin was commit0545f6b887"qapi: Better error messages for bad expressions", which checks the value of key 'name'. More sinning in commit2cbf09925a"qapi: More rigorous checking for type safety bypass", commitc818408e44"qapi: Implement boxed types for commands/events", and commit967c885108"qapi: add 'if' to top-level expressions". This commit does penance for the latter. The next commits will do penance for the others.
Quoted 2 lines
Signed-off-by Markus Armbruster <[email protected]>---
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 19/25 qapi: Improve reporting of invalid flags
In reply to Markus ArmbrusterSplit check_flags() off check_keys() and have check_exprs() call it later, so its error messages gain an "in definition" line. Tweak the error messages.
Checking values in a function named check_keys() is unclean anyway.
--- scripts/qapi/common.py | 22 ++++++++++++---------- tests/qapi-schema/allow-preconfig-test.err | 3 ++- tests/qapi-schema/args-bad-boxed.err | 3 ++- tests/qapi-schema/oob-test.err | 3 ++- tests/qapi-schema/type-bypass-bad-gen.err | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-)
scripts/qapi/common.py +12 -10
@@ -910,16 +910,17 @@ def check_keys(expr, info, meta, required, optional=[]): required = required + [meta] source = "%s '%s'" % (meta, name) check_known_keys(expr, info, source, required, optional) - for (key, value) in expr.items(): - if key in ['gen', 'success-response'] and value is not False: - raise QAPISemError(info, - "'%s' of %s '%s' should only use false value" - % (key, meta, name)) - if (key in ['boxed', 'allow-oob', 'allow-preconfig'] - and value is not True): - raise QAPISemError(info, - "'%s' of %s '%s' should only use true value" - % (key, meta, name)) + + +def check_flags(expr, info): + for key in ['gen', 'success-response']: + if key in expr and expr[key] is not False: + raise QAPISemError( + info, "flag '%s' may only use false value" % key) + for key in ['boxed', 'allow-oob', 'allow-preconfig']: + if key in expr and expr[key] is not True: + raise QAPISemError( + info, "flag '%s' may only use true value" % key) def normalize_enum(expr):
@@ -1022,6 +1023,7 @@ def check_exprs(exprs): assert False, 'unexpected meta type' check_if(expr, info) + check_flags(expr, info) if doc: doc.check_expr(expr)
tests/qapi-schema/allow-preconfig-test.err +2 -1
@@ -1 +1,2 @@ -tests/qapi-schema/allow-preconfig-test.json:2: 'allow-preconfig' of command 'allow-preconfig-test' should only use true value +tests/qapi-schema/allow-preconfig-test.json: In command 'allow-preconfig-test': +tests/qapi-schema/allow-preconfig-test.json:2: flag 'allow-preconfig' may only use true value
tests/qapi-schema/args-bad-boxed.err +2 -1
@@ -1 +1,2 @@ -tests/qapi-schema/args-bad-boxed.json:2: 'boxed' of command 'foo' should only use true value +tests/qapi-schema/args-bad-boxed.json: In command 'foo': +tests/qapi-schema/args-bad-boxed.json:2: flag 'boxed' may only use true value
tests/qapi-schema/oob-test.err +2 -1
@@ -1 +1,2 @@ -tests/qapi-schema/oob-test.json:2: 'allow-oob' of command 'oob-command-1' should only use true value +tests/qapi-schema/oob-test.json: In command 'oob-command-1': +tests/qapi-schema/oob-test.json:2: flag 'allow-oob' may only use true value
tests/qapi-schema/type-bypass-bad-gen.err +2 -1
@@ -1 +1,2 @@ -tests/qapi-schema/type-bypass-bad-gen.json:2: 'gen' of command 'foo' should only use false value +tests/qapi-schema/type-bypass-bad-gen.json: In command 'foo': +tests/qapi-schema/type-bypass-bad-gen.json:2: flag 'gen' may only use false value
Signature · 1 line
2.21.0
Re: [PATCH 19/25] qapi: Improve reporting of invalid flags
Quoted 16 lines · Markus Armbruster
Split
check_flags()offcheck_keys()and havecheck_exprs()call it later, so its error messages gain an "in definition" line. Tweak the error messages.Checking values in a function named
check_keys()is unclean anyway.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 22 ++++++++++++---------- tests/qapi-schema/allow-preconfig-test.err | 3 ++- tests/qapi-schema/args-bad-boxed.err | 3 ++- tests/qapi-schema/oob-test.err | 3 ++- tests/qapi-schema/type-bypass-bad-gen.err | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-)
scripts/qapi/common.py def check_keys(expr, info, meta, required, optional=[]): · line 917
Quoted 4 lines
scripts/qapi/common.py +4
-0+ +def check_flags(expr, info): + for key in ['gen', 'success-response']: + if key in expr and expr[key] is not False:
Is it any more pythonic and/or a micro-optimization to compress this to:
if expr.get(key, False) is not False:
scripts/qapi/common.py def check_keys(expr, info, meta, required, optional=[]): · line 921
Quoted 4 lines
scripts/qapi/common.py +4
-0+ raise QAPISemError( + info, "flag '%s' may only use false value" % key) + for key in ['boxed', 'allow-oob', 'allow-preconfig']: + if key in expr and expr[key] is not True:
and here too.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 19/25] qapi: Improve reporting of invalid flags
Quoted 24 lines · Eric Blake
Quoted 16 lines · Markus Armbruster
Split
check_flags()offcheck_keys()and havecheck_exprs()call it later, so its error messages gain an "in definition" line. Tweak the error messages.Checking values in a function named
check_keys()is unclean anyway.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 22 ++++++++++++---------- tests/qapi-schema/allow-preconfig-test.err | 3 ++- tests/qapi-schema/args-bad-boxed.err | 3 ++- tests/qapi-schema/oob-test.err | 3 ++- tests/qapi-schema/type-bypass-bad-gen.err | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-)scripts/qapi/common.py def check_keys(expr, info, meta, required, optional=[]): · line 917
Quoted 4 lines
scripts/qapi/common.py +4
-0+ +def check_flags(expr, info): + for key in ['gen', 'success-response']: + if key in expr and expr[key] is not False:Is it any more pythonic and/or a micro-optimization to compress this to:
Quoted 8 lines
if
expr.get(key, False)is not False:scripts/qapi/common.py def check_keys(expr, info, meta, required, optional=[]): · line 921
Quoted 4 lines
scripts/qapi/common.py +4
-0+ raise QAPISemError( + info, "flag '%s' may only use false value" % key) + for key in ['boxed', 'allow-oob', 'allow-preconfig']: + if key in expr and expr[key] is not True:and here too.
Will do.
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks!
Re: [PATCH 19/25] qapi: Improve reporting of invalid flags
Quoted 28 lines · Markus Armbruster
Quoted 26 lines · Eric Blake
Quoted 16 lines · Markus Armbruster
Split
check_flags()offcheck_keys()and havecheck_exprs()call it later, so its error messages gain an "in definition" line. Tweak the error messages.Checking values in a function named
check_keys()is unclean anyway.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 22 ++++++++++++---------- tests/qapi-schema/allow-preconfig-test.err | 3 ++- tests/qapi-schema/args-bad-boxed.err | 3 ++- tests/qapi-schema/oob-test.err | 3 ++- tests/qapi-schema/type-bypass-bad-gen.err | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-)scripts/qapi/common.py def check_keys(expr, info, meta, required, optional=[]): · line 917
Quoted 4 lines
scripts/qapi/common.py +4
-0+ +def check_flags(expr, info): + for key in ['gen', 'success-response']: + if key in expr and expr[key] is not False:Is it any more pythonic and/or a micro-optimization to compress this to:
if
expr.get(key, False)is not False:
Quoted 8 lines
Quoted 6 lines
scripts/qapi/common.py def check_keys(expr, info, meta, required, optional=[]): · line 921
Quoted 4 lines
scripts/qapi/common.py +4
-0+ raise QAPISemError( + info, "flag '%s' may only use false value" % key) + for key in ['boxed', 'allow-oob', 'allow-preconfig']: + if key in expr and expr[key] is not True:and here too.
Will do.
Second thoughts in the morning:
if key in expr and expr[key] is not VALUE:
feels slightly clearer than
if expr.get(key, VALUE) is not VALUE:
Quoted 3 lines
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>Thanks!
PATCH 20/25 qapi: Improve reporting of missing / unknown definition keys
In reply to Markus ArmbrusterHave check_exprs() call check_keys() later, so its error messages gain an "in definition" line.
Both check_keys() and check_name_is_str() check the definition's name is a string. Since check_keys() now runs after check_name_is_str() rather than before, its check is dead. Bury it. Checking values in check_keys() is unclean anyway.
--- scripts/qapi/common.py | 40 ++++++++++++------------- tests/qapi-schema/alternate-base.err | 1 + tests/qapi-schema/bad-type-bool.err | 2 +- tests/qapi-schema/bad-type-dict.err | 2 +- tests/qapi-schema/double-type.err | 1 + tests/qapi-schema/enum-missing-data.err | 1 + tests/qapi-schema/unknown-expr-key.err | 1 + 7 files changed, 25 insertions(+), 23 deletions(-)
scripts/qapi/common.py +19 -21
@@ -905,8 +905,6 @@ def check_known_keys(value, info, source, required, optional): def check_keys(expr, info, meta, required, optional=[]): name = expr[meta] - if not isinstance(name, str): - raise QAPISemError(info, "'%s' key must have a string value" % meta) required = required + [meta] source = "%s '%s'" % (meta, name) check_known_keys(expr, info, source, required, optional)
@@ -964,37 +962,18 @@ def check_exprs(exprs): if 'enum' in expr: meta = 'enum' - check_keys(expr, info, 'enum', ['data'], ['if', 'prefix']) - normalize_enum(expr) elif 'union' in expr: meta = 'union' - check_keys(expr, info, 'union', ['data'], - ['base', 'discriminator', 'if']) - normalize_members(expr.get('base')) - normalize_members(expr['data']) elif 'alternate' in expr: meta = 'alternate' - check_keys(expr, info, 'alternate', ['data'], ['if']) - normalize_members(expr['data']) elif 'struct' in expr: meta = 'struct' - check_keys(expr, info, 'struct', ['data'], - ['base', 'if', 'features']) - normalize_members(expr['data']) - normalize_features(expr.get('features')) elif 'command' in expr: meta = 'command' - check_keys(expr, info, 'command', [], - ['data', 'returns', 'gen', 'success-response', - 'boxed', 'allow-oob', 'allow-preconfig', 'if']) - normalize_members(expr.get('data')) elif 'event' in expr: meta = 'event' - check_keys(expr, info, 'event', [], ['data', 'boxed', 'if']) - normalize_members(expr.get('data')) else: raise QAPISemError(info, "expression is missing metatype") - normalize_if(expr) name = expr[meta] check_name_is_str(name, info, "'%s'" % meta)
@@ -1008,20 +987,39 @@ def check_exprs(exprs): % (name, doc.symbol)) if meta == 'enum': + check_keys(expr, info, 'enum', ['data'], ['if', 'prefix']) + normalize_enum(expr) check_enum(expr, info) elif meta == 'union': + check_keys(expr, info, 'union', ['data'], + ['base', 'discriminator', 'if']) + normalize_members(expr.get('base')) + normalize_members(expr['data']) check_union(expr, info) elif meta == 'alternate': + check_keys(expr, info, 'alternate', ['data'], ['if']) + normalize_members(expr['data']) check_alternate(expr, info) elif meta == 'struct': + check_keys(expr, info, 'struct', ['data'], + ['base', 'if', 'features']) + normalize_members(expr['data']) + normalize_features(expr.get('features')) check_struct(expr, info) elif meta == 'command': + check_keys(expr, info, 'command', [], + ['data', 'returns', 'gen', 'success-response', + 'boxed', 'allow-oob', 'allow-preconfig', 'if']) + normalize_members(expr.get('data')) check_command(expr, info) elif meta == 'event': + check_keys(expr, info, 'event', [], ['data', 'boxed', 'if']) + normalize_members(expr.get('data')) check_event(expr, info) else: assert False, 'unexpected meta type' + normalize_if(expr) check_if(expr, info) check_flags(expr, info)
tests/qapi-schema/alternate-base.err +1 -0
@@ -1,2 +1,3 @@ +tests/qapi-schema/alternate-base.json: In alternate 'Alt': tests/qapi-schema/alternate-base.json:4: unknown key 'base' in alternate 'Alt' Valid keys are 'alternate', 'data', 'if'.
tests/qapi-schema/bad-type-bool.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-type-bool.json:2: 'struct' key must have a string value +tests/qapi-schema/bad-type-bool.json:2: 'struct' requires a string name
tests/qapi-schema/bad-type-dict.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/bad-type-dict.json:2: 'command' key must have a string value +tests/qapi-schema/bad-type-dict.json:2: 'command' requires a string name
tests/qapi-schema/double-type.err +1 -0
@@ -1,2 +1,3 @@ +tests/qapi-schema/double-type.json: In struct 'bar': tests/qapi-schema/double-type.json:2: unknown key 'command' in struct 'bar' Valid keys are 'base', 'data', 'features', 'if', 'struct'.
tests/qapi-schema/enum-missing-data.err +1 -0
@@ -1 +1,2 @@ +tests/qapi-schema/enum-missing-data.json: In enum 'MyEnum': tests/qapi-schema/enum-missing-data.json:2: key 'data' is missing from enum 'MyEnum'
tests/qapi-schema/unknown-expr-key.err +1 -0
@@ -1,2 +1,3 @@ +tests/qapi-schema/unknown-expr-key.json: In struct 'bar': tests/qapi-schema/unknown-expr-key.json:2: unknown keys 'bogus', 'phony' in struct 'bar' Valid keys are 'base', 'data', 'features', 'if', 'struct'.
Signature · 1 line
2.21.0
Re: [PATCH 20/25] qapi: Improve reporting of missing / unknown definition keys
Quoted 13 lines · Markus Armbruster
Have
check_exprs()callcheck_keys()later, so its error messages gain an "in definition" line.Both
check_keys()andcheck_name_is_str()check the definition's name is a string. Sincecheck_keys()now runs aftercheck_name_is_str()rather than before, its check is dead. Bury it. Checking values incheck_keys()is unclean anyway.Signed-off-by Markus Armbruster <[email protected]>---
+++
b/scripts/qapi/common.py
scripts/qapi/common.py def check_known_keys(value, info, source, required, optional): · line 909
Quoted 5 lines
scripts/qapi/common.py +0
-2@@ -905,8 +905,6 @@ def check_known_keys(value, info, source, required, optional): def check_keys(expr, info, meta, required, optional=[]): name = expr[meta] - if not isinstance(name, str): - raise QAPISemError(info, "'%s' key must have a string value" % meta)
Should this be replaced with an assert? But I'm also okay just dropping it, since our testsuite shows that we still flag the problems that this message was originally used for.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 20/25] qapi: Improve reporting of missing / unknown definition keys
Quoted 15 lines · Eric Blake
Quoted 14 lines · Markus Armbruster
Have
check_exprs()callcheck_keys()later, so its error messages gain an "in definition" line.Both
check_keys()andcheck_name_is_str()check the definition's name is a string. Sincecheck_keys()now runs aftercheck_name_is_str()rather than before, its check is dead. Bury it. Checking values incheck_keys()is unclean anyway.Signed-off-by Markus Armbruster <[email protected]>---
+++
b/scripts/qapi/common.py(quoted diff) +0
-0@@ -905,8 +905,6 @@ def check_known_keys(value, info, source, required, optional):
Quoted 8 lines
scripts/qapi/common.py def check_known_keys(value, info, source, required, optional): · line 909
Quoted 4 lines
scripts/qapi/common.py +0
-2def check_keys(expr, info, meta, required, optional=[]): name = expr[meta] - if not isinstance(name, str): - raise QAPISemError(info, "'%s' key must have a string value" % meta)Should this be replaced with an assert? But I'm also okay just dropping it, since our testsuite shows that we still flag the problems that this message was originally used for.
I'd prefer not to assert, because as of this patch, check_keys() *only* checks keys, just like its name suggests.
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks!
PATCH 21/25 qapi: Avoid redundant definition references in error messages
In reply to Markus ArmbrusterMany error messages refer to the offending definition even though they're preceded by an "in definition" line. Rephrase them.
--- scripts/qapi/common.py | 113 +++++++----------- tests/qapi-schema/alternate-array.err | 2 +- tests/qapi-schema/alternate-base.err | 2 +- tests/qapi-schema/alternate-empty.err | 2 +- tests/qapi-schema/alternate-invalid-dict.err | 2 +- tests/qapi-schema/args-array-empty.err | 2 +- tests/qapi-schema/args-boxed-anon.err | 2 +- tests/qapi-schema/args-invalid.err | 2 +- tests/qapi-schema/args-member-array-bad.err | 2 +- tests/qapi-schema/args-member-case.err | 2 +- tests/qapi-schema/bad-data.err | 2 +- tests/qapi-schema/doc-bad-symbol.err | 2 +- tests/qapi-schema/double-type.err | 2 +- tests/qapi-schema/enum-bad-member.err | 2 +- tests/qapi-schema/enum-bad-name.err | 2 +- tests/qapi-schema/enum-bad-prefix.err | 2 +- .../qapi-schema/enum-dict-member-unknown.err | 2 +- tests/qapi-schema/enum-member-case.err | 2 +- tests/qapi-schema/enum-missing-data.err | 2 +- tests/qapi-schema/enum-wrong-data.err | 2 +- .../qapi-schema/event-member-invalid-dict.err | 2 +- tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/features-bad-type.err | 2 +- tests/qapi-schema/features-missing-name.err | 2 +- tests/qapi-schema/features-name-bad-type.err | 2 +- tests/qapi-schema/features-no-list.err | 2 +- tests/qapi-schema/features-unknown-key.err | 2 +- tests/qapi-schema/flat-union-array-branch.err | 2 +- .../flat-union-bad-discriminator.err | 2 +- .../flat-union-inline-invalid-dict.err | 2 +- tests/qapi-schema/flat-union-inline.err | 2 +- tests/qapi-schema/flat-union-no-base.err | 2 +- .../nested-struct-data-invalid-dict.err | 2 +- tests/qapi-schema/nested-struct-data.err | 2 +- tests/qapi-schema/reserved-enum-q.err | 2 +- tests/qapi-schema/reserved-member-has.err | 2 +- tests/qapi-schema/reserved-member-q.err | 2 +- tests/qapi-schema/reserved-member-u.err | 2 +- .../reserved-member-underscore.err | 2 +- tests/qapi-schema/reserved-type-kind.err | 2 +- tests/qapi-schema/reserved-type-list.err | 2 +- tests/qapi-schema/returns-array-bad.err | 2 +- tests/qapi-schema/returns-dict.err | 2 +- tests/qapi-schema/struct-data-invalid.err | 2 +- .../struct-member-invalid-dict.err | 2 +- tests/qapi-schema/struct-member-invalid.err | 2 +- .../union-base-no-discriminator.err | 2 +- tests/qapi-schema/union-branch-case.err | 2 +- .../qapi-schema/union-branch-invalid-dict.err | 2 +- tests/qapi-schema/union-optional-branch.err | 2 +- tests/qapi-schema/unknown-expr-key.err | 2 +- 51 files changed, 92 insertions(+), 121 deletions(-)
scripts/qapi/common.py +42 -71
@@ -694,8 +694,8 @@ def check_name_str(name, info, source, def check_defn_name_str(name, info, meta): check_name_str(name, info, meta, permit_upper=True) if name.endswith('Kind') or name.endswith('List'): - raise QAPISemError(info, "%s '%s' should not end in '%s'" - % (meta, name, name[-4:])) + raise QAPISemError(info, "%s name should not end in '%s'" + % (meta, name[-4:])) def check_if(expr, info):
@@ -752,42 +752,34 @@ def check_type(value, info, source, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): - check_name_str(key, info, "member of %s" % source, + key_source = "%s member '%s'" % (source, key) + check_name_str(key, info, key_source, allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): - raise QAPISemError( - info, "member of %s uses reserved name '%s'" % (source, key)) - check_known_keys(arg, info, "member '%s' of %s" % (key, source), - ['type'], ['if']) + raise QAPISemError(info, "%s uses reserved name" % key_source) + check_known_keys(arg, info, key_source, ['type'], ['if']) check_if(arg, info) normalize_if(arg) - check_type(arg['type'], info, "member '%s' of %s" % (key, source), - allow_array=True) + check_type(arg['type'], info, key_source, allow_array=True) def check_command(expr, info): - name = expr['command'] args = expr.get('data') boxed = expr.get('boxed', False) if boxed and args is None: raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data' for command '%s'" % name, - allow_dict=not boxed) - check_type(expr.get('returns'), info, - "'returns' for command '%s'" % name, - allow_array=True) + check_type(expr.get('data'), info, "'data'", allow_dict=not boxed) + check_type(expr.get('returns'), info, "'returns'", allow_array=True) def check_event(expr, info): - name = expr['event'] args = expr.get('data') boxed = expr.get('boxed', False) if boxed and args is None: raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data' for event '%s'" % name, - allow_dict=not boxed) + check_type(expr.get('data'), info, "'data'", allow_dict=not boxed) def check_union(expr, info):
@@ -798,45 +790,34 @@ def check_union(expr, info): if discriminator is None: # simple union if base is not None: - raise QAPISemError( - info, "simple union '%s' must not have a base" % name) + raise QAPISemError(info, "'base' requires 'discriminator'") else: # flat union - check_type(base, info, "'base' for union '%s'" % name, - allow_dict=name) + check_type(base, info, "'base'", allow_dict=name) if not base: - raise QAPISemError(info, "flat union '%s' must have a base" - % name) - check_name_is_str(discriminator, info, - "discriminator of flat union '%s'" % name) + raise QAPISemError(info, "'discriminator' requires 'base'") + check_name_is_str(discriminator, info, "'discriminator'") for (key, value) in members.items(): - check_name_str(key, info, "member of union '%s'" % name) - check_known_keys(value, info, - "member '%s' of union '%s'" % (key, name), - ['type'], ['if']) + source = "'data' member '%s'" % key + check_name_str(key, info, source) + check_known_keys(value, info, source, ['type'], ['if']) check_if(value, info) normalize_if(value) - check_type(value['type'], info, - "member '%s' of union '%s'" % (key, name), - allow_array=not base) + check_type(value['type'], info, source, allow_array=not base) def check_alternate(expr, info): - name = expr['alternate'] members = expr['data'] if len(members) == 0: - raise QAPISemError(info, - "alternate '%s' cannot have empty 'data'" % name) + raise QAPISemError(info, "'data' must not be empty") for (key, value) in members.items(): - check_name_str(key, info, "member of alternate '%s'" % name) - check_known_keys(value, info, - "member '%s' of alternate '%s'" % (key, name), - ['type'], ['if']) + source = "'data' member '%s'" % key + check_name_str(key, info, source) + check_known_keys(value, info, source, ['type'], ['if']) check_if(value, info) normalize_if(value) - check_type(value['type'], info, - "member '%s' of alternate '%s'" % (key, name)) + check_type(value['type'], info, source) def check_enum(expr, info):
@@ -845,20 +826,18 @@ def check_enum(expr, info): prefix = expr.get('prefix') if not isinstance(members, list): - raise QAPISemError(info, - "enum '%s' requires an array for 'data'" % name) + raise QAPISemError(info, "'data' must be an array") if prefix is not None and not isinstance(prefix, str): - raise QAPISemError(info, - "enum '%s' requires a string for 'prefix'" % name) + raise QAPISemError(info, "'prefix' must be a string") permit_upper = name in name_case_whitelist for member in members: - check_known_keys(member, info, "member of enum '%s'" % name, - ['name'], ['if']) + source = "'data' member" + check_known_keys(member, info, source, ['name'], ['if']) check_if(member, info) normalize_if(member) - check_name(member['name'], info, "member of enum '%s'" % name, + check_name(member['name'], info, source, enum_member=True, permit_upper=permit_upper)
@@ -867,22 +846,19 @@ def check_struct(expr, info): members = expr['data'] features = expr.get('features') - check_type(members, info, "'data' for struct '%s'" % name, - allow_dict=name) - check_type(expr.get('base'), info, "'base' for struct '%s'" % name) + check_type(members, info, "'data'", allow_dict=name) + check_type(expr.get('base'), info, "'base'") if features: if not isinstance(features, list): - raise QAPISemError( - info, "struct '%s' requires an array for 'features'" % name) + raise QAPISemError(info, "'features' must be an array") for f in features: + source = "'features' member" assert isinstance(f, dict) - check_known_keys(f, info, "feature of struct %s" % name, - ['name'], ['if']) - + check_known_keys(f, info, source, ['name'], ['if']) check_if(f, info) normalize_if(f) - check_name(f['name'], info, "feature of struct %s" % name) + check_name(f['name'], info, source) def check_known_keys(value, info, source, required, optional):
@@ -892,22 +868,19 @@ def check_known_keys(value, info, source, required, optional): missing = set(required) - set(value) if missing: - raise QAPISemError(info, "key%s %s %s missing from %s" - % ('s' if len(missing) > 1 else '', pprint(missing), - 'are' if len(missing) > 1 else 'is', source)) + raise QAPISemError(info, "%s misses key%s %s" + % (source, 's' if len(missing) > 1 else '', + pprint(missing))) allowed = set(required + optional) unknown = set(value) - allowed if unknown: - raise QAPISemError(info, "unknown key%s %s in %s\nValid keys are %s." - % ('s' if len(unknown) > 1 else '', pprint(unknown), - source, pprint(allowed))) + raise QAPISemError(info, "%s has unknown key%s %s\nValid keys are %s." + % (source, 's' if len(unknown) > 1 else '', + pprint(unknown), pprint(allowed))) def check_keys(expr, info, meta, required, optional=[]): - name = expr[meta] - required = required + [meta] - source = "%s '%s'" % (meta, name) - check_known_keys(expr, info, source, required, optional) + check_known_keys(expr, info, meta, required + [meta], optional) def check_flags(expr, info):
@@ -982,9 +955,7 @@ def check_exprs(exprs): if doc and doc.symbol != name: raise QAPISemError( - info, - "definition of '%s' follows documentation for '%s'" - % (name, doc.symbol)) + info, "documentation comment is for '%s'" % doc.symbol) if meta == 'enum': check_keys(expr, info, 'enum', ['data'], ['if', 'prefix'])
tests/qapi-schema/alternate-array.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-array.json: In alternate 'Alt': -tests/qapi-schema/alternate-array.json:5: member 'two' of alternate 'Alt' cannot be an array +tests/qapi-schema/alternate-array.json:5: 'data' member 'two' cannot be an array
tests/qapi-schema/alternate-base.err +1 -1
@@ -1,3 +1,3 @@ tests/qapi-schema/alternate-base.json: In alternate 'Alt': -tests/qapi-schema/alternate-base.json:4: unknown key 'base' in alternate 'Alt' +tests/qapi-schema/alternate-base.json:4: alternate has unknown key 'base' Valid keys are 'alternate', 'data', 'if'.
tests/qapi-schema/alternate-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-empty.json: In alternate 'Alt': -tests/qapi-schema/alternate-empty.json:2: alternate 'Alt' cannot have empty 'data' +tests/qapi-schema/alternate-empty.json:2: 'data' must not be empty
tests/qapi-schema/alternate-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/alternate-invalid-dict.json: In alternate 'Alt': -tests/qapi-schema/alternate-invalid-dict.json:2: key 'type' is missing from member 'two' of alternate 'Alt' +tests/qapi-schema/alternate-invalid-dict.json:2: 'data' member 'two' misses key 'type'
tests/qapi-schema/args-array-empty.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-array-empty.json: In command 'oops': -tests/qapi-schema/args-array-empty.json:2: member 'empty' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-array-empty.json:2: 'data' member 'empty': array type must contain single type name
tests/qapi-schema/args-boxed-anon.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-boxed-anon.json: In command 'foo': -tests/qapi-schema/args-boxed-anon.json:2: 'data' for command 'foo' should be a type name +tests/qapi-schema/args-boxed-anon.json:2: 'data' should be a type name
tests/qapi-schema/args-invalid.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-invalid.json: In command 'foo': -tests/qapi-schema/args-invalid.json:1: 'data' for command 'foo' should be an object or type name +tests/qapi-schema/args-invalid.json:1: 'data' should be an object or type name
tests/qapi-schema/args-member-array-bad.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-array-bad.json: In command 'oops': -tests/qapi-schema/args-member-array-bad.json:2: member 'member' of 'data' for command 'oops': array type must contain single type name +tests/qapi-schema/args-member-array-bad.json:2: 'data' member 'member': array type must contain single type name
tests/qapi-schema/args-member-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-case.json: In command 'no-way-this-will-get-whitelisted': -tests/qapi-schema/args-member-case.json:2: member of 'data' for command 'no-way-this-will-get-whitelisted' uses uppercase in name 'Arg' +tests/qapi-schema/args-member-case.json:2: 'data' member 'Arg' uses uppercase in name 'Arg'
tests/qapi-schema/bad-data.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/bad-data.json: In command 'oops': -tests/qapi-schema/bad-data.json:2: 'data' for command 'oops' cannot be an array +tests/qapi-schema/bad-data.json:2: 'data' cannot be an array
tests/qapi-schema/doc-bad-symbol.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/doc-bad-symbol.json: In command 'foo': -tests/qapi-schema/doc-bad-symbol.json:6: definition of 'foo' follows documentation for 'food' +tests/qapi-schema/doc-bad-symbol.json:6: documentation comment is for 'food'
tests/qapi-schema/double-type.err +1 -1
@@ -1,3 +1,3 @@ tests/qapi-schema/double-type.json: In struct 'bar': -tests/qapi-schema/double-type.json:2: unknown key 'command' in struct 'bar' +tests/qapi-schema/double-type.json:2: struct has unknown key 'command' Valid keys are 'base', 'data', 'features', 'if', 'struct'.
tests/qapi-schema/enum-bad-member.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-bad-member.json: In enum 'MyEnum': -tests/qapi-schema/enum-bad-member.json:2: member of enum 'MyEnum' requires a string name +tests/qapi-schema/enum-bad-member.json:2: 'data' member requires a string name
tests/qapi-schema/enum-bad-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-bad-name.json: In enum 'MyEnum': -tests/qapi-schema/enum-bad-name.json:3: member of enum 'MyEnum' uses invalid name 'not\possible' +tests/qapi-schema/enum-bad-name.json:3: 'data' member uses invalid name 'not\possible'
tests/qapi-schema/enum-bad-prefix.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-bad-prefix.json: In enum 'MyEnum': -tests/qapi-schema/enum-bad-prefix.json:2: enum 'MyEnum' requires a string for 'prefix' +tests/qapi-schema/enum-bad-prefix.json:2: 'prefix' must be a string
tests/qapi-schema/enum-dict-member-unknown.err +1 -1
@@ -1,3 +1,3 @@ tests/qapi-schema/enum-dict-member-unknown.json: In enum 'MyEnum': -tests/qapi-schema/enum-dict-member-unknown.json:2: unknown key 'bad-key' in member of enum 'MyEnum' +tests/qapi-schema/enum-dict-member-unknown.json:2: 'data' member has unknown key 'bad-key' Valid keys are 'if', 'name'.
tests/qapi-schema/enum-member-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-member-case.json: In enum 'NoWayThisWillGetWhitelisted': -tests/qapi-schema/enum-member-case.json:4: member of enum 'NoWayThisWillGetWhitelisted' uses uppercase in name 'Value' +tests/qapi-schema/enum-member-case.json:4: 'data' member uses uppercase in name 'Value'
tests/qapi-schema/enum-missing-data.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-missing-data.json: In enum 'MyEnum': -tests/qapi-schema/enum-missing-data.json:2: key 'data' is missing from enum 'MyEnum' +tests/qapi-schema/enum-missing-data.json:2: enum misses key 'data'
tests/qapi-schema/enum-wrong-data.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/enum-wrong-data.json: In enum 'MyEnum': -tests/qapi-schema/enum-wrong-data.json:2: enum 'MyEnum' requires an array for 'data' +tests/qapi-schema/enum-wrong-data.json:2: 'data' must be an array
tests/qapi-schema/event-member-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/event-member-invalid-dict.json: In event 'EVENT_A': -tests/qapi-schema/event-member-invalid-dict.json:1: key 'type' is missing from member 'a' of 'data' for event 'EVENT_A' +tests/qapi-schema/event-member-invalid-dict.json:1: 'data' member 'a' misses key 'type'
tests/qapi-schema/event-nest-struct.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/event-nest-struct.json: In event 'EVENT_A': -tests/qapi-schema/event-nest-struct.json:1: member 'a' of 'data' for event 'EVENT_A' should be a type name +tests/qapi-schema/event-nest-struct.json:1: 'data' member 'a' should be a type name
tests/qapi-schema/features-bad-type.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-bad-type.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-bad-type.json:1: feature of struct FeatureStruct0 requires a string name +tests/qapi-schema/features-bad-type.json:1: 'features' member requires a string name
tests/qapi-schema/features-missing-name.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-missing-name.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-missing-name.json:1: key 'name' is missing from feature of struct FeatureStruct0 +tests/qapi-schema/features-missing-name.json:1: 'features' member misses key 'name'
tests/qapi-schema/features-name-bad-type.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-name-bad-type.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-name-bad-type.json:1: feature of struct FeatureStruct0 requires a string name +tests/qapi-schema/features-name-bad-type.json:1: 'features' member requires a string name
tests/qapi-schema/features-no-list.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/features-no-list.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-no-list.json:1: struct 'FeatureStruct0' requires an array for 'features' +tests/qapi-schema/features-no-list.json:1: 'features' must be an array
tests/qapi-schema/features-unknown-key.err +1 -1
@@ -1,3 +1,3 @@ tests/qapi-schema/features-unknown-key.json: In struct 'FeatureStruct0': -tests/qapi-schema/features-unknown-key.json:1: unknown key 'colour' in feature of struct FeatureStruct0 +tests/qapi-schema/features-unknown-key.json:1: 'features' member has unknown key 'colour' Valid keys are 'if', 'name'.
tests/qapi-schema/flat-union-array-branch.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-array-branch.json: In union 'TestUnion': -tests/qapi-schema/flat-union-array-branch.json:8: member 'value1' of union 'TestUnion' cannot be an array +tests/qapi-schema/flat-union-array-branch.json:8: 'data' member 'value1' cannot be an array
tests/qapi-schema/flat-union-bad-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-bad-discriminator.json: In union 'TestUnion': -tests/qapi-schema/flat-union-bad-discriminator.json:11: discriminator of flat union 'TestUnion' requires a string name +tests/qapi-schema/flat-union-bad-discriminator.json:11: 'discriminator' requires a string name
tests/qapi-schema/flat-union-inline-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-inline-invalid-dict.json: In union 'TestUnion': -tests/qapi-schema/flat-union-inline-invalid-dict.json:7: key 'type' is missing from member 'value1' of union 'TestUnion' +tests/qapi-schema/flat-union-inline-invalid-dict.json:7: 'data' member 'value1' misses key 'type'
tests/qapi-schema/flat-union-inline.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-inline.json: In union 'TestUnion': -tests/qapi-schema/flat-union-inline.json:7: member 'value1' of union 'TestUnion' should be a type name +tests/qapi-schema/flat-union-inline.json:7: 'data' member 'value1' should be a type name
tests/qapi-schema/flat-union-no-base.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/flat-union-no-base.json: In union 'TestUnion': -tests/qapi-schema/flat-union-no-base.json:9: flat union 'TestUnion' must have a base +tests/qapi-schema/flat-union-no-base.json:9: 'discriminator' requires 'base'
tests/qapi-schema/nested-struct-data-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/nested-struct-data-invalid-dict.json: In command 'foo': -tests/qapi-schema/nested-struct-data-invalid-dict.json:2: key 'type' is missing from member 'a' of 'data' for command 'foo' +tests/qapi-schema/nested-struct-data-invalid-dict.json:2: 'data' member 'a' misses key 'type'
tests/qapi-schema/nested-struct-data.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/nested-struct-data.json: In command 'foo': -tests/qapi-schema/nested-struct-data.json:2: member 'a' of 'data' for command 'foo' should be a type name +tests/qapi-schema/nested-struct-data.json:2: 'data' member 'a' should be a type name
tests/qapi-schema/reserved-enum-q.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-enum-q.json: In enum 'Foo': -tests/qapi-schema/reserved-enum-q.json:4: member of enum 'Foo' uses invalid name 'q-Unix' +tests/qapi-schema/reserved-enum-q.json:4: 'data' member uses invalid name 'q-Unix'
tests/qapi-schema/reserved-member-has.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-has.json: In command 'oops': -tests/qapi-schema/reserved-member-has.json:5: member of 'data' for command 'oops' uses reserved name 'has-a' +tests/qapi-schema/reserved-member-has.json:5: 'data' member 'has-a' uses reserved name
tests/qapi-schema/reserved-member-q.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-q.json: In struct 'Foo': -tests/qapi-schema/reserved-member-q.json:4: member of 'data' for struct 'Foo' uses invalid name 'q-unix' +tests/qapi-schema/reserved-member-q.json:4: 'data' member 'q-unix' uses invalid name 'q-unix'
tests/qapi-schema/reserved-member-u.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-u.json: In struct 'Oops': -tests/qapi-schema/reserved-member-u.json:7: member of 'data' for struct 'Oops' uses reserved name 'u' +tests/qapi-schema/reserved-member-u.json:7: 'data' member 'u' uses reserved name
tests/qapi-schema/reserved-member-underscore.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-member-underscore.json: In struct 'Oops': -tests/qapi-schema/reserved-member-underscore.json:4: member of 'data' for struct 'Oops' uses invalid name '_oops' +tests/qapi-schema/reserved-member-underscore.json:4: 'data' member '_oops' uses invalid name '_oops'
tests/qapi-schema/reserved-type-kind.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-type-kind.json: In enum 'UnionKind': -tests/qapi-schema/reserved-type-kind.json:2: enum 'UnionKind' should not end in 'Kind' +tests/qapi-schema/reserved-type-kind.json:2: enum name should not end in 'Kind'
tests/qapi-schema/reserved-type-list.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/reserved-type-list.json: In struct 'FooList': -tests/qapi-schema/reserved-type-list.json:5: struct 'FooList' should not end in 'List' +tests/qapi-schema/reserved-type-list.json:5: struct name should not end in 'List'
tests/qapi-schema/returns-array-bad.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/returns-array-bad.json: In command 'oops': -tests/qapi-schema/returns-array-bad.json:2: 'returns' for command 'oops': array type must contain single type name +tests/qapi-schema/returns-array-bad.json:2: 'returns': array type must contain single type name
tests/qapi-schema/returns-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/returns-dict.json: In command 'oops': -tests/qapi-schema/returns-dict.json:2: 'returns' for command 'oops' should be a type name +tests/qapi-schema/returns-dict.json:2: 'returns' should be a type name
tests/qapi-schema/struct-data-invalid.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/struct-data-invalid.json: In struct 'foo': -tests/qapi-schema/struct-data-invalid.json:1: 'data' for struct 'foo' should be an object or type name +tests/qapi-schema/struct-data-invalid.json:1: 'data' should be an object or type name
tests/qapi-schema/struct-member-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/struct-member-invalid-dict.json: In struct 'foo': -tests/qapi-schema/struct-member-invalid-dict.json:2: key 'type' is missing from member '*a' of 'data' for struct 'foo' +tests/qapi-schema/struct-member-invalid-dict.json:2: 'data' member '*a' misses key 'type'
tests/qapi-schema/struct-member-invalid.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/struct-member-invalid.json: In struct 'foo': -tests/qapi-schema/struct-member-invalid.json:1: member 'a' of 'data' for struct 'foo' should be a type name +tests/qapi-schema/struct-member-invalid.json:1: 'data' member 'a' should be a type name
tests/qapi-schema/union-base-no-discriminator.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-base-no-discriminator.json: In union 'TestUnion': -tests/qapi-schema/union-base-no-discriminator.json:11: simple union 'TestUnion' must not have a base +tests/qapi-schema/union-base-no-discriminator.json:11: 'base' requires 'discriminator'
tests/qapi-schema/union-branch-case.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-branch-case.json: In union 'Uni': -tests/qapi-schema/union-branch-case.json:2: member of union 'Uni' uses uppercase in name 'Branch' +tests/qapi-schema/union-branch-case.json:2: 'data' member 'Branch' uses uppercase in name 'Branch'
tests/qapi-schema/union-branch-invalid-dict.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-branch-invalid-dict.json: In union 'UnionInvalidBranch': -tests/qapi-schema/union-branch-invalid-dict.json:2: key 'type' is missing from member 'integer' of union 'UnionInvalidBranch' +tests/qapi-schema/union-branch-invalid-dict.json:2: 'data' member 'integer' misses key 'type'
tests/qapi-schema/union-optional-branch.err +1 -1
@@ -1,2 +1,2 @@ tests/qapi-schema/union-optional-branch.json: In union 'Union': -tests/qapi-schema/union-optional-branch.json:2: member of union 'Union' uses invalid name '*a' +tests/qapi-schema/union-optional-branch.json:2: 'data' member '*a' uses invalid name '*a'
tests/qapi-schema/unknown-expr-key.err +1 -1
@@ -1,3 +1,3 @@ tests/qapi-schema/unknown-expr-key.json: In struct 'bar': -tests/qapi-schema/unknown-expr-key.json:2: unknown keys 'bogus', 'phony' in struct 'bar' +tests/qapi-schema/unknown-expr-key.json:2: struct has unknown keys 'bogus', 'phony' Valid keys are 'base', 'data', 'features', 'if', 'struct'.
Signature · 1 line
2.21.0
Re: [PATCH 21/25] qapi: Avoid redundant definition references in error messages
Quoted 2 lines · Markus Armbruster
Many error messages refer to the offending definition even though they're preceded by an "in definition" line. Rephrase them.
This is the cleanup promised earlier in the series.
Quoted 10 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 113 +++++++----------- tests/qapi-schema/alternate-array.err | 2 +-def
check_command(expr, info):scripts/qapi/common.py +0
-1- name = expr['command'] args = expr.get('data') boxed = expr.get('boxed', False)
scripts/qapi/common.py def check_type(value, info, source, · line 773
Quoted 10 lines
scripts/qapi/common.py +2
-5if boxed and args is None: raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data' for command '%s'" % name, - allow_dict=not boxed) - check_type(expr.get('returns'), info, - "'returns' for command '%s'" % name, - allow_array=True) + check_type(expr.get('data'), info, "'data'", allow_dict=not boxed) + check_type(expr.get('returns'), info, "'returns'", allow_array=True)
Why are you repeating expr.get('dat') here instead of reusing args? I guess it adds consistency with the expr.get('returns') in the next line.
scripts/qapi/common.py def check_type(value, info, source, · line 782
Quoted 12 lines
def
check_event(expr, info):scripts/qapi/common.py +1
-3- name = expr['event'] args = expr.get('data') boxed = expr.get('boxed', False) if boxed and args is None: raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data' for event '%s'" % name, - allow_dict=not boxed) + check_type(expr.get('data'), info, "'data'", allow_dict=not boxed)
Again, why not reuse args?
tests/qapi-schema/args-member-case.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/args-member-case.err
tests/qapi-schema/args-member-case.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-case.json: In command 'no-way-this-will-get-whitelisted': -tests/qapi-schema/args-member-case.json:2: member of 'data' for command 'no-way-this-will-get-whitelisted' uses uppercase in name 'Arg' +tests/qapi-schema/args-member-case.json:2: 'data' member 'Arg' uses uppercase in name 'Arg'
Better, but still feels redundant for calling out 'Arg' twice. Maybe you further clean this one later?
tests/qapi-schema/enum-member-case.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/enum-member-case.err
tests/qapi-schema/enum-member-case.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/enum-member-case.json: In enum 'NoWayThisWillGetWhitelisted': -tests/qapi-schema/enum-member-case.json:4: member of enum 'NoWayThisWillGetWhitelisted' uses uppercase in name 'Value' +tests/qapi-schema/enum-member-case.json:4: 'data' member uses uppercase in name 'Value'
Here's a similar error about uppercase that does not have the redundancy, for comparison.
tests/qapi-schema/union-branch-case.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/union-branch-case.err
tests/qapi-schema/union-branch-case.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/union-branch-case.json: In union 'Uni': -tests/qapi-schema/union-branch-case.json:2: member of union 'Uni' uses uppercase in name 'Branch' +tests/qapi-schema/union-branch-case.json:2: 'data' member 'Branch' uses uppercase in name 'Branch'
Another related one.
tests/qapi-schema/union-optional-branch.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/union-optional-branch.err
tests/qapi-schema/union-optional-branch.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/union-optional-branch.json: In union 'Union': -tests/qapi-schema/union-optional-branch.json:2: member of union 'Union' uses invalid name '*a' +tests/qapi-schema/union-optional-branch.json:2: 'data' member '*a' uses invalid name '*a'
Similar type of redundancy, but this time not related to uppercase.
Overall an improvement.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 21/25] qapi: Avoid redundant definition references in error messages
Quoted 27 lines · Eric Blake
Quoted 2 lines · Markus Armbruster
Many error messages refer to the offending definition even though they're preceded by an "in definition" line. Rephrase them.
This is the cleanup promised earlier in the series.
Quoted 10 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 113 +++++++----------- tests/qapi-schema/alternate-array.err | 2 +-def
check_command(expr, info):scripts/qapi/common.py +0
-1- name = expr['command'] args = expr.get('data') boxed = expr.get('boxed', False)scripts/qapi/common.py def check_type(value, info, source, · line 773
Quoted 10 lines
scripts/qapi/common.py +2
-5if boxed and args is None: raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data' for command '%s'" % name, - allow_dict=not boxed) - check_type(expr.get('returns'), info, - "'returns' for command '%s'" % name, - allow_array=True) + check_type(expr.get('data'), info, "'data'", allow_dict=not boxed) + check_type(expr.get('returns'), info, "'returns'", allow_array=True)
Quoted 2 lines
Why are you repeating
expr.get('dat')here instead of reusing args? I guess it adds consistency with theexpr.get('returns')in the next line.
Don't remember, might have been an accident. If I want consistency, I guess I should add rets = expr.get('returns').
Quoted 15 lines
scripts/qapi/common.py def check_type(value, info, source, · line 782
Quoted 12 lines
def
check_event(expr, info):scripts/qapi/common.py +1
-3- name = expr['event'] args = expr.get('data') boxed = expr.get('boxed', False) if boxed and args is None: raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data' for event '%s'" % name, - allow_dict=not boxed) + check_type(expr.get('data'), info, "'data'", allow_dict=not boxed)Again, why not reuse args?
Quoted 8 lines
tests/qapi-schema/args-member-case.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/args-member-case.err
tests/qapi-schema/args-member-case.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/args-member-case.json: In command 'no-way-this-will-get-whitelisted': -tests/qapi-schema/args-member-case.json:2: member of 'data' for command 'no-way-this-will-get-whitelisted' uses uppercase in name 'Arg' +tests/qapi-schema/args-member-case.json:2: 'data' member 'Arg' uses uppercase in name 'Arg'Better, but still feels redundant for calling out 'Arg' twice. Maybe you further clean this one later?
check_type()'s error messages interpolate @source received from by caller. Need to review all its messages and callers.
Quoted 18 lines
tests/qapi-schema/enum-member-case.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/enum-member-case.err
tests/qapi-schema/enum-member-case.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/enum-member-case.json: In enum 'NoWayThisWillGetWhitelisted': -tests/qapi-schema/enum-member-case.json:4: member of enum 'NoWayThisWillGetWhitelisted' uses uppercase in name 'Value' +tests/qapi-schema/enum-member-case.json:4: 'data' member uses uppercase in name 'Value'Here's a similar error about uppercase that does not have the redundancy, for comparison.
tests/qapi-schema/union-branch-case.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/union-branch-case.err
tests/qapi-schema/union-branch-case.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/union-branch-case.json: In union 'Uni': -tests/qapi-schema/union-branch-case.json:2: member of union 'Uni' uses uppercase in name 'Branch' +tests/qapi-schema/union-branch-case.json:2: 'data' member 'Branch' uses uppercase in name 'Branch'Another related one.
Quoted 7 lines
tests/qapi-schema/union-optional-branch.err line 2
Quoted 5 lines
+++ b/tests/qapi-schema/union-optional-branch.err
tests/qapi-schema/union-optional-branch.err +1
-1@@ -1,2 +1,2 @@ tests/qapi-schema/union-optional-branch.json: In union 'Union': -tests/qapi-schema/union-optional-branch.json:2: member of union 'Union' uses invalid name '*a' +tests/qapi-schema/union-optional-branch.json:2: 'data' member '*a' uses invalid name '*a'Similar type of redundancy, but this time not related to uppercase.
Same problem, different function: check_name_str().
Quoted 3 lines
Overall an improvement.
Reviewed-by Eric Blake <[email protected]>
Thanks!
PATCH 22/25 qapi: Eliminate check_keys(), rename check_known_keys()
In reply to Markus Armbrustercheck_keys() has become a trivial wrapper for check_known_keys(). Eliminate it.
This makes its name available. Rename check_known_keys().
--- scripts/qapi/common.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
scripts/qapi/common.py +21 -19
@@ -757,7 +757,7 @@ def check_type(value, info, source, allow_optional=True, permit_upper=permit_upper) if c_name(key, False) == 'u' or c_name(key, False).startswith('has_'): raise QAPISemError(info, "%s uses reserved name" % key_source) - check_known_keys(arg, info, key_source, ['type'], ['if']) + check_keys(arg, info, key_source, ['type'], ['if']) check_if(arg, info) normalize_if(arg) check_type(arg['type'], info, key_source, allow_array=True)
@@ -800,7 +800,7 @@ def check_union(expr, info): for (key, value) in members.items(): source = "'data' member '%s'" % key check_name_str(key, info, source) - check_known_keys(value, info, source, ['type'], ['if']) + check_keys(value, info, source, ['type'], ['if']) check_if(value, info) normalize_if(value) check_type(value['type'], info, source, allow_array=not base)
@@ -814,7 +814,7 @@ def check_alternate(expr, info): for (key, value) in members.items(): source = "'data' member '%s'" % key check_name_str(key, info, source) - check_known_keys(value, info, source, ['type'], ['if']) + check_keys(value, info, source, ['type'], ['if']) check_if(value, info) normalize_if(value) check_type(value['type'], info, source)
@@ -834,7 +834,7 @@ def check_enum(expr, info): for member in members: source = "'data' member" - check_known_keys(member, info, source, ['name'], ['if']) + check_keys(member, info, source, ['name'], ['if']) check_if(member, info) normalize_if(member) check_name(member['name'], info, source,
@@ -855,13 +855,13 @@ def check_struct(expr, info): for f in features: source = "'features' member" assert isinstance(f, dict) - check_known_keys(f, info, source, ['name'], ['if']) + check_keys(f, info, source, ['name'], ['if']) check_if(f, info) normalize_if(f) check_name(f['name'], info, source) -def check_known_keys(value, info, source, required, optional): +def check_keys(value, info, source, required, optional): def pprint(elems): return ', '.join("'" + e + "'" for e in sorted(elems))
@@ -879,10 +879,6 @@ def check_known_keys(value, info, source, required, optional): pprint(unknown), pprint(allowed))) -def check_keys(expr, info, meta, required, optional=[]): - check_known_keys(expr, info, meta, required + [meta], optional) - - def check_flags(expr, info): for key in ['gen', 'success-response']: if key in expr and expr[key] is not False:
@@ -958,33 +954,39 @@ def check_exprs(exprs): info, "documentation comment is for '%s'" % doc.symbol) if meta == 'enum': - check_keys(expr, info, 'enum', ['data'], ['if', 'prefix']) + check_keys(expr, info, meta, + ['enum', 'data'], ['if', 'prefix']) normalize_enum(expr) check_enum(expr, info) elif meta == 'union': - check_keys(expr, info, 'union', ['data'], + check_keys(expr, info, meta, + ['union', 'data'], ['base', 'discriminator', 'if']) normalize_members(expr.get('base')) normalize_members(expr['data']) check_union(expr, info) elif meta == 'alternate': - check_keys(expr, info, 'alternate', ['data'], ['if']) + check_keys(expr, info, meta, + ['alternate', 'data'], ['if']) normalize_members(expr['data']) check_alternate(expr, info) elif meta == 'struct': - check_keys(expr, info, 'struct', ['data'], - ['base', 'if', 'features']) + check_keys(expr, info, meta, + ['struct', 'data'], ['base', 'if', 'features']) normalize_members(expr['data']) normalize_features(expr.get('features')) check_struct(expr, info) elif meta == 'command': - check_keys(expr, info, 'command', [], - ['data', 'returns', 'gen', 'success-response', - 'boxed', 'allow-oob', 'allow-preconfig', 'if']) + check_keys(expr, info, meta, + ['command'], + ['data', 'returns', 'boxed', 'if', + 'gen', 'success-response', 'allow-oob', + 'allow-preconfig']) normalize_members(expr.get('data')) check_command(expr, info) elif meta == 'event': - check_keys(expr, info, 'event', [], ['data', 'boxed', 'if']) + check_keys(expr, info, meta, + ['event'], ['data', 'boxed', 'if']) normalize_members(expr.get('data')) check_event(expr, info) else:
Signature · 1 line
2.21.0
Re: [PATCH 22/25] qapi: Eliminate check_keys(), rename check_known_keys()
Quoted 10 lines · Markus Armbruster
check_keys()has become a trivial wrapper forcheck_known_keys(). Eliminate it.This makes its name available. Rename
check_known_keys().Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 23/25 qapi: Improve reporting of missing documentation comment
In reply to Markus ArmbrusterHave check_exprs() check this later, so the error message gains an "in definition line". Tweak the error message.
--- scripts/qapi/common.py | 18 ++++++++---------- tests/qapi-schema/doc-missing.err | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-)
scripts/qapi/common.py +8 -10
@@ -925,10 +925,6 @@ def check_exprs(exprs): if 'include' in expr: continue - if not doc and doc_required: - raise QAPISemError(info, - "definition missing documentation comment") - if 'enum' in expr: meta = 'enum' elif 'union' in expr:
@@ -949,9 +945,14 @@ def check_exprs(exprs): info.set_defn(meta, name) check_defn_name_str(name, info, meta) - if doc and doc.symbol != name: - raise QAPISemError( - info, "documentation comment is for '%s'" % doc.symbol) + if doc: + if doc.symbol != name: + raise QAPISemError( + info, "documentation comment is for '%s'" % doc.symbol) + doc.check_expr(expr) + elif doc_required: + raise QAPISemError(info, + "documentation comment required") if meta == 'enum': check_keys(expr, info, meta,
@@ -996,9 +997,6 @@ def check_exprs(exprs): check_if(expr, info) check_flags(expr, info) - if doc: - doc.check_expr(expr) - return exprs
tests/qapi-schema/doc-missing.err +2 -1
@@ -1 +1,2 @@ -tests/qapi-schema/doc-missing.json:5: definition missing documentation comment +tests/qapi-schema/doc-missing.json: In command 'undocumented': +tests/qapi-schema/doc-missing.json:5: documentation comment required
Signature · 1 line
2.21.0
Re: [PATCH 23/25] qapi: Improve reporting of missing documentation comment
Quoted 9 lines · Markus Armbruster
Have
check_exprs()check this later, so the error message gains an "in definition line". Tweak the error message.Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 18 ++++++++---------- tests/qapi-schema/doc-missing.err | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 24/25 qapi: Improve reporting of redefinition
In reply to Markus ArmbrusterPoint to the previous definition, unless it's a built-in.
--- scripts/qapi/common.py | 5 +++++ tests/qapi-schema/redefined-command.err | 4 +++- tests/qapi-schema/redefined-event.err | 4 +++- tests/qapi-schema/redefined-type.err | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-)
scripts/qapi/common.py +5 -0
@@ -1748,6 +1748,11 @@ class QAPISchema(object): # because they're liable to clash in generated C. other_ent = self._entity_dict.get(ent.name) if other_ent: + if other_ent.info: + where = QAPIError(other_ent.info, None, "previous definition") + raise QAPISemError( + ent.info, + "'%s' is already defined\n%s" % (ent.name, where)) raise QAPISemError( ent.info, "%s is already defined" % other_ent.describe()) self._entity_dict[ent.name] = ent
tests/qapi-schema/redefined-command.err +3 -1
@@ -1,2 +1,4 @@ tests/qapi-schema/redefined-command.json: In command 'foo': -tests/qapi-schema/redefined-command.json:3: command 'foo' is already defined +tests/qapi-schema/redefined-command.json:3: 'foo' is already defined +tests/qapi-schema/redefined-command.json: In command 'foo': +tests/qapi-schema/redefined-command.json:2: previous definition
tests/qapi-schema/redefined-event.err +3 -1
@@ -1,2 +1,4 @@ tests/qapi-schema/redefined-event.json: In event 'EVENT_A': -tests/qapi-schema/redefined-event.json:3: event 'EVENT_A' is already defined +tests/qapi-schema/redefined-event.json:3: 'EVENT_A' is already defined +tests/qapi-schema/redefined-event.json: In event 'EVENT_A': +tests/qapi-schema/redefined-event.json:2: previous definition
tests/qapi-schema/redefined-type.err +3 -1
@@ -1,2 +1,4 @@ tests/qapi-schema/redefined-type.json: In enum 'foo': -tests/qapi-schema/redefined-type.json:3: struct type 'foo' is already defined +tests/qapi-schema/redefined-type.json:3: 'foo' is already defined +tests/qapi-schema/redefined-type.json: In struct 'foo': +tests/qapi-schema/redefined-type.json:2: previous definition
Signature · 1 line
2.21.0
Re: [PATCH 24/25] qapi: Improve reporting of redefinition
scripts/qapi/common.py class QAPISchema(object): · line 1757
Quoted 13 lines · Markus Armbruster
Point to the previous definition, unless it's a built-in.
Signed-off-by Markus Armbruster <[email protected]>---
if
other_ent:scripts/qapi/common.py +5
-0+ if other_ent.info: + where = QAPIError(other_ent.info, None, "previous definition") + raise QAPISemError( + ent.info, + "'%s' is already defined\n%s" % (ent.name, where)) raise QAPISemError( ent.info, "%s is already defined" % other_ent.describe())
Nice.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
PATCH 25/25 qapi: Improve source file read error handling
In reply to Markus Armbrusterqap-gen.py crashes when it can't open the main schema file, and when it can't read from any schema file. Lazy.
Change QAPISchema.__init__() to take a file name instead of a file object. Move the open code from _include() to __init__(), so it's used for the main schema file, too.
Move the read into the try for good measure, and rephrase the error message.
Reporting open or read failure for the main schema file needs a QAPISourceInfo representing "no source". Make QAPISourceInfo cope with fname=None.
--- scripts/qapi/common.py | 46 +++++++++++++++------------ tests/qapi-schema/include-no-file.err | 2 +- 2 files changed, 27 insertions(+), 21 deletions(-)
scripts/qapi/common.py +26 -20
@@ -53,7 +53,12 @@ class QAPISourceInfo(object): return info def loc(self): - return '%s:%d' % (self.fname, self.line) + if self.fname is None: + return sys.argv[0] + ret = self.fname + if self.line is not None: + ret += ':%d' % self.line + return ret def in_defn(self): if self.defn_name:
@@ -382,14 +387,26 @@ class QAPIDoc(object): class QAPISchemaParser(object): - def __init__(self, fp, previously_included=[], incl_info=None): - self.fname = fp.name - previously_included.append(os.path.abspath(fp.name)) - self.src = fp.read() + def __init__(self, fname, previously_included=[], incl_info=None): + previously_included.append(os.path.abspath(fname)) + + try: + if sys.version_info[0] >= 3: + fp = open(fname, 'r', encoding='utf-8') + else: + fp = open(fname, 'r') + self.src = fp.read() + except IOError as e: + raise QAPISemError(incl_info or QAPISourceInfo(None, None, None), + "can't read %s file '%s': %s" + % ("include" if incl_info else "schema", + fname, + e.strerror)) + if self.src == '' or self.src[-1] != '\n': self.src += '\n' self.cursor = 0 - self.info = QAPISourceInfo(self.fname, 1, incl_info) + self.info = QAPISourceInfo(fname, 1, incl_info) self.line_pos = 0 self.exprs = [] self.docs = []
@@ -413,7 +430,7 @@ class QAPISchemaParser(object): if not isinstance(include, str): raise QAPISemError(info, "value of 'include' must be a string") - incl_fname = os.path.join(os.path.dirname(self.fname), + incl_fname = os.path.join(os.path.dirname(fname), include) self.exprs.append({'expr': {'include': incl_fname}, 'info': info})
@@ -465,14 +482,7 @@ class QAPISchemaParser(object): if incl_abs_fname in previously_included: return None - try: - if sys.version_info[0] >= 3: - fobj = open(incl_fname, 'r', encoding='utf-8') - else: - fobj = open(incl_fname, 'r') - except IOError as e: - raise QAPISemError(info, "%s: %s" % (e.strerror, incl_fname)) - return QAPISchemaParser(fobj, previously_included, info) + return QAPISchemaParser(incl_fname, previously_included, info) def _pragma(self, name, value, info): global doc_required, returns_whitelist, name_case_whitelist
@@ -1723,11 +1733,7 @@ class QAPISchemaEvent(QAPISchemaEntity): class QAPISchema(object): def __init__(self, fname): self.fname = fname - if sys.version_info[0] >= 3: - f = open(fname, 'r', encoding='utf-8') - else: - f = open(fname, 'r') - parser = QAPISchemaParser(f) + parser = QAPISchemaParser(fname) exprs = check_exprs(parser.exprs) self.docs = parser.docs self._entity_list = []
tests/qapi-schema/include-no-file.err +1 -1
@@ -1 +1 @@ -tests/qapi-schema/include-no-file.json:1: No such file or directory: tests/qapi-schema/include-no-file-sub.json +tests/qapi-schema/include-no-file.json:1: can't read include file 'tests/qapi-schema/include-no-file-sub.json': No such file or directory
Signature · 1 line
2.21.0
Re: [PATCH 25/25] qapi: Improve source file read error handling
Quoted 1 line · Markus Armbruster
qap-gen.pycrashes when it can't open the main schema file, and when
qapi-gen.py
Quoted 13 lines
it can't read from any schema file. Lazy.
Change
QAPISchema.__init__()to take a file name instead of a file object. Move the open code from_include()to__init__(), so it's used for the main schema file, too.Move the read into the try for good measure, and rephrase the error message.
Reporting open or read failure for the main schema file needs a QAPISourceInfo representing "no source". Make QAPISourceInfo cope with fname=None.
Quoted 6 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 46 +++++++++++++++------------ tests/qapi-schema/include-no-file.err | 2 +- 2 files changed, 27 insertions(+), 21 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH 25/25] qapi: Improve source file read error handling
Quoted 4 lines · Eric Blake
Quoted 1 line · Markus Armbruster
qap-gen.pycrashes when it can't open the main schema file, and when
qapi-gen.py
Will fix.
Quoted 13 lines
Quoted 13 lines
it can't read from any schema file. Lazy.
Change
QAPISchema.__init__()to take a file name instead of a file object. Move the open code from_include()to__init__(), so it's used for the main schema file, too.Move the read into the try for good measure, and rephrase the error message.
Reporting open or read failure for the main schema file needs a QAPISourceInfo representing "no source". Make QAPISourceInfo cope with fname=None.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Markus Armbruster <[email protected]>--- scripts/qapi/common.py | 46 +++++++++++++++------------ tests/qapi-schema/include-no-file.err | 2 +- 2 files changed, 27 insertions(+), 21 deletions(-)Reviewed-by Eric Blake <[email protected]>
Thanks!