bison-patches
[Top][All Lists]
Advanced

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

cex: style changes in state-item


From: Akim Demaille
Subject: cex: style changes in state-item
Date: Sat, 16 May 2020 15:32:21 +0200

commit e10c5990c4d88c4d8438ff431386b3bfa0746e6d
Author: Akim Demaille <address@hidden>
Date:   Sat May 16 15:10:35 2020 +0200

    cex: style changes in state-item
    
    * src/state-item.h, src/state-item.c (state_item): Make the state
    const.
    (state_item_set): Make it clearer that it works in the state_items
    global array.

diff --git a/src/state-item.c b/src/state-item.c
index 167e9ac1..8def146b 100644
--- a/src/state-item.c
+++ b/src/state-item.c
@@ -94,9 +94,8 @@ hash_pair_remove (Hash_table *tab, int key)
   hash_delete (tab, hp);
 }
 
-/* return a state_item from a state's id and the offset of the item
-  within the state.
- */
+/* A state_item from a state's id and the offset of the item within
+   the state. */
 state_item *
 state_item_lookup (state_number s, state_item_number off)
 {
@@ -104,12 +103,11 @@ state_item_lookup (state_number s, state_item_number off)
 }
 
 static inline void
-state_item_set (state_item_number sidx, state *s, item_number off)
+state_item_set (state_item_number sidx, const state *s, item_number off)
 {
-  state_item *si = state_items + sidx;
-  si->state = s;
-  si->item = &ritem[off];
-  si->lookahead = NULL;
+  state_items[sidx].state = s;
+  state_items[sidx].item = &ritem[off];
+  state_items[sidx].lookahead = NULL;
   si_trans[sidx] = -1;
 }
 
@@ -123,11 +121,11 @@ init_state_items (void)
   bitsetv production_items = bitsetv_create (nstates, nritems, BITSET_SPARSE);
   for (int i = 0; i < nstates; ++i)
     {
-      state *s = states[i];
+      const state *s = states[i];
       nstate_items += s->nitems;
       closure (s->items, s->nitems);
       for (size_t j = 0; j < nitemset; ++j)
-        if (itemset[j] > 0
+        if (0 < itemset[j]
             && item_number_is_rule_number (ritem[itemset[j] - 1]))
           {
             bitset_set (production_items[i], itemset[j]);
@@ -143,8 +141,8 @@ init_state_items (void)
     {
       state_item_map[i] = sidx;
       int rule_search_idx = 0;
-      state *s = states[i];
-      reductions *red = s->reductions;
+      const state *s = states[i];
+      const reductions *red = s->reductions;
       for (int j = 0; j < s->nitems; ++j)
         {
           state_item_set (sidx, s, s->items[j]);
diff --git a/src/state-item.h b/src/state-item.h
index 748c5390..3b98132d 100644
--- a/src/state-item.h
+++ b/src/state-item.h
@@ -63,7 +63,7 @@ typedef int state_item_number;
 
 typedef struct
 {
-  state *state;
+  const state *state;
   item_number *item;
   bitset lookahead;
 } state_item;




reply via email to

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