From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ypfj0-0003pC-PB for qemu-devel@nongnu.org; Tue, 05 May 2015 12:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ypfiv-0008Hf-GH for qemu-devel@nongnu.org; Tue, 05 May 2015 12:29:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ypfiv-0008HU-6h for qemu-devel@nongnu.org; Tue, 05 May 2015 12:29:33 -0400 From: Markus Armbruster References: <1430751937-17523-1-git-send-email-eblake@redhat.com> <1430751937-17523-21-git-send-email-eblake@redhat.com> <87ioc7v16e.fsf@blackfin.pond.sub.org> <5548C004.5080403@redhat.com> Date: Tue, 05 May 2015 18:28:48 +0200 In-Reply-To: <5548C004.5080403@redhat.com> (Eric Blake's message of "Tue, 05 May 2015 07:05:08 -0600") Message-ID: <87twvrng3j.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v8 20/40] qapi: Better error messages for duplicated expressions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org Eric Blake writes: > On 05/05/2015 03:11 AM, Markus Armbruster wrote: >> Eric Blake writes: >> >>> The previous commit demonstrated that the generator overlooked >>> duplicate expressions: >>> - a complex type or command reusing a built-in type name >>> - redeclaration of a type name, whether by the same or different >>> metatype >>> - redeclaration of a command or event >>> - collision of a type with implicit 'Kind' enum for a union >>> - collision with an implicit MAX enum constant >>> >>> Since the c_type() function in the generator treats all names >>> as being in the same namespace, this patch adds a global array >>> to track all known names and their source, to prevent collisions >>> before it can cause further problems. While valid .json files >>> won't trigger any of these cases, we might as well be nicer to >>> developers that make a typo while trying to add new QAPI code. >>> > >>> +def add_name(name, info, meta, implicit = False): >>> + global all_names >>> + if name in all_names: >>> + raise QAPIExprError(info, >>> + "%s '%s' is already defined" >>> + %(all_names[name], name)) >> >> Let's put a space between binary operator % and its right operand. > > I was copying existing examples, but I can easily do a separate followup > patch that unifies the style of % formatting (or switches to + > concatenation where that is more legible). That would be nice. >>> + if not implicit and name[-4:] == 'Kind': >>> + raise QAPIExprError(info, >>> + "%s '%s' should not end in 'Kind'" >>> + %(meta, name)) >> >> Likewise. Can fix up on commit. > > Of course, I'll wait until any of your fixups in the pull request are > already in place to write such a followup, to minimize rebase churn. I'm working towards a pull request. It has the appended cleanups squashed into this patch and PATCH 40. diff --git a/scripts/qapi.py b/scripts/qapi.py index edfaf9e..166b74f 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -421,10 +421,10 @@ def check_member_clash(expr_info, base_name, data, source = ""): for key in data.keys(): if key.startswith('*'): key = key[1:] - if key in base_members or "*%s" %key in base_members: + 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)) + % (key, source, base_name)) if base.get('base'): check_member_clash(expr_info, base['base'], data, source) @@ -524,7 +524,7 @@ def check_union(expr, expr_info): branch_struct = find_struct(value) assert branch_struct check_member_clash(expr_info, base, branch_struct['data'], - " of branch '%s'" %key) + " of branch '%s'" % key) # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. @@ -800,11 +800,11 @@ def add_name(name, info, meta, implicit = False): if name in all_names: raise QAPIExprError(info, "%s '%s' is already defined" - %(all_names[name], name)) + % (all_names[name], name)) if not implicit and name[-4:] == 'Kind': raise QAPIExprError(info, "%s '%s' should not end in 'Kind'" - %(meta, name)) + % (meta, name)) all_names[name] = meta def add_struct(definition, info):