qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v8 20/40] qapi: Better error messages for duplic


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v8 20/40] qapi: Better error messages for duplicated expressions
Date: Tue, 05 May 2015 11:11:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Eric Blake <address@hidden> 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.
>
> Signed-off-by: Eric Blake <address@hidden>
> Reviewed-by: Markus Armbruster <address@hidden>
[...]
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index 868f08b..eea0976 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
[...]
> @@ -567,12 +589,22 @@ def type_name(name):
>          return c_list_type(name[0])
>      return name
>
> -enum_types = []
> -struct_types = []
> -union_types = []
> +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.

> +    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.

> +    all_names[name] = meta
>
> -def add_struct(definition):
> +def add_struct(definition, info):
>      global struct_types
> +    name = definition['type']
> +    add_name(name, info, 'struct')
>      struct_types.append(definition)
>
>  def find_struct(name):
[...]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]