From nobody Fri Nov 14 03:47:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584480244; cv=none; d=zohomail.com; s=zohoarc; b=ELfm6wvYj3D+gUGn8scVEnQ5c9ULZQnZ5OLn5y2lU+drdHoKBM2QZXHty57BPkxOx5CA+k10AMaFC4odxjh8WAZd6NarZur1a7vwEW1AOVXdeXtpTVAenway/wobIf8tGOk/7lZj0h+svaN0CgOiAJ9QgiiCTCfG+lc5OFkQjyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584480244; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o83Eyled8X0fr2m5QHDMR1IsxIiMbVHgbSJ98uRmFvQ=; b=hrKGWMSYRC187nXGwy/9tP9yy0cXSTtFk1cdM1Z3HJvVuQMaNzCHQRZzPtyZeRs1khco3gokMguviYOauetYWiPl2fl2hBGy0tWNzuOlbCAlopafaCBlSBItvWBrWELKnvUvtEYA4WSe/NAaEeYNd+S3KZ9ZAlKAqMzqe3xaIZ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584480244747158.0432715505375; Tue, 17 Mar 2020 14:24:04 -0700 (PDT) Received: from localhost ([::1]:41704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEJgx-00084u-P2 for importer@patchew.org; Tue, 17 Mar 2020 17:24:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51893) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEJLV-0003F7-AW for qemu-devel@nongnu.org; Tue, 17 Mar 2020 17:01:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEJLT-0004eP-Qt for qemu-devel@nongnu.org; Tue, 17 Mar 2020 17:01:53 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:21519) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEJLR-0004a3-UF for qemu-devel@nongnu.org; Tue, 17 Mar 2020 17:01:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-46DWmezrMPGb6XKQec8hLA-1; Tue, 17 Mar 2020 17:01:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65A3913F6 for ; Tue, 17 Mar 2020 21:01:21 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-130.ams2.redhat.com [10.36.112.130]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E17A1001938; Tue, 17 Mar 2020 21:01:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 662E81135A59; Tue, 17 Mar 2020 22:01:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584478909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o83Eyled8X0fr2m5QHDMR1IsxIiMbVHgbSJ98uRmFvQ=; b=I+y5y7VTdam8f3iIpc6QnBseUupyWOJccTKvbuwK2V4jjZkNDZhjIrGzak/O3vTUBUj5nO q8M4AxwnJNffakVVnwo2MizgLUllfka89BJq0oeVlH6mbuWJEQv4RAcqZLuCsRzOaGUmsm bDUty+bvlWqUCIJdbaypU15DytALLUM= X-MC-Unique: 46DWmezrMPGb6XKQec8hLA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 16/30] qapi/introspect: Factor out _make_tree() Date: Tue, 17 Mar 2020 22:01:01 +0100 Message-Id: <20200317210115.8864-17-armbru@redhat.com> In-Reply-To: <20200317210115.8864-1-armbru@redhat.com> References: <20200317210115.8864-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The value of @qmp_schema_qlit is generated from an expression tree. Tree nodes are created in several places. Factor out the common code into _make_tree(). This isn't much of a win now. It will pay off when we add feature flags in the next few commits. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20200317115459.31821-16-armbru@redhat.com> --- scripts/qapi/introspect.py | 44 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index e4fc9d90f1..a3fa9865db 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -16,6 +16,18 @@ from qapi.schema import (QAPISchemaArrayType, QAPISchema= BuiltinType, QAPISchemaType) =20 =20 +def _make_tree(obj, ifcond, features, extra=3DNone): + if extra is None: + extra =3D {} + if ifcond: + extra['if'] =3D ifcond + if features: + obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in features] + if extra: + return (obj, extra) + return obj + + def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): =20 def indent(level): @@ -146,47 +158,38 @@ const QLitObject %(c_name)s =3D %(c_string)s; return self._name(typ.name) =20 def _gen_tree(self, name, mtype, obj, ifcond, features): - extra =3D {} + extra =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: # Output a comment to make it easy to map masked names # back to the source when reading the generated output. - extra['comment'] =3D '"%s" =3D %s' % (self._name(name), na= me) + extra =3D {'comment': '"%s" =3D %s' % (self._name(name), n= ame)} name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in featu= res] - if ifcond: - extra['if'] =3D ifcond - if extra: - self._trees.append((obj, extra)) - else: - self._trees.append(obj) + self._trees.append(_make_tree(obj, ifcond, features, extra)) =20 def _gen_member(self, member): - ret =3D {'name': member.name, 'type': self._use_type(member.type)} + obj =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: - ret['default'] =3D None - if member.ifcond: - ret =3D (ret, {'if': member.ifcond}) - return ret + obj['default'] =3D None + return _make_tree(obj, member.ifcond, None) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, 'variants': [self._gen_variant(v) for v in variants]} =20 def _gen_variant(self, variant): - return ({'case': variant.name, 'type': self._use_type(variant.type= )}, - {'if': variant.ifcond}) + obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} + return _make_tree(obj, variant.ifcond, None) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =20 def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): self._gen_tree(name, 'enum', - {'values': - [(m.name, {'if': m.ifcond}) for m in members]}, + {'values': [_make_tree(m.name, m.ifcond, None) + for m in members]}, ifcond, features) =20 def visit_array_type(self, name, info, ifcond, element_type): @@ -206,7 +209,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; def visit_alternate_type(self, name, info, ifcond, features, variants): self._gen_tree(name, 'alternate', {'members': [ - ({'type': self._use_type(m.type)}, {'if': m.ifc= ond}) + _make_tree({'type': self._use_type(m.type)}, + m.ifcond, None) for m in variants.variants]}, ifcond, features) =20 --=20 2.21.1