]> git.saurik.com Git - bison.git/blobdiff - src/conflicts.c
* src/LR0.c (save_reductions): Remove, replaced by...
[bison.git] / src / conflicts.c
index e09b6d8772b6796b459417d57452d55d77973f57..aef33e6d3b44f4cc944dde96d71b9f90aa038245 100644 (file)
@@ -139,7 +139,7 @@ log_resolution (rule_t *rule, int token,
 static void
 flush_shift (state_t *state, int token)
 {
-  shifts *shiftp = state->shifts;
+  shifts_t *shiftp = state->shifts;
   int i;
 
   bitset_reset (lookaheadset, token);
@@ -179,7 +179,7 @@ resolve_sr_conflict (state_t *state, int lookahead)
   rule_t *redrule = state->lookaheads_rule[lookahead];
   int redprec = redrule->prec->prec;
   bitset lookaheads = state->lookaheads[lookahead];
-  errs *errp = errs_new (ntokens + 1);
+  errs_t *errp = errs_new (ntokens + 1);
   errp->nerrs = 0;
 
   for (i = 0; i < ntokens; i++)
@@ -249,7 +249,7 @@ static void
 set_conflicts (state_t *state)
 {
   int i;
-  shifts *shiftp;
+  shifts_t *shiftp;
 
   if (state->consistent)
     return;
@@ -287,7 +287,7 @@ set_conflicts (state_t *state)
 void
 conflicts_solve (void)
 {
-  size_t i;
+  state_number_t i;
 
   conflicts = XCALLOC (char, nstates);
   shiftset = bitset_create (ntokens, BITSET_FIXED);
@@ -308,7 +308,7 @@ count_sr_conflicts (state_t *state)
 {
   int i;
   int src_count = 0;
-  shifts *shiftp = state->shifts;
+  shifts_t *shiftp = state->shifts;
 
   if (!shiftp)
     return 0;
@@ -331,12 +331,15 @@ count_sr_conflicts (state_t *state)
 }
 
 
-/*----------------------------------------------.
-| Count the number of reduce/reduce conflicts.  |
-`----------------------------------------------*/
+/*----------------------------------------------------------------.
+| Count the number of reduce/reduce conflicts.  If ONE_PER_TOKEN, |
+| count one conflict for each token that has any reduce/reduce    |
+| conflicts.  Otherwise, count one conflict for each pair of      |
+| conflicting reductions.                                         |
++`----------------------------------------------------------------*/
 
 static int
-count_rr_conflicts (state_t *state)
+count_rr_conflicts (state_t *state, int one_per_token)
 {
   int i;
   int rrc_count = 0;
@@ -353,7 +356,7 @@ count_rr_conflicts (state_t *state)
          count++;
 
       if (count >= 2)
-       rrc_count++;
+       rrc_count += one_per_token ? 1 : count-1;
     }
 
   return rrc_count;
@@ -406,19 +409,43 @@ void
 conflicts_output (FILE *out)
 {
   bool printed_sth = FALSE;
-  size_t i;
+  state_number_t i;
   for (i = 0; i < nstates; i++)
     if (conflicts[i])
       {
        fprintf (out, _("State %d contains "), i);
        fputs (conflict_report (count_sr_conflicts (states[i]),
-                               count_rr_conflicts (states[i])), out);
+                               count_rr_conflicts (states[i], TRUE)), out);
        printed_sth = TRUE;
       }
   if (printed_sth)
     fputs ("\n\n", out);
 }
 
+/*--------------------------------------------------------.
+| Total the number of S/R and R/R conflicts.  Unlike the  |
+| code in conflicts_output, however, count EACH pair of   |
+| reductions for the same state and lookahead as one      |
+| conflict.                                              |
+`--------------------------------------------------------*/
+
+int
+conflicts_total_count (void)
+{
+  state_number_t i;
+  int count;
+
+  /* Conflicts by state.  */
+  count = 0;
+  for (i = 0; i < nstates; i++)
+    if (conflicts[i])
+      {
+       count += count_sr_conflicts (states[i]);
+       count += count_rr_conflicts (states[i], FALSE);
+      }
+  return count;
+}
+
 
 /*------------------------------------------.
 | Reporting the total number of conflicts.  |
@@ -427,8 +454,6 @@ conflicts_output (FILE *out)
 void
 conflicts_print (void)
 {
-  size_t i;
-
   /* 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.  */
@@ -438,12 +463,16 @@ conflicts_print (void)
   int rrc_total = 0;
 
   /* Conflicts by state.  */
-  for (i = 0; i < nstates; i++)
-    if (conflicts[i])
-      {
-       src_total += count_sr_conflicts (states[i]);
-       rrc_total += count_rr_conflicts (states[i]);
-      }
+  {
+    state_number_t i;
+
+    for (i = 0; i < nstates; i++)
+      if (conflicts[i])
+       {
+         src_total += count_sr_conflicts (states[i]);
+         rrc_total += count_rr_conflicts (states[i], TRUE);
+       }
+  }
 
   src_ok = src_total == (expected_conflicts == -1 ? 0 : expected_conflicts);