]> git.saurik.com Git - bison.git/commitdiff
* src/state.h (state_t): Replace the `lookaheadsp' member, a
authorAkim Demaille <akim@epita.fr>
Sat, 15 Jun 2002 18:23:50 +0000 (18:23 +0000)
committerAkim Demaille <akim@epita.fr>
Sat, 15 Jun 2002 18:23:50 +0000 (18:23 +0000)
short, with `lookaheads' (bitsetv), `lookaheads_rule' (rule_t**).
Adjust all dependencies.
* src/lalr.c (initialize_lookaheads): Split into...
(states_lookaheads_count, states_lookaheads_initialize): these.
(lalr): Adjust.

ChangeLog
src/conflicts.c
src/lalr.c
src/output.c
src/print.c
src/print_graph.c
src/state.h

index ab0b47da8f4106788ec48b1086f0611f4e6444d6..ec64bd63727d8e48c6cea584b752b5aeff075f9f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2002-06-15  Akim Demaille  <akim@epita.fr>
+
+       * src/state.h (state_t): Replace the `lookaheadsp' member, a
+       short, with `lookaheads' (bitsetv), `lookaheads_rule' (rule_t**).
+       Adjust all dependencies.
+       * src/lalr.c (initialize_lookaheads): Split into...
+       (states_lookaheads_count, states_lookaheads_initialize): these.
+       (lalr): Adjust.
+
+       
 2002-06-15  Akim Demaille  <akim@epita.fr>
 
        * src/gram.h, src/gram.c (grammar_rules_partial_print): New, eved
index a7f4646ecd9fefbad3bd436968ad3e4f6be22c67..2cf6ce28b5d2df9191e7db80b406f8ea6a458822 100644 (file)
@@ -256,11 +256,11 @@ set_conflicts (state_t *state)
      check for shift-reduce conflict, and try to resolve using
      precedence */
   for (i = 0; i < state->nlookaheads; ++i)
-    if (LArule[state->lookaheadsp + i]->prec
-       && LArule[state->lookaheadsp + i]->prec->prec
-       && !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
+    if (state->lookaheads_rule[i]->prec
+       && state->lookaheads_rule[i]->prec->prec
+       && !bitset_disjoint_p (state->lookaheads[i], lookaheadset))
       {
-       resolve_sr_conflict (state, state->lookaheadsp + i);
+       resolve_sr_conflict (state, (state->lookaheads - LA) + i);
        break;
       }
 
@@ -268,10 +268,10 @@ set_conflicts (state_t *state)
      for conflicts not resolved above.  */
   for (i = 0; i < state->nlookaheads; ++i)
     {
-      if (!bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
+      if (!bitset_disjoint_p (state->lookaheads[i], lookaheadset))
        conflicts[state->number] = 1;
 
-      bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
+      bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]);
     }
 }
 
@@ -312,7 +312,7 @@ count_sr_conflicts (state_t *state)
       bitset_set (shiftset, SHIFT_SYMBOL (shiftp, i));
 
   for (i = 0; i < state->nlookaheads; ++i)
-    bitset_or (lookaheadset, lookaheadset, LA[state->lookaheadsp + i]);
+    bitset_or (lookaheadset, lookaheadset, state->lookaheads[i]);
 
   bitset_and (lookaheadset, lookaheadset, shiftset);
 
@@ -340,7 +340,7 @@ count_rr_conflicts (state_t *state)
       int count = 0;
       int j;
       for (j = 0; j < state->nlookaheads; ++j)
-       if (bitset_test (LA[state->lookaheadsp + j], i))
+       if (bitset_test (state->lookaheads[j], i))
          count++;
 
       if (count >= 2)
index dfc06bc9105343a7017facb8437fcb59003b7b23..6d7b34ffe9bf529550e7528be4c2840ad10ff3ef 100644 (file)
@@ -298,15 +298,15 @@ add_lookback_edge (state_t *state, int ruleno, int gotono)
   shorts *sp;
 
   for (i = 0; i < state->nlookaheads; ++i)
-    if (LArule[state->lookaheadsp + i]->number == ruleno)
+    if (state->lookaheads_rule[i]->number == ruleno)
       break;
 
-  assert (LArule[state->lookaheadsp + i]->number == ruleno);
+  assert (state->lookaheads_rule[i]->number == ruleno);
 
   sp = XCALLOC (shorts, 1);
-  sp->next = lookback[state->lookaheadsp + i];
+  sp->next = lookback[(state->lookaheads - LA) + i];
   sp->value = gotono;
-  lookback[state->lookaheadsp + i] = sp;
+  lookback[(state->lookaheads - LA) + i] = sp;
 }
 
 
@@ -506,15 +506,18 @@ compute_lookaheads (void)
 }
 
 
-/*--------------------------------------.
-| Initializing the lookaheads members.  |
-`--------------------------------------*/
+/*-------------------------------------------------------------.
+| Count the number of lookaheads required for each state       |
+| (NLOOKAHEADS member).  Compute the total number of LA, NLA.  |
+`-------------------------------------------------------------*/
 
 static void
