bison-patches
[Top][All Lists]
Advanced

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

RFC: diagnostics: complain about Bison directives when -Wyacc


From: Akim Demaille
Subject: RFC: diagnostics: complain about Bison directives when -Wyacc
Date: Tue, 27 Nov 2018 20:27:41 +0100

This commit was sitting on my disk since 2013.  It emits more
warnings about features of Bison that are not provided by Yacc
(it seems important to some people).

The reason it was not pushed before is... Autoconf.  Autoconf's
AC_PROG_YACC used to set YACC to bison -y _only_ to make sure
Bison generates y.tab.c as output file.  Unfortunately, -y not
only means "generate y.tab.c like Yacc does" but also "warn for
Bisonisms".  So this commit could not be installed as is, until
Autoconf was fixed.

This was does in Autoconf 2.70.  As a matter of fact, Bison's
3.0 NEWS includes:

> *** Use of YACC='bison -y'
> 
>   TL;DR: With Autoconf <= 2.69, pass -Wno-yacc to (AM_)YFLAGS if you use
>   Bison extensions.
> 
>   Traditional Yacc generates 'y.tab.c' whatever the name of the input file.
>   Therefore Makefiles written for Yacc expect 'y.tab.c' (and possibly
>   'y.tab.h' and 'y.outout') to be generated from 'foo.y'.
> 
>   To this end, for ages, AC_PROG_YACC, Autoconf's macro to look for an
>   implementation of Yacc, was using Bison as 'bison -y'.  While it does
>   ensure compatible output file names, it also enables warnings for
>   incompatibilities with POSIX Yacc.  In other words, 'bison -y' triggers
>   warnings for Bison extensions.
> 
>   Autoconf 2.70+ fixes this incompatibility by using YACC='bison -o y.tab.c'
>   (which also generates 'y.tab.h' and 'y.output' when needed).
>   Alternatively, disable Yacc warnings by passing '-Wno-yacc' to your Yacc
>   flags (YFLAGS, or AM_YFLAGS with Automake).

I think we can now install this patch.  Anyway, there's a way
out for people who stick to an old Autoconf: pass -Wno-yacc
to Bison.


commit a3ec0dfcf563360305b8f4741d2a8ddfc5852114
Author: Akim Demaille <address@hidden>
Date:   Wed Feb 27 15:43:26 2013 +0100

    diagnostics: complain about Bison directives when -Wyacc
    
    * src/complain.h, src/complain.c (bison_directive): New.
    * src/scan-gram.l (BISON_DIRECTIVE): New.
    Use it for Bison extensions.

diff --git a/src/complain.c b/src/complain.c
index 6c1acf39..7367a21d 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -374,6 +374,14 @@ complain_args (location const *loc, warnings w, unsigned 
*indent,
   }
 }
 
