From 0b6d43c52f4ffdc4cd57149bf050c31c63696ac5 Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Sat, 23 May 2009 02:25:28 -0400 Subject: [PATCH] Convert multiple variable definition warnings to complaints. * NEWS (2.5): Add a new entry for that change. * doc/bison.texinfo (Decl Summary): Update %define entry. (Bison Options): Update -D/--define/-F/--force-define entry. * src/muscle-tab.c (muscle_percent_define_insert): Implement. * src/muscle-tab.h (muscle_percent_define_insert): Update comments. * tests/input.at (`%define errors'): Update. (`%define, --define, --force-define'): Update. (cherry picked from commit e3a33f7c23fc9febd1bbff33045c8b455a1972a8) --- ChangeLog | 12 +++++++++++ NEWS | 2 ++ doc/bison.texinfo | 23 ++++++++++++--------- src/muscle-tab.c | 6 +++--- src/muscle-tab.h | 2 +- tests/input.at | 52 ++++++++++++++++++++++++++++------------------- 6 files changed, 62 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 948b5612..34cb6fe6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-05-22 Joel E. Denny + + Convert multiple variable definition warnings to complaints. + * NEWS (2.5): Add a new entry for that change. + * doc/bison.texinfo (Decl Summary): Update %define entry. + (Bison Options): Update -D/--define/-F/--force-define entry. + * src/muscle-tab.c (muscle_percent_define_insert): Implement. + * src/muscle-tab.h (muscle_percent_define_insert): Update + comments. + * tests/input.at (`%define errors'): Update. + (`%define, --define, --force-define'): Update. + 2009-05-22 Joel E. Denny -F/--force-define and relative %define/-D/--define priorities. diff --git a/NEWS b/NEWS index 3d5a561b..3c99a876 100644 --- a/NEWS +++ b/NEWS @@ -57,6 +57,8 @@ Bison News These features are experimental. More user feedback will help to stabilize them. +** Multiple %define's for any variable is now an error not a warning. + ** %define can now be invoked via the command line. Each of these command-line options diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 45a6075e..3dd43503 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -4845,8 +4845,8 @@ The possible choices for @var{variable}, as well as their meanings, depend on the selected target language and/or the parser skeleton (@pxref{Decl Summary,,%language}, @pxref{Decl Summary,,%skeleton}). -Bison will warn if a @var{variable} is defined by @code{%define} -multiple times, but @ref{Bison Options,,-D @var{name}[=@var{value}]}. +It is an error if a @var{variable} is defined by @code{%define} multiple +times, but @ref{Bison Options,,-D @var{name}[=@var{value}]}. Omitting @code{"@var{value}"} is always equivalent to specifying it as @code{""}. @@ -8149,16 +8149,19 @@ definitions for the same @var{name} as follows: @itemize @item -Bison processes all command-line definitions in order and then processes -all @code{%define} definitions in order. +Bison quietly ignores all command-line definitions for @var{name} except +the last. @item -Later definitions override earlier definitions except that Bison quietly -ignores all @code{%define} definitions if the last command-line -definition is specified by @code{-F} or @code{--force-define}. +If that command-line definition is specified by a @code{-D} or +@code{--define}, Bison reports an error for any @code{%define} +definition for @var{name}. @item -Bison never warns when a command-line definition overrides another -definition, but Bison always warns when a @code{%define} definition -overrides a command-line or @code{%define} definition. +If that command-line definition is specified by a @code{-F} or +@code{--force-define} instead, Bison quietly ignores all @code{%define} +definitions for @var{name}. +@item +Otherwise, Bison reports an error if there are multiple @code{%define} +definitions for @var{name}. @end itemize You should avoid using @code{-F} and @code{--force-define} in your diff --git a/src/muscle-tab.c b/src/muscle-tab.c index 99ff9716..c410a551 100644 --- a/src/muscle-tab.c +++ b/src/muscle-tab.c @@ -436,9 +436,9 @@ muscle_percent_define_insert (char const *variable, location variable_loc, free (variable_tr); return; } - warn_at (variable_loc, _("%s `%s' redefined"), - "%define variable", variable); - warn_at (muscle_percent_define_get_loc (variable), + complain_at (variable_loc, _("%s `%s' redefined"), + "%define variable", variable); + complain_at (muscle_percent_define_get_loc (variable), _("previous definition")); } diff --git a/src/muscle-tab.h b/src/muscle-tab.h index ce198629..a1fd9210 100644 --- a/src/muscle-tab.h +++ b/src/muscle-tab.h @@ -136,7 +136,7 @@ typedef enum { /* Define the muscles for %define variable VARIABLE with VALUE specified at VARIABLE_LOC in the manner HOW unless it was specified in the grammar file while the previous definition for VARIABLE was specified - with -F/--force-define. Warn if a previous definition is being + with -F/--force-define. Complain if a previous definition is being overridden and the new definition is specified in the grammar file. (These rules support the documented behavior as long as command-line definitions are processed before grammar file definitions.) Record diff --git a/tests/input.at b/tests/input.at index f3a52640..c43aeb1e 100644 --- a/tests/input.at +++ b/tests/input.at @@ -888,7 +888,7 @@ AT_CLEANUP AT_SETUP([%define errors]) -AT_DATA([input.y], +AT_DATA([input-redefined.y], [[%define var "value1" %define var "value1" %define var "value2" @@ -898,16 +898,21 @@ AT_DATA([input.y], start: ; ]]) -AT_BISON_CHECK([[input.y]], [0], [], -[[input.y:2.9-11: warning: %define variable `var' redefined -input.y:1.9-11: warning: previous definition -input.y:3.10-12: warning: %define variable `var' redefined -input.y:2.9-11: warning: previous definition -input.y:1.9-11: warning: %define variable `var' is not used -input.y:2.9-11: warning: %define variable `var' is not used -input.y:3.10-12: warning: %define variable `var' is not used -input.y:4.9-16: warning: %define variable `special1' is not used -input.y:5.9-16: warning: %define variable `special2' is not used +AT_BISON_CHECK([[input-redefined.y]], [[1]], [], +[[input-redefined.y:2.9-11: %define variable `var' redefined +input-redefined.y:1.9-11: previous definition +input-redefined.y:3.10-12: %define variable `var' redefined +input-redefined.y:2.9-11: previous definition +]]) + +AT_DATA([input-unused.y], +[[%define var "value" +%% +start: ; +]]) + +AT_BISON_CHECK([[input-unused.y]], [[0]], [], +[[input-unused.y:1.9-11: warning: %define variable `var' is not used ]]) AT_CLEANUP @@ -924,40 +929,45 @@ AT_DATA([skel.c], @output(b4_parser_file_name@)@ [var-dd: ]b4_percent_define_get([[var-dd]])[ var-ff: ]b4_percent_define_get([[var-ff]])[ -var-dg: ]b4_percent_define_get([[var-dg]])[ var-dfg: ]b4_percent_define_get([[var-dfg]])[ var-fd: ]b4_percent_define_get([[var-fd]]) m4@&t@_divert_pop(0) ]]) AT_DATA([input.y], -[[%define var-dg "gram" -%define var-dfg "gram" +[[%define var-dfg "gram" %% start: ; ]]) AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \ -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \ - -Dvar-dg=cmd-d \ -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \ -Fvar-fd=cmd-f -Dvar-fd=cmd-d \ -Dunused-d -Funused-f \ - --skeleton ./skel.c input.y]], [0], [], -[[input.y:1.9-14: warning: %define variable `var-dg' redefined -:6: warning: previous definition -:11: warning: %define variable `unused-d' is not used -:12: warning: %define variable `unused-f' is not used + --skeleton ./skel.c input.y]], [[0]], [], +[[:10: warning: %define variable `unused-d' is not used +:11: warning: %define variable `unused-f' is not used ]]) AT_CHECK([[cat input.tab.c]], [[0]], [[var-dd: cmd-d2 var-ff: cmd-f2 -var-dg: gram var-dfg: cmd-f var-fd: cmd-d ]]) +AT_DATA([input-dg.y], +[[%define var "gram" +%% +start: ; +]]) + +AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [], +[[input-dg.y:1.9-11: %define variable `var' redefined +:2: previous definition +]]) + AT_CLEANUP ## --------------------------- ## -- 2.45.2