mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
output: record what generated files are source or report files
* src/files.h, src/files.c (output_file_name_check): Take an additional argument to record whether a file is a source or report file. * src/files.c (generated_file): New. (file_names, file_names_count): Replace with... (generated_files, generated_files_size): these. * src/scan-skel.l: Adjust.
This commit is contained in:
40
src/files.c
40
src/files.c
@@ -51,8 +51,17 @@ char *spec_defines_file = NULL; /* for --defines. */
|
|||||||
char *parser_file_name;
|
char *parser_file_name;
|
||||||
|
|
||||||
/* All computed output file names. */
|
/* All computed output file names. */
|
||||||
static char **file_names = NULL;
|
typedef struct generated_file
|
||||||
static int file_names_count = 0;
|
{
|
||||||
|
/** File name. */
|
||||||
|
char *name;
|
||||||
|
/** Whether is a generated source file (e.g., *.c, *.java...), as
|
||||||
|
opposed to the report file (e.g., *.output). When late errors
|
||||||
|
are detected, generated source files are removed. */
|
||||||
|
bool is_source;
|
||||||
|
} generated_file;
|
||||||
|
static generated_file *generated_files = NULL;
|
||||||
|
static int generated_files_size = 0;
|
||||||
|
|
||||||
uniqstr grammar_file = NULL;
|
uniqstr grammar_file = NULL;
|
||||||
uniqstr current_file = NULL;
|
uniqstr current_file = NULL;
|
||||||
@@ -332,21 +341,21 @@ compute_output_file_names (void)
|
|||||||
{
|
{
|
||||||
if (! spec_graph_file)
|
if (! spec_graph_file)
|
||||||
spec_graph_file = concat2 (all_but_tab_ext, ".dot");
|
spec_graph_file = concat2 (all_but_tab_ext, ".dot");
|
||||||
output_file_name_check (&spec_graph_file);
|
output_file_name_check (&spec_graph_file, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xml_flag)
|
if (xml_flag)
|
||||||
{
|
{
|
||||||
if (! spec_xml_file)
|
if (! spec_xml_file)
|
||||||
spec_xml_file = concat2 (all_but_tab_ext, ".xml");
|
spec_xml_file = concat2 (all_but_tab_ext, ".xml");
|
||||||
output_file_name_check (&spec_xml_file);
|
output_file_name_check (&spec_xml_file, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (report_flag)
|
if (report_flag)
|
||||||
{
|
{
|
||||||
if (!spec_verbose_file)
|
if (!spec_verbose_file)
|
||||||
spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT);
|
spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT);
|
||||||
output_file_name_check (&spec_verbose_file);
|
output_file_name_check (&spec_verbose_file, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
free (all_but_tab_ext);
|
free (all_but_tab_ext);
|
||||||
@@ -355,7 +364,7 @@ compute_output_file_names (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
output_file_name_check (char **file_name)
|
output_file_name_check (char **file_name, bool source)
|
||||||
{
|
{
|
||||||
bool conflict = false;
|
bool conflict = false;
|
||||||
if (STREQ (*file_name, grammar_file))
|
if (STREQ (*file_name, grammar_file))
|
||||||
@@ -367,11 +376,11 @@ output_file_name_check (char **file_name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < file_names_count; i++)
|
for (i = 0; i < generated_files_size; i++)
|
||||||
if (STREQ (file_names[i], *file_name))
|
if (STREQ (generated_files[i].name, *file_name))
|
||||||
{
|
{
|
||||||
complain (NULL, Wother, _("conflicting outputs to file %s"),
|
complain (NULL, Wother, _("conflicting outputs to file %s"),
|
||||||
quote (*file_name));
|
quote (generated_files[i].name));
|
||||||
conflict = true;
|
conflict = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,9 +391,10 @@ output_file_name_check (char **file_name)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file_names = xnrealloc (file_names, ++file_names_count,
|
generated_files = xnrealloc (generated_files, ++generated_files_size,
|
||||||
sizeof *file_names);
|
sizeof *generated_files);
|
||||||
file_names[file_names_count-1] = xstrdup (*file_name);
|
generated_files[generated_files_size-1].name = xstrdup (*file_name);
|
||||||
|
generated_files[generated_files_size-1].is_source = source;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,8 +410,8 @@ output_file_names_free (void)
|
|||||||
free (dir_prefix);
|
free (dir_prefix);
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < file_names_count; i++)
|
for (i = 0; i < generated_files_size; i++)
|
||||||
free (file_names[i]);
|
free (generated_files[i].name);
|
||||||
}
|
}
|
||||||
free (file_names);
|
free (generated_files);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,12 @@ extern char *all_but_ext;
|
|||||||
|
|
||||||
void compute_output_file_names (void);
|
void compute_output_file_names (void);
|
||||||
void output_file_names_free (void);
|
void output_file_names_free (void);
|
||||||
void output_file_name_check (char **file_name);
|
|
||||||
|
/** Record that we generate file \a file_name.
|
||||||
|
* \param source whether this is a source file (*c, *.java...)
|
||||||
|
* as opposed to a report (*.output, *.dot...).
|
||||||
|
*/
|
||||||
|
void output_file_name_check (char **file_name, bool source);
|
||||||
|
|
||||||
FILE *xfopen (const char *name, char const *mode);
|
FILE *xfopen (const char *name, char const *mode);
|
||||||
void xfclose (FILE *ptr);
|
void xfclose (FILE *ptr);
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
|
|||||||
xfclose (yyout);
|
xfclose (yyout);
|
||||||
}
|
}
|
||||||
*out_namep = xstrdup (argv[1]);
|
*out_namep = xstrdup (argv[1]);
|
||||||
output_file_name_check (out_namep);
|
output_file_name_check (out_namep, true);
|
||||||
/* If there were errors, do not generate the output. */
|
/* If there were errors, do not generate the output. */
|
||||||
yyout = xfopen (complaint_status ? "/dev/null" : *out_namep, "w");
|
yyout = xfopen (complaint_status ? "/dev/null" : *out_namep, "w");
|
||||||
*out_linenop = 1;
|
*out_linenop = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user