cex: use better type names

There are too many gl_list_t in there, it's hard to understand what is
going on.  Introduce and use more precise types.  I sure can be wrong
in some places, it's hard to tell without proper tool support.

* src/counterexample.c, src/lssi.c, src/lssi.h, src/parse-simulation.c,
* src/parse-simulation.h, src/state-item.c, src/state-item.h
(si_bfs_node_list, search_state_list, ssb_list, lssi_list)
(state_item_list): New.
This commit is contained in:
Akim Demaille
2020-07-12 14:18:49 +02:00
parent 1e12219775
commit cd099edf2d
7 changed files with 78 additions and 65 deletions

View File

@@ -175,6 +175,8 @@ si_bfs_free (si_bfs_node *n)
} }
} }
typedef gl_list_t si_bfs_node_list;
/** /**
* start is a state_item such that conflict_sym is an element of FIRSTS of the * start is a state_item such that conflict_sym is an element of FIRSTS of the
* nonterminal after the dot in start. Because of this, we should be able to * nonterminal after the dot in start. Because of this, we should be able to
@@ -188,9 +190,10 @@ expand_to_conflict (state_item_number start, symbol_number conflict_sym)
{ {
si_bfs_node *init = si_bfs_new (start, NULL); si_bfs_node *init = si_bfs_new (start, NULL);
gl_list_t queue = gl_list_create (GL_LINKED_LIST, NULL, NULL, si_bfs_node_list queue
(gl_listelement_dispose_fn) si_bfs_free, = gl_list_create (GL_LINKED_LIST, NULL, NULL,
true, 1, (const void **) &init); (gl_listelement_dispose_fn) si_bfs_free,
true, 1, (const void **) &init);
si_bfs_node *node = NULL; si_bfs_node *node = NULL;
// breadth-first search for a path of productions to the conflict symbol // breadth-first search for a path of productions to the conflict symbol
while (gl_list_size (queue) > 0) while (gl_list_size (queue) > 0)
@@ -274,7 +277,7 @@ expand_to_conflict (state_item_number start, symbol_number conflict_sym)
*/ */
static derivation * static derivation *
complete_diverging_example (symbol_number conflict_sym, complete_diverging_example (symbol_number conflict_sym,
gl_list_t path, derivation_list derivs) state_item_list path, derivation_list derivs)
{ {
// The idea is to transfer each pending symbol on the productions // The idea is to transfer each pending symbol on the productions
// associated with the given StateItems to the resulting derivation. // associated with the given StateItems to the resulting derivation.
@@ -395,15 +398,15 @@ complete_diverging_example (symbol_number conflict_sym,
/* Iterate backwards through the shifts of the path in the reduce /* Iterate backwards through the shifts of the path in the reduce
conflict, and find a path of shifts from the shift conflict that conflict, and find a path of shifts from the shift conflict that
goes through the same states. */ goes through the same states. */
static gl_list_t static state_item_list
nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict) nonunifying_shift_path (state_item_list reduce_path, state_item *shift_conflict)
{ {
gl_list_node_t tmp = gl_list_add_last (reduce_path, NULL); gl_list_node_t tmp = gl_list_add_last (reduce_path, NULL);
gl_list_node_t next_node = gl_list_previous_node (reduce_path, tmp); gl_list_node_t next_node = gl_list_previous_node (reduce_path, tmp);
gl_list_node_t node = gl_list_previous_node (reduce_path, next_node); gl_list_node_t node = gl_list_previous_node (reduce_path, next_node);
gl_list_remove_node (reduce_path, tmp); gl_list_remove_node (reduce_path, tmp);
state_item *si = shift_conflict; state_item *si = shift_conflict;
gl_list_t result = state_item_list result =
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true); gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
// FIXME: bool paths_merged; // FIXME: bool paths_merged;
for (; node != NULL; next_node = node, for (; node != NULL; next_node = node,
@@ -425,10 +428,10 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
// bfs to find a shift to the right state // bfs to find a shift to the right state
si_bfs_node *init = si_bfs_new (si - state_items, NULL); si_bfs_node *init = si_bfs_new (si - state_items, NULL);
gl_list_t queue = si_bfs_node_list queue
gl_list_create (GL_LINKED_LIST, NULL, NULL, = gl_list_create (GL_LINKED_LIST, NULL, NULL,
(gl_listelement_dispose_fn) si_bfs_free, (gl_listelement_dispose_fn) si_bfs_free,
true, 1, (const void **) &init); true, 1, (const void **) &init);
si_bfs_node *sis = NULL; si_bfs_node *sis = NULL;
state_item *prevsi = NULL; state_item *prevsi = NULL;
while (gl_list_size (queue) > 0) while (gl_list_size (queue) > 0)
@@ -493,11 +496,11 @@ nonunifying_shift_path (gl_list_t reduce_path, state_item *shift_conflict)
static counterexample * static counterexample *
example_from_path (bool shift_reduce, example_from_path (bool shift_reduce,
state_item_number itm2, state_item_number itm2,
gl_list_t shortest_path, symbol_number next_sym) state_item_list shortest_path, symbol_number next_sym)
{ {
derivation *deriv1 = derivation *deriv1 =
complete_diverging_example (next_sym, shortest_path, NULL); complete_diverging_example (next_sym, shortest_path, NULL);
gl_list_t path_2 state_item_list path_2
= shift_reduce = shift_reduce
? nonunifying_shift_path (shortest_path, &state_items [itm2]) ? nonunifying_shift_path (shortest_path, &state_items [itm2])
: shortest_path_from_start (itm2, next_sym); : shortest_path_from_start (itm2, next_sym);
@@ -583,6 +586,8 @@ search_state_print (search_state *ss)
putc ('\n', stderr); putc ('\n', stderr);
} }
typedef gl_list_t search_state_list;
static inline bool static inline bool
search_state_list_next (gl_list_iterator_t *it, search_state **ss) search_state_list_next (gl_list_iterator_t *it, search_state **ss)
{ {
@@ -619,7 +624,7 @@ complete_diverging_examples (search_state *ss,
derivation *new_derivs[2]; derivation *new_derivs[2];
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{ {
gl_list_t sitems; state_item_list sitems;
derivation_list derivs; derivation_list derivs;
parse_state_lists (ss->states[i], &sitems, &derivs); parse_state_lists (ss->states[i], &sitems, &derivs);
new_derivs[i] = complete_diverging_example (next_sym, sitems, derivs); new_derivs[i] = complete_diverging_example (next_sym, sitems, derivs);
@@ -635,7 +640,7 @@ complete_diverging_examples (search_state *ss,
*/ */
typedef struct typedef struct
{ {
gl_list_t states; search_state_list states;
int complexity; int complexity;
} search_state_bundle; } search_state_bundle;
@@ -664,6 +669,8 @@ ssb_equals (const search_state_bundle *s1, const search_state_bundle *s2)
return s1->complexity == s2->complexity; return s1->complexity == s2->complexity;
} }
typedef gl_list_t ssb_list;
static size_t static size_t
visited_hasher (const search_state *ss, size_t max) visited_hasher (const search_state *ss, size_t max)
{ {
@@ -679,7 +686,7 @@ visited_comparator (const search_state *ss1, const search_state *ss2)
} }
/* Priority queue for search states with minimal complexity. */ /* Priority queue for search states with minimal complexity. */
static gl_list_t ssb_queue; static ssb_list ssb_queue;
static Hash_table *visited; static Hash_table *visited;
/* The set of parser states on the shortest lookahead-sensitive path. */ /* The set of parser states on the shortest lookahead-sensitive path. */
static bitset scp_set = NULL; static bitset scp_set = NULL;
@@ -756,12 +763,12 @@ reduction_cost (const parse_state *ps)
return SHIFT_COST * shifts + PRODUCTION_COST * productions; return SHIFT_COST * shifts + PRODUCTION_COST * productions;
} }
static gl_list_t static search_state_list
reduction_step (search_state *ss, const item_number *conflict_item, reduction_step (search_state *ss, const item_number *conflict_item,
int parser_state, int rule_len) int parser_state, int rule_len)
{ {
(void) conflict_item; // FIXME: Unused (void) conflict_item; // FIXME: Unused
gl_list_t result = search_state_list result =
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, 1); gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, 1);
parse_state *ps = ss->states[parser_state]; parse_state *ps = ss->states[parser_state];
@@ -988,14 +995,14 @@ generate_next_states (search_state *ss, state_item *conflict1,
// prepended further, reduce. // prepended further, reduce.
if (ready1 && ready2) if (ready1 && ready2)
{ {
gl_list_t reduced1 = reduction_step (ss, conflict1->item, 0, len1); search_state_list reduced1 = reduction_step (ss, conflict1->item, 0, len1);
gl_list_add_last (reduced1, ss); gl_list_add_last (reduced1, ss);
search_state *red1 = NULL; search_state *red1 = NULL;
for (gl_list_iterator_t iter = gl_list_iterator (reduced1); for (gl_list_iterator_t iter = gl_list_iterator (reduced1);
search_state_list_next (&iter, &red1); search_state_list_next (&iter, &red1);
) )
{ {
gl_list_t reduced2 = search_state_list reduced2 =
reduction_step (red1, conflict2->item, 1, len2); reduction_step (red1, conflict2->item, 1, len2);
search_state *red2 = NULL; search_state *red2 = NULL;
for (gl_list_iterator_t iter2 = gl_list_iterator (reduced2); for (gl_list_iterator_t iter2 = gl_list_iterator (reduced2);
@@ -1011,7 +1018,7 @@ generate_next_states (search_state *ss, state_item *conflict1,
} }
else if (ready1) else if (ready1)
{ {
gl_list_t reduced1 = reduction_step (ss, conflict1->item, 0, len1); search_state_list reduced1 = reduction_step (ss, conflict1->item, 0, len1);
search_state *red1 = NULL; search_state *red1 = NULL;
for (gl_list_iterator_t iter = gl_list_iterator (reduced1); for (gl_list_iterator_t iter = gl_list_iterator (reduced1);
search_state_list_next (&iter, &red1); search_state_list_next (&iter, &red1);
@@ -1021,7 +1028,7 @@ generate_next_states (search_state *ss, state_item *conflict1,
} }
else if (ready2) else if (ready2)
{ {
gl_list_t reduced2 = reduction_step (ss, conflict2->item, 1, len2); search_state_list reduced2 = reduction_step (ss, conflict2->item, 1, len2);
search_state *red2 = NULL; search_state *red2 = NULL;
for (gl_list_iterator_t iter2 = gl_list_iterator (reduced2); for (gl_list_iterator_t iter2 = gl_list_iterator (reduced2);
search_state_list_next (&iter2, &red2); search_state_list_next (&iter2, &red2);
@@ -1055,7 +1062,7 @@ static counterexample *
unifying_example (state_item_number itm1, unifying_example (state_item_number itm1,
state_item_number itm2, state_item_number itm2,
bool shift_reduce, bool shift_reduce,
gl_list_t reduce_path, symbol_number next_sym) state_item_list reduce_path, symbol_number next_sym)
{ {
state_item *conflict1 = &state_items[itm1]; state_item *conflict1 = &state_items[itm1];
state_item *conflict2 = &state_items[itm2]; state_item *conflict2 = &state_items[itm2];
@@ -1190,7 +1197,7 @@ counterexample_report (state_item_number itm1, state_item_number itm2,
{ {
// Compute the shortest lookahead-sensitive path and associated sets of // Compute the shortest lookahead-sensitive path and associated sets of
// parser states. // parser states.
gl_list_t shortest_path = shortest_path_from_start (itm1, next_sym); state_item_list shortest_path = shortest_path_from_start (itm1, next_sym);
bool reduce_prod_reached = false; bool reduce_prod_reached = false;
const rule *reduce_rule = item_rule (state_items[itm1].item); const rule *reduce_rule = item_rule (state_items[itm1].item);
@@ -1226,7 +1233,8 @@ counterexample_report_shift_reduce (state_item_number itm1, state_item_number it
{ {
fputs (prefix, out); fputs (prefix, out);
fprintf (out, _("Shift/reduce conflict on token %s:\n"), symbols[next_sym]->tag); fprintf (out, _("Shift/reduce conflict on token %s:\n"), symbols[next_sym]->tag);
if (*prefix) // In the report, print the items.
if (*prefix || trace_flag & trace_cex)
{ {
print_state_item (&state_items[itm1], out, prefix); print_state_item (&state_items[itm1], out, prefix);
print_state_item (&state_items[itm2], out, prefix); print_state_item (&state_items[itm2], out, prefix);
@@ -1254,7 +1262,8 @@ counterexample_report_reduce_reduce (state_item_number itm1, state_item_number i
} }
fputs (_(":\n"), out); fputs (_(":\n"), out);
} }
if (*prefix) // In the report, print the items.
if (*prefix || trace_flag & trace_cex)
{ {
print_state_item (&state_items[itm1], out, prefix); print_state_item (&state_items[itm1], out, prefix);
print_state_item (&state_items[itm2], out, prefix); print_state_item (&state_items[itm2], out, prefix);

View File

@@ -82,8 +82,10 @@ lssi_comparator (lssi *s1, lssi *s2)
return false; return false;
} }
typedef gl_list_t lssi_list;
static inline bool static inline bool
append_lssi (lssi *sn, Hash_table *visited, gl_list_t queue) append_lssi (lssi *sn, Hash_table *visited, lssi_list queue)
{ {
if (hash_lookup (visited, sn)) if (hash_lookup (visited, sn))
{ {
@@ -121,7 +123,7 @@ static bitset
eligible_state_items (state_item *target) eligible_state_items (state_item *target)
{ {
bitset result = bitset_create (nstate_items, BITSET_FIXED); bitset result = bitset_create (nstate_items, BITSET_FIXED);
gl_list_t queue = state_item_list queue =
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1, gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
(const void **) &target); (const void **) &target);
while (gl_list_size (queue) > 0) while (gl_list_size (queue) > 0)
@@ -147,7 +149,7 @@ eligible_state_items (state_item *target)
* this conflict. If optimized is true, only consider parser states * this conflict. If optimized is true, only consider parser states
* that can reach the conflict state. * that can reach the conflict state.
*/ */
gl_list_t state_item_list
shortest_path_from_start (state_item_number target, symbol_number next_sym) shortest_path_from_start (state_item_number target, symbol_number next_sym)
{ {
bitset eligible = eligible_state_items (&state_items[target]); bitset eligible = eligible_state_items (&state_items[target]);
@@ -159,7 +161,7 @@ shortest_path_from_start (state_item_number target, symbol_number next_sym)
bitset il = bitset_create (nsyms, BITSET_FIXED); bitset il = bitset_create (nsyms, BITSET_FIXED);
bitset_set (il, 0); bitset_set (il, 0);
lssi *init = new_lssi (0, NULL, il, true); lssi *init = new_lssi (0, NULL, il, true);
gl_list_t queue = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, lssi_list queue = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL,
NULL, true); NULL, true);
append_lssi (init, visited, queue); append_lssi (init, visited, queue);
// breadth-first search // breadth-first search
@@ -240,7 +242,7 @@ shortest_path_from_start (state_item_number target, symbol_number next_sym)
fputs ("Cannot find shortest path to conflict state.", stderr); fputs ("Cannot find shortest path to conflict state.", stderr);
abort (); abort ();
} }
gl_list_t res = state_item_list res =
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true); gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
for (lssi *sn = n; sn != NULL; sn = sn->parent) for (lssi *sn = n; sn != NULL; sn = sn->parent)
gl_list_add_first (res, &state_items[sn->si]); gl_list_add_first (res, &state_items[sn->si]);
@@ -306,10 +308,10 @@ intersect (bitset ts, bitset syms)
* Compute a list of state_items that have a production to n with respect * Compute a list of state_items that have a production to n with respect
* to its lookahead * to its lookahead
*/ */
gl_list_t state_item_list
lssi_reverse_production (const state_item *si, bitset lookahead) lssi_reverse_production (const state_item *si, bitset lookahead)
{ {
gl_list_t result = state_item_list result =
gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true); gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
if (SI_TRANSITION (si)) if (SI_TRANSITION (si))
return result; return result;

View File

@@ -32,8 +32,8 @@
* find shortest lookahead-sensitive path of state-items to target such that * find shortest lookahead-sensitive path of state-items to target such that
* next_sym is in the follow_L set of target in that position. * next_sym is in the follow_L set of target in that position.
*/ */
gl_list_t shortest_path_from_start (state_item_number target, state_item_list shortest_path_from_start (state_item_number target,
symbol_number next_sym); symbol_number next_sym);
/** /**
* Determine if the given terminal is in the given symbol set or can begin * Determine if the given terminal is in the given symbol set or can begin
@@ -52,6 +52,6 @@ bool intersect (bitset ts, bitset syms);
* to this state-item such that the resulting possible lookahead symbols are * to this state-item such that the resulting possible lookahead symbols are
* as given. * as given.
*/ */
gl_list_t lssi_reverse_production (const state_item *si, bitset lookahead); state_item_list lssi_reverse_production (const state_item *si, bitset lookahead);
#endif /* LSSI_H */ #endif /* LSSI_H */

View File

@@ -34,7 +34,7 @@ typedef struct parse_state
struct si_chunk struct si_chunk
{ {
// elements newly added in this chunk // elements newly added in this chunk
gl_list_t contents; state_item_list contents;
// properties of the linked list this chunk represents // properties of the linked list this chunk represents
const state_item *head_elt; const state_item *head_elt;
const state_item *tail_elt; const state_item *tail_elt;
@@ -252,7 +252,7 @@ parse_state_completed_steps (const parse_state *ps, int *shifts, int *production
while (root_ps->parent) while (root_ps->parent)
root_ps = root_ps->parent; root_ps = root_ps->parent;
gl_list_t sis = root_ps->state_items.contents; state_item_list sis = root_ps->state_items.contents;
int count = 0; int count = 0;
state_item *last = NULL; state_item *last = NULL;
@@ -337,19 +337,17 @@ parser_pop (parse_state *ps, int deriv_index,
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
chunks[i] = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true); chunks[i] = gl_list_create_empty (GL_LINKED_LIST, NULL, NULL, NULL, true);
for (parse_state *pn = ps; pn != NULL; pn = pn->parent) for (parse_state *pn = ps; pn != NULL; pn = pn->parent)
{ if (pn->prepend)
if (pn->prepend) {
{ gl_list_add_last (chunks[0], pn->state_items.contents);
gl_list_add_last (chunks[0], pn->state_items.contents); gl_list_add_last (chunks[2], pn->derivs.contents);
gl_list_add_last (chunks[2], pn->derivs.contents); }
} else
else {
{ gl_list_add_first (chunks[1], pn->state_items.contents);
gl_list_add_first (chunks[1], pn->state_items.contents); gl_list_add_first (chunks[3], pn->derivs.contents);
gl_list_add_first (chunks[3], pn->derivs.contents); }
} derivation_list popped_derivs = derivation_list_new ();
}
gl_list_t popped_derivs = derivation_list_new ();
gl_list_t ret_chunks[4] = { ret->state_items.contents, NULL, gl_list_t ret_chunks[4] = { ret->state_items.contents, NULL,
ret->derivs.contents, popped_derivs ret->derivs.contents, popped_derivs
}; };
@@ -390,7 +388,7 @@ parser_pop (parse_state *ps, int deriv_index,
} }
void void
parse_state_lists (parse_state *ps, gl_list_t *sitems, parse_state_lists (parse_state *ps, state_item_list *sitems,
derivation_list *derivs) derivation_list *derivs)
{ {
parse_state *temp = empty_parse_state (); parse_state *temp = empty_parse_state ();
@@ -431,14 +429,14 @@ nullable_closure (parse_state *ps, state_item *si, parse_state_list state_list)
} }
} }
gl_list_t parse_state_list
simulate_transition (parse_state *ps) simulate_transition (parse_state *ps)
{ {
const state_item *si = ps->state_items.tail_elt; const state_item *si = ps->state_items.tail_elt;
symbol_number sym = item_number_as_symbol_number (*si->item); symbol_number sym = item_number_as_symbol_number (*si->item);
// Transition on the same next symbol, taking nullable // Transition on the same next symbol, taking nullable
// symbols into account. // symbols into account.
gl_list_t result = parse_state_list_new (); parse_state_list result = parse_state_list_new ();
state_item_number si_next = si->trans; state_item_number si_next = si->trans;
// check for disabled transition, shouldn't happen // check for disabled transition, shouldn't happen
// as any state_items that lead to these should be // as any state_items that lead to these should be
@@ -473,10 +471,10 @@ compatible (symbol_number sym1, symbol_number sym2)
return false; return false;
} }
gl_list_t parse_state_list
simulate_production (parse_state *ps, symbol_number compat_sym) simulate_production (parse_state *ps, symbol_number compat_sym)
{ {
gl_list_t result = parse_state_list_new (); parse_state_list result = parse_state_list_new ();
const state_item *si = parse_state_tail (ps); const state_item *si = parse_state_tail (ps);
if (si->prods) if (si->prods)
{ {
@@ -504,10 +502,10 @@ simulate_production (parse_state *ps, symbol_number compat_sym)
// simulates a reduction on the given parse state, conflict_item is the // simulates a reduction on the given parse state, conflict_item is the
// item associated with ps's conflict. symbol_set is a lookahead set this // item associated with ps's conflict. symbol_set is a lookahead set this
// reduction must be compatible with // reduction must be compatible with
gl_list_t parse_state_list
simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set) simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
{ {
gl_list_t result = parse_state_list_new (); parse_state_list result = parse_state_list_new ();
int s_size = ps->state_items.total_size; int s_size = ps->state_items.total_size;
int d_size = ps->derivs.total_size; int d_size = ps->derivs.total_size;
@@ -537,7 +535,7 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
// The head state_item is a production item, so we need to prepend // The head state_item is a production item, so we need to prepend
// with possible source state-items. // with possible source state-items.
const state_item *head = ps->state_items.head_elt; const state_item *head = ps->state_items.head_elt;
gl_list_t prev = lssi_reverse_production (head, symbol_set); state_item_list prev = lssi_reverse_production (head, symbol_set);
// TODO: better understand what causes this case. // TODO: better understand what causes this case.
if (gl_list_size (prev) == 0) if (gl_list_size (prev) == 0)
{ {
@@ -570,10 +568,10 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
return result; return result;
} }
gl_list_t parse_state_list
parser_prepend (parse_state *ps) parser_prepend (parse_state *ps)
{ {
gl_list_t res = parse_state_list_new (); parse_state_list res = parse_state_list_new ();
const state_item *head = ps->state_items.head_elt; const state_item *head = ps->state_items.head_elt;
symbol_number prepend_sym = symbol_number prepend_sym =
item_number_as_symbol_number (*(head->item - 1)); item_number_as_symbol_number (*(head->item - 1));

View File

@@ -113,7 +113,7 @@ int parse_state_length (const parse_state *ps);
int parse_state_depth (const parse_state *ps); int parse_state_depth (const parse_state *ps);
/* returns the linked lists that the parse state is supposed to represent */ /* returns the linked lists that the parse state is supposed to represent */
void parse_state_lists (parse_state *ps, gl_list_t *state_items, void parse_state_lists (parse_state *ps, state_item_list *state_items,
derivation_list *derivs); derivation_list *derivs);
/* various functions that return a list of states based off of /* various functions that return a list of states based off of

View File

@@ -304,7 +304,7 @@ gen_lookaheads (void)
continue; continue;
bitset lookahead = si->lookahead; bitset lookahead = si->lookahead;
gl_list_t queue = state_item_list queue =
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1, gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
(const void **) &si); (const void **) &si);
@@ -390,7 +390,7 @@ disable_state_item (state_item *si)
static void static void
prune_forward (const state_item *si) prune_forward (const state_item *si)
{ {
gl_list_t queue = state_item_list queue =
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1, gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
(const void **) &si); (const void **) &si);
@@ -425,7 +425,7 @@ prune_forward (const state_item *si)
static void static void
prune_backward (const state_item *si) prune_backward (const state_item *si)
{ {
gl_list_t queue = state_item_list queue =
gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1, gl_list_create (GL_LINKED_LIST, NULL, NULL, NULL, true, 1,
(const void **) &si); (const void **) &si);

View File

@@ -69,6 +69,9 @@ typedef struct
bitset lookahead; bitset lookahead;
} state_item; } state_item;
// A path of state-items.
typedef gl_list_t state_item_list;
extern bitsetv firsts; extern bitsetv firsts;
# define FIRSTS(sym) firsts[(sym) - ntokens] # define FIRSTS(sym) firsts[(sym) - ntokens]
@@ -92,6 +95,7 @@ void state_items_free (void);
bool production_allowed (const state_item *si, const state_item *next); bool production_allowed (const state_item *si, const state_item *next);
// Iterating on a state_item_list.
static inline bool static inline bool
state_item_list_next (gl_list_iterator_t *it, state_item **si) state_item_list_next (gl_list_iterator_t *it, state_item **si)
{ {