From patchwork Thu Mar 17 22:48:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8614951 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 76B599FC32 for ; Thu, 17 Mar 2016 22:56:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B685E20306 for ; Thu, 17 Mar 2016 22:56:14 +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 C3130202FE for ; Thu, 17 Mar 2016 22:56:13 +0000 (UTC) Received: from localhost ([::1]:40447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggpx-00072e-7J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 18:56:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggiw-0001AQ-Ci for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:48:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aggit-0007q3-Gx for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:48:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42946) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggit-0007pz-9w for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:48:55 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id E232264D11; Thu, 17 Mar 2016 22:48:54 +0000 (UTC) Received: from red.redhat.com (ovpn-113-69.phx2.redhat.com [10.3.113.69]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2HMmgGx004178; Thu, 17 Mar 2016 18:48:54 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 17 Mar 2016 16:48:41 -0600 Message-Id: <1458254921-17042-17-git-send-email-eblake@redhat.com> In-Reply-To: <1458254921-17042-1-git-send-email-eblake@redhat.com> References: <1458254921-17042-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 17 Mar 2016 22:48:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v6 16/16] qapi: Consolidate object visitors 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 Rather than having two separate visitor callbacks with items already broken out, pass the actual QAPISchemaObjectType object to the visitor. This lets the visitor access things like type.is_implicit() without needing another parameter, resolving a TODO from previous patches. For convenience and consistency, the 'name' and 'info' parameters are still provided, even though they are now redundant with 'typ.name' and 'typ.info'. Signed-off-by: Eric Blake --- v6: new patch --- scripts/qapi.py | 10 ++-------- scripts/qapi-introspect.py | 10 +++++----- scripts/qapi-types.py | 13 ++++++------- scripts/qapi-visit.py | 12 ++++++------ 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index b13ae47..4dde43a 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -808,10 +808,7 @@ class QAPISchemaVisitor(object): def visit_array_type(self, name, info, element_type): pass - def visit_object_type(self, name, info, base, members, variants): - pass - - def visit_object_type_flat(self, name, info, members, variants): + def visit_object_type(self, name, info, typ): pass def visit_alternate_type(self, name, info, variants): @@ -1005,10 +1002,7 @@ class QAPISchemaObjectType(QAPISchemaType): return 'object' def visit(self, visitor): - visitor.visit_object_type(self.name, self.info, - self.base, self.local_members, self.variants) - visitor.visit_object_type_flat(self.name, self.info, - self.members, self.variants) + visitor.visit_object_type(self.name, self.info, self) class QAPISchemaMember(object): diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index e0f926b..474eafd 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -141,11 +141,11 @@ const char %(c_name)s[] = %(c_string)s; element = self._use_type(element_type) self._gen_json('[' + element + ']', 'array', {'element-type': element}) - def visit_object_type_flat(self, name, info, members, variants): - obj = {'members': [self._gen_member(m) for m in members]} - if variants: - obj.update(self._gen_variants(variants.tag_member.name, - variants.variants)) + def visit_object_type(self, name, info, typ): + obj = {'members': [self._gen_member(m) for m in typ.members]} + if typ.variants: + obj.update(self._gen_variants(typ.variants.tag_member.name, + typ.variants.variants)) self._gen_json(name, 'object', obj) def visit_alternate_type(self, name, info, variants): diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index e09c875..40c4c1d 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -220,17 +220,16 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.decl += 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, typ): # Nothing to do for the special empty builtin if name == 'q_empty': return self._fwdecl += gen_fwd_object_or_array(name) - self.decl += gen_object(name, base, members, variants) - if base and not base.is_implicit(): - self.decl += gen_upcast(name, base) - # TODO Worth changing the visitor signature, so we could - # directly use rather than repeat type.is_implicit()? - if not name.startswith('q_'): + self.decl += gen_object(name, typ.base, typ.local_members, + typ.variants) + if typ.base and not typ.base.is_implicit(): + self.decl += gen_upcast(name, typ.base) + if not typ.is_implicit(): # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index c147990..e756545 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -289,18 +289,18 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl += decl self.defn += defn - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, typ): # Nothing to do for the special empty builtin if name == 'q_empty': return self.decl += gen_visit_members_decl(name) - self.defn += gen_visit_object_members(name, base, members, variants) - # TODO Worth changing the visitor signature, so we could - # directly use rather than repeat type.is_implicit()? - if not name.startswith('q_'): + self.defn += gen_visit_object_members(name, typ.base, + typ.local_members, typ.variants) + if not typ.is_implicit(): # only explicit types need an allocating visit self.decl += gen_visit_decl(name) - self.defn += gen_visit_object(name, base, members, variants) + self.defn += gen_visit_object(name, typ.base, typ.local_members, + typ.variants) def visit_alternate_type(self, name, info, variants): self.decl += gen_visit_decl(name)