X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/8dd162d3ff10fd7fb6f748a885f8055232691c48..927b425baae16fc1d50e092b78b944e281b521f6:/src/conflicts.c diff --git a/src/conflicts.c b/src/conflicts.c index 73ad45e9..e2e9855f 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -1,6 +1,6 @@ /* Find and resolve or report look-ahead conflicts for bison, - Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004 + Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -17,9 +17,10 @@ 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, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ +#include #include "system.h" #include @@ -38,7 +39,7 @@ /* -1 stands for not specified. */ int expected_sr_conflicts = -1; int expected_rr_conflicts = -1; -static char *conflicts = NULL; +static char *conflicts; struct obstack solved_conflicts_obstack; static bitset shift_set; @@ -215,6 +216,9 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors) switch (symbols[i]->assoc) { + default: + abort (); + case right_assoc: log_resolution (redrule, i, right_resolution); flush_reduce (look_ahead_tokens, i); @@ -232,9 +236,6 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors) /* Record an explicit error for this token. */ errors[nerrs++] = symbols[i]; break; - - case undef_assoc: - abort (); } } @@ -305,9 +306,9 @@ conflicts_solve (void) { state_number i; /* List of look-ahead tokens on which we explicitly raise a syntax error. */ - symbol **errors = MALLOC (errors, ntokens + 1); + symbol **errors = xnmalloc (ntokens + 1, sizeof *errors); - CALLOC (conflicts, nstates); + conflicts = xcalloc (nstates, sizeof *conflicts); shift_set = bitset_create (ntokens, BITSET_FIXED); look_ahead_set = bitset_create (ntokens, BITSET_FIXED); obstack_init (&solved_conflicts_obstack); @@ -464,11 +465,13 @@ conflicts_print (void) /* Is the number of SR conflicts OK? Either EXPECTED_CONFLICTS is not set, and then we want 0 SR, or else it is specified, in which case we want equality. */ - bool src_ok = false; - bool rrc_ok = false; + bool src_ok; + bool rrc_ok; int src_total = 0; int rrc_total = 0; + int src_expected; + int rrc_expected; /* Conflicts by state. */ { @@ -488,33 +491,36 @@ conflicts_print (void) expected_rr_conflicts = -1; } - src_ok = - src_total == (expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts); - rrc_ok = - rrc_total == (expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts); + src_expected = expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts; + rrc_expected = expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts; + src_ok = src_total == src_expected; + rrc_ok = rrc_total == rrc_expected; /* If there are as many RR conflicts and SR conflicts as expected, then there is nothing to report. */ - if (rrc_ok && src_ok) + if (rrc_ok & src_ok) return; /* Report the total number of conflicts on STDERR. */ - if (! yacc_flag) - fprintf (stderr, "%s: ", current_file); - conflict_report (stderr, src_total, rrc_total); + if (src_total | rrc_total) + { + if (! yacc_flag) + fprintf (stderr, "%s: ", current_file); + conflict_report (stderr, src_total, rrc_total); + } if (expected_sr_conflicts != -1 || expected_rr_conflicts != -1) { - int sr = expected_sr_conflicts == -1 ? 0 : expected_sr_conflicts; - int rr = expected_rr_conflicts == -1 ? 0 : expected_rr_conflicts; if (! src_ok) - warn (ngettext ("expected %d shift/reduce conflict", - "expected %d shift/reduce conflicts", - sr), sr); + complain (ngettext ("expected %d shift/reduce conflict", + "expected %d shift/reduce conflicts", + src_expected), + src_expected); if (! rrc_ok) - warn (ngettext ("expected %d reduce/reduce conflict", - "expected %d reduce/reduce conflicts", - rr), rr); + complain (ngettext ("expected %d reduce/reduce conflict", + "expected %d reduce/reduce conflicts", + rrc_expected), + rrc_expected); } } @@ -522,7 +528,7 @@ conflicts_print (void) void conflicts_free (void) { - XFREE (conflicts); + free (conflicts); bitset_free (shift_set); bitset_free (look_ahead_set); obstack_free (&solved_conflicts_obstack, NULL);