bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] warnings: raise warning for useless printers or destructors


From: Akim Demaille
Subject: Re: [PATCH] warnings: raise warning for useless printers or destructors
Date: Tue, 26 Jun 2012 16:22:39 +0200

Hi Victor,

You have sent the following message to me alone.  I have made a
number of changes, and applied it in master as attached.

Please, note that you do not seem to handle the case of <> and
<*> printer/destructors.  On the following example, there is no
warning at all.

%printer {} <> <*>
%%
exp: 'a';

You should address this case too.

Attachment: 0001-warnings-raise-warning-for-useless-printers-or-destr.patch
Description: Binary data

Le 25 juin 2012 à 11:53, santet_v a écrit :

>> From f9cbce6f7843a052911a33d243fdc4582c7429ea Mon Sep 17 00:00:00 2001
> From: Victor Santet <address@hidden>
> Date: Thu, 14 Jun 2012 14:20:07 +0200
> Subject: [PATCH] warnings: raise warning for useless printers or destructors
> 
> * src/scan-code.h (code_props): Add field 'is_useful'.
> * src/symtab.c (symbol_check_defined): If a symbol does not have a
> destructor (resp. printer) but has a type which has a destructor (resp.
> printer), then set field 'is_useful' to True.
> (semantic_type_check_defined): If a type has a destructor (resp. printer)
> but all symbols of this type have already a destructor (resp. printer),
> then raise a warning.
> * tests/input.at (Useless printers or destructors): New.
> ---
> NEWS            |   26 ++++++++++++++++++++++++++
> src/scan-code.h |    3 +++
> src/symtab.c    |   20 +++++++++++++++++++-
> tests/input.at  |   40 ++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 88 insertions(+), 1 deletion(-)
> 
> diff --git a/NEWS b/NEWS
> index 9fccc0d..11f6397 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -2,6 +2,32 @@ GNU Bison NEWS
> 
> * Noteworthy changes in release ?.? (????-??-??) [?]
> 
> +** Warnings about useless destructors or printers
> +
> +  Bison did not detect useless destructors or printers uses.
> +
> +    %token <type1> token1
> +    %token <type2> token2
> +    %token <type3> token3
> +    %token <type4> token4
> +
> +    %printer    {} token1
> +    %destructor {} token2
> +
> +    %printer    {} <type1>
> +    %destructor {} <type2>
> +    %printer    {} <type3>
> +    %destructor {} <type4>
> +
> +  In this example, the printer for 'type1' and the destructor for 'type2' are
> +  useless because all symbols of 'type1' ('token1') have already a printer,
> +  and all symbols of type 'type2' ('token2') have already a destructor.
> +  Raise these two warnings.
> +
> +  The type3's printer and the type4's destructor are usefull because it 
> exists
> +  one symbol of 'type3' which has not a printer ('token3') and exists one 
> symbol
> +  of 'type4' which has not a destructor ('token4').
> +
> ** Warnings about useless semantic types
> 
>   Bison did not detect useless semantic types. A semantic type T may be
> diff --git a/src/scan-code.h b/src/scan-code.h
> index 3fa5ea9..f0c267a 100644
> --- a/src/scan-code.h
> +++ b/src/scan-code.h
> @@ -70,6 +70,9 @@ typedef struct code_props {
>   bool is_predicate;
> 
> 
> +  bool is_useful;
> +
> +
>   /** \c NULL iff \c code_props::kind is not \c CODE_PROPS_RULE_ACTION.  */
>   struct symbol_list *rule;
> 
> diff --git a/src/symtab.c b/src/symtab.c
> index da89afe..8e669aa 100644
> --- a/src/symtab.c
> +++ b/src/symtab.c
> @@ -419,6 +419,15 @@ symbol_check_defined (symbol *sym)
>       sym->number = nvars++;
>     }
> 
> +  for (int i = 0; i < 2; ++i)
> +    if (sym->props[i].kind == CODE_PROPS_NONE && sym->type_name)
> +      {
> +        semantic_type *sem_type = semantic_type_get (sym->type_name, NULL);
> +        if (sem_type
> +            && sem_type->props[i].kind != CODE_PROPS_NONE)
> +          sem_type->props[i].is_useful = true;
> +      }
> +
>   /* Set the semantic type status associated to the current symbol to
>      'declared' so that we could check semantic types unnecessary uses. */
>   if (sym->type_name)
> @@ -434,7 +443,16 @@ symbol_check_defined (symbol *sym)
> static inline bool
> semantic_type_check_defined (semantic_type *sem_type)
> {
> -  if (sem_type->status != declared)
> +  if (sem_type->status == declared)
> +    {
> +      for (int i = 0; i < 2; ++i)
> +        if (sem_type->props[i].kind != CODE_PROPS_NONE
> +            && ! sem_type->props[i].is_useful)
> +          warn_at (sem_type->location,
> +                   _("useless %s for type <%s>"),
> +                   code_props_type_string (i), sem_type->tag);
> +    }
> +  else
>     warn_at (sem_type->location,
>              _("type <%s> is used, but is not associated to any symbol"),
>              sem_type->tag);
> diff --git a/tests/input.at b/tests/input.at
> index d84ee93..54384f8 100644
> --- a/tests/input.at
> +++ b/tests/input.at
> @@ -317,6 +317,46 @@ input.y:5.25-31: warning: type <type4> is used, but is 
> not associated to any sym
> 
> AT_CLEANUP
> 
> +AT_SETUP([Useless printers or destructors])
> +
> +AT_DATA([[input.y]],
> +[[%token <type1> token1
> +%token <type2> token2
> +%token <type3> token3
> +%token <type4> token4
> +%token <type5> token51 token52
> +%token <type6> token61 token62
> +%token <type7> token7
> +
> +%printer { } token1
> +%destructor { } token2
> +%printer { } token51
> +%destructor { } token61
> +
> +%printer { } token7
> +
> +%printer { } <type1>
> +%destructor { } <type2>
> +%printer { } <type3>
> +%destructor { } <type4>
> +
> +%printer { } <type5>
> +%destructor { } <type6>
> +
> +%destructor { } <type7>
> +
> +%%
> +
> +exp: "a";
> +]])
> +
> +AT_BISON_CHECK([input.y], [0], [],
> +[[input.y:16.14-20: warning: useless %printer for type <type1>
> +input.y:17.17-23: warning: useless %destructor for type <type2>
> +]])
> +
> +
> +AT_CLEANUP
> 
> ## ---------------------------------------- ##
> ## Unused values with default %destructor.  ##
> -- 
> 1.7.9.5
> 
> 
> 
> 
> Victor SANTET
> Téléphone Portable : +33 (0) 6 42 08 15 32
> Etudiant EPITA - Infospé
> 


reply via email to

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