mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
fixits: suggest running --update if there are fixits
* src/fixits.h, src/fixits.c (fixits_empty): New. * src/complain.c (deprecated_directive): Register the Wdeprecated fixits only if -Wdeprecated was enabled, so that we don't apply updates if the user didn't ask for them. * src/main.c (main): If there were fixits, issue a warning suggesting running with --update. Free uniqstrs after the fixits, since the latter use the former. * tests/headers.at, tests/input.at: Update expectations.
This commit is contained in:
@@ -394,7 +394,9 @@ deprecated_directive (location const *loc, char const *old, char const *upd)
|
|||||||
complain (loc, Wdeprecated,
|
complain (loc, Wdeprecated,
|
||||||
_("deprecated directive: %s, use %s"),
|
_("deprecated directive: %s, use %s"),
|
||||||
quote (old), quote_n (1, upd));
|
quote (old), quote_n (1, upd));
|
||||||
fixits_register (loc, upd);
|
/* Register updates only if -Wdeprecated is enabled. */
|
||||||
|
if (warnings_flag[warning_deprecated] != severity_disabled)
|
||||||
|
fixits_register (loc, upd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ fixits_register (location const *loc, char const* fix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
fixits_empty (void)
|
||||||
|
{
|
||||||
|
return !fixits;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
fixits_run (void)
|
fixits_run (void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ void fixits_register (location const *loc, char const* update);
|
|||||||
/* Apply the fixits: update the source file. */
|
/* Apply the fixits: update the source file. */
|
||||||
void fixits_run (void);
|
void fixits_run (void);
|
||||||
|
|
||||||
|
/* Whether there are no fixits. */
|
||||||
|
bool fixits_empty (void);
|
||||||
|
|
||||||
/* Free the registered fixits. */
|
/* Free the registered fixits. */
|
||||||
void fixits_free (void);
|
void fixits_free (void);
|
||||||
|
|
||||||
|
|||||||
20
src/main.c
20
src/main.c
@@ -103,12 +103,6 @@ main (int argc, char *argv[])
|
|||||||
reader ();
|
reader ();
|
||||||
timevar_pop (tv_reader);
|
timevar_pop (tv_reader);
|
||||||
|
|
||||||
/* Fix input file now, even if there are errors: that's less
|
|
||||||
warnings in the following runs. */
|
|
||||||
if (update_flag)
|
|
||||||
fixits_run ();
|
|
||||||
fixits_free ();
|
|
||||||
|
|
||||||
if (complaint_status == status_complaint)
|
if (complaint_status == status_complaint)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
@@ -217,7 +211,6 @@ main (int argc, char *argv[])
|
|||||||
contains things such as user actions, prologue, epilogue etc. */
|
contains things such as user actions, prologue, epilogue etc. */
|
||||||
gram_scanner_free ();
|
gram_scanner_free ();
|
||||||
muscle_free ();
|
muscle_free ();
|
||||||
uniqstrs_free ();
|
|
||||||
code_scanner_free ();
|
code_scanner_free ();
|
||||||
skel_scanner_free ();
|
skel_scanner_free ();
|
||||||
quotearg_free ();
|
quotearg_free ();
|
||||||
@@ -234,5 +227,18 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
cleanup_caret ();
|
cleanup_caret ();
|
||||||
|
|
||||||
|
/* Fix input file now, even if there are errors: that's less
|
||||||
|
warnings in the following runs. */
|
||||||
|
if (!fixits_empty ())
|
||||||
|
{
|
||||||
|
if (update_flag)
|
||||||
|
fixits_run ();
|
||||||
|
else
|
||||||
|
complain (NULL, Wother,
|
||||||
|
_("fix-its can be applied. Rerun with option '--update'."));
|
||||||
|
fixits_free ();
|
||||||
|
}
|
||||||
|
uniqstrs_free ();
|
||||||
|
|
||||||
return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS;
|
return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ exp: %empty;
|
|||||||
|
|
||||||
AT_BISON_CHECK([--defines -o input.c input.y], [], [],
|
AT_BISON_CHECK([--defines -o input.c input.y], [], [],
|
||||||
[[input.y:11.1-18: warning: deprecated directive: '%name-prefix "my_"', use '%define api.prefix {my_}' [-Wdeprecated]
|
[[input.y:11.1-18: warning: deprecated directive: '%name-prefix "my_"', use '%define api.prefix {my_}' [-Wdeprecated]
|
||||||
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
# YYLTYPE should be defined, and MY_LLOC declared.
|
# YYLTYPE should be defined, and MY_LLOC declared.
|
||||||
|
|||||||
@@ -1744,6 +1744,7 @@ AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
|
|||||||
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
|
||||||
|
input-redefined.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_DATA([input-unused.y],
|
AT_DATA([input-unused.y],
|
||||||
@@ -1799,6 +1800,7 @@ start: %empty;
|
|||||||
AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
|
AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
|
||||||
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
|
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
|
||||||
<command line>:2: previous definition
|
<command line>:2: previous definition
|
||||||
|
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_DATA([[input-dg.y]],
|
AT_DATA([[input-dg.y]],
|
||||||
@@ -1811,6 +1813,7 @@ AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
|
|||||||
%define var "gram"
|
%define var "gram"
|
||||||
^~~~~~~~~~~~~~~~~~
|
^~~~~~~~~~~~~~~~~~
|
||||||
<command line>:3: previous definition
|
<command line>:3: previous definition
|
||||||
|
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_DATA([[input-unused.y]],
|
AT_DATA([[input-unused.y]],
|
||||||
@@ -2017,6 +2020,7 @@ input.y:5.1-15: warning: deprecated directive, use '%define api.value.type varia
|
|||||||
input.y:6.1-34: warning: deprecated directive, use '%define api.parser.class {parser}' [-Wdeprecated]
|
input.y:6.1-34: warning: deprecated directive, use '%define api.parser.class {parser}' [-Wdeprecated]
|
||||||
%define parser_class_name {parser}
|
%define parser_class_name {parser}
|
||||||
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -2354,6 +2358,7 @@ AT_TEST([[%union foo {};
|
|||||||
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: error: %define variable 'api.value.union.name' redefined
|
||||||
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]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_TEST([[%define api.value.union.name {foo}]],
|
AT_TEST([[%define api.value.union.name {foo}]],
|
||||||
@@ -2542,6 +2547,7 @@ 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: deprecated directive: '%name-prefix "bar"', use '%define api.prefix {bar}' [-Wdeprecated]
|
input.y:29.1-18: warning: deprecated directive: '%name-prefix "bar"', use '%define api.prefix {bar}' [-Wdeprecated]
|
||||||
fix-it:"input.y":{29:1-29:19}:"%define api.prefix {bar}"
|
fix-it:"input.y":{29:1-29:19}:"%define api.prefix {bar}"
|
||||||
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
|
AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
|
||||||
@@ -2599,6 +2605,7 @@ AT_BISON_CHECK([[-fcaret input.y]], [[1]], [],
|
|||||||
input.y:19.1-24: previous definition
|
input.y:19.1-24: previous definition
|
||||||
%define api.prefix {foo}
|
%define api.prefix {foo}
|
||||||
^~~~~~~~~~~~~~~~~~~~~~~~
|
^~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -2636,6 +2643,7 @@ input.y:13.16-29: error: %define variable 'parse.error' redefined
|
|||||||
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: error: %define variable 'parse.error' redefined
|
||||||
input.y:13.16-29: previous definition
|
input.y:13.16-29: previous definition
|
||||||
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|||||||
Reference in New Issue
Block a user