From patchwork Thu Mar 3 16:16:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8493801 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A2D509F8A8 for ; Thu, 3 Mar 2016 16:21:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EA7BE202FF for ; Thu, 3 Mar 2016 16:21:49 +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 20CF3200E0 for ; Thu, 3 Mar 2016 16:21:48 +0000 (UTC) Received: from localhost ([::1]:36039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abW0Z-00025I-7w for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Mar 2016 11:21:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abVvx-00030b-I4 for qemu-devel@nongnu.org; Thu, 03 Mar 2016 11:17:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abVvt-0003rd-3d for qemu-devel@nongnu.org; Thu, 03 Mar 2016 11:17:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abVvs-0003rF-Su for qemu-devel@nongnu.org; Thu, 03 Mar 2016 11:16:57 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 9885F13930; Thu, 3 Mar 2016 16:16:56 +0000 (UTC) Received: from red.redhat.com (ovpn-113-165.phx2.redhat.com [10.3.113.165]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u23GGsrn021507; Thu, 3 Mar 2016 11:16:56 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 3 Mar 2016 09:16:45 -0700 Message-Id: <1457021813-10704-4-git-send-email-eblake@redhat.com> In-Reply-To: <1457021813-10704-1-git-send-email-eblake@redhat.com> References: <1457021813-10704-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v3 03/10] qapi-visit: Expose visit_type_FOO_members() 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 members, then store that pointer in the union type. But now that things are unboxed, we need a way to visit the members without allocation, done by exposing visit_type_FOO_members() to the user. Before the patch, we had quite a bit of code associated with object_members_seen to make sure that a declaration of the helper was in scope before any use of the function. But now that the helper is public and declared in the header, the .c file no longer needs to worry about topological sorting (the helper is always in scope), which leads to some nice cleanups. Signed-off-by: Eric Blake --- v3: no change v2: Rebase atop s/fields/members/rename, don't provide useless declaration on alternates --- scripts/qapi-visit.py | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 1e52f76..a712e9a 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -15,10 +15,6 @@ from qapi import * import re -# visit_type_FOO_members() is always emitted; track if a forward declaration -# or implementation has already been output. -object_members_seen = set() - def gen_visit_decl(name, scalar=False): c_type = c_name(name) + ' *' @@ -30,37 +26,23 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_type)sobj, Error ** c_name=c_name(name), c_type=c_type) -def gen_visit_members_decl(typ): - if typ.name in object_members_seen: - return '' - object_members_seen.add(typ.name) +def gen_visit_members_decl(name): return mcgen(''' -static void visit_type_%(c_type)s_members(Visitor *v, %(c_type)s *obj, Error **errp); +void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp); ''', - c_type=typ.c_name()) + c_name=c_name(name)) def gen_visit_object_members(name, base, members, variants): - ret = '' + ret = mcgen(''' - if base: - ret += gen_visit_members_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_members_decl(var.type) - - object_members_seen.add(name) - ret += mcgen(''' - -static void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp) +void visit_type_%(c_name)s_members(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 +155,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_members_decl(var.type) ret += mcgen(''' @@ -316,6 +296,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.defn += defn def visit_object_type(self, name, info, base, members, variants): + self.decl += gen_visit_members_decl(name) self.decl += gen_visit_decl(name) self.defn += gen_visit_object(name, base, members, variants)