bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] {master} Useless precedence warning


From: Akim Demaille
Subject: Re: [PATCH] {master} Useless precedence warning
Date: Tue, 29 Jan 2013 14:57:52 +0100

Le 29 janv. 2013 à 11:39, Valentin Tolmer <address@hidden> a écrit :

> Patch correction attached (The previous one got wrapped).
> <0001-grammar-warn-about-unused-precedence-for-symbols.patch>

Thanks, installed with the following changes.  Please, pay attention
to making a richer commit message.

commit 0c9752f616aed0a37c140dfbd7a7afe95d8ac67b
Author: Valentin Tolmer <address@hidden>
Date:   Tue Jan 29 14:55:53 2013 +0100

    grammar: warn about unused precedence for symbols
    
    Symbols with precedence but no associativity, and whose precedence is
    never used, can be declared with %token instead.  The used precedence
    relationships are recorded and a warning about useless ones is issued.
    
    * src/conflicts.c (resolve_sr_conflict): Record precedence relation.
    * src/symtab.c, src/symtab.h (prec_nodes, init_prec_nodes)
    (symgraphlink_new, register_precedence_second_symbol)
    (print_precedence_warnings): New.
    Record relationships in a graph and warn about useless ones.
    * src/main.c (main): Print precedence warnings.
    * tests/conflicts.at: New.


diff --git a/NEWS b/NEWS
index 95c1437..62f834b 100644
--- a/NEWS
+++ b/NEWS
@@ -202,7 +202,7 @@ GNU Bison NEWS
 
   Bison now warns about symbols with a declared precedence but no declared
   associativity (i.e. declared with %precedence), and whose precedence is
-  never used.  In that case, the symbol can be safely declared with a %token
+  never used.  In that case, the symbol can be safely declared with %token
   instead, without modifying the parsing tables.
 
 ** Additional yylex/yyparse arguments
diff --git a/src/symtab.c b/src/symtab.c
index f3d8b9f..3028df9 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -984,11 +984,11 @@ symbols_pack (void)
 static void
 init_prec_nodes (void)
 {
-  prec_nodes = xcalloc (nsyms, sizeof (* prec_nodes));
   int i;
+  prec_nodes = xcalloc (nsyms, sizeof *prec_nodes);
   for (i = 0; i < nsyms; ++i)
     {
-      prec_nodes[i] = xmalloc (sizeof (*prec_nodes[i]));
+      prec_nodes[i] = xmalloc (sizeof *prec_nodes[i]);
       symgraph *s = prec_nodes[i];
       s->id = i;
       s->succ = 0;
@@ -996,29 +996,30 @@ init_prec_nodes (void)
     }
 }
 
-/*--------------------------.
-| Routine to create a link. |
-`--------------------------*/
+/*----------------.
+| Create a link.  |
+`----------------*/
 
 static symgraphlink *
-create_symgraphlink (graphid id, symgraphlink *next)
+symgraphlink_new (graphid id, symgraphlink *next)
 {
-  symgraphlink *l = xmalloc (sizeof (*l));
+  symgraphlink *l = xmalloc (sizeof *l);
   l->id = id;
   l->next = next;
   return l;
 }
 
-/*-----------------------------------------------------------------------.
-| Registers the second symbol of the precedence relation. Should only be |
-| used in add_precedence_relation.                                       |
-`-----------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------.
+| Register the second symbol of the precedence relation, and return |
+| whether this relation is new.  Use only in register_precedence.   |
+`------------------------------------------------------------------*/
 
 static bool
 register_precedence_second_symbol (symgraphlink **first, graphid sym)
 {
   if (!*first || sym < (*first)->id)
-      *first = create_symgraphlink (sym, *first);
+    *first = symgraphlink_new (sym, *first);
   else
     {
       symgraphlink *slist = *first;
@@ -1027,10 +1028,10 @@ register_precedence_second_symbol (symgraphlink 
**first, graphid sym)
         slist = slist->next;
 
       if (slist->id == sym)
-      /* Relation already present. */
+        /* Relation already present. */
         return false;
 
-      slist->next = create_symgraphlink (sym, slist->next);
+      slist->next = symgraphlink_new (sym, slist->next);
     }
   return true;
 }
@@ -1049,23 +1050,9 @@ register_precedence (graphid first, graphid snd)
   register_precedence_second_symbol (&(prec_nodes[snd]->pred), first);
 }
 
-/*-----------------------------.
-| Free a simple symgraph list. |
-`-----------------------------*/
-
-static void
-free_symgraphlink (symgraphlink *s)
-{
-  if (s)
-    {
-      free_symgraphlink (s->next);
-      free (s);
-    }
-}
-
 
 /*--------------------------------------------------.
-| Print a warning for unused precedence relations. |
+| Print a warning for unused precedence relations.  |
 `--------------------------------------------------*/
 
 void
diff --git a/tests/conflicts.at b/tests/conflicts.at
index 8aaa76e..d2fb298 100644
--- a/tests/conflicts.at
+++ b/tests/conflicts.at
@@ -78,7 +78,15 @@ int main (void)
 }
 ]])
 
-AT_FULL_COMPILE([input])
+AT_BISON_CHECK([-o input.c input.y], [], [],
+[[input.y:24.13: warning: useless precedence for R [-Wother]
+input.y:24.15: warning: useless precedence for S [-Wother]
+input.y:24.17: warning: useless precedence for T [-Wother]
+input.y:24.19: warning: useless precedence for U [-Wother]
+input.y:25.13: warning: useless precedence for V [-Wother]
+input.y:25.15: warning: useless precedence for W [-Wother]
+]])
+AT_COMPILE([input])
 
 AT_PARSER_CHECK([./input])
 




reply via email to

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