From patchwork Mon Sep 21 21:57:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 520609 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 2B9881401AF for ; Tue, 22 Sep 2015 08:03:57 +1000 (AEST) Received: from localhost ([::1]:34218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze9Bj-0008Kq-Az for incoming@patchwork.ozlabs.org; Mon, 21 Sep 2015 18:03:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze96I-0007ef-SF for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ze96H-0000r5-IS for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ze96H-0000qu-Bh for qemu-devel@nongnu.org; Mon, 21 Sep 2015 17:58:17 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id F32838C1B3; Mon, 21 Sep 2015 21:58:16 +0000 (UTC) Received: from red.redhat.com (ovpn-113-166.phx2.redhat.com [10.3.113.166]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8LLw4bb027229; Mon, 21 Sep 2015 17:58:16 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 21 Sep 2015 15:57:31 -0600 Message-Id: <1442872682-6523-16-git-send-email-eblake@redhat.com> In-Reply-To: <1442872682-6523-1-git-send-email-eblake@redhat.com> References: <1442872682-6523-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Michael Roth , marcandre.lureau@redhat.com, DirtY.iCE.hu@gmail.com, armbru@redhat.com, ehabkost@redhat.com Subject: [Qemu-devel] [PATCH v5 15/46] qapi: Defer duplicate member checks to schema check() 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 With the previous commit, we have two different locations for detecting member name clashes - one at parse time, and another at schema check() time. Consolidate the checks into a single place, which is also in line with our TODO to eventually defer all of the parse time semantic checking into the newer schema code. The check_member_clash() function is no longer needed. The wording of the error messages has changed, but should still convey enough information to not be termed a regression. Signed-off-by: Eric Blake --- scripts/qapi.py | 45 ++++++++++----------------- tests/qapi-schema/flat-union-branch-clash.err | 2 +- tests/qapi-schema/flat-union-cycle.err | 2 +- tests/qapi-schema/struct-base-clash-deep.err | 2 +- tests/qapi-schema/struct-base-clash.err | 2 +- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 0a0ac90..f5f1c60 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -499,21 +499,6 @@ def check_type(expr_info, source, value, allow_array=False, 'enum']) -def check_member_clash(expr_info, base_name, data, source=""): - base = find_struct(base_name) - assert base - base_members = base['data'] - for key in data.keys(): - if key.startswith('*'): - key = key[1:] - if key in base_members or "*" + key in base_members: - raise QAPIExprError(expr_info, - "Member name '%s'%s clashes with base '%s'" - % (key, source, base_name)) - if base.get('base'): - check_member_clash(expr_info, base['base'], data, source) - - def check_command(expr, expr_info): name = expr['command'] @@ -592,15 +577,9 @@ def check_union(expr, expr_info): for (key, value) in members.items(): check_name(expr_info, "Member of union '%s'" % name, key) - # Each value must name a known type; furthermore, in flat unions, - # branches must be a struct with no overlapping member names + # Each value must name a known type check_type(expr_info, "Member '%s' of union '%s'" % (key, name), value, allow_array=not base, allow_metas=allow_metas) - if base: - branch_struct = find_struct(value) - assert branch_struct - check_member_clash(expr_info, base, branch_struct['data'], - " of branch '%s'" % key) # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. @@ -684,8 +663,6 @@ def check_struct(expr, expr_info): allow_dict=True, allow_optional=True) check_type(expr_info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=['struct']) - if expr.get('base'): - check_member_clash(expr_info, expr['base'], expr['data']) def check_keys(expr_elem, meta, required, optional=[]): @@ -999,7 +976,7 @@ class QAPISchemaObjectTypeMember(object): self.optional = optional self._owner = owner - def check(self, schema, info, all_members, seen): + def check(self, schema, info, all_members, seen, flat=False): if self.c_name() in seen: raise QAPIExprError(info, "%s collides with %s" @@ -1007,6 +984,17 @@ class QAPISchemaObjectTypeMember(object): seen[self.c_name()].describe())) self.type = schema.lookup_type(self._type_name) assert self.type + if flat: + self.type.check(schema) + assert isinstance(self.type.members, list) + assert not self.type.variants # not implemented + for m in self.type.members: + if m.c_name() in seen: + raise QAPIExprError(info, + "Member '%s' of branch '%s' collides " + "with %s" + % (m.name, self.name, + seen[m.c_name()].describe())) all_members.append(self) seen[self.c_name()] = self @@ -1042,15 +1030,16 @@ class QAPISchemaObjectTypeVariants(object): assert isinstance(self.tag_member.type, QAPISchemaEnumType) for v in self.variants: vseen = dict(seen) - v.check(schema, info, self.tag_member.type, vseen) + v.check(schema, info, self.tag_member.type, vseen, + self.tag_name is not None) class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): def __init__(self, name, typ, owner): QAPISchemaObjectTypeMember.__init__(self, name, typ, False, owner) - def check(self, schema, info, tag_type, seen): - QAPISchemaObjectTypeMember.check(self, schema, info, [], seen) + def check(self, schema, info, tag_type, seen, flat): + QAPISchemaObjectTypeMember.check(self, schema, info, [], seen, flat) assert self.name in tag_type.values def describe(self): diff --git a/tests/qapi-schema/flat-union-branch-clash.err b/tests/qapi-schema/flat-union-branch-clash.err index f112766..e220ea4 100644 --- a/tests/qapi-schema/flat-union-branch-clash.err +++ b/tests/qapi-schema/flat-union-branch-clash.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-branch-clash.json:10: Member name 'name' of branch 'value1' clashes with base 'Base' +tests/qapi-schema/flat-union-branch-clash.json:10: Member 'name' of branch 'value1' collides with 'name' (member of Base) diff --git a/tests/qapi-schema/flat-union-cycle.err b/tests/qapi-schema/flat-union-cycle.err index 152c6f0..5b431d7 100644 --- a/tests/qapi-schema/flat-union-cycle.err +++ b/tests/qapi-schema/flat-union-cycle.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-cycle.json:5: Member name 'switch' of branch 'loop' clashes with base 'Base' +tests/qapi-schema/flat-union-cycle.json:5: Member 'switch' of branch 'loop' collides with 'switch' (member of Base) diff --git a/tests/qapi-schema/struct-base-clash-deep.err b/tests/qapi-schema/struct-base-clash-deep.err index e3e9f8d..280fa03 100644 --- a/tests/qapi-schema/struct-base-clash-deep.err +++ b/tests/qapi-schema/struct-base-clash-deep.err @@ -1 +1 @@ -tests/qapi-schema/struct-base-clash-deep.json:7: Member name 'name' clashes with base 'Base' +tests/qapi-schema/struct-base-clash-deep.json:7: 'name' (member of Sub) collides with 'name' (member of Base) diff --git a/tests/qapi-schema/struct-base-clash.err b/tests/qapi-schema/struct-base-clash.err index 3ac37fb..2d5ceb0 100644 --- a/tests/qapi-schema/struct-base-clash.err +++ b/tests/qapi-schema/struct-base-clash.err @@ -1 +1 @@ -tests/qapi-schema/struct-base-clash.json:4: Member name 'name' clashes with base 'Base' +tests/qapi-schema/struct-base-clash.json:4: 'name' (member of Sub) collides with 'name' (member of Base)