diagnostics: let redundant definitions be only warnings

After all, this is clearly harmless.

* src/muscle-tab.c (muscle_percent_define_insert): Let equal
definitions of a %define variable be only a warning.
Adjust test cases.
This commit is contained in:
Akim Demaille
2019-01-21 19:37:36 +01:00
parent 7498ede3ab
commit 36cae8e752
2 changed files with 37 additions and 29 deletions

View File

@@ -520,21 +520,27 @@ muscle_percent_define_insert (char const *var, location variable_loc,
/* Command-line options are processed before the grammar file. */ /* Command-line options are processed before the grammar file. */
bool warned = false; bool warned = false;
if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE)
&& muscle_find_const (name))
{ {
muscle_percent_define_how how_old = atoi (muscle_find_const (how_name)); char const *current_value = muscle_find_const (name);
if (how_old == MUSCLE_PERCENT_DEFINE_F) if (current_value)
goto end; {
unsigned i = 0; muscle_percent_define_how how_old
complain_indent (&variable_loc, complaint, &i, = atoi (muscle_find_const (how_name));
_("%%define variable %s redefined"), if (how_old == MUSCLE_PERCENT_DEFINE_F)
quote (variable)); goto end;
i += SUB_INDENT; unsigned i = 0;
location loc = muscle_percent_define_get_loc (variable); /* If assigning the same value, make it a warning. */
complain_indent (&loc, complaint, &i, _("previous definition")); warnings warn = STREQ (value, current_value) ? Wother : complaint;
fixits_register (&variable_loc, ""); complain_indent (&variable_loc, warn, &i,
warned = true; _("%%define variable %s redefined"),
quote (variable));
i += SUB_INDENT;
location loc = muscle_percent_define_get_loc (variable);
complain_indent (&loc, warn, &i, _("previous definition"));
fixits_register (&variable_loc, "");
warned = true;
}
} }
if (!warned && old && upd) if (!warned && old && upd)

View File

@@ -1740,7 +1740,7 @@ start: %empty;
]]) ]])
AT_BISON_CHECK([[input-redefined.y]], [[1]], [], AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
[[input-redefined.y:2.1-20: error: %define variable 'var' redefined [[input-redefined.y:2.1-20: warning: %define variable 'var' redefined [-Wother]
input-redefined.y:1.1-20: previous definition input-redefined.y:1.1-20: previous definition
input-redefined.y:3.2-21: error: %define variable 'var' redefined input-redefined.y:3.2-21: error: %define variable 'var' redefined
input-redefined.y:2.1-20: previous definition input-redefined.y:2.1-20: previous definition
@@ -2333,8 +2333,8 @@ AT_CLEANUP
AT_SETUP([[Redefined %union name]]) AT_SETUP([[Redefined %union name]])
# AT_TEST(DIRECTIVES, ERROR) # AT_TEST(DIRECTIVES, EXIT-STATUS, ERROR)
# -------------------------- # ---------------------------------------
m4_pushdef([AT_TEST], m4_pushdef([AT_TEST],
[AT_DATA([[input.y]], [AT_DATA([[input.y]],
[$1 [$1
@@ -2342,27 +2342,28 @@ m4_pushdef([AT_TEST],
exp: %empty; exp: %empty;
]) ])
AT_BISON_CHECK([[input.y]], [[1]], [[]], AT_BISON_CHECK([[input.y]], [$2], [[]],
[$2]) [$3])
]) ])
AT_TEST([[%union foo {}; AT_TEST([[%union foo {};
%union {}; %union {};
%union foo {}; %union foo {};
%define api.value.union.name foo]], %define api.value.union.name foo]],
[[input.y:3.8-10: error: %define variable 'api.value.union.name' redefined [0],
[[input.y:3.8-10: warning: %define variable 'api.value.union.name' redefined [-Wother]
input.y:1.8-10: previous definition input.y:1.8-10: previous definition
input.y:4.1-32: error: %define variable 'api.value.union.name' redefined input.y:4.1-32: warning: %define variable 'api.value.union.name' redefined [-Wother]
input.y:3.8-10: previous definition input.y:3.8-10: previous definition
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]]) ]])
AT_TEST([[%define api.value.union.name {foo}]], AT_TEST([[%define api.value.union.name {foo}]], [1],
[[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values
input.y:1.1-34: error: %define variable 'api.value.union.name' is not used input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
]]) ]])
AT_TEST([[%define api.value.union.name "foo"]], AT_TEST([[%define api.value.union.name "foo"]], [1],
[[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values
input.y:1.1-34: error: %define variable 'api.value.union.name' is not used input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
]]) ]])
@@ -2543,7 +2544,7 @@ input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%pure-parse
fix-it:"input.y":{25:1-25:13}:"%pure-parser" fix-it:"input.y":{25:1-25:13}:"%pure-parser"
input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated] input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
fix-it:"input.y":{26:1-26:13}:"%token-table" fix-it:"input.y":{26:1-26:13}:"%token-table"
input.y:27.1-14: error: %define variable 'parse.error' redefined input.y:27.1-14: warning: %define variable 'parse.error' redefined [-Wother]
input.y:11.1-14: previous definition input.y:11.1-14: previous definition
fix-it:"input.y":{27:1-27:15}:"" fix-it:"input.y":{27:1-27:15}:""
input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother] input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother]
@@ -2553,16 +2554,16 @@ input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wothe
]]) ]])
AT_CHECK([cp errors-all experr]) AT_CHECK([cp errors-all experr])
AT_BISON_CHECK([[-ffixit input.y]], [[1]], [[]], [experr]) AT_BISON_CHECK([[-ffixit input.y]], [], [], [experr])
AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]]) AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
AT_BISON_CHECK([[input.y]], [[1]], [[]], [experr]) AT_BISON_CHECK([[input.y]], [], [], [experr])
# Update the input file. # Update the input file.
AT_CHECK([cp input.y input.y.orig]) AT_CHECK([cp input.y input.y.orig])
AT_CHECK([sed -e '/fix-it/d' <errors-all >experr]) AT_CHECK([sed -e '/fix-it/d' <errors-all >experr])
AT_CHECK([echo "bison: file 'input.y' was updated (backup: 'input.y~')" >>experr]) AT_CHECK([echo "bison: file 'input.y' was updated (backup: 'input.y~')" >>experr])
AT_BISON_CHECK([[--update input.y]], [[1]], [[]], [experr]) AT_BISON_CHECK([[--update input.y]], [], [[]], [experr])
# Check the backup. # Check the backup.
AT_CHECK([diff input.y.orig input.y~]) AT_CHECK([diff input.y.orig input.y~])
@@ -2628,10 +2629,11 @@ AT_BISON_CHECK([[input.y]], [[1]], [[]],
input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated] input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated] input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
input.y:13.16-29: error: %define variable 'parse.error' redefined input.y:13.16-29: warning: %define variable 'parse.error' redefined [-Wother]
input.y:13.1-14: previous definition input.y:13.1-14: previous definition
input.y:14.16-29: error: %define variable 'parse.error' redefined input.y:14.16-29: warning: %define variable 'parse.error' redefined [-Wother]
input.y:13.16-29: previous definition input.y:13.16-29: previous definition
input.y: error: reduce/reduce conflicts: 0 found, 42 expected
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
]]) ]])