mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
style: decouple different uses of item_number
item_number is used for elements of ritem as well as indices into ritem which is fairly confusing. Introduce item_index to represent indices into ritem. * src/gram.h (item_index): Introduce it for ritem indices. * src/closure.h, src/closure.c, src/ielr.c, src/lr0.c, * src/print-graph.c, src/state.h, src/state.h: Replace uses of item_number with item_index where appropriate.
This commit is contained in:
committed by
Akim Demaille
parent
dd878d1851
commit
6a1a681fd2
@@ -32,7 +32,7 @@
|
|||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
|
|
||||||
/* NITEMSET is the size of the array ITEMSET. */
|
/* NITEMSET is the size of the array ITEMSET. */
|
||||||
item_number *itemset;
|
item_index *itemset;
|
||||||
size_t nitemset;
|
size_t nitemset;
|
||||||
|
|
||||||
/* RULESET contains a bit for each rule. CLOSURE sets the bits for
|
/* RULESET contains a bit for each rule. CLOSURE sets the bits for
|
||||||
@@ -54,13 +54,13 @@ static bitsetv firsts = NULL;
|
|||||||
`-----------------*/
|
`-----------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
closure_print (char const *title, item_number const *array, size_t size)
|
closure_print (char const *title, item_index const *array, size_t size)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Closure: %s\n", title);
|
fprintf (stderr, "Closure: %s\n", title);
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
fprintf (stderr, " %2d: .", array[i]);
|
fprintf (stderr, " %2d: .", array[i]);
|
||||||
item_number *rp;
|
item_index *rp;
|
||||||
for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
|
for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
|
||||||
fprintf (stderr, " %s", symbols[*rp]->tag);
|
fprintf (stderr, " %s", symbols[*rp]->tag);
|
||||||
fprintf (stderr, " (rule %d)\n", -*rp - 1);
|
fprintf (stderr, " (rule %d)\n", -*rp - 1);
|
||||||
@@ -182,7 +182,7 @@ closure_new (int n)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
closure (item_number const *core, size_t n)
|
closure (item_index const *core, size_t n)
|
||||||
{
|
{
|
||||||
if (trace_flag & trace_closure)
|
if (trace_flag & trace_closure)
|
||||||
closure_print ("input", core, n);
|
closure_print ("input", core, n);
|
||||||
@@ -203,7 +203,7 @@ closure (item_number const *core, size_t n)
|
|||||||
bitset_iterator iter;
|
bitset_iterator iter;
|
||||||
BITSET_FOR_EACH (iter, ruleset, ruleno, 0)
|
BITSET_FOR_EACH (iter, ruleset, ruleno, 0)
|
||||||
{
|
{
|
||||||
item_number itemno = rules[ruleno].rhs - ritem;
|
item_index itemno = rules[ruleno].rhs - ritem;
|
||||||
while (c < n && core[c] < itemno)
|
while (c < n && core[c] < itemno)
|
||||||
{
|
{
|
||||||
itemset[nitemset] = core[c];
|
itemset[nitemset] = core[c];
|
||||||
|
|||||||
@@ -30,12 +30,12 @@
|
|||||||
void closure_new (int n);
|
void closure_new (int n);
|
||||||
|
|
||||||
|
|
||||||
/* Given the kernel (aka core) of a state (a sorted vector of item numbers
|
/* Given the kernel (aka core) of a state (a sorted vector of item indices
|
||||||
ITEMS, of length N), set up RULESET and ITEMSET to indicate what
|
ITEMS, of length N), set up RULESET and ITEMSET to indicate what
|
||||||
rules could be run and which items could be accepted when those
|
rules could be run and which items could be accepted when those
|
||||||
items are the active ones. */
|
items are the active ones. */
|
||||||
|
|
||||||
void closure (item_number const *items, size_t n);
|
void closure (item_index const *items, size_t n);
|
||||||
|
|
||||||
|
|
||||||
/* Free ITEMSET, RULESET and internal data. */
|
/* Free ITEMSET, RULESET and internal data. */
|
||||||
@@ -43,12 +43,12 @@ void closure (item_number const *items, size_t n);
|
|||||||
void closure_free (void);
|
void closure_free (void);
|
||||||
|
|
||||||
|
|
||||||
/* ITEMSET is a sorted vector of item numbers; NITEMSET is its size
|
/* ITEMSET is a sorted vector of item indices; NITEMSET is its size
|
||||||
(actually, points to just beyond the end of the part of it that is
|
(actually, points to just beyond the end of the part of it that is
|
||||||
significant). CLOSURE places there the indices of all items which
|
significant). CLOSURE places there the indices of all items which
|
||||||
represent units of input that could arrive next. */
|
represent units of input that could arrive next. */
|
||||||
|
|
||||||
extern item_number *itemset;
|
extern item_index *itemset;
|
||||||
extern size_t nitemset;
|
extern size_t nitemset;
|
||||||
|
|
||||||
#endif /* !CLOSURE_H_ */
|
#endif /* !CLOSURE_H_ */
|
||||||
|
|||||||
@@ -111,7 +111,10 @@ extern int nsyms;
|
|||||||
extern int ntokens;
|
extern int ntokens;
|
||||||
extern int nvars;
|
extern int nvars;
|
||||||
|
|
||||||
|
/* elements of ritem */
|
||||||
typedef int item_number;
|
typedef int item_number;
|
||||||
|
/* indices into ritem */
|
||||||
|
typedef int item_index;
|
||||||
# define ITEM_NUMBER_MAX INT_MAX
|
# define ITEM_NUMBER_MAX INT_MAX
|
||||||
extern item_number *ritem;
|
extern item_number *ritem;
|
||||||
extern int nritems;
|
extern int nritems;
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ ielr_compute_follow_kernel_items (bitset ritem_sees_lookahead_set,
|
|||||||
for (goto_number i = 0; i < ngotos; ++i)
|
for (goto_number i = 0; i < ngotos; ++i)
|
||||||
{
|
{
|
||||||
size_t nitems = states[from_state[i]]->nitems;
|
size_t nitems = states[from_state[i]]->nitems;
|
||||||
item_number *items = states[from_state[i]]->items;
|
item_index *items = states[from_state[i]]->items;
|
||||||
for (size_t j = 0; j < nitems; ++j)
|
for (size_t j = 0; j < nitems; ++j)
|
||||||
/* If this item has this goto and if all subsequent symbols in this
|
/* If this item has this goto and if all subsequent symbols in this
|
||||||
RHS (if any) are nullable nonterminals, then record this item as
|
RHS (if any) are nullable nonterminals, then record this item as
|
||||||
|
|||||||
14
src/lr0.c
14
src/lr0.c
@@ -49,7 +49,7 @@ static state_list *last_state = NULL;
|
|||||||
|
|
||||||
/* Print CORE for debugging. */
|
/* Print CORE for debugging. */
|
||||||
static void
|
static void
|
||||||
core_print (size_t core_size, item_number *core, FILE *out)
|
core_print (size_t core_size, item_index *core, FILE *out)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < core_size; ++i)
|
for (int i = 0; i < core_size; ++i)
|
||||||
{
|
{
|
||||||
@@ -65,7 +65,7 @@ core_print (size_t core_size, item_number *core, FILE *out)
|
|||||||
`-----------------------------------------------------------------*/
|
`-----------------------------------------------------------------*/
|
||||||
|
|
||||||
static state *
|
static state *
|
||||||
state_list_append (symbol_number sym, size_t core_size, item_number *core)
|
state_list_append (symbol_number sym, size_t core_size, item_index *core)
|
||||||
{
|
{
|
||||||
state_list *node = xmalloc (sizeof *node);
|
state_list *node = xmalloc (sizeof *node);
|
||||||
state *res = state_new (sym, core_size, core);
|
state *res = state_new (sym, core_size, core);
|
||||||
@@ -98,14 +98,14 @@ static rule **redset;
|
|||||||
static state **shiftset;
|
static state **shiftset;
|
||||||
|
|
||||||
|
|
||||||
/* KERNEL_BASE[symbol-number] -> list of item numbers (offsets inside
|
/* KERNEL_BASE[symbol-number] -> list of item indices (offsets inside
|
||||||
RITEM) of length KERNEL_SIZE[symbol-number]. */
|
RITEM) of length KERNEL_SIZE[symbol-number]. */
|
||||||
static item_number **kernel_base;
|
static item_index **kernel_base;
|
||||||
static int *kernel_size;
|
static int *kernel_size;
|
||||||
|
|
||||||
/* A single dimension array that serves as storage for
|
/* A single dimension array that serves as storage for
|
||||||
KERNEL_BASE. */
|
KERNEL_BASE. */
|
||||||
static item_number *kernel_items;
|
static item_index *kernel_items;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -257,7 +257,7 @@ new_itemsets (state *s)
|
|||||||
`--------------------------------------------------------------*/
|
`--------------------------------------------------------------*/
|
||||||
|
|
||||||
static state *
|
static state *
|
||||||
get_state (symbol_number sym, size_t core_size, item_number *core)
|
get_state (symbol_number sym, size_t core_size, item_index *core)
|
||||||
{
|
{
|
||||||
if (trace_flag & trace_automaton)
|
if (trace_flag & trace_automaton)
|
||||||
{
|
{
|
||||||
@@ -394,7 +394,7 @@ generate_states (void)
|
|||||||
|
|
||||||
/* Create the initial state. The 0 at the lhs is the index of the
|
/* Create the initial state. The 0 at the lhs is the index of the
|
||||||
item of this initial rule. */
|
item of this initial rule. */
|
||||||
item_number initial_core = 0;
|
item_index initial_core = 0;
|
||||||
state_list_append (0, 1, &initial_core);
|
state_list_append (0, 1, &initial_core);
|
||||||
|
|
||||||
/* States are queued when they are created; process them all. */
|
/* States are queued when they are created; process them all. */
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
static void
|
static void
|
||||||
print_core (struct obstack *oout, state *s)
|
print_core (struct obstack *oout, state *s)
|
||||||
{
|
{
|
||||||
item_number const *sitems = s->items;
|
item_index const *sitems = s->items;
|
||||||
sym_content *previous_lhs = NULL;
|
sym_content *previous_lhs = NULL;
|
||||||
size_t snritems = s->nitems;
|
size_t snritems = s->nitems;
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ state *final_state = NULL;
|
|||||||
|
|
||||||
state *
|
state *
|
||||||
state_new (symbol_number accessing_symbol,
|
state_new (symbol_number accessing_symbol,
|
||||||
size_t nitems, item_number *core)
|
size_t nitems, item_index *core)
|
||||||
{
|
{
|
||||||
aver (nstates < STATE_NUMBER_MAXIMUM);
|
aver (nstates < STATE_NUMBER_MAXIMUM);
|
||||||
|
|
||||||
@@ -395,7 +395,7 @@ state_hash_insert (state *s)
|
|||||||
`------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
state *
|
state *
|
||||||
state_hash_lookup (size_t nitems, item_number *core)
|
state_hash_lookup (size_t nitems, item_index *core)
|
||||||
{
|
{
|
||||||
size_t items_size = nitems * sizeof *core;
|
size_t items_size = nitems * sizeof *core;
|
||||||
state *probe = xmalloc (offsetof (state, items) + items_size);
|
state *probe = xmalloc (offsetof (state, items) + items_size);
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ struct state
|
|||||||
/* Its items. Must be last, since ITEMS can be arbitrarily large. Sorted
|
/* Its items. Must be last, since ITEMS can be arbitrarily large. Sorted
|
||||||
ascendingly on item index in RITEM, which is sorted on rule number. */
|
ascendingly on item index in RITEM, which is sorted on rule number. */
|
||||||
size_t nitems;
|
size_t nitems;
|
||||||
item_number items[1];
|
item_index items[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern state_number nstates;
|
extern state_number nstates;
|
||||||
@@ -233,7 +233,7 @@ extern state *final_state;
|
|||||||
|
|
||||||
/* Create a new state with ACCESSING_SYMBOL for those items. */
|
/* Create a new state with ACCESSING_SYMBOL for those items. */
|
||||||
state *state_new (symbol_number accessing_symbol,
|
state *state_new (symbol_number accessing_symbol,
|
||||||
size_t core_size, item_number *core);
|
size_t core_size, item_index *core);
|
||||||
state *state_new_isocore (state const *s);
|
state *state_new_isocore (state const *s);
|
||||||
|
|
||||||
/* Record that from S we can reach all the DST states (NUM of them). */
|
/* Record that from S we can reach all the DST states (NUM of them). */
|
||||||
@@ -264,7 +264,7 @@ void state_hash_free (void);
|
|||||||
|
|
||||||
/* Find the state associated to the CORE, and return it. If it does
|
/* Find the state associated to the CORE, and return it. If it does
|
||||||
not exist yet, return NULL. */
|
not exist yet, return NULL. */
|
||||||
state *state_hash_lookup (size_t core_size, item_number *core);
|
state *state_hash_lookup (size_t core_size, item_index *core);
|
||||||
|
|
||||||
/* Insert STATE in the state hash table. */
|
/* Insert STATE in the state hash table. */
|
||||||
void state_hash_insert (state *s);
|
void state_hash_insert (state *s);
|
||||||
|
|||||||
Reference in New Issue
Block a user