bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

style: comment changes and refactoring in state.


From: Akim Demaille
Subject: style: comment changes and refactoring in state.
Date: Tue, 5 Feb 2019 18:57:13 +0100

commit 40b5f89ee0be1efe60c19014bec6bcd202f5df72
Author: Akim Demaille <address@hidden>
Date:   Thu Jan 31 06:31:14 2019 +0100

    style: comment changes and refactoring in state.c
    
    * src/state.h, src/state.c: Comment changes.
    (transitions_to): Take a state* as argument.
    * src/lalr.h, src/lalr.c: Comment changes.
    (initialize_F): Use clear variable names.

diff --git a/src/lalr.c b/src/lalr.c
index 4255650c..5e78b229 100644
--- a/src/lalr.c
+++ b/src/lalr.c
@@ -153,8 +153,8 @@ initialize_F (void)
 
   for (goto_number i = 0; i < ngotos; ++i)
     {
-      state_number stateno = to_state[i];
-      const transitions *sp = states[stateno]->transitions;
+      state_number dst = to_state[i];
+      const transitions *sp = states[dst]->transitions;
 
       int j;
       FOR_EACH_SHIFT (sp, j)
@@ -164,7 +164,7 @@ initialize_F (void)
         {
           symbol_number sym = TRANSITION_SYMBOL (sp, j);
           if (nullable[sym - ntokens])
-            edge[nedges++] = map_goto (stateno, sym);
+            edge[nedges++] = map_goto (dst, sym);
         }
 
       if (nedges == 0)
@@ -215,15 +215,15 @@ build_relations (void)
 
       for (rule **rulep = derives[symbol1 - ntokens]; *rulep; rulep++)
         {
-          int length = 1;
-          item_number const *rp;
           state *s = states[from_state[i]];
           states1[0] = s->number;
 
-          for (rp = (*rulep)->rhs; ! item_number_is_rule_number (*rp); rp++)
+          int length = 1;
+          item_number const *rp;
+          for (rp = (*rulep)->rhs; 0 <= *rp; rp++)
             {
-              s = transitions_to (s->transitions,
-                                  item_number_as_symbol_number (*rp));
+              symbol_number sym = item_number_as_symbol_number (*rp);
+              s = transitions_to (s, sym);
               states1[length++] = s->number;
             }
 
diff --git a/src/lalr.h b/src/lalr.h
index b06b3051..c8ca6277 100644
--- a/src/lalr.h
+++ b/src/lalr.h
@@ -83,8 +83,8 @@ typedef size_t goto_number;
 /** Index into #from_state and #to_state.
 
    All the transitions that accept a particular variable are grouped
-   together and GOTO_MAP[I - NTOKENS] is the index in FROM_STATE and
-   TO_STATE of the first of them.  */
+   together in FROM_STATE and TO_STATE, with indexes from GOTO_MAP[I -
+   NTOKENS] to GOTO_MAP[I - NTOKENS + 1] - 1 (including both).  */
 extern goto_number *goto_map;
 
 /** The size of #from_state and #to_state.  */
@@ -96,8 +96,8 @@ extern state_number *from_state;
 /** State number it leads to.  */
 extern state_number *to_state;
 
-/** Map a state/symbol pair into its numeric representation.  */
-goto_number map_goto (state_number s0, symbol_number sym);
+/** Find the goto number of the goto from S on non-terminal SYM.  */
+goto_number map_goto (state_number s, symbol_number sym);
 
 /* goto_follows[i] is the set of tokens following goto i.  */
 extern bitsetv goto_follows;
diff --git a/src/state.c b/src/state.c
index b673ec4f..781e49c3 100644
--- a/src/state.c
+++ b/src/state.c
@@ -51,20 +51,14 @@ transitions_new (int num, state **dst)
 }
 
 
-/*-------------------------------------------------------.
-| Return the state such that SHIFTS contain a shift/goto |
-| to it on SYM.  Abort if none found.                    |
-`-------------------------------------------------------*/
-
 state *
-transitions_to (transitions *shifts, symbol_number sym)
+transitions_to (state *s, symbol_number sym)
 {
-  for (int j = 0; ; j++)
-    {
-      aver (j < shifts->num);
-      if (TRANSITION_SYMBOL (shifts, j) == sym)
-        return shifts->states[j];
-    }
+  transitions *trans = s->transitions;
+  for (int i = 0; i < trans->num; ++i)
+    if (TRANSITION_SYMBOL (trans, i) == sym)
+      return trans->states[i];
+  abort ();
 }
 
 
diff --git a/src/state.h b/src/state.h
index 975b69d5..16066049 100644
--- a/src/state.h
+++ b/src/state.h
@@ -159,9 +159,9 @@ typedef struct
     if (!TRANSITION_IS_DISABLED (Transitions, Iter))
 
 
-/* Return the state such SHIFTS contain a shift/goto to it on SYM.
-   Abort if none found.  */
-struct state *transitions_to (transitions *shifts, symbol_number sym);
+/* The destination of the transition (shift/goto) from state S on
+   label SYM (term or nterm).  Abort if none found.  */
+struct state *transitions_to (state *s, symbol_number sym);
 
 
 /*-------.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]