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.
This commit is contained in:
Akim Demaille
2020-05-16 15:10:35 +02:00
parent f3ef847539
commit ac3b6c18a5
2 changed files with 11 additions and 13 deletions

View File

@@ -94,9 +94,8 @@ hash_pair_remove (Hash_table *tab, int key)
hash_delete (tab, hp); hash_delete (tab, hp);
} }
/* return a state_item from a state's id and the offset of the item /* A state_item from a state's id and the offset of the item within
within the state. the state. */
*/
state_item * state_item *
state_item_lookup (state_number s, state_item_number off) 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 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; state_items[sidx].state = s;
si->state = s; state_items[sidx].item = &ritem[off];
si->item = &ritem[off]; state_items[sidx].lookahead = NULL;
si->lookahead = NULL;
si_trans[sidx] = -1; si_trans[sidx] = -1;
} }
@@ -123,11 +121,11 @@ init_state_items (void)
bitsetv production_items = bitsetv_create (nstates, nritems, BITSET_SPARSE); bitsetv production_items = bitsetv_create (nstates, nritems, BITSET_SPARSE);
for (int i = 0; i < nstates; ++i) for (int i = 0; i < nstates; ++i)
{ {
state *s = states[i]; const state *s = states[i];
nstate_items += s->nitems; nstate_items += s->nitems;
closure (s->items, s->nitems); closure (s->items, s->nitems);
for (size_t j = 0; j < nitemset; ++j) 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])) && item_number_is_rule_number (ritem[itemset[j] - 1]))
{ {
bitset_set (production_items[i], itemset[j]); bitset_set (production_items[i], itemset[j]);
@@ -143,8 +141,8 @@ init_state_items (void)
{ {
state_item_map[i] = sidx; state_item_map[i] = sidx;
int rule_search_idx = 0; int rule_search_idx = 0;
state *s = states[i]; const state *s = states[i];
reductions *red = s->reductions; const reductions *red = s->reductions;
for (int j = 0; j < s->nitems; ++j) for (int j = 0; j < s->nitems; ++j)
{ {
state_item_set (sidx, s, s->items[j]); state_item_set (sidx, s, s->items[j]);

View File

@@ -63,7 +63,7 @@ typedef int state_item_number;
typedef struct typedef struct
{ {
state *state; const state *state;
item_number *item; item_number *item;
bitset lookahead; bitset lookahead;
} state_item; } state_item;