A future patch will enable error detection in the various QapiSchema check() methods. But since all errors have to have an associated 'info' location, we need a location to be associated with all implicit types. Easiest is to reuse the location of the enclosing entity that includes the dictionary defining the implicit type.
While at it, we were always passing None as the location of array types, making that parameter useless; sharing the location (if any) of the underlying element type makes sense. Signed-off-by: Eric Blake <ebl...@redhat.com> --- scripts/qapi.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 1dc7641..e982970 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -908,8 +908,8 @@ class QAPISchemaEnumType(QAPISchemaType): class QAPISchemaArrayType(QAPISchemaType): - def __init__(self, name, info, element_type): - QAPISchemaType.__init__(self, name, info) + def __init__(self, name, element_type): + QAPISchemaType.__init__(self, name, None) assert isinstance(element_type, str) self._element_type_name = element_type self.element_type = None @@ -917,6 +917,7 @@ class QAPISchemaArrayType(QAPISchemaType): def check(self, schema): self.element_type = schema.lookup_type(self._element_type_name) assert self.element_type + self._info = self.element_type._info def json_type(self): return 'array' @@ -928,6 +929,7 @@ class QAPISchemaArrayType(QAPISchemaType): class QAPISchemaObjectType(QAPISchemaType): def __init__(self, name, info, base, local_members, variants): QAPISchemaType.__init__(self, name, info) + assert info or name == ':empty' assert base is None or isinstance(base, str) for m in local_members: assert isinstance(m, QAPISchemaObjectTypeMember) @@ -1165,15 +1167,15 @@ class QAPISchema(object): def _make_array_type(self, element_type): name = element_type + 'List' if not self.lookup_type(name): - self._def_entity(QAPISchemaArrayType(name, None, element_type)) + self._def_entity(QAPISchemaArrayType(name, element_type)) return name - def _make_implicit_object_type(self, name, role, members): + def _make_implicit_object_type(self, name, info, role, members): if not members: return None name = ':obj-%s-%s' % (name, role) if not self.lookup_entity(name, QAPISchemaObjectType): - self._def_entity(QAPISchemaObjectType(name, None, None, + self._def_entity(QAPISchemaObjectType(name, info, None, members, None)) return name @@ -1210,11 +1212,11 @@ class QAPISchema(object): def _make_variant(self, case, typ): return QAPISchemaObjectTypeVariant(case, typ) - def _make_simple_variant(self, case, typ): + def _make_simple_variant(self, info, case, typ): if isinstance(typ, list): assert len(typ) == 1 typ = self._make_array_type(typ[0]) - typ = self._make_implicit_object_type(typ, 'wrapper', + typ = self._make_implicit_object_type(typ, info, 'wrapper', [self._make_member('data', typ)]) return QAPISchemaObjectTypeVariant(case, typ) @@ -1232,7 +1234,7 @@ class QAPISchema(object): variants = [self._make_variant(key, value) for (key, value) in data.iteritems()] else: - variants = [self._make_simple_variant(key, value) + variants = [self._make_simple_variant(info, key, value) for (key, value) in data.iteritems()] tag_enum = self._make_tag_enum(name, variants) self._def_entity( @@ -1263,7 +1265,7 @@ class QAPISchema(object): gen = expr.get('gen', True) success_response = expr.get('success-response', True) if isinstance(data, OrderedDict): - data = self._make_implicit_object_type(name, 'arg', + data = self._make_implicit_object_type(name, info, 'arg', self._make_members(data)) if isinstance(rets, list): assert len(rets) == 1 @@ -1275,7 +1277,7 @@ class QAPISchema(object): name = expr['event'] data = expr.get('data') if isinstance(data, OrderedDict): - data = self._make_implicit_object_type(name, 'arg', + data = self._make_implicit_object_type(name, info, 'arg', self._make_members(data)) self._def_entity(QAPISchemaEvent(name, info, data)) -- 2.4.3