bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] -Werror: fix for rules useless in parser after conflicts.


From: Joel E. Denny
Subject: Re: [PATCH] -Werror: fix for rules useless in parser after conflicts.
Date: Sat, 9 Apr 2011 15:03:12 -0400 (EDT)
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)

On Mon, 28 Mar 2011, Akim Demaille wrote:

> 
> Le 28 mars 2011 à 04:58, Joel E. Denny a écrit :
> 
> >> Actually, we should probably split -Wconflicts into -Wconflicts-sr and 
> >> -Wconflicts-rr given that S/R and R/R conflicts are usually considered to 
> >> be very different levels of severity.
> > 
> > Implemented below, but I still need to add some test cases, so I'll do 
> > more work later and push if there are no objections.
> 
> None here.

Thanks.  I folded in the following diff and pushed to branch-2.5 and 
master.

diff --git a/ChangeLog b/ChangeLog
index 4b07a28..27c6a8d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,9 +19,12 @@
        (usage): Update.
        * src/getargs.h (enum warnings): Add entries for
        warnings_conflicts_sr and warnings_conflicts_rr.
+       * tests/conflicts.at (-W versus %expect and %expect-rr): New test
+       group.
        * tests/local.at (AT_BISON_CHECK_NO_XML): Update now that the
        conflict report can produce a "warnings being treated as errors"
-       message.
+       message.  Also, check that stderr is now fully scrubbed by -Wnone
+       when the exit status is 0.
 
 2011-03-27  Joel E. Denny  <address@hidden>
 
diff --git a/src/conflicts.c b/src/conflicts.c
index ef8d648..d8eddf0 100644
--- a/src/conflicts.c
+++ b/src/conflicts.c
@@ -603,7 +603,8 @@ conflicts_print (void)
     }
   if (src_total | rrc_total)
     {
-      set_warning_issued ();
+      if (expected_sr_conflicts == -1 && expected_rr_conflicts == -1)
+        set_warning_issued ();
       if (! yacc_flag)
        fprintf (stderr, "%s: ", current_file);
       conflict_report (stderr, src_total, rrc_total);
diff --git a/tests/conflicts.at b/tests/conflicts.at
index e7a1c1c..1fcd69b 100644
--- a/tests/conflicts.at
+++ b/tests/conflicts.at
@@ -1440,3 +1440,104 @@ AT_CHECK([[cat input.output | sed -n '/^state 
0$/,/^state 1$/p']], 0,
 state 1
 ]])
 AT_CLEANUP
+
+
+## --------------------------------- ##
+## -W versus %expect and %expect-rr  ##
+## --------------------------------- ##
+
+AT_SETUP([[-W versus %expect and %expect-rr]])
+
+AT_DATA([[sr-rr.y]],
+[[%glr-parser
+%%
+start: 'a' | A 'a' | B 'a' ;
+A: ;
+B: ;
+]])
+AT_DATA([[sr.y]],
+[[%glr-parser
+%%
+start: 'a' | A 'a' ;
+A: ;
+]])
+AT_DATA([[rr.y]],
+[[%glr-parser
+%%
+start: A | B ;
+A: ;
+B: ;
+]])
+
+AT_BISON_CHECK([[sr-rr.y]], [[0]], [[]],
+[[sr-rr.y: conflicts: 1 shift/reduce, 1 reduce/reduce
+]])
+AT_BISON_CHECK([[-Wno-conflicts-sr sr-rr.y]], [[0]], [[]],
+[[sr-rr.y: conflicts: 1 reduce/reduce
+]])
+AT_BISON_CHECK([[-Wno-conflicts-rr sr-rr.y]], [[0]], [[]],
+[[sr-rr.y: conflicts: 1 shift/reduce
+]])
+
+[for gram in sr-rr sr rr; do
+  for sr_exp_i in '' 0 1 2; do
+    for rr_exp_i in '' 0 1 2; do
+      test -z "$sr_exp_i" && test -z "$rr_exp_i" && continue
+
+      # Build grammar file.
+      sr_exp=0
+      rr_exp=0
+      file=$gram
+      directives=
+      if test -n "$sr_exp_i"; then
+        sr_exp=$sr_exp_i
+        file=$file-expect-$sr_exp
+        directives="%expect $sr_exp"
+      fi
+      if test -n "$rr_exp_i"; then
+        rr_exp=$rr_exp_i
+        file=$file-expect-rr-$rr_exp
+        directives="$directives %expect-rr $rr_exp"
+      fi
+      file=$file.y
+      echo "$directives" > $file
+      cat $gram.y >> $file
+
+      # Count actual conflicts.
+      conflicts=
+      sr_count=0
+      rr_count=0
+      if test $gram = sr || test $gram = sr-rr; then
+        conflicts="1 shift/reduce"
+        sr_count=1
+      fi
+      if test $gram = rr || test $gram = sr-rr; then
+        if test -n "$conflicts"; then
+          conflicts="$conflicts, "
+        fi
+        conflicts="${conflicts}1 reduce/reduce"
+        rr_count=1
+      fi
+
+      # Run tests.
+      if test $sr_count -eq $sr_exp && test $rr_count -eq $rr_exp; then
+        ]AT_BISON_CHECK([[-Wnone $file]])[
+        ]AT_BISON_CHECK([[-Werror $file]])[
+      else
+        echo "$file: conflicts: $conflicts" > experr
+        if test $sr_count -ne $sr_exp; then
+          if test $sr_exp -ne 1; then s=s; else s= ; fi
+          echo "$file: expected $sr_exp shift/reduce conflict$s" >> experr
+        fi
+        if test $rr_count -ne $rr_exp; then
+          if test $rr_exp -ne 1; then s=s; else s= ; fi
+          echo "$file: expected $rr_exp reduce/reduce conflict$s" >> experr
+        fi
+        ]AT_BISON_CHECK([[-Wnone $file]], [[1]], [[]], [[experr]])[
+        ]AT_BISON_CHECK([[-Werror $file]], [[1]], [[]], [[experr]])[
+      fi
+    done
+  done
+done]
+
+AT_CLEANUP
diff --git a/tests/local.at b/tests/local.at
index 867ae97..33f00fa 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -337,9 +337,9 @@ m4_if(m4_bregexp([$4], [: warning: ]), [-1], [],
           # -Werror doesn't change the exit status when -Wnone or
           # --warnings=none is specified.
           ]AT_CHECK(AT_QUELL_VALGRIND[[ bison ]$1[ -Wnone -Werror]],
-                    [[0]], [expout], [ignore])[
+                    [[0]], [expout])[
           ]AT_CHECK(AT_QUELL_VALGRIND[[ bison ]$1[ --warnings=none \
-                    -Werror]], [[0]], [expout], [ignore])[
+                    -Werror]], [[0]], [expout])[
 
           # Restore caller's files.
           if test -f at-bison-check-expout.bak; then

reply via email to

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