From ea5607fd01a420fe362d6dfc6f9b75d568f2694b Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 20 Dec 2000 10:29:43 +0000 Subject: [PATCH] * src/files.c (guard_obstack): New. (open_files): Initialize it. (output_files): Dump it... * src/files.h: Export it. * src/reader.c (copy_guard): Use it. --- ChangeLog | 8 ++++++++ src/files.c | 17 ++++++++++------- src/files.h | 15 +++++++-------- src/getargs.c | 3 --- src/output.c | 9 ++------- src/reader.c | 30 ++++++++++++++---------------- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89c60329..4ebe4a5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2000-12-20 Akim Demaille + + * src/files.c (guard_obstack): New. + (open_files): Initialize it. + (output_files): Dump it... + * src/files.h: Export it. + * src/reader.c (copy_guard): Use it. + 2000-12-19 Akim Demaille * src/files.c (outfile, defsfile, actfile): Removed as global diff --git a/src/files.c b/src/files.c index 235deb03..b2f84a2a 100644 --- a/src/files.c +++ b/src/files.c @@ -28,19 +28,19 @@ FILE *finput = NULL; FILE *foutput = NULL; -FILE *fguard = NULL; struct obstack action_obstack; struct obstack attrs_obstack; struct obstack table_obstack; struct obstack defines_obstack; +struct obstack guard_obstack; -/* File name specified with -o for the output file, or 0 if no -o. */ -char *spec_outfile; +char *spec_outfile; /* for -o. */ +char *spec_file_prefix; /* for -b. */ +char *spec_name_prefix; /* for -p. */ char *infile; char *attrsfile; -char *guardfile; static char *base_name; static char *short_base_name; @@ -255,13 +255,13 @@ open_files (void) foutput = xfopen (stringappend (base_name, EXT_OUTPUT), "w"); attrsfile = stringappend (short_base_name, EXT_STYPE_H); - guardfile = stringappend (short_base_name, EXT_GUARD_C); /* Initialize the obstacks. */ obstack_init (&action_obstack); obstack_init (&attrs_obstack); obstack_init (&table_obstack); obstack_init (&defines_obstack); + obstack_init (&guard_obstack); } @@ -273,7 +273,6 @@ open_files (void) void output_files (void) { - xfclose (fguard); xfclose (finput); xfclose (foutput); @@ -294,5 +293,9 @@ output_files (void) /* If we produced a semantic parser ATTRS_OBSTACK must be dumped into its own file, ATTTRSFILE. */ if (semantic_parser) - obstack_save (&attrs_obstack, attrsfile); + { + obstack_save (&attrs_obstack, attrsfile); + obstack_save (&guard_obstack, + stringappend (short_base_name, EXT_GUARD_C)); + } } diff --git a/src/files.h b/src/files.h index adf734b4..96799891 100644 --- a/src/files.h +++ b/src/files.h @@ -27,7 +27,7 @@ /* File name specified with -o for the output file, or 0 if no -o. */ extern char *spec_outfile; -/* For -a, from getargs.c */ +/* For -a. */ extern char *spec_name_prefix; /* File name pfx specified with -b, or 0 if no -b. */ @@ -40,16 +40,10 @@ extern FILE *finput; /* Optionally output messages describing the actions taken. */ extern FILE *foutput; -/* If semantic parser, output yyguard, containing all the guard code. */ -extern FILE *fguard; - /* Output all the action code; precise form depends on which parser. */ extern struct obstack action_obstack; -/* If semantic parser, output a .h file that defines YYSTYPE */ -extern struct obstack attrs_obstack; - /* Output the tables and the parser and also contains all the %{ ... %} definitions. */ extern struct obstack table_obstack; @@ -57,10 +51,15 @@ extern struct obstack table_obstack; /* optionally output #define's for token numbers. */ extern struct obstack defines_obstack; +/* If semantic parser, output a .h file that defines YYSTYPE... */ +extern struct obstack attrs_obstack; + +/* ... and output yyguard, containing all the guard code. */ +extern struct obstack guard_obstack; + extern char *infile; extern char *attrsfile; -extern char *guardfile; void open_files PARAMS((void)); diff --git a/src/getargs.c b/src/getargs.c index 6ee6cf89..c45f11eb 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -24,9 +24,6 @@ #include "files.h" #include "getargs.h" -char *spec_file_prefix; /* for -b. */ -char *spec_name_prefix; /* for -p. */ - int debug_flag = 0; int defines_flag = 0; int locations_flag = 0; diff --git a/src/output.c b/src/output.c index 609d9801..a5a0a606 100644 --- a/src/output.c +++ b/src/output.c @@ -226,7 +226,7 @@ output_headers (void) char *attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile); if (semantic_parser) - fprintf (fguard, GUARDSTR, attrsfile_quoted); + obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted); if (no_parser_flag) return; @@ -236,11 +236,6 @@ output_headers (void) else obstack_grow_string (&action_obstack, ACTSTR_SIMPLE); -/* if (semantic_parser) JF moved this below - fprintf(ftable, "#include \"%s\"\n", attrsfile); - fprintf(ftable, "#include \n\n"); -*/ - /* Rename certain symbols if -p was specified. */ if (spec_name_prefix) { @@ -270,7 +265,7 @@ void output_trailers (void) { if (semantic_parser) - fprintf (fguard, "\n }\n}\n"); + obstack_grow_string (&guard_obstack, "\n }\n}\n"); obstack_1grow (&action_obstack, '\n'); diff --git a/src/reader.c b/src/reader.c index 156fa452..60566736 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1002,8 +1002,6 @@ read_declarations (void) break; case SEMANTIC_PARSER: - if (!semantic_parser) - fguard = xfopen (guardfile, "w"); semantic_parser = 1; break; @@ -1140,11 +1138,11 @@ copy_guard (symbol_list *rule, int stack_offset) if (semantic_parser) stack_offset = 0; - fprintf (fguard, "\ncase %d:\n", nrules); + obstack_fgrow1 (&guard_obstack, "\ncase %d:\n", nrules); if (!no_lines_flag) - fprintf (fguard, "#line %d %s\n", - lineno, quotearg_style (c_quoting_style, infile)); - putc ('{', fguard); + obstack_fgrow2 (&guard_obstack, "#line %d %s\n", + lineno, quotearg_style (c_quoting_style, infile)); + obstack_1grow (&guard_obstack, '{'); count = 0; c = getc (finput); @@ -1154,18 +1152,18 @@ copy_guard (symbol_list *rule, int stack_offset) switch (c) { case '\n': - putc (c, fguard); + obstack_1grow (&guard_obstack, c); lineno++; break; case '{': - putc (c, fguard); + obstack_1grow (&guard_obstack, c); brace_flag = 1; count++; break; case '}': - putc (c, fguard); + obstack_1grow (&guard_obstack, c); if (count > 0) count--; else @@ -1177,26 +1175,26 @@ copy_guard (symbol_list *rule, int stack_offset) case '\'': case '"': - copy_string (finput, fguard, 0, c); + copy_string (finput, 0, &guard_obstack, c); break; case '/': - copy_comment (finput, fguard, 0); + copy_comment (finput, 0, &guard_obstack); break; case '$': - copy_dollar (finput, fguard, 0, rule, stack_offset); + copy_dollar (finput, 0, &guard_obstack, rule, stack_offset); break; case '@': - copy_at (finput, fguard, 0, stack_offset); + copy_at (finput, 0, &guard_obstack, stack_offset); break; case EOF: fatal ("%s", _("unterminated %guard clause")); default: - putc (c, fguard); + obstack_1grow (&guard_obstack, c); } if (c != '}' || count != 0) @@ -1205,7 +1203,7 @@ copy_guard (symbol_list *rule, int stack_offset) c = skip_white_space (); - fprintf (fguard, ";\n break;}"); + obstack_grow_string (&guard_obstack, ";\n break;}"); if (c == '{') copy_action (rule, stack_offset); else if (c == '=') @@ -1898,7 +1896,7 @@ packgram (void) /*-------------------------------------------------------------------. | Read in the grammar specification and record it in the format | -| described in gram.h. All guards are copied into the FGUARD file | +| described in gram.h. All guards are copied into the GUARD_OBSTACK | | and all actions into ACTION_OBSTACK, in each case forming the body | | of a C function (YYGUARD or YYACTION) which contains a switch | | statement to decide which guard or action to execute. | -- 2.45.2