-initialize_lookaheads (void)
+states_lookaheads_count (void)
 {
   size_t i;
   nLA = 0;
+
+  /* Count   */
   for (i = 0; i < nstates; i++)
     {
       int k;
@@ -540,12 +543,34 @@ initialize_lookaheads (void)
          }
 
       states[i]->nlookaheads = nlookaheads;
-      states[i]->lookaheadsp = nLA;
       nLA += nlookaheads;
     }
 }
 
 
+/*--------------------------------------.
+| Initializing the lookaheads members.  |
+`--------------------------------------*/
+
+static void
+states_lookaheads_initialize (void)
+{
+  size_t i;
+  bitsetv pLA = LA;
+  rule_t **pLArule = LArule;
+
+  /* Count the number of lookaheads required for each state
+     (NLOOKAHEADS member).  */
+  for (i = 0; i < nstates; i++)
+    {
+      states[i]->lookaheads = pLA;
+      states[i]->lookaheads_rule = pLArule;
+      pLA += states[i]->nlookaheads;
+      pLArule += states[i]->nlookaheads;
+    }
+}
+
+
 /*---------------------------------------.
 | Output the lookaheads for each state.  |
 `---------------------------------------*/
@@ -563,10 +588,10 @@ lookaheads_print (FILE *out)
 
       for (j = 0; j < states[i]->nlookaheads; ++j)
        for (k = 0; k < ntokens; ++k)
-         if (bitset_test (LA[states[i]->lookaheadsp + j], k))
+         if (bitset_test (states[i]->lookaheads[j], k))
            fprintf (out, "   on %d (%s) -> rule %d\n",
                     k, symbol_tag_get (symbols[k]),
-                    LArule[states[i]->lookaheadsp + j]->number - 1);
+                    states[i]->lookaheads_rule[j]->number - 1);
     }
   fprintf (out, "Lookaheads: END\n");
 }
@@ -574,8 +599,9 @@ lookaheads_print (FILE *out)
 void
 lalr (void)
 {
-  initialize_lookaheads ();
+  states_lookaheads_count ();
   initialize_LA ();
+  states_lookaheads_initialize ();
   set_goto_map ();
   initialize_F ();
   build_relations ();
index 7ee3214cab0b577e284062e0db82b7ae466529f1..350d7ed85535edc8fe4d1270c5d1e1765970dd9a 100644 (file)
@@ -380,8 +380,8 @@ 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 (bitset_test (LA[state->lookaheadsp + i], j))
-           actrow[j] = -LArule[state->lookaheadsp + i]->number;
+         if (bitset_test (state->lookaheads[i], j))
+           actrow[j] = -state->lookaheads_rule[i]->number;
     }
 
   /* Now see which tokens are allowed for shifts in this state.  For
@@ -428,7 +428,7 @@ action_row (state_t *state)
          for (i = 0; i < state->nlookaheads; i++)
            {
              int count = 0;
-             int rule = -LArule[state->lookaheadsp + i]->number;
+             int rule = -state->lookaheads_rule[i]->number;
              int j;
 
              for (j = 0; j < ntokens; j++)
index 280ac8d8417acbe5c4ffe8def58090df8968d31c..027f3fe3e027139adc988335598e92f652991a96 100644 (file)
@@ -99,16 +99,16 @@ print_core (FILE *out, state_t *state)
              /* Look for lookaheads corresponding to this rule. */
              for (j = 0; j < state->nlookaheads; ++j)
                for (k = 0; k < ntokens; ++k)
