summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Imbimbo <vmi6@cornell.edu>2020-05-24 11:09:49 -0400
committerAkim Demaille <akim.demaille@gmail.com>2020-05-25 07:14:34 +0200
commit6a1a681fd2cf99e29a6133b8cae02b5d7233373b (patch)
treeff289d377604099089cd5fd69efecfc9619dd4e0
parentdd878d18519689c7bbcd72de4c9f9e53085a3cbf (diff)
downloadbison-6a1a681fd2cf99e29a6133b8cae02b5d7233373b.tar.gz
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.
-rw-r--r--src/closure.c10
-rw-r--r--src/closure.h8
-rw-r--r--src/gram.h3
-rw-r--r--src/ielr.c2
-rw-r--r--src/lr0.c14
-rw-r--r--src/print-graph.c2
-rw-r--r--src/state.c4
-rw-r--r--src/state.h6
8 files changed, 26 insertions, 23 deletions
diff --git a/src/closure.c b/src/closure.c
index 5a93ded7..94439b13 100644
--- a/src/closure.c
+++ b/src/closure.c
@@ -32,7 +32,7 @@
#include "symtab.h"
/* NITEMSET is the size of the array ITEMSET. */
-item_number *itemset;
+item_index *itemset;
size_t nitemset;
/* RULESET contains a bit for each rule. CLOSURE sets the bits for
@@ -54,13 +54,13 @@ static bitsetv firsts = NULL;
`-----------------*/
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);
for (size_t i = 0; i < size; ++i)
{
fprintf (stderr, " %2d: .", array[i]);
- item_number *rp;
+ item_index *rp;
for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
fprintf (stderr, " %s", symbols[*rp]->tag);
fprintf (stderr, " (rule %d)\n", -*rp - 1);
@@ -182,7 +182,7 @@ closure_new (int n)
void
-closure (item_number const *core, size_t n)
+closure (item_index const *core, size_t n)
{
if (trace_flag & trace_closure)
closure_print ("input", core, n);
@@ -203,7 +203,7 @@ closure (item_number const *core, size_t n)
bitset_iterator iter;
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)
{
itemset[nitemset] = core[c];
diff --git a/src/closure.h b/src/closure.h
index 21d6ba19..8fa1ed60 100644
--- a/src/closure.h
+++ b/src/closure.h
@@ -30,12 +30,12 @@
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
rules could be run and which items could be accepted when those
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. */
@@ -43,12 +43,12 @@ void closure (item_number const *items, size_t n);
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
significant). CLOSURE places there the indices of all items which
represent units of input that could arrive next. */
-extern item_number *itemset;
+extern item_index *itemset;
extern size_t nitemset;
#endif /* !CLOSURE_H_ */
diff --git a/src/gram.h b/src/gram.h
index 22a4e2e9..a4b58f0a 100644
--- a/src/gram.h
+++ b/src/gram.h
@@ -111,7 +111,10 @@ extern int nsyms;
extern int ntokens;
extern int nvars;
+/* elements of ritem */
typedef int item_number;
+/* indices into ritem */
+typedef int item_index;
# define ITEM_NUMBER_MAX INT_MAX
extern item_number *ritem;
extern int nritems;
diff --git a/src/ielr.c b/src/ielr.c
index 8e34b2cc..f86cd461 100644
--- a/src/ielr.c
+++ b/src/ielr.c
@@ -230,7 +230,7 @@ ielr_compute_follow_kernel_items (bitset ritem_sees_lookahead_set,
for (goto_number i = 0; i < ngotos; ++i)
{
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)
/* If this item has this goto and if all subsequent symbols in this
RHS (if any) are nullable nonterminals, then record this item as
diff --git a/src/lr0.c b/src/lr0.c
index 2ebdcf8a..fb06edae 100644
--- a/src/lr0.c
+++ b/src/lr0.c
@@ -49,7 +49,7 @@ static state_list *last_state = NULL;
/* Print CORE for debugging. */
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)
{
@@ -65,7 +65,7 @@ core_print (size_t core_size, item_number *core, FILE *out)
`-----------------------------------------------------------------*/
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 *res = state_new (sym, core_size, core);
@@ -98,14 +98,14 @@ static rule **redset;
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]. */
-static item_number **kernel_base;
+static item_index **kernel_base;
static int *kernel_size;
/* A single dimension array that serves as storage for
KERNEL_BASE. */
-static item_number *kernel_items;
+static item_index *kernel_items;
static void
@@ -257,7 +257,7 @@ new_itemsets (state *s)
`--------------------------------------------------------------*/
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)
{
@@ -394,7 +394,7 @@ generate_states (void)
/* Create the initial state. The 0 at the lhs is the index of the
item of this initial rule. */
- item_number initial_core = 0;
+ item_index initial_core = 0;
state_list_append (0, 1, &initial_core);
/* States are queued when they are created; process them all. */
diff --git a/src/print-graph.c b/src/print-graph.c
index 1dd6b15e..5691c6d8 100644
--- a/src/print-graph.c
+++ b/src/print-graph.c
@@ -47,7 +47,7 @@
static void
print_core (struct obstack *oout, state *s)
{
- item_number const *sitems = s->items;
+ item_index const *sitems = s->items;
sym_content *previous_lhs = NULL;
size_t snritems = s->nitems;
diff --git a/src/state.c b/src/state.c
index 6118445a..8f17a00c 100644
--- a/src/state.c
+++ b/src/state.c
@@ -126,7 +126,7 @@ state *final_state = NULL;
state *
state_new (symbol_number accessing_symbol,
- size_t nitems, item_number *core)
+ size_t nitems, item_index *core)
{
aver (nstates < STATE_NUMBER_MAXIMUM);
@@ -395,7 +395,7 @@ state_hash_insert (state *s)
`------------------------------------------------------------------*/
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;
state *probe = xmalloc (offsetof (state, items) + items_size);
diff --git a/src/state.h b/src/state.h
index a087dc83..4f0cfd10 100644
--- a/src/state.h
+++ b/src/state.h
@@ -225,7 +225,7 @@ struct state
/* Its items. Must be last, since ITEMS can be arbitrarily large. Sorted
ascendingly on item index in RITEM, which is sorted on rule number. */
size_t nitems;
- item_number items[1];
+ item_index items[1];
};
extern state_number nstates;
@@ -233,7 +233,7 @@ extern state *final_state;
/* Create a new state with ACCESSING_SYMBOL for those items. */
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);
/* 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
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. */
void state_hash_insert (state *s);