X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/70e7d534a9d05b85073fc88e97846c142b89dd32..bba97eb2c13a632c9a23306a834de312df16e4e0:/src/output.c diff --git a/src/output.c b/src/output.c index 998b707e..acb453c6 100644 --- a/src/output.c +++ b/src/output.c @@ -89,6 +89,7 @@ negative short int. Used to flag ?? */ #include "system.h" +#include "bitsetv.h" #include "quotearg.h" #include "error.h" #include "getargs.h" @@ -191,8 +192,8 @@ output_gram (void) { int i; short *values = XCALLOC (short, nrules + 1); - for (i = 0; i < nrules + 1; ++i) - values[i] = rules[i].rhs; + for (i = 1; i < nrules + 1; ++i) + values[i] = rules[i].rhs - ritem; output_table_data (&format_obstack, values, 0, 1, nrules + 1); XFREE (values); @@ -226,7 +227,7 @@ output_gram (void) static void output_stos (void) { - int i; + size_t i; short *values = (short *) alloca (sizeof (short) * nstates); for (i = 0; i < nstates; ++i) values[i] = states[i]->accessing_symbol; @@ -245,7 +246,7 @@ output_rule_data (void) { short *values = XCALLOC (short, nrules + 1); - for (i = 0; i < nrules + 1; ++i) + for (i = 1; i < nrules + 1; ++i) values[i] = rules[i].line; output_table_data (&format_obstack, values, 0, 1, nrules + 1); @@ -298,8 +299,8 @@ output_rule_data (void) /* Output YYR1. */ { short *values = XCALLOC (short, nrules + 1); - for (i = 0; i < nrules + 1; ++i) - values[i] = rules[i].lhs; + for (i = 1; i < nrules + 1; ++i) + values[i] = rules[i].lhs->number; output_table_data (&format_obstack, values, 0, 1, nrules + 1); muscle_insert ("r1", obstack_finish (&format_obstack)); @@ -310,7 +311,7 @@ output_rule_data (void) short_tab = XMALLOC (short, nrules + 1); for (i = 1; i < nrules; i++) short_tab[i] = rules[i + 1].rhs - rules[i].rhs - 1; - short_tab[nrules] = nritems - rules[nrules].rhs - 1; + short_tab[nrules] = nritems - (rules[nrules].rhs - ritem) - 1; output_table_data (&format_obstack, short_tab, 0, 1, nrules + 1); muscle_insert ("r2", obstack_finish (&format_obstack)); @@ -356,7 +357,7 @@ action_row (state_t *state) for (j = 0; j < ntokens; j++) /* and record this rule as the rule to use if that token follows. */ - if (BITISSET (LA (state->lookaheadsp + i), j)) + if (bitset_test (LA[state->lookaheadsp + i], j)) actrow[j] = -LAruleno[state->lookaheadsp + i]; } @@ -488,7 +489,7 @@ save_row (int state) static void token_actions (void) { - int i; + size_t i; short *yydefact = XCALLOC (short, nstates); actrow = XCALLOC (short, ntokens); @@ -567,6 +568,7 @@ void token_definitions_output (FILE *out) { int i; + int first = 1; for (i = 0; i < ntokens; ++i) { bucket *symbol = symbols[i]; @@ -575,7 +577,7 @@ token_definitions_output (FILE *out) if (number == SALIAS) continue; /* Skip error token. */ - if (symbol->value == error_token_number) + if (symbol->number == error_token_number) continue; if (symbol->tag[0] == '\'') continue; /* skip literal character */ @@ -593,12 +595,13 @@ token_definitions_output (FILE *out) if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$')) continue; - fprintf (out, "# define %s\t%d\n", - symbol->tag, number); + fprintf (out, "%s [[[%s]], [%d]]", + first ? "" : ",\n", symbol->tag, number); if (semantic_parser) /* FIXME: This is probably wrong, and should be just as above. --akim. */ - fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value); + fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->number); + first = 0; } } @@ -641,9 +644,9 @@ save_column (int symbol, int default_state) static int default_goto (int symbol) { - int i; - int m = goto_map[symbol]; - int n = goto_map[symbol + 1]; + size_t i; + size_t m = goto_map[symbol]; + size_t n = goto_map[symbol + 1]; int default_state = -1; int max = 0; @@ -741,7 +744,7 @@ matching_state (int vector) int w; int prev; - if (i >= nstates) + if (i >= (int) nstates) return -1; t = tally[i]; @@ -913,7 +916,7 @@ output_check (void) static void output_actions (void) { - int i; + size_t i; nvectors = nstates + nvars; froms = XCALLOC (short *, nvectors); @@ -922,7 +925,7 @@ output_actions (void) width = XCALLOC (short, nvectors); token_actions (); - XFREE (LA); + bitsetv_free (LA); XFREE (LAruleno); goto_actions (); @@ -957,10 +960,9 @@ static void output_skeleton (void) { /* Store the definition of all the muscles. */ - char *tempdir = getenv ("TMPDIR"); + const char *tempdir = getenv ("TMPDIR"); char *tempfile = NULL; FILE *out = NULL; - ssize_t bytes_read; int fd; if (tempdir == NULL) @@ -988,9 +990,9 @@ output_skeleton (void) guards_output (out); fputs ("]])\n\n", out); - fputs ("m4_define([b4_tokendef], \n[[", out); + fputs ("m4_define([b4_tokens], \n[", out); token_definitions_output (out); - fputs ("]])\n\n", out); + fputs ("])\n\n", out); muscles_m4_output (out); @@ -1084,7 +1086,6 @@ output (void) output_token_translations (); output_gram (); - XFREE (ritem); if (semantic_parser) output_stos (); output_rule_data (); @@ -1095,7 +1096,6 @@ output (void) /* Process the selected skeleton file. */ output_skeleton (); - free (rules + 1); obstack_free (&muscle_obstack, NULL); obstack_free (&format_obstack, NULL); obstack_free (&action_obstack, NULL);