From patchwork Wed Dec 2 05:20:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 551161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F01CE140291 for ; Wed, 2 Dec 2015 16:23:25 +1100 (AEDT) Received: from localhost ([::1]:56192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3zsx-0004Cw-OZ for incoming@patchwork.ozlabs.org; Wed, 02 Dec 2015 00:23:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3zqn-0007lu-Rs for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:21:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3zqm-0007R4-Fk for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:21:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59829) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3zqm-0007Qy-AT for qemu-devel@nongnu.org; Wed, 02 Dec 2015 00:21:08 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id D8DFFC0A517E; Wed, 2 Dec 2015 05:21:07 +0000 (UTC) Received: from red.redhat.com (ovpn-113-144.phx2.redhat.com [10.3.113.144]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tB25L2Rj018809; Wed, 2 Dec 2015 00:21:07 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 1 Dec 2015 22:20:54 -0700 Message-Id: <1449033659-25497-11-git-send-email-eblake@redhat.com> In-Reply-To: <1449033659-25497-1-git-send-email-eblake@redhat.com> References: <1449033659-25497-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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 v14 10/15] qapi: Prepare new QAPISchemaMember base class 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We want to share some clash detection code between enum values and object type members. To assist with that, split off part of QAPISchemaObjectTypeMember into a new base class QAPISchemaMember that tracks name, owner, and common clash detection code; while the former keeps the additional fields for type and optional flag. Signed-off-by: Eric Blake --- v14: no change v13: new patch --- scripts/qapi.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 085455b..2748464 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1018,28 +1018,18 @@ class QAPISchemaObjectType(QAPISchemaType): self.members, self.variants) -class QAPISchemaObjectTypeMember(object): +class QAPISchemaMember(object): role = 'member' - def __init__(self, name, typ, optional): + def __init__(self, name): assert isinstance(name, str) - assert isinstance(typ, str) - assert isinstance(optional, bool) self.name = name - self._type_name = typ - self.type = None - self.optional = optional self.owner = None def set_owner(self, name): assert not self.owner self.owner = name - def check(self, schema): - assert self.owner - self.type = schema.lookup_type(self._type_name) - assert self.type - def check_clash(self, info, seen): cname = c_name(self.name) if cname in seen: @@ -1065,6 +1055,21 @@ class QAPISchemaObjectTypeMember(object): return "'%s' %s" % (self.name, self._pretty_owner()) +class QAPISchemaObjectTypeMember(QAPISchemaMember): + def __init__(self, name, typ, optional): + QAPISchemaMember.__init__(self, name) + assert isinstance(typ, str) + assert isinstance(optional, bool) + self._type_name = typ + self.type = None + self.optional = optional + + def check(self, schema): + assert self.owner + self.type = schema.lookup_type(self._type_name) + assert self.type + + class QAPISchemaObjectTypeVariants(object): def __init__(self, tag_name, tag_member, variants): # Flat unions pass tag_name but not tag_member.