+
+void
+bison_directive (location const *loc, char const *directive)
+{
+  complain (loc, Wyacc,
+            _("POSIX Yacc does not support %s"), directive);
+}
+
 void
 deprecated_directive (location const *loc, char const *old, char const *upd)
 {
diff --git a/src/complain.h b/src/complain.h
index 41d0c566..4191832d 100644
--- a/src/complain.h
+++ b/src/complain.h
@@ -119,6 +119,9 @@ void complain_indent (location const *loc, warnings flags, 
unsigned *indent,
   __attribute__ ((__format__ (__printf__, 4, 5)));
 
 
+/** GNU Bison extension not valid with POSIX Yacc.  */
+void bison_directive (location const *loc, char const *directive);
+
 /** Report an obsolete syntax, suggest the updated one.  */
 void deprecated_directive (location const *loc,
                            char const *obsolete, char const *updated);
diff --git a/src/scan-gram.l b/src/scan-gram.l
index 2b77226b..e56f91f2 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -53,6 +53,10 @@ static boundary scanner_cursor;
 static size_t no_cr_read (FILE *, char *, size_t);
 #define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
 
+/* Report that yytext is an extension, and evaluate to its token type.  */
+#define BISON_DIRECTIVE(Directive)                              \
+  (bison_directive (loc, yytext), PERCENT_ ## Directive)
+
 #define RETURN_PERCENT_PARAM(Value)             \
   RETURN_VALUE(PERCENT_PARAM, param_ ## Value)
 
@@ -215,48 +219,48 @@ eqopt    ([[:space:]]*=)?
 <INITIAL>
 {
   "%binary"                         return PERCENT_NONASSOC;
-  "%code"                           return PERCENT_CODE;
+  "%code"                           return BISON_DIRECTIVE(CODE);
   "%debug"                          RETURN_PERCENT_FLAG("parse.trace");
-  "%default-prec"                   return PERCENT_DEFAULT_PREC;
-  "%define"                         return PERCENT_DEFINE;
-  "%defines"                        return PERCENT_DEFINES;
-  "%destructor"                     return PERCENT_DESTRUCTOR;
-  "%dprec"                          return PERCENT_DPREC;
-  "%empty"                          return PERCENT_EMPTY;
-  "%expect"                         return PERCENT_EXPECT;
-  "%expect-rr"                      return PERCENT_EXPECT_RR;
-  "%file-prefix"                    return PERCENT_FILE_PREFIX;
-  "%fixed-output-files"             return PERCENT_YACC;
-  "%initial-action"                 return PERCENT_INITIAL_ACTION;
-  "%glr-parser"                     return PERCENT_GLR_PARSER;
-  "%language"                       return PERCENT_LANGUAGE;
+  "%default-prec"                   return BISON_DIRECTIVE(DEFAULT_PREC);
+  "%define"                         return BISON_DIRECTIVE(DEFINE);
+  "%defines"                        return BISON_DIRECTIVE(DEFINES);
+  "%destructor"                     return BISON_DIRECTIVE(DESTRUCTOR);
+  "%dprec"                          return BISON_DIRECTIVE(DPREC);
+  "%empty"                          return BISON_DIRECTIVE(EMPTY);
+  "%expect"                         return BISON_DIRECTIVE(EXPECT);
+  "%expect-rr"                      return BISON_DIRECTIVE(EXPECT_RR);
+  "%file-prefix"                    return BISON_DIRECTIVE(FILE_PREFIX);
+  "%fixed-output-files"             return BISON_DIRECTIVE(YACC);
+  "%initial-action"                 return BISON_DIRECTIVE(INITIAL_ACTION);
+  "%glr-parser"                     return BISON_DIRECTIVE(GLR_PARSER);
+  "%language"                       return BISON_DIRECTIVE(LANGUAGE);
   "%left"                           return PERCENT_LEFT;
   "%lex-param"                      RETURN_PERCENT_PARAM(lex);
   "%locations"                      RETURN_PERCENT_FLAG("locations");
-  "%merge"                          return PERCENT_MERGE;
-  "%name-prefix"                    return PERCENT_NAME_PREFIX;
-  "%no-default-prec"                return PERCENT_NO_DEFAULT_PREC;
-  "%no-lines"                       return PERCENT_NO_LINES;
+  "%merge"                          return BISON_DIRECTIVE(MERGE);
+  "%name-prefix"                    return BISON_DIRECTIVE(NAME_PREFIX);
+  "%no-default-prec"                return BISON_DIRECTIVE(NO_DEFAULT_PREC);
+  "%no-lines"                       return BISON_DIRECTIVE(NO_LINES);
   "%nonassoc"                       return PERCENT_NONASSOC;
-  "%nondeterministic-parser"        return PERCENT_NONDETERMINISTIC_PARSER;
-  "%output"                         return PERCENT_OUTPUT;
+  "%nondeterministic-parser"        return 
BISON_DIRECTIVE(NONDETERMINISTIC_PARSER);
+  "%output"                         return BISON_DIRECTIVE(OUTPUT);
   "%param"                          RETURN_PERCENT_PARAM(both);
   "%parse-param"                    RETURN_PERCENT_PARAM(parse);
   "%prec"                           return PERCENT_PREC;
-  "%precedence"                     return PERCENT_PRECEDENCE;
-  "%printer"                        return PERCENT_PRINTER;
+  "%precedence"                     return BISON_DIRECTIVE(PRECEDENCE);
+  "%printer"                        return BISON_DIRECTIVE(PRINTER);
   "%pure-parser"                    RETURN_PERCENT_FLAG("api.pure");
-  "%require"                        return PERCENT_REQUIRE;
+  "%require"                        return BISON_DIRECTIVE(REQUIRE);
   "%right"                          return PERCENT_RIGHT;
-  "%skeleton"                       return PERCENT_SKELETON;
+  "%skeleton"                       return BISON_DIRECTIVE(SKELETON);
   "%start"                          return PERCENT_START;
   "%term"                           return PERCENT_TOKEN;
   "%token"                          return PERCENT_TOKEN;
-  "%token-table"                    return PERCENT_TOKEN_TABLE;
+  "%token-table"                    return BISON_DIRECTIVE(TOKEN_TABLE);
   "%type"                           return PERCENT_TYPE;
   "%union"                          return PERCENT_UNION;
-  "%verbose"                        return PERCENT_VERBOSE;
-  "%yacc"                           return PERCENT_YACC;
+  "%verbose"                        return BISON_DIRECTIVE(VERBOSE);
+  "%yacc"                           return BISON_DIRECTIVE(YACC);
 
   /* Deprecated since Bison 3.0 (2013-07-25), but the warning is
      issued only since Bison 3.3. */
diff --git a/tests/input.at b/tests/input.at
index 19c1fafc..0ada606e 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -433,7 +433,13 @@ input.y:26.40-42: warning: unset value: $][$ [-Wother]
 
 AT_BISON_CHECK([-Wnone,yacc -fcaret input.y],
                [0], [],
-[[input.y:24.23-34: warning: POSIX Yacc does not support typed midrule actions 
[-Wyacc]
+[m4_ifval([$1], [], [[input.y:3.1-11: warning: POSIX Yacc does not support 
%destructor [-Wyacc]
+ %destructor { destroy ($$); } <integer>;
+ ^^^^^^^^^^^
+]])[input.y:13.10-15: warning: POSIX Yacc does not support %empty [-Wyacc]
+ b: INT | %empty;
+          ^^^^^^
+input.y:24.23-34: warning: POSIX Yacc does not support typed midrule actions 
[-Wyacc]
  m: INT | INT <integer>{ $][$ = $][1; } INT <integer>{ $][$ = $][2 + $][3; } 
INT { $][$ = $][4 + $][5; };
                        ^^^^^^^^^^^^
 input.y:24.49-65: warning: POSIX Yacc does not support typed midrule actions 
[-Wyacc]
@@ -451,7 +457,10 @@ input.y:26.23-25: warning: POSIX Yacc does not support 
typed midrule actions [-W
 input.y:26.40-42: warning: POSIX Yacc does not support typed midrule actions 
[-Wyacc]
  o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + 
$][4 + $][5; };
                                         ^^^
-]])
+]m4_ifval([$1], [[input.y:30.1-11: warning: POSIX Yacc does not support 
%destructor [-Wyacc]
+ %destructor { destroy ($$); } <integer>;
+ ^^^^^^^^^^^
+]])])
 ])
 
 ## --------------- ##
@@ -1169,7 +1178,9 @@ AT_BISON_OPTION_POPDEFS
 
 # POSIX Yacc accept periods, but not dashes.
 AT_BISON_CHECK([--yacc input.y], [1], [],
-[[input.y:9.8-16: error: POSIX Yacc forbids dashes in symbol names: WITH-DASH 
[-Werror=yacc]
+[[input.y:1.1-5: error: POSIX Yacc does not support %code [-Werror=yacc]
+input.y:9.8-16: error: POSIX Yacc forbids dashes in symbol names: WITH-DASH 
[-Werror=yacc]
+input.y:13.1-5: error: POSIX Yacc does not support %code [-Werror=yacc]
 input.y:20.8-16: error: POSIX Yacc forbids dashes in symbol names: with-dash 
[-Werror=yacc]
 ]])
 
diff --git a/tests/output.at b/tests/output.at
index e1137002..b00746f8 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -44,7 +44,7 @@ done
 ]AT_DATA([$1],
 [$2[
 %%
-foo: %empty {};
+foo: '0' {};
 ]])
 
 # There is not AT_DATA_UNQUOTED.
diff --git a/tests/regression.at b/tests/regression.at
index 0e4e7693..d0cb5107 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -88,7 +88,9 @@ AT_SETUP([Early token definitions with --yacc])
 # prologue, so that they can use the token definitions in it.
 
 AT_BISON_OPTION_PUSHDEFS
-AT_DATA_GRAMMAR([input.y],
+
+# Not AT_DATA_GRAMMAR, which uses %code, which is not supported by Yacc.
+AT_DATA([input.y],
 [[%{
 ]AT_YYERROR_DECLARE_EXTERN[
 ]AT_YYLEX_DECLARE_EXTERN[




reply via email to

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