X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/f2acea59d91fe5384859772a0a74f09e7f53a296..f282676b7e6c9ae1b66233dbfc522bb685c3ece2:/src/output.c diff --git a/src/output.c b/src/output.c index 56538f0c..a426ad8f 100644 --- a/src/output.c +++ b/src/output.c @@ -92,33 +92,19 @@ #include "system.h" #include "getargs.h" -#include "alloc.h" +#include "xalloc.h" #include "files.h" #include "gram.h" -#include "state.h" +#include "LR0.h" #include "complain.h" #include "output.h" +#include "lalr.h" +#include "reader.h" +#include "conflicts.h" extern void berror PARAMS((const char *)); -extern char **tags; -extern short *user_toknums; -extern int tokensetsize; -extern int final_state; -extern core **state_table; -extern shifts **shift_table; -extern errs **err_table; -extern reductions **reduction_table; -extern short *accessing_symbol; -extern unsigned *LA; -extern short *LAruleno; -extern short *lookaheads; -extern char *consistent; -extern short *goto_map; -extern short *from_state; -extern short *to_state; - -extern void reader_output_yylsp PARAMS ((FILE *)); + static int nvectors; static int nentries; @@ -217,7 +203,7 @@ output_headers (void) if (semantic_parser) fprintf (fguard, GUARDSTR, attrsfile); - if (noparserflag) + if (no_parser_flag) return; fprintf (faction, (semantic_parser ? ACTSTR : ACTSTR_SIMPLE), attrsfile); @@ -252,7 +238,7 @@ output_trailers (void) fprintf (faction, "\n"); - if (noparserflag) + if (no_parser_flag) return; if (semantic_parser) @@ -314,8 +300,8 @@ output_gram (void) /* With the ordinary parser, yyprhs and yyrhs are needed only for yydebug. */ - /* With the noparser option, all tables are generated */ - if (!semantic_parser && !noparserflag) + /* With the no_parser option, all tables are generated */ + if (!semantic_parser && !no_parser_flag) fprintf (ftable, "\n#if YYDEBUG != 0\n"); output_short_table (ftable, "yyprhs", rrhs, @@ -346,7 +332,7 @@ output_gram (void) fprintf (ftable, "\n};\n"); - if (!semantic_parser && !noparserflag) + if (!semantic_parser && !no_parser_flag) fprintf (ftable, "\n#endif\n"); } @@ -375,7 +361,7 @@ output_rule_data (void) fputs ("#endif\n\n", ftable); - if (toknumflag || noparserflag) + if (token_table_flag || no_parser_flag) { fprintf (ftable, "#define YYNTOKENS %d\n", ntokens); fprintf (ftable, "#define YYNNTS %d\n", nvars); @@ -384,7 +370,7 @@ output_rule_data (void) fprintf (ftable, "#define YYMAXUTOK %d\n\n", max_user_token_number); } - if (!toknumflag && !noparserflag) + if (!token_table_flag && !no_parser_flag) fprintf (ftable, "\n#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)\n\n"); /* Output the table of symbol names. */ @@ -450,11 +436,11 @@ output_rule_data (void) /* add a NULL entry to list of tokens */ fprintf (ftable, ", NULL\n};\n"); - if (!toknumflag && !noparserflag) + if (!token_table_flag && !no_parser_flag) fprintf (ftable, "#endif\n\n"); /* Output YYTOKNUM. */ - if (toknumflag) + if (token_table_flag) { output_short_table (ftable, "yytoknum", user_toknums, 0, 1, ntokens + 1); @@ -466,7 +452,7 @@ output_rule_data (void) output_short_table (ftable, "yyr1", rlhs, 0, 1, nrules + 1); - FREE (rlhs + 1); + XFREE (rlhs + 1); putc ('\n', ftable); @@ -497,7 +483,7 @@ static const short yyr2[] = { 0", ftable); putc ('\n', ftable); fprintf (ftable, "%6d\n};\n", nitems - rrhs[nrules] - 1); - FREE (rrhs + 1); + XFREE (rrhs + 1); } @@ -713,8 +699,8 @@ save_row (int state) if (count == 0) return; - froms[state] = sp1 = sp = NEW2 (count, short); - tos[state] = sp2 = NEW2 (count, short); + froms[state] = sp1 = sp = XCALLOC (short, count); + tos[state] = sp2 = XCALLOC (short, count); for (i = 0; i < ntokens; i++) { @@ -742,19 +728,19 @@ static void token_actions (void) { int i; - short *yydefact = NEW2 (nstates, short); + short *yydefact = XCALLOC (short, nstates); - actrow = NEW2 (ntokens, short); + actrow = XCALLOC (short, ntokens); for (i = 0; i < nstates; ++i) { yydefact[i] = action_row (i); save_row (i); } - FREE (actrow); + XFREE (actrow); output_short_table (ftable, "yydefact", yydefact, yydefact[0], 1, nstates); - FREE (yydefact); + XFREE (yydefact); } @@ -763,12 +749,12 @@ free_shifts (void) { shifts *sp, *sptmp; /* JF derefrenced freed ptr */ - FREE (shift_table); + XFREE (shift_table); for (sp = first_shift; sp; sp = sptmp) { sptmp = sp->next; - FREE (sp); + XFREE (sp); } } @@ -778,12 +764,12 @@ free_reductions (void) { reductions *rp, *rptmp; /* JF fixed freed ptr */ - FREE (reduction_table); + XFREE (reduction_table); for (rp = first_reduction; rp; rp = rptmp) { rptmp = rp->next; - FREE (rp); + XFREE (rp); } } @@ -816,8 +802,8 @@ save_column (int symbol, int default_state) symno = symbol - ntokens + nstates; - froms[symno] = sp1 = sp = NEW2 (count, short); - tos[symno] = sp2 = NEW2 (count, short); + froms[symno] = sp1 = sp = XCALLOC (short, count); + tos[symno] = sp2 = XCALLOC (short, count); for (i = m; i < n; i++) { @@ -883,7 +869,7 @@ goto_actions (void) { int i, j, k; - state_count = NEW2 (nstates, short); + state_count = XCALLOC (short, nstates); k = default_goto (ntokens); fprintf (ftable, "\nstatic const short yydefgoto[] = {%6d", k); @@ -910,7 +896,7 @@ goto_actions (void) } fprintf (ftable, "\n};\n"); - FREE (state_count); + XFREE (state_count); } @@ -926,7 +912,7 @@ sort_actions (void) int t; int w; - order = NEW2 (nvectors, short); + order = XCALLOC (short, nvectors); nentries = 0; for (i = 0; i < nvectors; i++) @@ -1007,8 +993,7 @@ pack_vector (int vector) i = order[vector]; t = tally[i]; - if (t == 0) - berror ("pack_vector"); + assert (t); from = froms[i]; to = tos[i]; @@ -1064,10 +1049,10 @@ pack_table (void) int place; int state; - base = NEW2 (nvectors, short); - pos = NEW2 (nentries, short); - table = NEW2 (MAXTABLE, short); - check = NEW2 (MAXTABLE, short); + base = XCALLOC (short, nvectors); + pos = XCALLOC (short, nentries); + table = XCALLOC (short, MAXTABLE); + check = XCALLOC (short, MAXTABLE); lowzero = 0; high = 0; @@ -1094,14 +1079,14 @@ pack_table (void) for (i = 0; i < nvectors; i++) { if (froms[i]) - FREE (froms[i]); + XFREE (froms[i]); if (tos[i]) - FREE (tos[i]); + XFREE (tos[i]); } - FREE (froms); - FREE (tos); - FREE (pos); + XFREE (froms); + XFREE (tos); + XFREE (pos); } /* the following functions output yytable, yycheck @@ -1118,7 +1103,7 @@ output_base (void) output_short_table (ftable, "yypgoto", base, base[nstates], nstates + 1, nvectors); - FREE (base); + XFREE (base); } @@ -1128,7 +1113,7 @@ output_table (void) fprintf (ftable, "\n\n#define\tYYLAST\t\t%d\n\n\n", high); output_short_table (ftable, "yytable", table, table[0], 1, high + 1); - FREE (table); + XFREE (table); } @@ -1137,7 +1122,7 @@ output_check (void) { output_short_table (ftable, "yycheck", check, check[0], 1, high + 1); - FREE (check); + XFREE (check); } /* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable @@ -1148,23 +1133,23 @@ output_actions (void) { nvectors = nstates + nvars; - froms = NEW2 (nvectors, short *); - tos = NEW2 (nvectors, short *); - tally = NEW2 (nvectors, short); - width = NEW2 (nvectors, short); + froms = XCALLOC (short *, nvectors); + tos = XCALLOC (short *, nvectors); + tally = XCALLOC (short, nvectors); + width = XCALLOC (short, nvectors); token_actions (); free_shifts (); free_reductions (); - FREE (lookaheads); - FREE (LA); - FREE (LAruleno); - FREE (accessing_symbol); + XFREE (lookaheads); + XFREE (LA); + XFREE (LAruleno); + XFREE (accessing_symbol); goto_actions (); - FREE (goto_map + ntokens); - FREE (from_state); - FREE (to_state); + XFREE (goto_map + ntokens); + XFREE (from_state); + XFREE (to_state); sort_actions (); pack_table (); @@ -1181,6 +1166,7 @@ static void output_parser (void) { int c; + static int number_of_dollar_signs = 0; #ifdef DONTDEF FILE *fpars; #else @@ -1190,8 +1176,9 @@ output_parser (void) if (pure_parser) fprintf (ftable, "#define YYPURE 1\n\n"); -#ifdef DONTDEF /* JF no longer needed 'cuz open_extra_files changes the - currently open parser from bison.simple to bison.hairy */ +#ifdef DONTDEF + /* JF no longer needed 'cuz open_extra_files changes the currently + open parser from bison.simple to bison.hairy */ if (semantic_parser) fpars = fparser; else @@ -1208,7 +1195,7 @@ output_parser (void) /* See if the line starts with `#line. If so, set write_line to 0. */ - if (nolinesflag) + if (no_lines_flag) if (c == '#') { c = getc (fpars); @@ -1242,11 +1229,15 @@ output_parser (void) { if (c == '$') { + number_of_dollar_signs++; + assert (number_of_dollar_signs == 1); /* `$' in the parser file indicates where to put the actions. Copy them in at this point. */ rewind (faction); for (c = getc (faction); c != EOF; c = getc (faction)) putc (c, ftable); + /* Skip the end of the line containing `$'. */ + write_line = 0; } else putc (c, ftable); @@ -1255,6 +1246,7 @@ output_parser (void) break; putc (c, ftable); } + assert (number_of_dollar_signs == 1); } static void @@ -1262,7 +1254,7 @@ output_program (void) { int c; - if (!nolinesflag) + if (!no_lines_flag) fprintf (ftable, "#line %d \"%s\"\n", lineno, infile); c = getc (finput); @@ -1279,12 +1271,12 @@ free_itemsets (void) { core *cp, *cptmp; - FREE (state_table); + XFREE (state_table); for (cp = first_state; cp; cp = cptmp) { cptmp = cp->next; - FREE (cp); + XFREE (cp); } } @@ -1306,10 +1298,10 @@ output (void) putc (c, ftable); } reader_output_yylsp (ftable); - if (debugflag) + if (debug_flag) fputs ("\ #ifndef YYDEBUG\n\ -#define YYDEBUG 1\n\ +# define YYDEBUG 1\n\ #endif\n\ \n", ftable); @@ -1317,7 +1309,7 @@ output (void) if (semantic_parser) fprintf (ftable, "#include \"%s\"\n", attrsfile); - if (!noparserflag) + if (!no_parser_flag) fprintf (ftable, "#include \n\n"); /* Make "const" do nothing if not in ANSI C. */ @@ -1336,12 +1328,12 @@ output (void) /* if (semantic_parser) */ /* This is now unconditional because debugging printouts can use it. */ output_gram (); - FREE (ritem); + XFREE (ritem); if (semantic_parser) output_stos (); output_rule_data (); output_actions (); - if (!noparserflag) + if (!no_parser_flag) output_parser (); output_program (); }