From nobody Mon Feb 9 19:53:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489583925159611.929699995615; Wed, 15 Mar 2017 06:18:45 -0700 (PDT) Received: from localhost ([::1]:37104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1co8p5-0001uz-R0 for importer@patchew.org; Wed, 15 Mar 2017 09:18:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33496) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1co8Uu-0001XF-8n for qemu-devel@nongnu.org; Wed, 15 Mar 2017 08:57:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1co8Up-0000JS-Rx for qemu-devel@nongnu.org; Wed, 15 Mar 2017 08:57:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1co8Up-0000HO-Cn for qemu-devel@nongnu.org; Wed, 15 Mar 2017 08:57:43 -0400 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1BCF2624AB; Wed, 15 Mar 2017 12:57:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 855562D5C7; Wed, 15 Mar 2017 12:57:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9F984113860A; Wed, 15 Mar 2017 13:57:36 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1BCF2624AB Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1BCF2624AB From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 15 Mar 2017 13:57:03 +0100 Message-Id: <1489582656-31133-15-git-send-email-armbru@redhat.com> In-Reply-To: <1489582656-31133-1-git-send-email-armbru@redhat.com> References: <1489582656-31133-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 15 Mar 2017 12:57:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 for-2.9 14/47] qapi: Prepare for requiring more complete documentation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We currently neglect to check all enumeration values, common members of object types and members of alternate types are documented. Unsurprisingly, many aren't. Add the necessary plumbing to find undocumented ones, except for variant members of object types. Don't enforce anything just yet, but connect each QAPIDoc.ArgSection to its QAPISchemaMember. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi.py | 110 +++++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index dd083b7..c1e0bed 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -116,7 +116,12 @@ class QAPIDoc(object): return "\n".join(self.content).strip() =20 class ArgSection(Section): - pass + def __init__(self, name): + QAPIDoc.Section.__init__(self, name) + self.member =3D None + + def connect(self, member): + self.member =3D member =20 def __init__(self, parser, info): # self.parser is used to report errors with QAPIParseError. The @@ -216,6 +221,13 @@ class QAPIDoc(object): line =3D line.strip() self.section.append(line) =20 + def connect_member(self, member): + if member.name not in self.args: + # Undocumented TODO outlaw + pass + else: + self.args[member.name].connect(member) + =20 class QAPISchemaParser(object): =20 @@ -1021,7 +1033,7 @@ def check_docs(docs): # =20 class QAPISchemaEntity(object): - def __init__(self, name, info): + def __init__(self, name, info, doc): assert isinstance(name, str) self.name =3D name # For explicitly defined entities, info points to the (explicit) @@ -1030,6 +1042,7 @@ class QAPISchemaEntity(object): # triggered the implicit definition (there may be more than one # such place). self.info =3D info + self.doc =3D doc =20 def c_name(self): return c_name(self.name) @@ -1111,7 +1124,7 @@ class QAPISchemaType(QAPISchemaEntity): =20 class QAPISchemaBuiltinType(QAPISchemaType): def __init__(self, name, json_type, c_type): - QAPISchemaType.__init__(self, name, None) + QAPISchemaType.__init__(self, name, None, None) assert not c_type or isinstance(c_type, str) assert json_type in ('string', 'number', 'int', 'boolean', 'null', 'value') @@ -1137,8 +1150,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): =20 =20 class QAPISchemaEnumType(QAPISchemaType): - def __init__(self, name, info, values, prefix): - QAPISchemaType.__init__(self, name, info) + def __init__(self, name, info, doc, values, prefix): + QAPISchemaType.__init__(self, name, info, doc) for v in values: assert isinstance(v, QAPISchemaMember) v.set_owner(name) @@ -1150,6 +1163,8 @@ class QAPISchemaEnumType(QAPISchemaType): seen =3D {} for v in self.values: v.check_clash(self.info, seen) + if self.doc: + self.doc.connect_member(v) =20 def is_implicit(self): # See QAPISchema._make_implicit_enum_type() and ._def_predefineds() @@ -1171,7 +1186,7 @@ class QAPISchemaEnumType(QAPISchemaType): =20 class QAPISchemaArrayType(QAPISchemaType): def __init__(self, name, info, element_type): - QAPISchemaType.__init__(self, name, info) + QAPISchemaType.__init__(self, name, info, None) assert isinstance(element_type, str) self._element_type_name =3D element_type self.element_type =3D None @@ -1194,11 +1209,11 @@ class QAPISchemaArrayType(QAPISchemaType): =20 =20 class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, base, local_members, variants): + def __init__(self, name, info, doc, base, local_members, variants): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base - QAPISchemaType.__init__(self, name, info) + QAPISchemaType.__init__(self, name, info, doc) assert base is None or isinstance(base, str) for m in local_members: assert isinstance(m, QAPISchemaObjectTypeMember) @@ -1228,6 +1243,8 @@ class QAPISchemaObjectType(QAPISchemaType): for m in self.local_members: m.check(schema) m.check_clash(self.info, seen) + if self.doc: + self.doc.connect_member(m) self.members =3D seen.values() if self.variants: self.variants.check(schema, seen) @@ -1382,8 +1399,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTyp= eMember): =20 =20 class QAPISchemaAlternateType(QAPISchemaType): - def __init__(self, name, info, variants): - QAPISchemaType.__init__(self, name, info) + def __init__(self, name, info, doc, variants): + QAPISchemaType.__init__(self, name, info, doc) assert isinstance(variants, QAPISchemaObjectTypeVariants) assert variants.tag_member variants.set_owner(name) @@ -1400,6 +1417,8 @@ class QAPISchemaAlternateType(QAPISchemaType): seen =3D {} for v in self.variants.variants: v.check_clash(self.info, seen) + if self.doc: + self.doc.connect_member(v) =20 def c_type(self): return c_name(self.name) + pointer_suffix @@ -1415,9 +1434,9 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 =20 class QAPISchemaCommand(QAPISchemaEntity): - def __init__(self, name, info, arg_type, ret_type, gen, success_respon= se, - boxed): - QAPISchemaEntity.__init__(self, name, info) + def __init__(self, name, info, doc, arg_type, ret_type, + gen, success_response, boxed): + QAPISchemaEntity.__init__(self, name, info, doc) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) self._arg_type_name =3D arg_type @@ -1454,8 +1473,8 @@ class QAPISchemaCommand(QAPISchemaEntity): =20 =20 class QAPISchemaEvent(QAPISchemaEntity): - def __init__(self, name, info, arg_type, boxed): - QAPISchemaEntity.__init__(self, name, info) + def __init__(self, name, info, doc, arg_type, boxed): + QAPISchemaEntity.__init__(self, name, info, doc) assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type self.arg_type =3D None @@ -1537,14 +1556,14 @@ class QAPISchema(object): ('bool', 'boolean', 'bool'), ('any', 'value', 'QObject' + pointer_suffix)]: self._def_builtin_type(*t) - self.the_empty_object_type =3D QAPISchemaObjectType('q_empty', Non= e, - None, [], None) + self.the_empty_object_type =3D QAPISchemaObjectType( + 'q_empty', None, None, None, [], None) self._def_entity(self.the_empty_object_type) qtype_values =3D self._make_enum_members(['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist= ', 'qfloat', 'qbool']) - self._def_entity(QAPISchemaEnumType('QType', None, qtype_values, - 'QTYPE')) + self._def_entity(QAPISchemaEnumType('QType', None, None, + qtype_values, 'QTYPE')) =20 def _make_enum_members(self, values): return [QAPISchemaMember(v) for v in values] @@ -1553,7 +1572,7 @@ class QAPISchema(object): # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D name + 'Kind' # Use namespace reserved by add_name() self._def_entity(QAPISchemaEnumType( - name, info, self._make_enum_members(values), None)) + name, info, None, self._make_enum_members(values), None)) return name =20 def _make_array_type(self, element_type, info): @@ -1562,22 +1581,22 @@ class QAPISchema(object): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name =20 - def _make_implicit_object_type(self, name, info, role, members): + def _make_implicit_object_type(self, name, info, doc, role, members): if not members: return None # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D 'q_obj_%s-%s' % (name, role) if not self.lookup_entity(name, QAPISchemaObjectType): - self._def_entity(QAPISchemaObjectType(name, info, None, + self._def_entity(QAPISchemaObjectType(name, info, doc, None, members, None)) return name =20 - def _def_enum_type(self, expr, info): + def _def_enum_type(self, expr, info, doc): name =3D expr['enum'] data =3D expr['data'] prefix =3D expr.get('prefix') self._def_entity(QAPISchemaEnumType( - name, info, self._make_enum_members(data), prefix)) + name, info, doc, self._make_enum_members(data), prefix)) =20 def _make_member(self, name, typ, info): optional =3D False @@ -1593,11 +1612,11 @@ class QAPISchema(object): return [self._make_member(key, value, info) for (key, value) in data.iteritems()] =20 - def _def_struct_type(self, expr, info): + def _def_struct_type(self, expr, info, doc): name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] - self._def_entity(QAPISchemaObjectType(name, info, base, + self._def_entity(QAPISchemaObjectType(name, info, doc, base, self._make_members(data, inf= o), None)) =20 @@ -1609,10 +1628,10 @@ class QAPISchema(object): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) typ =3D self._make_implicit_object_type( - typ, info, 'wrapper', [self._make_member('data', typ, info)]) + typ, info, None, 'wrapper', [self._make_member('data', typ, in= fo)]) return QAPISchemaObjectTypeVariant(case, typ) =20 - def _def_union_type(self, expr, info): + def _def_union_type(self, expr, info, doc): name =3D expr['union'] data =3D expr['data'] base =3D expr.get('base') @@ -1620,7 +1639,7 @@ class QAPISchema(object): tag_member =3D None if isinstance(base, dict): base =3D (self._make_implicit_object_type( - name, info, 'base', self._make_members(base, info))) + name, info, doc, 'base', self._make_members(base, info= ))) if tag_name: variants =3D [self._make_variant(key, value) for (key, value) in data.iteritems()] @@ -1633,24 +1652,24 @@ class QAPISchema(object): tag_member =3D QAPISchemaObjectTypeMember('type', typ, False) members =3D [tag_member] self._def_entity( - QAPISchemaObjectType(name, info, base, members, + QAPISchemaObjectType(name, info, doc, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, variants))) =20 - def _def_alternate_type(self, expr, info): + def _def_alternate_type(self, expr, info, doc): name =3D expr['alternate'] data =3D expr['data'] variants =3D [self._make_variant(key, value) for (key, value) in data.iteritems()] tag_member =3D QAPISchemaObjectTypeMember('type', 'QType', False) self._def_entity( - QAPISchemaAlternateType(name, info, + QAPISchemaAlternateType(name, info, doc, QAPISchemaObjectTypeVariants(None, tag_membe= r, variants)= )) =20 - def _def_command(self, expr, info): + def _def_command(self, expr, info, doc): name =3D expr['command'] data =3D expr.get('data') rets =3D expr.get('returns') @@ -1659,38 +1678,39 @@ class QAPISchema(object): boxed =3D expr.get('boxed', False) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, 'arg', self._make_members(data, info)) + name, info, doc, 'arg', self._make_members(data, info)) if isinstance(rets, list): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) - self._def_entity(QAPISchemaCommand(name, info, data, rets, gen, - success_response, boxed)) + self._def_entity(QAPISchemaCommand(name, info, doc, data, rets, + gen, success_response, boxed)) =20 - def _def_event(self, expr, info): + def _def_event(self, expr, info, doc): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, data, boxed)) + name, info, doc, 'arg', self._make_members(data, info)) + self._def_entity(QAPISchemaEvent(name, info, doc, data, boxed)) =20 def _def_exprs(self): for expr_elem in self.exprs: expr =3D expr_elem['expr'] info =3D expr_elem['info'] + doc =3D expr_elem.get('doc') if 'enum' in expr: - self._def_enum_type(expr, info) + self._def_enum_type(expr, info, doc) elif 'struct' in expr: - self._def_struct_type(expr, info) + self._def_struct_type(expr, info, doc) elif 'union' in expr: - self._def_union_type(expr, info) + self._def_union_type(expr, info, doc) elif 'alternate' in expr: - self._def_alternate_type(expr, info) + self._def_alternate_type(expr, info, doc) elif 'command' in expr: - self._def_command(expr, info) + self._def_command(expr, info, doc) elif 'event' in expr: - self._def_event(expr, info) + self._def_event(expr, info, doc) else: assert False =20 --=20 2.7.4