--update: when used, do not generate the output files

It is inconvenient that we also generate the output files when we
update the grammar file, and it's somewhat unexpected.  Let's not do
that.

* src/main.c (main): Skip generation when --update is passed.
* src/getargs.c (usage): Update the help message.
* doc/bison.texi (Bison Options): Likewise.
* tests/input.at: Check that we don't generate the output.
This commit is contained in:
Akim Demaille
2019-01-21 19:37:10 +01:00
parent 36cae8e752
commit 5ec9c99662
4 changed files with 42 additions and 31 deletions

View File

@@ -10272,8 +10272,8 @@ Print the name of the directory containing skeletons and XSLT.
@item -u @item -u
@item --update @item --update
Update the grammar file (remove duplicates, update deprecated directives, Update the grammar file (remove duplicates, update deprecated directives,
etc.). Leaves a backup of the original file with a @code{~} appended. For etc.) and exit (i.e., do not generate any of the output files). Leaves a
instance: backup of the original file with a @code{~} appended. For instance:
@example @example
@group @group

View File

@@ -287,7 +287,7 @@ Operation modes:\n\
and exit\n\ and exit\n\
--print-datadir output directory containing skeletons and XSLT\n\ --print-datadir output directory containing skeletons and XSLT\n\
and exit\n\ and exit\n\
-u, --update apply fixes to the source grammar file\n\ -u, --update apply fixes to the source grammar file and exit\n\
-y, --yacc emulate POSIX Yacc\n\ -y, --yacc emulate POSIX Yacc\n\
-W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\ -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\
-f, --feature[=FEATURE] activate miscellaneous features\n\ -f, --feature[=FEATURE] activate miscellaneous features\n\

View File

@@ -155,31 +155,34 @@ main (int argc, char *argv[])
print_precedence_warnings (); print_precedence_warnings ();
/* Output file names. */ if (!update_flag)
compute_output_file_names ();
/* Output the detailed report on the grammar. */
if (report_flag)
{ {
timevar_push (tv_report); /* Output file names. */
print_results (); compute_output_file_names ();
timevar_pop (tv_report);
}
/* Output the graph. */ /* Output the detailed report on the grammar. */
if (graph_flag) if (report_flag)
{ {
timevar_push (tv_graph); timevar_push (tv_report);
print_graph (); print_results ();
timevar_pop (tv_graph); timevar_pop (tv_report);
} }
/* Output xml. */ /* Output the graph. */
if (xml_flag) if (graph_flag)
{ {
timevar_push (tv_xml); timevar_push (tv_graph);
print_xml (); print_graph ();
timevar_pop (tv_xml); timevar_pop (tv_graph);
}
/* Output xml. */
if (xml_flag)
{
timevar_push (tv_xml);
print_xml ();
timevar_pop (tv_xml);
}
} }
/* Stop if there were errors, to avoid trashing previous output /* Stop if there were errors, to avoid trashing previous output
@@ -193,9 +196,12 @@ main (int argc, char *argv[])
timevar_pop (tv_free); timevar_pop (tv_free);
/* Output the tables and the parser to ftable. In file output. */ /* Output the tables and the parser to ftable. In file output. */
timevar_push (tv_parser); if (!update_flag)
output (); {
timevar_pop (tv_parser); timevar_push (tv_parser);
output ();
timevar_pop (tv_parser);
}
timevar_push (tv_free); timevar_push (tv_free);
nullable_free (); nullable_free ();

View File

@@ -2500,7 +2500,7 @@ AT_DATA_GRAMMAR([[input.y]],
%no-default_prec %no-default_prec
%no_default-prec %no_default-prec
%no_lines %no_lines
%output = "foo" %output = "output.c"
%pure_parser %pure_parser
%token_table %token_table
%error-verbose %error-verbose
@@ -2559,7 +2559,9 @@ 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]], [], [], [experr]) AT_BISON_CHECK([[input.y]], [], [], [experr])
# Update the input file.
# Update the input file. Make sure we generated nothing.
AT_CHECK([rm -f output.c])
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])
@@ -2568,6 +2570,9 @@ 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~])
# Check we did not generate any file.
AT_CHECK([test ! -f output.c])
# Check the update. # Check the update.
AT_CHECK([cat input.y], [], AT_CHECK([cat input.y], [],
[[%code top { [[%code top {
@@ -2588,7 +2593,7 @@ AT_CHECK([cat input.y], [],
%no-default-prec %no-default-prec
%no-default-prec %no-default-prec
%no-lines %no-lines
%output "foo" %output "output.c"
%pure-parser %pure-parser
%token-table %token-table
%glr-parser %glr-parser