]> git.saurik.com Git - bison.git/commitdiff
api.value.type: diagnose guaranteed failure with --yacc
authorAkim Demaille <akim@lrde.epita.fr>
Wed, 27 Mar 2013 08:18:32 +0000 (09:18 +0100)
committerAkim Demaille <akim@lrde.epita.fr>
Tue, 9 Apr 2013 12:07:52 +0000 (14:07 +0200)
Instead of generating invalid C code, generate an error when --yacc and
'%define api.value.type union' are used together.

* data/bison.m4: Issue an error in this case.
* tests/types.at (%yacc vs. %define api.value.type union): New, check this
error.
* doc/bison.texi (Type Generation): Document it.
* tests/output.at: Check that '-o y.tab.c' and '-y' behave equally
wrt generated file names.
* NEWS (Use of YACC='bison -y'): New.
Promote the use of 'bison -o y.tab.c'.

NEWS
data/bison.m4
doc/bison.texi
tests/output.at
tests/types.at

diff --git a/NEWS b/NEWS
index 3816fdd510dae9804d8f79a748582ed19daa3ed4..60a62e1de44d8f3f590e41da06a724931f74803d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,26 @@ GNU Bison NEWS
   Missing semicolons at the end of actions are no longer added (as announced
   in the release 2.5).
 
   Missing semicolons at the end of actions are no longer added (as announced
   in the release 2.5).
 
+*** 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).
+
 ** Bug fixes
 
 *** The epilogue is no longer affected by internal #defines (glr.c)
 ** Bug fixes
 
 *** The epilogue is no longer affected by internal #defines (glr.c)
@@ -276,7 +296,8 @@ GNU Bison NEWS
 
   The %define variable api.value.type supports several special values.  The
   value "union" means that the user provides genuine types, not union member
 
   The %define variable api.value.type supports several special values.  The
   value "union" means that the user provides genuine types, not union member
-  names such as "ival" and "sval" above.
+  names such as "ival" and "sval" above (WARNING: will fail if
+  -y/--yacc/%yacc is enabled).
 
     %define api.value.type "union"
     %token <int> INT "integer"
 
     %define api.value.type "union"
     %token <int> INT "integer"
index 8e105d0dbb497d5f7cfaea79bae43cae3fb67872..e536ceb383bb19429ea36ac12d969504ecf43b18 100644 (file)
@@ -960,7 +960,12 @@ m4_define_default([b4_parse_param], [])
 m4_define_default([b4_location_initial_column], [1])
 m4_define_default([b4_location_initial_line],   [1])
 
 m4_define_default([b4_location_initial_column], [1])
 m4_define_default([b4_location_initial_line],   [1])
 
-# Sanity checks.
+
+## --------------- ##
+## Sanity checks.  ##
+## --------------- ##
+
+# api.prefix >< %name-prefix.
 b4_percent_define_ifdef([api.prefix],
 [m4_ifdef([b4_prefix],
 [b4_complain_at(b4_percent_define_get_loc([api.prefix]),
 b4_percent_define_ifdef([api.prefix],
 [m4_ifdef([b4_prefix],
 [b4_complain_at(b4_percent_define_get_loc([api.prefix]),
@@ -968,9 +973,19 @@ b4_percent_define_ifdef([api.prefix],
                 [%name-prefix],
                 [%define api.prefix])])])
 
                 [%name-prefix],
                 [%define api.prefix])])])
 
+# api.value.type >< %union.
 b4_percent_define_ifdef([api.value.type],
 [m4_ifdef([b4_union_members],
 [b4_complain_at(b4_percent_define_get_loc([api.value.type]),
                 [['%s' and '%s' cannot be used together]],
                 [%union],
                 [%define api.value.type])])])
 b4_percent_define_ifdef([api.value.type],
 [m4_ifdef([b4_union_members],
 [b4_complain_at(b4_percent_define_get_loc([api.value.type]),
                 [['%s' and '%s' cannot be used together]],
                 [%union],
                 [%define api.value.type])])])
+
+# api.value.type=union >< %yacc.
+b4_percent_define_ifdef([api.value.type],
+[m4_if(b4_percent_define_get([api.value.type]), [union],
+[b4_yacc_if(dnl
+[b4_complain_at(b4_percent_define_get_loc([api.value.type]),
+                [['%s' and '%s' cannot be used together]],
+                [%yacc],
+                [%define api.value.type "union"])])])])
index 6f50658ac9cae0272acacdb3a3913b095c576d7f..198403feacd5f164c09ae67df4ef8fe374d4652d 100644 (file)
@@ -3795,6 +3795,11 @@ yylval.TOK_INT = 42;
 return TOK_INT;
 @end example
 
 return TOK_INT;
 @end example
 
+This Bison extension cannot work if @code{%yacc} (or
+@option{-y}/@option{--yacc}) is enabled, as POSIX mandates that Yacc
+generate tokens as macros (e.g., @samp{#define INT 258}, or @samp{#define
+TOK_INT 258}).
+
 This feature is new, and user feedback would be most welcome.
 
 A similar feature is provided for C++ that in addition overcomes C++
 This feature is new, and user feedback would be most welcome.
 
 A similar feature is provided for C++ that in addition overcomes C++
index 5f7ff3870d5dac23844f492f9b3d26160e20fa03..7dbc3db7488d613fac3228cd4ecf126e21d98f29 100644 (file)
@@ -62,8 +62,13 @@ AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.c],
                 [foo.c foo.h foo.output])
 AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.tab.c],
                 [foo.output foo.tab.c foo.tab.h])
                 [foo.c foo.h foo.output])
 AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.tab.c],
                 [foo.output foo.tab.c foo.tab.h])
-AT_CHECK_OUTPUT([foo.y], [], [-dv -y],
-                [y.output y.tab.c y.tab.h])
+
+AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -y],
+                [y.dot y.output y.tab.c y.tab.h y.xml])
+# With '-o y.tab.c', we expect 'y.output' etc. (for compatility with Yacc).
+AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -o y.tab.c],
+                [y.dot y.output y.tab.c y.tab.h y.xml])
+
 AT_CHECK_OUTPUT([foo.y], [], [-dv -b bar],
                 [bar.output bar.tab.c bar.tab.h])
 AT_CHECK_OUTPUT([foo.y], [], [-dv -g -o foo.c],
 AT_CHECK_OUTPUT([foo.y], [], [-dv -b bar],
                 [bar.output bar.tab.c bar.tab.h])
 AT_CHECK_OUTPUT([foo.y], [], [-dv -g -o foo.c],
index 7cf0b23dbf57182b43b0f5651c9c196942525202..acd0e1c49aa86362d1fa60003428b66e88fc437d 100644 (file)
@@ -37,6 +37,26 @@ AT_BISON_CHECK([[input.y]], [[1]], [[]],
 
 AT_CLEANUP
 
 
 AT_CLEANUP
 
+## ---------------------------------------- ##
+## %yacc vs. %define api.value.type union.  ##
+## ---------------------------------------- ##
+
+AT_SETUP([[%yacc vs. %define api.value.type union]])
+
+AT_DATA([[input.y]],
+[[%yacc
+%define api.value.type "union"
+%%
+exp: %empty;
+]])
+
+AT_BISON_CHECK([[input.y]], [[1]], [[]],
+[[input.y:2.9-22: error: '%yacc' and '%define api.value.type "union"' cannot be used together
+]])
+
+AT_CLEANUP
+
+
 ## ---------------- ##
 ## api.value.type.  ##
 ## ---------------- ##
 ## ---------------- ##
 ## api.value.type.  ##
 ## ---------------- ##