From 3f7ca628535da8ee4296061580cc9a944bcf4ab4 Mon Sep 17 00:00:00 2001 From: "Joel E. Denny" Date: Sun, 10 Dec 2006 00:16:15 +0000 Subject: [PATCH] Warn about output files that are generated by the skeletons and that conflict with other output files. * data/glr.c: Don't generate the header file here when glr.cc does. * src/files.c (file_names, file_names_count): New static globals. (compute_output_file_names): Invoke output_file_name_check for files not generated by the skeletons and remove existing checks. (output_file_name_check): New function that warns about conflicting output file names. (output_file_names_free): Free file_names. * src/files.h (output_file_name_check): Declare. * src/scan-skel.l: Invoke output_file_name_check for files generated by the skeletons. * tests/output.at (AT_CHECK_CONFLICTING_OUTPUT): New. (Conflicting output files): New tests. --- ChangeLog | 17 +++++++++++++++++ data/glr.c | 8 ++++++-- src/files.c | 40 ++++++++++++++++++++++++++-------------- src/files.h | 1 + src/scan-skel.l | 1 + tests/output.at | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 27c551e6..9f6eb374 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2006-12-09 Joel E. Denny + + Warn about output files that are generated by the skeletons and that + conflict with other output files. + * data/glr.c: Don't generate the header file here when glr.cc does. + * src/files.c (file_names, file_names_count): New static globals. + (compute_output_file_names): Invoke output_file_name_check for files + not generated by the skeletons and remove existing checks. + (output_file_name_check): New function that warns about conflicting + output file names. + (output_file_names_free): Free file_names. + * src/files.h (output_file_name_check): Declare. + * src/scan-skel.l: Invoke output_file_name_check for files generated by + the skeletons. + * tests/output.at (AT_CHECK_CONFLICTING_OUTPUT): New. + (Conflicting output files): New tests. + 2006-12-09 Ralf Wildenhues * doc/bison.texinfo: Fix a couple of typos. diff --git a/data/glr.c b/data/glr.c index 406e3393..e51d5904 100644 --- a/data/glr.c +++ b/data/glr.c @@ -2624,7 +2624,11 @@ yypdumpstack (yyGLRStack* yystackp) ] b4_epilogue -b4_defines_if( +dnl +dnl glr.cc produces its own header. +dnl +m4_if(b4_skeleton, ["glr.c"], +[b4_defines_if( [@output @output_header_name@ b4_copyright([Skeleton interface for Bison GLR parsers in C], [2002, 2003, 2004, 2005, 2006]) @@ -2636,4 +2640,4 @@ extern YYSTYPE b4_prefix[]lval; b4_locations_if([b4_pure_if([], [extern YYLTYPE b4_prefix[]lloc;]) ]) -]) +])]) diff --git a/src/files.c b/src/files.c index 934e1143..05985d8e 100644 --- a/src/files.c +++ b/src/files.c @@ -53,6 +53,10 @@ char *spec_graph_file = NULL; /* for -g. */ char *spec_defines_file = NULL; /* for --defines. */ char *parser_file_name; +/* All computed output file names. */ +static char **file_names = NULL; +static int file_names_count = 0; + uniqstr grammar_file = NULL; uniqstr current_file = NULL; @@ -292,11 +296,6 @@ compute_file_name_parts (void) void compute_output_file_names (void) { - char const *name[4]; - int i; - int j; - int names = 0; - compute_file_name_parts (); /* If not yet done. */ @@ -305,7 +304,7 @@ compute_output_file_names (void) if (!header_extension) header_extension = xstrdup (".h"); - name[names++] = parser_file_name = + parser_file_name = (spec_outfile ? xstrdup (spec_outfile) : concat2 (all_but_ext, src_extension)); @@ -314,33 +313,40 @@ compute_output_file_names (void) { if (! spec_defines_file) spec_defines_file = concat2 (all_but_ext, header_extension); - name[names++] = spec_defines_file; } if (graph_flag) { if (! spec_graph_file) spec_graph_file = concat2 (all_but_tab_ext, ".dot"); - name[names++] = spec_graph_file; + output_file_name_check (spec_graph_file); } if (report_flag) { spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT); - name[names++] = spec_verbose_file; + output_file_name_check (spec_verbose_file); } - for (j = 0; j < names; j++) - for (i = 0; i < j; i++) - if (strcmp (name[i], name[j]) == 0) - warn (_("conflicting outputs to file %s"), quote (name[i])); - free (all_but_ext); free (all_but_tab_ext); free (src_extension); free (header_extension); } +void +output_file_name_check (char const *file_name) +{ + { + int i; + for (i = 0; i < file_names_count; i++) + if (0 == strcmp (file_names[i], file_name)) + warn (_("conflicting outputs to file %s"), quote (file_name)); + } + file_names = xnrealloc (file_names, ++file_names_count, sizeof *file_names); + file_names[file_names_count-1] = xstrdup (file_name); +} + void output_file_names_free (void) { @@ -349,4 +355,10 @@ output_file_names_free (void) free (spec_defines_file); free (parser_file_name); free (dir_prefix); + { + int i; + for (i = 0; i < file_names_count; i++) + free (file_names[i]); + } + free (file_names); } diff --git a/src/files.h b/src/files.h index e702db65..1afcf7a5 100644 --- a/src/files.h +++ b/src/files.h @@ -64,6 +64,7 @@ extern uniqstr current_file; void compute_output_file_names (void); void output_file_names_free (void); +void output_file_name_check (char const *file_name); FILE *xfopen (const char *name, const char *mode); void xfclose (FILE *ptr); diff --git a/src/scan-skel.l b/src/scan-skel.l index 6c516097..b4661743 100644 --- a/src/scan-skel.l +++ b/src/scan-skel.l @@ -81,6 +81,7 @@ int skel_lex (void); xfclose (yyout); } outname = xstrdup (file_name); + output_file_name_check (file_name); yyout = xfopen (outname, "w"); lineno = 1; } diff --git a/tests/output.at b/tests/output.at index 468aa5fd..6362ef2d 100644 --- a/tests/output.at +++ b/tests/output.at @@ -116,3 +116,36 @@ AT_CHECK_OUTPUT([subdir/foo.yy], [%skeleton "lalr1.cc" %defines %verbose], [-o subdir/foo.cc], [subdir/foo.cc subdir/foo.hh subdir/foo.output subdir/location.hh subdir/stack.hh subdir/position.hh], [], [AT_CHECK_NO_SUBDIR_PART([subdir/foo])]) + + +# AT_CHECK_CONFLICTING_OUTPUT(INPUT-FILE, DIRECTIVES, FLAGS, STDERR) +# ----------------------------------------------------------------------------- +m4_define([AT_CHECK_CONFLICTING_OUTPUT], +[AT_SETUP([Conflicting output files: $2 $3]) +case "$1" in + */*) mkdir `echo "$1" | sed 's,/.*,,'`;; +esac +AT_DATA([$1], +[[$2 +%% +foo: {}; +]]) + +AT_CHECK([bison $3 $1], 0, [], [$4]) +AT_CLEANUP +]) + +AT_CHECK_CONFLICTING_OUTPUT([foo.y], +[], [--graph="foo.tab.c"], +[foo.y: warning: conflicting outputs to file `foo.tab.c' +]) + +AT_CHECK_CONFLICTING_OUTPUT([foo.y], +[%defines "foo.output"], [-v], +[foo.y: warning: conflicting outputs to file `foo.output' +]) + +AT_CHECK_CONFLICTING_OUTPUT([foo.y], +[%skeleton "lalr1.cc" %defines], [--graph="location.hh"], +[foo.y: warning: conflicting outputs to file `location.hh' +]) -- 2.45.2