mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
style: factor the access to a rule from its items
* src/counterexample.c (item_rule): Move to... * src/counterexample.h: here. * src/AnnotationList.c, src/counterexample.c, src/ielr.c: Use it.
This commit is contained in:
@@ -185,7 +185,7 @@ AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
AnnotationList__compute_lhs_contributions (state *s, rule *the_rule,
|
AnnotationList__compute_lhs_contributions (state *s, const rule *the_rule,
|
||||||
symbol_number conflicted_token,
|
symbol_number conflicted_token,
|
||||||
bitsetv follow_kernel_items,
|
bitsetv follow_kernel_items,
|
||||||
bitsetv always_follows,
|
bitsetv always_follows,
|
||||||
@@ -263,18 +263,12 @@ AnnotationList__computePredecessorAnnotations (
|
|||||||
/* If this kernel item is next to the beginning of the RHS,
|
/* If this kernel item is next to the beginning of the RHS,
|
||||||
then check all of the predecessor's goto follows for the
|
then check all of the predecessor's goto follows for the
|
||||||
LHS. */
|
LHS. */
|
||||||
if (item_number_is_rule_number (ritem[s->items[self_item]
|
if (item_number_is_rule_number (ritem[s->items[self_item] - 2]))
|
||||||
- 2]))
|
|
||||||
{
|
{
|
||||||
int rulei;
|
|
||||||
for (rulei = s->items[self_item];
|
|
||||||
!item_number_is_rule_number (ritem[rulei]);
|
|
||||||
++rulei)
|
|
||||||
continue;
|
|
||||||
Sbitset items;
|
Sbitset items;
|
||||||
if (AnnotationList__compute_lhs_contributions (
|
if (AnnotationList__compute_lhs_contributions (
|
||||||
*predecessor,
|
*predecessor,
|
||||||
&rules[item_number_as_rule_number (ritem[rulei])],
|
item_rule (&ritem[s->items[self_item]]),
|
||||||
contribution_token,
|
contribution_token,
|
||||||
follow_kernel_items, always_follows, predecessors,
|
follow_kernel_items, always_follows, predecessors,
|
||||||
item_lookahead_sets, &items, annotations_obstackp))
|
item_lookahead_sets, &items, annotations_obstackp))
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ complete_diverging_example (symbol_number conflict_sym,
|
|||||||
lookahead_required = false;
|
lookahead_required = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rule_number r = item_number_as_rule_number (*i);
|
const rule *r = &rules[item_number_as_rule_number (*i)];
|
||||||
// add derivations for symbols before dot
|
// add derivations for symbols before dot
|
||||||
for (i = item - 1; !item_number_is_rule_number (*i) && i >= ritem; i--)
|
for (i = item - 1; !item_number_is_rule_number (*i) && i >= ritem; i--)
|
||||||
{
|
{
|
||||||
@@ -381,7 +381,7 @@ complete_diverging_example (symbol_number conflict_sym,
|
|||||||
derivation_list_prepend (result, derivation_new_leaf (*i));
|
derivation_list_prepend (result, derivation_new_leaf (*i));
|
||||||
}
|
}
|
||||||
// completing the derivation
|
// completing the derivation
|
||||||
derivation *new_deriv = derivation_new (rules[r].lhs->number, result);
|
derivation *new_deriv = derivation_new (r->lhs->number, result);
|
||||||
result = derivation_list_new ();
|
result = derivation_list_new ();
|
||||||
derivation_list_append (result, new_deriv);
|
derivation_list_append (result, new_deriv);
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/gram.c
11
src/gram.c
@@ -48,17 +48,6 @@ int max_code = 256;
|
|||||||
|
|
||||||
int required_version = 0;
|
int required_version = 0;
|
||||||
|
|
||||||
rule const *
|
|
||||||
item_rule (item_number const *item)
|
|
||||||
{
|
|
||||||
item_number const *sp = item;
|
|
||||||
while (0 <= *sp)
|
|
||||||
++sp;
|
|
||||||
rule_number r = item_number_as_rule_number (*sp);
|
|
||||||
return &rules[r];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
item_print (item_number *item, rule const *previous_rule, FILE *out)
|
item_print (item_number *item, rule const *previous_rule, FILE *out)
|
||||||
{
|
{
|
||||||
|
|||||||
10
src/gram.h
10
src/gram.h
@@ -237,7 +237,15 @@ print_dot (FILE *out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the rule associated to this item. ITEM points inside RITEM. */
|
/* Get the rule associated to this item. ITEM points inside RITEM. */
|
||||||
rule const *item_rule (item_number const *item);
|
static inline rule const *
|
||||||
|
item_rule (item_number const *item)
|
||||||
|
{
|
||||||
|
item_number const *sp = item;
|
||||||
|
while (!item_number_is_rule_number (*sp))
|
||||||
|
++sp;
|
||||||
|
rule_number r = item_number_as_rule_number (*sp);
|
||||||
|
return &rules[r];
|
||||||
|
}
|
||||||
|
|
||||||
/* Pretty-print this ITEM (as in the report). ITEM points inside
|
/* Pretty-print this ITEM (as in the report). ITEM points inside
|
||||||
RITEM. PREVIOUS_RULE is used to see if the lhs is common, in which
|
RITEM. PREVIOUS_RULE is used to see if the lhs is common, in which
|
||||||
|
|||||||
24
src/ielr.c
24
src/ielr.c
@@ -418,14 +418,7 @@ ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item,
|
|||||||
/* If the LHS symbol of this item isn't known (because this is a
|
/* If the LHS symbol of this item isn't known (because this is a
|
||||||
top-level invocation), go get it. */
|
top-level invocation), go get it. */
|
||||||
if (!lhs)
|
if (!lhs)
|
||||||
{
|
lhs = item_rule (&ritem[s->items[item]])->lhs->number;
|
||||||
int i;
|
|
||||||
for (i = s->items[item];
|
|
||||||
!item_number_is_rule_number (ritem[i]);
|
|
||||||
++i)
|
|
||||||
continue;
|
|
||||||
lhs = rules[item_number_as_rule_number (ritem[i])].lhs->number;
|
|
||||||
}
|
|
||||||
/* If this kernel item is next to the beginning of the RHS, then
|
/* If this kernel item is next to the beginning of the RHS, then
|
||||||
check all predecessors' goto follows for the LHS. */
|
check all predecessors' goto follows for the LHS. */
|
||||||
if (item_number_is_rule_number (ritem[s->items[item] - 2]))
|
if (item_number_is_rule_number (ritem[s->items[item] - 2]))
|
||||||
@@ -633,17 +626,10 @@ ielr_compute_lookaheads (bitsetv follow_kernel_items, bitsetv always_follows,
|
|||||||
&& !bitset_empty_p (lookahead_filter[t_item]))
|
&& !bitset_empty_p (lookahead_filter[t_item]))
|
||||||
{
|
{
|
||||||
if (item_number_is_rule_number (ritem[t->items[t_item] - 2]))
|
if (item_number_is_rule_number (ritem[t->items[t_item] - 2]))
|
||||||
{
|
ielr_compute_goto_follow_set (
|
||||||
int rule_item;
|
follow_kernel_items, always_follows, s,
|
||||||
for (rule_item = t->items[t_item];
|
item_rule (&ritem[t->items[t_item]])->lhs,
|
||||||
!item_number_is_rule_number (ritem[rule_item]);
|
lookaheads[t_item]);
|
||||||
++rule_item)
|
|
||||||
;
|
|
||||||
ielr_compute_goto_follow_set (
|
|
||||||
follow_kernel_items, always_follows, s,
|
|
||||||
rules[item_number_as_rule_number (ritem[rule_item])].lhs,
|
|
||||||
lookaheads[t_item]);
|
|
||||||
}
|
|
||||||
else if (s->lookaheads)
|
else if (s->lookaheads)
|
||||||
{
|
{
|
||||||
/* We don't have to start the s item search at the beginning
|
/* We don't have to start the s item search at the beginning
|
||||||
|
|||||||
Reference in New Issue
Block a user