-                 if (bitset_test (LA[state->lookaheadsp + j], k)
-                     && LArule[state->lookaheadsp + j]->number == rule)
+                 if (bitset_test (state->lookaheads[j], k)
+                     && state->lookaheads_rule[j]->number == rule)
                    nlookaheads++;
              if (nlookaheads)
                {
                  fprintf (out, "  [");
                  for (j = 0; j < state->nlookaheads; ++j)
                    for (k = 0; k < ntokens; ++k)
-                     if (bitset_test (LA[state->lookaheadsp + j], k)
-                         && LArule[state->lookaheadsp + j]->number == rule)
+                     if (bitset_test (state->lookaheads[j], k)
+                         && state->lookaheads_rule[j]->number == rule)
                        fprintf (out, "%s%s",
                                 symbol_tag_get (symbols[k]),
                                 --nlookaheads ? ", " : "");
@@ -225,9 +225,9 @@ print_reductions (FILE *out, state_t *state)
 
   if (state->nlookaheads == 1 && !nodefault)
     {
-      rule_t *default_rule = LArule[state->lookaheadsp];
+      rule_t *default_rule = state->lookaheads_rule[0];
 
-      bitset_and (lookaheadset, LA[state->lookaheadsp], shiftset);
+      bitset_and (lookaheadset, state->lookaheads[0], shiftset);
 
       for (i = 0; i < ntokens; i++)
        if (bitset_test (lookaheadset, i))
@@ -252,7 +252,7 @@ print_reductions (FILE *out, state_t *state)
            int count = 0;
            int j;
 
-           bitset_andn (lookaheadset, LA[state->lookaheadsp + i], shiftset);
+           bitset_andn (lookaheadset, state->lookaheads[i], shiftset);
 
            for (j = 0; j < ntokens; j++)
              if (bitset_test (lookaheadset, j))
@@ -261,8 +261,8 @@ print_reductions (FILE *out, state_t *state)
            if (count > cmax)
              {
                cmax = count;
-               default_LA = state->lookaheadsp + i;
-               default_rule = LArule[state->lookaheadsp + i];
+               default_LA = i;
+               default_rule = state->lookaheads_rule[i];
              }
 
            bitset_or (shiftset, shiftset, lookaheadset);
@@ -281,16 +281,16 @@ print_reductions (FILE *out, state_t *state)
          int count = bitset_test (shiftset, i);
 
          for (j = 0; j < state->nlookaheads; ++j)
-           if (bitset_test (LA[state->lookaheadsp + j], i))
+           if (bitset_test (state->lookaheads[j], i))
              {
                if (count == 0)
                  {
-                   if (state->lookaheadsp + j != default_LA)
+                   if (j != default_LA)
                      fprintf (out,
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               symbol_tag_get (symbols[i]),
-                              LArule[state->lookaheadsp + j]->number - 1,
-                              symbol_tag_get_n (LArule[state->lookaheadsp + j]->lhs, 1));
+                              state->lookaheads_rule[j]->number - 1,
+                              symbol_tag_get_n (state->lookaheads_rule[j]->lhs, 1));
                    else
                      defaulted = 1;
 
@@ -302,14 +302,14 @@ print_reductions (FILE *out, state_t *state)
                      fprintf (out,
                               _("    %-4s\treduce using rule %d (%s)\n"),
                               symbol_tag_get (symbols[i]),
-                              LArule[default_LA]->number - 1,
-                              symbol_tag_get_n (LArule[default_LA]->lhs, 1));
+                              state->lookaheads_rule[default_LA]->number - 1,
+                              symbol_tag_get_n (state->lookaheads_rule[default_LA]->lhs, 1));
                    defaulted = 0;
                    fprintf (out,
                             _("    %-4s\t[reduce using rule %d (%s)]\n"),
                             symbol_tag_get (symbols[i]),
-                            LArule[state->lookaheadsp + j]->number - 1,
-                            symbol_tag_get_n (LArule[state->lookaheadsp + j]->lhs, 1));
+                            state->lookaheads_rule[j]->number - 1,
+                            symbol_tag_get_n (state->lookaheads_rule[j]->lhs, 1));
                  }
              }
        }
index 49acaa7ea460eca75f82c3206c4193c86d9c2d08..e0aa0c31acb7660b7813c3bfb9e95af37355dc30 100644 (file)
@@ -93,16 +93,16 @@ print_core (struct obstack *oout, state_t *state)
          /* Look for lookaheads corresponding to this rule. */
          for (j = 0; j < state->nlookaheads; ++j)
            for (k = 0; k < ntokens; ++k)
-             if (bitset_test (LA[state->lookaheadsp + j], k)
-                 && LArule[state->lookaheadsp + j]->number == rule)
+             if (bitset_test (state->lookaheads[j], k)
+                 && state->lookaheads_rule[j]->number == rule)
                nlookaheads++;
          if (nlookaheads)
            {
              obstack_sgrow (oout, "  [");
              for (j = 0; j < state->nlookaheads; ++j)
                for (k = 0; k < ntokens; ++k)
-                 if (bitset_test (LA[state->lookaheadsp + j], k)
-                     && LArule[state->lookaheadsp + j]->number == rule)
+                 if (bitset_test (state->lookaheads[j], k)
+                     && state->lookaheads_rule[j]->number == rule)
                    obstack_fgrow2 (oout, "%s%s",
                                    symbol_tag_get (symbols[k]),
                                    --nlookaheads ? ", " : "");
index 95b716d89c3e10f2be650d6db6e9f5568cd373dc..7f578bdc004fe7f2988d886f1c646daea16b1283 100644 (file)
@@ -88,6 +88,7 @@
 #ifndef STATE_H_
 # define STATE_H_
 
+# include "bitsetv.h"
 
 /*---------.
 | Shifts.  |
@@ -180,9 +181,9 @@ typedef struct state_s
   char consistent;
 
   /* Used in LALR, not LR(0). */
-  /* Pseudo pointer into LA. */
-  short lookaheadsp;
   int nlookaheads;
+  bitsetv lookaheads;
+  rule_t **lookaheads_rule;
 
   /* If some conflicts were solved thanks to precedence/associativity,
      a human readable description of the resolution.  */