X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/08089d5d35ece0c7d41659cc1bc09638e2abb151..8dc26b76aef4027ea594146529bdf06c204a0867:/src/conflicts.c diff --git a/src/conflicts.c b/src/conflicts.c index 4ed9dea7..92f54876 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -1,5 +1,5 @@ /* Find and resolve or report look-ahead conflicts for bison, - Copyright (C) 1984, 1989 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1992 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -15,32 +15,18 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Bison; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ -#ifdef _AIX - #pragma alloca -#endif #include #include "system.h" #include "machine.h" -#include "new.h" +#include "alloc.h" #include "files.h" #include "gram.h" #include "state.h" -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -#ifdef HAVE_ALLOCA_H -#include -#else -#ifndef _AIX -extern char *alloca (); -#endif -#endif -#endif - extern char **tags; extern int tokensetsize; extern char *consistent; @@ -50,14 +36,20 @@ extern unsigned *LA; extern short *LAruleno; extern short *lookaheads; extern int verboseflag; - -void set_conflicts(); -void resolve_sr_conflict(); -void flush_shift(); -void log_resolution(); -void total_conflicts(); -void count_sr_conflicts(); -void count_rr_conflicts(); +extern int fixed_outfiles; + +void initialize_conflicts PARAMS((void)); +void set_conflicts PARAMS((int)); +void resolve_sr_conflict PARAMS((int, int)); +void flush_shift PARAMS((int, int)); +void log_resolution PARAMS((int, int, int, char *)); +void conflict_log PARAMS((void)); +void verbose_conflict_log PARAMS((void)); +void total_conflicts PARAMS((void)); +void count_sr_conflicts PARAMS((int)); +void count_rr_conflicts PARAMS((int)); +void print_reductions PARAMS((int)); +void finalize_conflicts PARAMS((void)); char any_conflicts; char *conflicts; @@ -74,7 +66,7 @@ static int rrc_count; void -initialize_conflicts() +initialize_conflicts (void) { register int i; /* register errs *sp; JF unused */ @@ -93,8 +85,7 @@ initialize_conflicts() void -set_conflicts(state) -int state; +set_conflicts (int state) { register int i; register int k; @@ -180,17 +171,14 @@ A conflict is resolved by modifying the shift or reduce tables so that there is no longer a conflict. */ void -resolve_sr_conflict(state, lookaheadnum) -int state; -int lookaheadnum; +resolve_sr_conflict (int state, int lookaheadnum) { register int i; register int mask; register unsigned *fp1; register unsigned *fp2; register int redprec; - /* Extra parens avoid errors on Ultrix 4.3. */ - errs *errp = (errs *) alloca ((sizeof(errs) + ntokens * sizeof(short))); + errs *errp = (errs *) xmalloc (sizeof(errs) + ntokens * sizeof(short)); short *errtokens = errp->errs; /* find the rule to reduce by to get precedence of reduction */ @@ -208,13 +196,13 @@ int lookaheadnum; { if (sprec[i] < redprec) { - if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce"); + if (verboseflag) log_resolution(state, lookaheadnum, i, _("reduce")); *fp2 &= ~mask; /* flush the shift for this token */ flush_shift(state, i); } else if (sprec[i] > redprec) { - if (verboseflag) log_resolution(state, lookaheadnum, i, "shift"); + if (verboseflag) log_resolution(state, lookaheadnum, i, _("shift")); *fp1 &= ~mask; /* flush the reduce for this token */ } else @@ -228,15 +216,15 @@ int lookaheadnum; { case RIGHT_ASSOC: - if (verboseflag) log_resolution(state, lookaheadnum, i, "shift"); + if (verboseflag) log_resolution(state, lookaheadnum, i, _("shift")); break; case LEFT_ASSOC: - if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce"); + if (verboseflag) log_resolution(state, lookaheadnum, i, _("reduce")); break; case NON_ASSOC: - if (verboseflag) log_resolution(state, lookaheadnum, i, "an error"); + if (verboseflag) log_resolution(state, lookaheadnum, i, _("an error")); break; } @@ -275,6 +263,7 @@ int lookaheadnum; } else err_table[state] = 0; + free(errp); } @@ -283,9 +272,7 @@ int lookaheadnum; Used when we resolve a shift-reduce conflict in favor of the reduction. */ void -flush_shift(state, token) -int state; -int token; +flush_shift (int state, int token) { register shifts *shiftp; register int k, i; @@ -306,18 +293,16 @@ int token; void -log_resolution(state, LAno, token, resolution) -int state, LAno, token; -char *resolution; +log_resolution (int state, int LAno, int token, char *resolution) { fprintf(foutput, - "Conflict in state %d between rule %d and token %s resolved as %s.\n", + _("Conflict in state %d between rule %d and token %s resolved as %s.\n"), state, LAruleno[LAno], tags[token], resolution); } void -conflict_log() +conflict_log (void) { register int i; @@ -340,7 +325,7 @@ conflict_log() void -verbose_conflict_log() +verbose_conflict_log (void) { register int i; @@ -356,20 +341,20 @@ verbose_conflict_log() src_total += src_count; rrc_total += rrc_count; - fprintf(foutput, "State %d contains", i); + fprintf(foutput, _("State %d contains"), i); if (src_count == 1) - fprintf(foutput, " 1 shift/reduce conflict"); + fprintf(foutput, _(" 1 shift/reduce conflict")); else if (src_count > 1) - fprintf(foutput, " %d shift/reduce conflicts", src_count); + fprintf(foutput, _(" %d shift/reduce conflicts"), src_count); if (src_count > 0 && rrc_count > 0) - fprintf(foutput, " and"); + fprintf(foutput, _(" and")); if (rrc_count == 1) - fprintf(foutput, " 1 reduce/reduce conflict"); + fprintf(foutput, _(" 1 reduce/reduce conflict")); else if (rrc_count > 1) - fprintf(foutput, " %d reduce/reduce conflicts", rrc_count); + fprintf(foutput, _(" %d reduce/reduce conflicts"), rrc_count); putc('.', foutput); putc('\n', foutput); @@ -381,10 +366,8 @@ verbose_conflict_log() void -total_conflicts() +total_conflicts (void) { - extern int fixed_outfiles; - if (src_total == expected_conflicts && rrc_total == 0) return; @@ -392,31 +375,31 @@ total_conflicts() { /* If invoked under the name `yacc', use the output format specified by POSIX. */ - fprintf(stderr, "conflicts: "); + fprintf(stderr, _("conflicts: ")); if (src_total > 0) - fprintf(stderr, " %d shift/reduce", src_total); + fprintf(stderr, _(" %d shift/reduce"), src_total); if (src_total > 0 && rrc_total > 0) fprintf(stderr, ","); if (rrc_total > 0) - fprintf(stderr, " %d reduce/reduce", rrc_total); + fprintf(stderr, _(" %d reduce/reduce"), rrc_total); putc('\n', stderr); } else { - fprintf(stderr, "%s contains", infile); + fprintf(stderr, _("%s contains"), infile); if (src_total == 1) - fprintf(stderr, " 1 shift/reduce conflict"); + fprintf(stderr, _(" 1 shift/reduce conflict")); else if (src_total > 1) - fprintf(stderr, " %d shift/reduce conflicts", src_total); + fprintf(stderr, _(" %d shift/reduce conflicts"), src_total); if (src_total > 0 && rrc_total > 0) - fprintf(stderr, " and"); + fprintf(stderr, _(" and")); if (rrc_total == 1) - fprintf(stderr, " 1 reduce/reduce conflict"); + fprintf(stderr, _(" 1 reduce/reduce conflict")); else if (rrc_total > 1) - fprintf(stderr, " %d reduce/reduce conflicts", rrc_total); + fprintf(stderr, _(" %d reduce/reduce conflicts"), rrc_total); putc('.', stderr); putc('\n', stderr); @@ -425,8 +408,7 @@ total_conflicts() void -count_sr_conflicts(state) -int state; +count_sr_conflicts (int state) { register int i; register int k; @@ -493,8 +475,7 @@ int state; void -count_rr_conflicts(state) -int state; +count_rr_conflicts (int state) { register int i; register int j; @@ -540,8 +521,7 @@ int state; void -print_reductions(state) -int state; +print_reductions (int state) { register int i; register int j; @@ -556,7 +536,7 @@ int state; register int m; register int n; register int default_LA; - register int default_rule; + register int default_rule = 0; register int cmax; register int count; register shifts *shiftp; @@ -615,7 +595,7 @@ int state; for (i = 0; i < ntokens; i++) { if (mask & *fp3) - fprintf(foutput, " %-4s\t[reduce using rule %d (%s)]\n", + fprintf(foutput, _(" %-4s\t[reduce using rule %d (%s)]\n"), tags[i], default_rule, tags[rlhs[default_rule]]); mask <<= 1; @@ -626,7 +606,7 @@ int state; } } - fprintf(foutput, " $default\treduce using rule %d (%s)\n\n", + fprintf(foutput, _(" $default\treduce using rule %d (%s)\n\n"), default_rule, tags[rlhs[default_rule]]); } else if (n - m >= 1) @@ -643,7 +623,7 @@ int state; fp3 = lookaheadset; while (fp3 < fp4) - *fp3++ = *fp1++ & ( ~ (*fp2++)); + *fp3++ = *fp1++ & (~(*fp2++)); count = 0; mask = 1; @@ -712,7 +692,7 @@ int state; if (j != default_LA) { rule = LAruleno[j]; - fprintf(foutput, " %-4s\treduce using rule %d (%s)\n", + fprintf(foutput, _(" %-4s\treduce using rule %d (%s)\n"), tags[i], rule, tags[rlhs[rule]]); } else defaulted = 1; @@ -724,12 +704,12 @@ int state; if (defaulted) { rule = LAruleno[default_LA]; - fprintf(foutput, " %-4s\treduce using rule %d (%s)\n", + fprintf(foutput, _(" %-4s\treduce using rule %d (%s)\n"), tags[i], rule, tags[rlhs[rule]]); defaulted = 0; } rule = LAruleno[j]; - fprintf(foutput, " %-4s\t[reduce using rule %d (%s)]\n", + fprintf(foutput, _(" %-4s\t[reduce using rule %d (%s)]\n"), tags[i], rule, tags[rlhs[rule]]); } } @@ -741,16 +721,16 @@ int state; if (mask == 0) { mask = 1; - /* This used to be fp1, but I think fp2 is right - because fp2 is where the words are fetched to test with mask - in this loop. */ + /* We tried incrementing just fp1, and just fp2; both seem wrong. + It seems necessary to increment both in sync. */ + fp1++; fp2++; } } if (default_LA >= 0) { - fprintf(foutput, " $default\treduce using rule %d (%s)\n", + fprintf(foutput, _(" $default\treduce using rule %d (%s)\n"), default_rule, tags[rlhs[default_rule]]); } @@ -760,7 +740,7 @@ int state; void -finalize_conflicts() +finalize_conflicts (void) { FREE(conflicts); FREE(shiftset);