From patchwork Tue Feb 23 21:14:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8396241 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 29EF9C0553 for ; Tue, 23 Feb 2016 21:22:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 64EF6202EC for ; Tue, 23 Feb 2016 21:22:09 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 9F6B120212 for ; Tue, 23 Feb 2016 21:22:08 +0000 (UTC) Received: from localhost ([::1]:60006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYKPH-00051V-Nq for patchwork-qemu-devel@patchwork.kernel.org; Tue, 23 Feb 2016 16:22:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYKIC-0001DG-6M for qemu-devel@nongnu.org; Tue, 23 Feb 2016 16:14:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYKI7-0001hR-Ri for qemu-devel@nongnu.org; Tue, 23 Feb 2016 16:14:48 -0500 Received: from resqmta-po-02v.sys.comcast.net ([96.114.154.161]:57624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYKI7-0001hK-Mw for qemu-devel@nongnu.org; Tue, 23 Feb 2016 16:14:43 -0500 Received: from resomta-po-11v.sys.comcast.net ([96.114.154.235]) by resqmta-po-02v.sys.comcast.net with comcast id MxCR1s00654zqzk01xEiwj; Tue, 23 Feb 2016 21:14:42 +0000 Received: from red.redhat.com ([24.10.254.122]) by resomta-po-11v.sys.comcast.net with comcast id MxEe1s0062fD5rL01xEi7N; Tue, 23 Feb 2016 21:14:42 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 23 Feb 2016 14:14:34 -0700 Message-Id: <1456262075-3311-3-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456262075-3311-1-git-send-email-eblake@redhat.com> References: <1456262075-3311-1-git-send-email-eblake@redhat.com> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1456262082; bh=olS7VUobAiTmpAwhRZKPbu6Q6pLu4uciHcTfv1YGA0g=; h=Received:Received:From:To:Subject:Date:Message-Id; b=FbUid8YkswKzrCWC4lpkI8720fewn3URYoKssmPYLv8M0mL4122nCGlDJNt02XHXl DtNr5Sn/bm7fcwsQJQzXAlCGEGny18PUBHo/DrMWDJrix6bNT8qCD+ri+fs0ibWj2C du5wvX2XmtSuB6Yj/iKgP3eNE9LGbDLCZTsUnoJdVGTd8eyklibML9gQM2bFDtUhA+ y+EpCt1+rFG6N1wBVoF0g6mungrnt/GWvTFGQyi+RN55HhakWzIStr3cgn8C/yw8vD xXNi5LUSyYijB7VllX363iHXXHFIaoJLomGR3ji76/PS2qb5TbnmH8/MAJdxT0pB7i jd5Fsk2C3ObjQ== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 96.114.154.161 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH 2/3] qapi-visit: Expose visit_type_FOO_fields() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Dan Berrange reported a case where he needs to work with a QCryptoBlockOptions union type using the OptsVisitor, but only visit one of the branches of that type (the discriminator is not visited directly, but learned externally). When things were boxed, it was easy: just visit the variant directly, which took care of both allocating the variant and visiting its fields. But now that things are unboxed, we need a way to visit the fields without allocation, done by exposing visit_type_FOO_fields() to the user. Of course, this should only be done for objects, not lists, so we need another flag to gen_visit_decl(). Since the function is now public, we no longer need to preserve topological ordering via struct_fields_seen. Signed-off-by: Eric Blake --- Minor conflicts with pending series "qapi implicit types"; I can rebase whichever series gets reviewed second. --- scripts/qapi-visit.py | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 2308268..35efe7c 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -15,52 +15,33 @@ from qapi import * import re -# visit_type_FOO_fields() is always emitted; track if a forward declaration -# or implementation has already been output. -struct_fields_seen = set() - -def gen_visit_decl(name, scalar=False): +def gen_visit_decl(name, scalar=False, list=False): + ret = '' c_type = c_name(name) + ' *' if not scalar: + if not list: + ret += mcgen(''' +void visit_type_%(c_name)s_fields(Visitor *v, %(c_type)sobj, Error **errp); +''', + c_name=c_name(name), c_type=c_type) c_type += '*' - return mcgen(''' + ret += mcgen(''' void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_type)sobj, Error **errp); ''', c_name=c_name(name), c_type=c_type) - - -def gen_visit_fields_decl(typ): - if typ.name in struct_fields_seen: - return '' - struct_fields_seen.add(typ.name) - return mcgen(''' - -static void visit_type_%(c_type)s_fields(Visitor *v, %(c_type)s *obj, Error **errp); -''', - c_type=typ.c_name()) + return ret def gen_visit_struct_fields(name, base, members, variants): - ret = '' + ret = mcgen(''' - if base: - ret += gen_visit_fields_decl(base) - if variants: - for var in variants.variants: - # Ugly special case for simple union TODO get rid of it - if not var.simple_union_type(): - ret += gen_visit_fields_decl(var.type) - - struct_fields_seen.add(name) - ret += mcgen(''' - -static void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **errp) +void visit_type_%(c_name)s_fields(Visitor *v, %(c_name)s *obj, Error **errp) { Error *err = NULL; ''', - c_name=c_name(name)) + c_name=c_name(name)) if base: ret += mcgen(''' @@ -173,8 +154,6 @@ def gen_visit_alternate(name, variants): for var in variants.variants: if var.type.alternate_qtype() == 'QTYPE_QINT': promote_int = 'false' - if isinstance(var.type, QAPISchemaObjectType): - ret += gen_visit_fields_decl(var.type) ret += mcgen(''' @@ -305,7 +284,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.defn += gen_visit_enum(name) def visit_array_type(self, name, info, element_type): - decl = gen_visit_decl(name) + decl = gen_visit_decl(name, list=True) defn = gen_visit_list(name, element_type) if isinstance(element_type, QAPISchemaBuiltinType): self._btin += decl