From nobody Thu Nov 13 23:24:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583253358; cv=none; d=zohomail.com; s=zohoarc; b=Z4ZQe4Nxk1XiLN6SnxZ0qQQwZkyV3/pOfVVU2fERVa6r6ASkK/iKQRV7xh4OXf3BTzhXCOKsK5dB1WAB5umBTpgB8s11VzdVaU6ZGd82TjzBDIXNh5VUblE6iBS6zyzuH1H2ytatGdc4DWuIJV66qoTRpancdHyVi70hVJ5ihbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583253358; 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=LYRBn1WKH6uNvCj8WQZtPRk+MzbUUTNl8UbjVjr+4JU=; b=FMHtlyMXasM9Qjn/zxZzuXebHqJFDAIQE2xepli9/waAigFWhsnO4NcOmd0fXRUkERk0SHj0zT1My1ll4U6pZcdCt6eGdgKt2fbLgJRRi8RuIk88sAVyxiws4tV+1Qid3Oo9AIKvc1iFjX/U2mR5hVUONUuQrRdUsrlPnhTsR1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 158325335891195.62015096652249; Tue, 3 Mar 2020 08:35:58 -0800 (PST) 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-239-IE4pQcg5NDGqRiZwPHx2ZQ-1; Tue, 03 Mar 2020 11:35:53 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 924BB9B584; Tue, 3 Mar 2020 16:35:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6AB2491D62; Tue, 3 Mar 2020 16:35:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 13A0186A12; Tue, 3 Mar 2020 16:35:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 023GZDLb001224 for ; Tue, 3 Mar 2020 11:35:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7A02210027AB; Tue, 3 Mar 2020 16:35:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-129.ams2.redhat.com [10.36.116.129]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45D461001920; Tue, 3 Mar 2020 16:35:13 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E04E61132A03; Tue, 3 Mar 2020 17:35:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583253355; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LYRBn1WKH6uNvCj8WQZtPRk+MzbUUTNl8UbjVjr+4JU=; b=QwU8Ielm0AgUb1Ohd7ySh2+Q+P5T7ctgmHVE9GXfHp3VMAlPvqpq6J3jlZLh8oe7wBA6QY nt4ZPHB/fQXeoR1dKsH3wnI6/rQZejPxKS2JlOPnezYw4i4evQFCgP2UBfx2Sc5gjIEDNz hLWgMybp6HF/6veSe0rBmKVrzziIXA4= X-MC-Unique: IE4pQcg5NDGqRiZwPHx2ZQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 15/30] qapi/introspect: Factor out _make_tree() Date: Tue, 3 Mar 2020 17:34:50 +0100 Message-Id: <20200303163505.32041-16-armbru@redhat.com> In-Reply-To: <20200303163505.32041-1-armbru@redhat.com> References: <20200303163505.32041-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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 --- 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