From patchwork Fri May 11 09:05:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10393701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 918C8602B1 for ; Fri, 11 May 2018 09:08:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B909328BF2 for ; Fri, 11 May 2018 09:08:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD0C728C20; Fri, 11 May 2018 09:08:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B326428BF2 for ; Fri, 11 May 2018 09:08:08 +0000 (UTC) Received: from localhost ([::1]:37791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH423-0001QZ-Mx for patchwork-qemu-devel@patchwork.kernel.org; Fri, 11 May 2018 05:08:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH3zz-0000aP-51 for qemu-devel@nongnu.org; Fri, 11 May 2018 05:06:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH3zu-0000fG-Si for qemu-devel@nongnu.org; Fri, 11 May 2018 05:05:59 -0400 Received: from mail-he1eur01on0724.outbound.protection.outlook.com ([2a01:111:f400:fe1e::724]:32813 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fH3zu-0000WI-HL for qemu-devel@nongnu.org; Fri, 11 May 2018 05:05:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PxHxTtBU1O0E41MBBauZaalpYU5cxHQ0FqU2H0DMEOs=; b=MqqnHlDzjp5zGukKtStsPU7g/4NRlzK0KSilcoYmpACd0IKKi3xiylGje8Wt33bTPAyxBK4ifwMUeXJ2OYp1U3PcRO7CuvUwxQM+LL9YNDF6wEmt9DhoMTOEPyuDEU/4MIln6hugbBx+51wGv4ChuW5GJwetnLy3BAtKKa/a2IY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM6PR08MB3352.eurprd08.prod.outlook.com (2603:10a6:209:48::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Fri, 11 May 2018 09:05:51 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 12:05:33 +0300 Message-Id: <1526029534-35771-2-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526029534-35771-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1526029534-35771-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR05CA0150.eurprd05.prod.outlook.com (2603:10a6:7:28::37) To AM6PR08MB3352.eurprd08.prod.outlook.com (2603:10a6:209:48::21) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:AM6PR08MB3352; X-Microsoft-Exchange-Diagnostics: 1; AM6PR08MB3352; 3:KxVCDhzRfK3l/PFqI8HDPfUvn+3C2ZeZHg5RK7of6+1CXBWZXoeo6/+y7PjUSyNjl0SvWe5cLFPi1CRq+rmEnSd4cStmZeJe3ymAQwZgbRJ/JIsYZqXu0olJq0cq2k9izaQbJH9Niwcc7jovM1fDb0inoaOcpTleZ0lHfrkH8VHPO5y8bCLUO+Q/QyRE33eZIM2WIB0PgEqWLUQL4sIoFKRmToqORLKcVft/iF+/SVXL6eAk7133nvCp5pEGh8vz; 25:RYm7/bTgXGNUwwK/tOHEmfyg6RuQXQuc2B5LV5A0vjKrrRojno5ywyNi7obAKphE/3n7sOf6RZmVHUw4M7btNQTQviFmWw5nsidTxC5UY8HmaJf6M0pooP5oj3bnCW/GU1wVwKQN16YLd1Pyj1HdILRwZIanRs8akmR1j6ipC4u+tMCUY3fh2GWCiK61IoM1QmYxmTBS7rsPjtCZPuhLYomHPZ/WPg7c0tVidUEPhjzFiSVHOdg1DGY2FRtYPTc4tdk7lnXcz2guedBpLWmh0ywN41Oe4L0r/nBp8+Dk4bli+qsBhWjloZFkSu2GRUfpLNT8Q1ZYJEas6Z0Kp5Ai9g==; 31:x54608yuyNUVKmka12stEU3dZlRF4I9aREtXuYIfpoH1+td55JUwU8e1pkGEC5od+YewYVYbxk7tqeTFE3cQjaKaxblBing+72qzLQQhIPefY1u37H+TWjlMzyVZ5rSfggAnvLeT8ATN2x4gkbpG3aM1VGp5DbomZu0fyLvR4Vj+UXpFMlZDv7NTqVRMpteyuLItKS/zCIokVbZK3pUPnIwD5BKyfZpzs/r3bW33wUs= X-MS-TrafficTypeDiagnostic: AM6PR08MB3352: X-Microsoft-Exchange-Diagnostics: 1; AM6PR08MB3352; 20:fdsgbnbgDT29Flz2w8+7MRhzoGFX6xofhhIV8FVdIRH3AsKrG8OT5otYOPZeT5HIfSdutQcAWiO+fdaIovGK4JP29uGr9LaqdblrFZjHXaUS8be8b1iuxF1CURmtJjc0HCehkLFDudM0cafZAXjovHDtJxbiVaURa0SfOC6tBw1tG4JB9e26Ed49CcrKHKVkrbk2KPLcC/AEpEy+Z5fK5RYPDW145ArAZ/sPtg9f4bbSFbHvaLO69S7DHzBs7e7p58QAersW+E1Dcr36oRGH3AyfnZRMw3AsEa60eyLVo0Vp6HqSGAc5BfwRYkfYfdiFxV5fKLw8JO6x/iYco65O8lB0iZQtx+k3nOdCsr2qsAJLHl5mbMLVwzDSLU4gRLL2K5wETYWnafATPankb2VChvCuVit0ANGGQ0peGAtJnsCo0l2uQxPtQMxfWsN4CyYwKNWL+cuOr64Au+HEm5Iio/zyfBAwV4in4xLK0KN6+CmHOMDekpqmmc7yZMNmR68I; 4:a85t8n0TDqz8/sz4hRR26gQJmntjwjQMl2G+J+qcBtcfaRpQ+0pWMFwfj0nLAckhgllqR+XY/8l33QorquwBh8Z+2UOtRU4dxArtHa7wKkh0VM6WhmmUTaEQaOPuvWgW0S3HpudQzgbVBvZ0ncPAHngQtsbm1AK9YD1VjmURH+GGR1fedjwp1wc5A3uHuHTIp1SN4HzRtJEELHsI5Abm7RAbjdOouHM71A1bxzAOhVACWhcoXb9AbTPgCWNFwIeSJVx5zzsQ5jWW0rVXB6jZxg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:AM6PR08MB3352; BCL:0; PCL:0; RULEID:; SRVR:AM6PR08MB3352; X-Forefront-PRVS: 06691A4183 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(366004)(39850400004)(396003)(376002)(346002)(39380400002)(189003)(199004)(11346002)(446003)(486006)(2616005)(4326008)(476003)(575784001)(6512007)(44832011)(53936002)(2351001)(2361001)(66066001)(86362001)(305945005)(51416003)(107886003)(47776003)(97736004)(956004)(386003)(26005)(6506007)(55236004)(52116002)(76176011)(16526019)(7736002)(50226002)(36756003)(2906002)(3846002)(50466002)(6116002)(6486002)(316002)(8936002)(6916009)(186003)(8676002)(81156014)(106356001)(81166006)(53416004)(16586007)(69596002)(6666003)(48376002)(25786009)(105586002)(478600001)(68736007)(5660300001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM6PR08MB3352; H:xantnef-ws.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM6PR08MB3352; 23:phphAB1ueax/TEd+2na+3WPiSAe07ELBsU16CaKHB?= =?us-ascii?Q?xMo//giGD3z8KfGu4AJGgfVqyrzdul8WR8eJoir9k03vLKm0qJ4qbg/+Tucs?= =?us-ascii?Q?JEi3LUuqmt3E6+/6SWxveOMrruxh+ejU+MEcjO0IMq5+DxBVdKd/Y7gXWXbB?= =?us-ascii?Q?TMW6XY2k85jENm5ddFWDFZsAqanFfwceqjeHGZRhxo1R+/ehjoz3APphhSeI?= =?us-ascii?Q?jiDoTR1y6/OVRlbaCmlJN5eTTmBQ1WLgYDEkykcLxjVn5sGwNPie/sGWmf/Y?= =?us-ascii?Q?U8NhoRJdChG6KWEJxGjZK3ZnXZssutGBJZ3l85423hx2/wEUg+rzg7KzoOS2?= =?us-ascii?Q?1X1ZVF2S7TJznPs7ip/gU4L71GqdV03PNmZ+90Lbdm8wUYR5iaS6RcIAs4vZ?= =?us-ascii?Q?MNQJtZpbQHDPVd90rBHS53ak3oWt83MmMYm9zoEVUh4egL8rQDMSiPViS2jU?= =?us-ascii?Q?cSyu2UE5X37xLMcQUAMLJwii1EZMvV7rSbVbom7LjmkWIc9s6AXOmGA72cxY?= =?us-ascii?Q?l1YS9JHazpt/zSkm6NImGVohnLeYUvCvCKMDTs7bcycyrxj65WxUkwQXRJuq?= =?us-ascii?Q?2u1eVJhlfCOYHY7QDMBQ9yWjvNzjr7doWLmp+hH+S/XMluN5tPRmqnBRW6jg?= =?us-ascii?Q?N/LzT8o8wd7huQBp6xHBo0Ki1FiAcrhsJkjdrS3MF96rUUk/ehr6Nrc8/FtF?= =?us-ascii?Q?ClZdFMI421YfGg/6g2My6gQx4kkE4Y+0Rht5cNtaNnMq+QFcbcJdVMhV587T?= =?us-ascii?Q?7bez4W8eo9tvc98uRYzaEzUa+nrWaCaUPLVGHNF9gye86HFVkQbxWnAXDrMb?= =?us-ascii?Q?k8Odludg0SnnSsQ72brsEmqcuRaxGY2RRxTkLme30nFjPdx7pYqJSBx0w7jY?= =?us-ascii?Q?lxiCNmBgO6ENIV70GWPsJz9iPrjtJcvJRgDo5f19XdmVaC9RoVihjCd84o6a?= =?us-ascii?Q?fVVJNfO/feH5t+rLp1jE0g6c/BTB4ZtpuFW7/5LYIU77uSRNK8z1Ljha1c1i?= =?us-ascii?Q?UvprSxEGtjJMXqaQFjbU2J8X9+jlFzFyUmWaIaxdHIvIFpshbVaJ5TPrK9Gj?= =?us-ascii?Q?DiSgJKa6UdTGdMWg+8pdXO5pybMBnGE5/eYxrWLt8gEbSfFYoo204UhNZ3JN?= =?us-ascii?Q?cyXCiO4H1Vvtd/9pUeDc1ZWDKsFA3yat7bOZCGq2DPH1Al1yUM8oV8389ZCF?= =?us-ascii?Q?8leJEBdBCcMB+SQJcOsx0k/B2EsyG9W99vxg+hKVybmWmUFQwpj5r7eut0Zu?= =?us-ascii?Q?+/SWoT6ox3bXaErWWpUmQQQ5nnkRl630jUSkok+pKl+ExScPy/hR+pqfUFwK?= =?us-ascii?Q?aWEikjGBIrZyPyxouffPVGgsK5u7QiRuroJ7G3vheurHUu85HBkOxgKKCpFm?= =?us-ascii?Q?UxbmQ=3D=3D?= X-Microsoft-Antispam-Message-Info: Izw4+7/gDuvr+R5FjIn1RzrbLWiLlcW4MdwVh5OWVuALAe2vTSw247medx/ugi4as13qodM8T8EKX0unYBAFJqxC7Y9rqZRAEJLkf/1T/zb3oP3deRrOLp6LsaBblWp0uYd2xNB2bGQmBtDadq/yQAoTFa8fgJrMUAQA5G0tePTtaBRmN9yL6srofXLaFpc8 X-Microsoft-Exchange-Diagnostics: 1; AM6PR08MB3352; 6:W9n74SQbz/86ITQT4VFnLdTBNIYn/GkZrZqqF2oIFalsddq86eF5O3XCM5prjMTwAR9v+0exz3pRb+/spMV2EDp4AjsVEbgrK1N7UUWQa+QV7skGdkF7Q4GX8KdQDinqeLpD63g/YY4AZUnBcyk/EyODkWKlSWlry2+mkw6kjSSq16VBlzjnwYG0pr0HqV5ARg2Ss9hmCvpjxrI/3dYPkm/Wgp0Xprb55XyVdhQVg93Z3am1ncgh0CtRzC7K2jQOzFxFIgeEOV6K413uBDVlalAD562wu4u9FZqaIMiJNembUMXuT3KPbudAIeuNcepFcmsgop6rQ+9i1u9VWwWGmD+mhu89bV74uIsCIyjH3eWJviK7ZmfeBGU1TsLm3ejCPX6RU5tyjJHi+7TbZVXxRdhkdZZ3Q5RjEP6WGCadFag5W4NyDEFCl05sJGgN+W07prc6MXVR2398+WG95wDL7Q==; 5:l2EHUHnkPj5ab7kk9Lqu+5mcqFyadbM1UJHw0NiQE9YBA9qAbgTytMAS59WpeMn38SUhWwPV3VQy/kMhfVKVM6amBzTBTdOl/comDG9pfY/zJkrsg/Bulr3LvmxPGGmAZjyGR1LlymBZskE9lhnDPpTOrA8Xca/J5R67tVib90s=; 24:ZsitMUKPO6k/Ka8SWHZ45TqV9xQupYY98dULPgfgYHmb5AVSEVDhuFB0w2snV5cnVmEkkm/NglKby+1aCxqirb7HiPYsQVEV+qxWmi2PRJE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM6PR08MB3352; 7:iAbLHbjffJT834fZdz6oBdCvbA7cTM1R2tpKhQjM/1IguQms/8VVEAP5qWUwGcnTjYd+j8i0Em3IKeWSicphqN+4l8VuzuN2kQ3JeGmjlyEa0XFFtwYdCNw7p7yAIBvRfRfHMJ2ESMAFYBCjDErqCWVjfv7BNEGFpFg6xG8Huu2gGmt+clp0X/rohZT1wlN15kay3SYihmkou53VFTCNoPZmsHY82bvPNsUwc9knZvYqVS6nJWP7EXaTdOyqzwLp; 20:wBIhiV1PPPtqWEvT+HEpu4fouMsjAPgPZ8HPd7Ok4nluijyEdgqernO0aa0I7EtMn31nth9aHQO0rqEyP7JNPQBPmFkwpzQ+aGDtWFnewWWwrSckpLtRtV7QsCNUzS3mQpHsJXzCiYOSXfMrsDGKZuHZ94eq9okQ6qFHX478wCU= X-MS-Office365-Filtering-Correlation-Id: 632d8f7b-b12f-453f-5985-08d5b71e6560 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2018 09:05:51.6289 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 632d8f7b-b12f-453f-5985-08d5b71e6560 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3352 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe1e::724 Subject: [Qemu-devel] [PATCH 1/2] qapi: allow flat unions with empty branches 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: Anton Nefedov , armbru@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The patch makes possible to avoid introducing dummy empty types for the flat union branches that have no data. Signed-off-by: Anton Nefedov --- scripts/qapi/common.py | 18 ++++++++++++------ scripts/qapi/doc.py | 2 +- scripts/qapi/types.py | 2 +- scripts/qapi/visit.py | 12 +++++++----- tests/qapi-schema/test-qapi.py | 2 +- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index a032cec..ec5cf28 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -721,6 +721,7 @@ def check_union(expr, info): name = expr['union'] base = expr.get('base') discriminator = expr.get('discriminator') + partial = expr.get('data-partial', False) members = expr['data'] # Two types of unions, determined by discriminator. @@ -783,7 +784,7 @@ def check_union(expr, info): % (key, enum_define['enum'])) # If discriminator is user-defined, ensure all values are covered - if enum_define: + if enum_define and not partial: for value in enum_define['data']: if value not in members.keys(): raise QAPISemError(info, "Union '%s' data missing '%s' branch" @@ -909,7 +910,7 @@ def check_exprs(exprs): elif 'union' in expr: meta = 'union' check_keys(expr_elem, 'union', ['data'], - ['base', 'discriminator']) + ['base', 'discriminator', 'data-partial']) union_types[expr[meta]] = expr elif 'alternate' in expr: meta = 'alternate' @@ -1035,7 +1036,7 @@ class QAPISchemaVisitor(object): def visit_array_type(self, name, info, element_type): pass - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, partial): pass def visit_object_type_flat(self, name, info, members, variants): @@ -1192,7 +1193,8 @@ class QAPISchemaArrayType(QAPISchemaType): class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, doc, base, local_members, variants): + def __init__(self, name, info, doc, base, local_members, variants, + partial = False): # 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 @@ -1209,6 +1211,7 @@ class QAPISchemaObjectType(QAPISchemaType): self.local_members = local_members self.variants = variants self.members = None + self.partial = partial def check(self, schema): if self.members is False: # check for cycles @@ -1269,7 +1272,8 @@ class QAPISchemaObjectType(QAPISchemaType): def visit(self, visitor): visitor.visit_object_type(self.name, self.info, - self.base, self.local_members, self.variants) + self.base, self.local_members, self.variants, + self.partial) visitor.visit_object_type_flat(self.name, self.info, self.members, self.variants) @@ -1636,6 +1640,7 @@ class QAPISchema(object): name = expr['union'] data = expr['data'] base = expr.get('base') + partial = expr.get('data-partial', False) tag_name = expr.get('discriminator') tag_member = None if isinstance(base, dict): @@ -1656,7 +1661,8 @@ class QAPISchema(object): QAPISchemaObjectType(name, info, doc, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, - variants))) + variants), + partial)) def _def_alternate_type(self, expr, info, doc): name = expr['alternate'] diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index 9b312b2..40dffc4 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -211,7 +211,7 @@ class QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor): body=texi_entity(doc, 'Values', member_func=texi_enum_value))) - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, partial): doc = self.cur_doc if base and base.is_implicit(): base = None diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 64d9c0f..e805509 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -215,7 +215,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_array(name, element_type)) self._gen_type_cleanup(name) - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, partial): # Nothing to do for the special empty builtin if name == 'q_empty': return diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 5d72d89..3ee64bb 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -34,7 +34,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp); c_name=c_name(name)) -def gen_visit_object_members(name, base, members, variants): +def gen_visit_object_members(name, base, members, variants, partial): ret = mcgen(''' void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) @@ -93,9 +93,10 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) ret += mcgen(''' default: - abort(); + %(action)s } -''') +''', + action="break;" if partial else "abort();") # 'goto out' produced for base, for each member, and if variants were # present @@ -309,12 +310,13 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, partial): # Nothing to do for the special empty builtin if name == 'q_empty': return self._genh.add(gen_visit_members_decl(name)) - self._genc.add(gen_visit_object_members(name, base, members, variants)) + self._genc.add(gen_visit_object_members(name, base, members, variants, + partial)) # TODO Worth changing the visitor signature, so we could # directly use rather than repeat type.is_implicit()? if not name.startswith('q_'): diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index c1a144b..95cd575 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -28,7 +28,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): if prefix: print(' prefix %s' % prefix) - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, partial): print('object %s' % name) if base: print(' base %s' % base.name)