Skip to content

Commit

Permalink
style: s/lookahead_tokens/lookaheads/g
Browse files Browse the repository at this point in the history
Currently we use both names.  Let's stick to the short one.

* src/AnnotationList.c, src/conflicts.c, src/counterexample.c,
* src/getargs.c, src/getargs.h, src/graphviz.c, src/ielr.c,
* src/lalr.c, src/print-graph.c, src/print-xml.c, src/print.c,
* src/state-item.c, src/state.c, src/state.h, src/tables.c:
s/lookahead_token/lookahead/gi.
  • Loading branch information
akimd committed Jul 12, 2020
1 parent b0ed6ab commit 577f594
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 107 deletions.
10 changes: 5 additions & 5 deletions src/AnnotationList.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
bitset_copy (tokens, shift_tokens);
for (int i = 0; i < reds->num; ++i)
{
bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]);
bitset_and (conflicted_tokens_rule, tokens, reds->lookaheads[i]);
bitset_or (conflicted_tokens,
conflicted_tokens, conflicted_tokens_rule);
bitset_or (tokens, tokens, reds->lookahead_tokens[i]);
bitset_or (tokens, tokens, reds->lookaheads[i]);
/* Check that rules are sorted on rule number or the next step in
AnnotationList__compute_from_inadequacies will misbehave. */
aver (i == 0 || reds->rules[i-1] < reds->rules[i]);
Expand Down Expand Up @@ -401,7 +401,7 @@ AnnotationList__compute_from_inadequacies (
struct obstack *annotations_obstackp,
InadequacyListNodeCount *inadequacy_list_node_count)
{
/* Return an empty list if s->lookahead_tokens = NULL. */
/* Return an empty list if s->lookaheads = NULL. */
if (s->consistent)
return;

Expand All @@ -422,7 +422,7 @@ AnnotationList__compute_from_inadequacies (
/* Allocate the annotation node. */
{
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
if (bitset_test (s->reductions->lookahead_tokens[rule_i],
if (bitset_test (s->reductions->lookaheads[rule_i],
conflicted_token))
++contribution_count;
if (bitset_test (shift_tokens, conflicted_token))
Expand All @@ -445,7 +445,7 @@ AnnotationList__compute_from_inadequacies (
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
{
rule *the_rule = s->reductions->rules[rule_i];
if (bitset_test (s->reductions->lookahead_tokens[rule_i],
if (bitset_test (s->reductions->lookaheads[rule_i],
conflicted_token))
{
bitset_set (actions, rule_i);
Expand Down
34 changes: 17 additions & 17 deletions src/conflicts.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ flush_shift (state *s, int token)
`--------------------------------------------------------------------*/

static void
flush_reduce (bitset lookahead_tokens, int token)
flush_reduce (bitset lookaheads, int token)
{
bitset_reset (lookahead_tokens, token);
bitset_reset (lookaheads, token);
}


Expand All @@ -275,10 +275,10 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
/* Find the rule to reduce by to get precedence of reduction. */
rule *redrule = reds->rules[ruleno];
int redprec = redrule->prec->prec;
bitset lookahead_tokens = reds->lookahead_tokens[ruleno];
bitset lookaheads = reds->lookaheads[ruleno];

for (symbol_number i = 0; i < ntokens; ++i)
if (bitset_test (lookahead_tokens, i)
if (bitset_test (lookaheads, i)
&& bitset_test (lookahead_set, i)
&& symbols[i]->content->prec)
{
Expand All @@ -295,7 +295,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
{
register_precedence (i, redrule->prec->number);
log_resolution (redrule, i, shift_resolution);
flush_reduce (lookahead_tokens, i);
flush_reduce (lookaheads, i);
}
else
/* Matching precedence levels.
Expand All @@ -316,7 +316,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
case right_assoc:
register_assoc (i, redrule->prec->number);
log_resolution (redrule, i, right_resolution);
flush_reduce (lookahead_tokens, i);
flush_reduce (lookaheads, i);
break;

case left_assoc:
Expand All @@ -329,7 +329,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
register_assoc (i, redrule->prec->number);
log_resolution (redrule, i, nonassoc_resolution);
flush_shift (s, i);
flush_reduce (lookahead_tokens, i);
flush_reduce (lookaheads, i);
/* Record an explicit error for this token. */
errors[(*nerrs)++] = symbols[i];
break;
Expand Down Expand Up @@ -369,7 +369,7 @@ set_conflicts (state *s, symbol **errors)
for (int i = 0; i < reds->num; ++i)
if (reds->rules[i]->prec
&& reds->rules[i]->prec->prec
&& !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
&& !bitset_disjoint_p (reds->lookaheads[i], lookahead_set))
resolve_sr_conflict (s, i, errors, &nerrs);

if (nerrs)
Expand All @@ -385,13 +385,13 @@ set_conflicts (state *s, symbol **errors)
/* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above.
reds->lookahead_tokens can be NULL if the LR type is LR(0). */
if (reds->lookahead_tokens)
reds->lookaheads can be NULL if the LR type is LR(0). */
if (reds->lookaheads)
for (int i = 0; i < reds->num; ++i)
{
if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
if (!bitset_disjoint_p (reds->lookaheads[i], lookahead_set))
conflicts[s->number] = true;
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
bitset_or (lookahead_set, lookahead_set, reds->lookaheads[i]);
}
}

Expand Down Expand Up @@ -460,7 +460,7 @@ count_state_sr_conflicts (const state *s)
}

for (int i = 0; i < reds->num; ++i)
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
bitset_or (lookahead_set, lookahead_set, reds->lookaheads[i]);

bitset_and (lookahead_set, lookahead_set, shift_set);

Expand Down Expand Up @@ -499,7 +499,7 @@ count_state_rr_conflicts (const state *s)
{
int count = 0;
for (int j = 0; j < reds->num; ++j)
count += bitset_test (reds->lookahead_tokens[j], i);
count += bitset_test (reds->lookaheads[j], i);
if (2 <= count)
res += count-1;
}
Expand Down Expand Up @@ -534,7 +534,7 @@ count_rule_state_sr_conflicts (rule *r, state *s)
for (int i = 0; i < reds->num; ++i)
if (reds->rules[i] == r)
{
bitset lookaheads = reds->lookahead_tokens[i];
bitset lookaheads = reds->lookaheads[i];
int j;
FOR_EACH_SHIFT (trans, j)
res += bitset_test (lookaheads, TRANSITION_SYMBOL (trans, j));
Expand Down Expand Up @@ -576,8 +576,8 @@ count_rule_state_rr_conflicts (rule *r, state *s)
if (reds->rules[j] != r)
{
bitset_and (lookaheads,
reds->lookahead_tokens[i],
reds->lookahead_tokens[j]);
reds->lookaheads[i],
reds->lookaheads[j]);
res += bitset_count (lookaheads);
}
bitset_free (lookaheads);
Expand Down
16 changes: 8 additions & 8 deletions src/counterexample.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ counterexample_report_state (const state *s, FILE *out, const char *prefix)
{
const state_number sn = s->number;
const reductions *reds = s->reductions;
bitset lookahead_tokens = bitset_create (ntokens, BITSET_FIXED);
bitset lookaheads = bitset_create (ntokens, BITSET_FIXED);
for (int i = 0; i < reds->num; ++i)
{
const rule *r1 = reds->rules[i];
Expand All @@ -1296,25 +1296,25 @@ counterexample_report_state (const state *s, FILE *out, const char *prefix)
{
item_number conf = *state_items[c2].item;
if (item_number_is_symbol_number (conf)
&& bitset_test (reds->lookahead_tokens[i], conf))
&& bitset_test (reds->lookaheads[i], conf))
counterexample_report_shift_reduce (c1, c2, conf, out, prefix);
}
for (int j = i+1; j < reds->num; ++j)
{
const rule *r2 = reds->rules[j];
// Conflicts: common lookaheads.
bitset_intersection (lookahead_tokens,
reds->lookahead_tokens[i],
reds->lookahead_tokens[j]);
if (!bitset_empty_p (lookahead_tokens))
bitset_intersection (lookaheads,
reds->lookaheads[i],
reds->lookaheads[j]);
if (!bitset_empty_p (lookaheads))
for (state_item_number c2 = state_item_map[sn]; c2 < state_item_map[sn + 1]; ++c2)
if (!SI_DISABLED (c2)
&& item_rule (state_items[c2].item) == r2)
{
counterexample_report_reduce_reduce (c1, c2, lookahead_tokens, out, prefix);
counterexample_report_reduce_reduce (c1, c2, lookaheads, out, prefix);
break;
}
}
}
bitset_free (lookahead_tokens);
bitset_free (lookaheads);
}
2 changes: 1 addition & 1 deletion src/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static const argmatch_report_arg argmatch_report_args[] =
{ "none", report_none },
{ "states", report_states },
{ "itemsets", report_states | report_itemsets },
{ "lookaheads", report_states | report_lookahead_tokens },
{ "lookaheads", report_states | report_lookaheads },
{ "solved", report_states | report_solved_conflicts },
{ "counterexamples", report_cex },
{ "cex", report_cex },
Expand Down
2 changes: 1 addition & 1 deletion src/getargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum report
report_none = 0,
report_states = 1 << 0,
report_itemsets = 1 << 1,
report_lookahead_tokens = 1 << 2,
report_lookaheads = 1 << 2,
report_solved_conflicts = 1 << 3,
report_cex = 1 << 4,
report_all = ~0
Expand Down
4 changes: 2 additions & 2 deletions src/graphviz.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ output_red (state const *s, reductions const *reds, FILE *fout)
bool firste = true;
rule_number ruleno = reds->rules[j]->number;

if (reds->lookahead_tokens)
if (reds->lookaheads)
for (int i = 0; i < ntokens; i++)
if (bitset_test (reds->lookahead_tokens[j], i))
if (bitset_test (reds->lookaheads[j], i))
{
if (bitset_test (no_reduce_set, i))
firstd = print_token (&dout, firstd, symbols[i]->tag);
Expand Down
2 changes: 1 addition & 1 deletion src/ielr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows,
{
rule *this_rule = node->state->reductions->rules[r];
bitset lookahead_set =
node->state->reductions->lookahead_tokens[r];
node->state->reductions->lookaheads[r];
if (item_number_is_rule_number (*this_rule->rhs))
ielr_compute_goto_follow_set (follow_kernel_items,
always_follows, node,
Expand Down
51 changes: 24 additions & 27 deletions src/lalr.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ lookback_find_state (int lookback_index)
state *res = NULL;
for (int j = 0; j < nstates; ++j)
if (states[j]->reductions
&& states[j]->reductions->lookahead_tokens)
&& states[j]->reductions->lookaheads)
{
if (states[j]->reductions->lookahead_tokens - LA > lookback_index)
if (states[j]->reductions->lookaheads - LA > lookback_index)
/* Went too far. */
break;
else
Expand All @@ -280,7 +280,7 @@ lookback_print (FILE *out)
{
fprintf (out, " %3d = ", i);
const state *s = lookback_find_state (i);
int rnum = i - (s->reductions->lookahead_tokens - LA);
int rnum = i - (s->reductions->lookaheads - LA);
const rule *r = s->reductions->rules[rnum];
fprintf (out, "(%3d, ", s->number);
rule_print (r, NULL, out);
Expand All @@ -305,7 +305,7 @@ static void
add_lookback_edge (state *s, rule const *r, goto_number gotono)
{
int ri = state_reduction_find (s, r);
int idx = (s->reductions->lookahead_tokens - LA) + ri;
int idx = (s->reductions->lookaheads - LA) + ri;
lookback[idx] = goto_list_new (gotono, lookback[idx]);
}

Expand Down Expand Up @@ -421,7 +421,7 @@ compute_follows (void)


static void
compute_lookahead_tokens (void)
compute_lookaheads (void)
{
if (trace_flag & trace_automaton)
lookback_print (stderr);
Expand All @@ -437,13 +437,12 @@ compute_lookahead_tokens (void)
}


/*----------------------------------------------------.
| Count the number of lookahead tokens required for S |
| (N_LOOKAHEAD_TOKENS member). |
`----------------------------------------------------*/
/*------------------------------------------------------.
| Count the number of lookahead tokens required for S. |
`------------------------------------------------------*/

static int
state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
state_lookaheads_count (state *s, bool default_reduction_only_for_accept)
{
const reductions *reds = s->reductions;
const transitions *trans = s->transitions;
Expand Down Expand Up @@ -473,9 +472,9 @@ state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
}


/*----------------------------------------------------.
| Compute LA, NLA, and the lookahead_tokens members. |
`----------------------------------------------------*/
/*----------------------------------------------.
| Compute LA, NLA, and the lookaheads members. |
`----------------------------------------------*/

void
initialize_LA (void)
Expand All @@ -491,25 +490,23 @@ initialize_LA (void)
/* Compute the total number of reductions requiring a lookahead. */
nLA = 0;
for (state_number i = 0; i < nstates; ++i)
nLA +=
state_lookahead_tokens_count (states[i],
default_reduction_only_for_accept);
nLA += state_lookaheads_count (states[i],
default_reduction_only_for_accept);
/* Avoid having to special case 0. */
if (!nLA)
nLA = 1;

bitsetv pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);

/* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
/* Initialize the members LOOKAHEADS for each state whose reductions
require lookahead tokens. */
for (state_number i = 0; i < nstates; ++i)
{
int count =
state_lookahead_tokens_count (states[i],
default_reduction_only_for_accept);
int count = state_lookaheads_count (states[i],
default_reduction_only_for_accept);
if (count)
{
states[i]->reductions->lookahead_tokens = pLA;
states[i]->reductions->lookaheads = pLA;
pLA += count;
}
}
Expand All @@ -521,7 +518,7 @@ initialize_LA (void)
`---------------------------------------------*/

static void
lookahead_tokens_print (FILE *out)
lookaheads_print (FILE *out)
{
fputs ("Lookaheads:\n", out);
for (state_number i = 0; i < nstates; ++i)
Expand All @@ -533,11 +530,11 @@ lookahead_tokens_print (FILE *out)
for (int j = 0; j < reds->num; ++j)
{
fprintf (out, " rule %d:", reds->rules[j]->number);
if (reds->lookahead_tokens)
if (reds->lookaheads)
{
bitset_iterator iter;
int k;
BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0)
BITSET_FOR_EACH (iter, reds->lookaheads[j], k, 0)
fprintf (out, " %s", symbols[k]->tag);
}
fputc ('\n', out);
Expand All @@ -564,10 +561,10 @@ lalr (void)
lookback = xcalloc (nLA, sizeof *lookback);
build_relations ();
compute_follows ();
compute_lookahead_tokens ();
compute_lookaheads ();

if (trace_flag & trace_sets)
lookahead_tokens_print (stderr);
lookaheads_print (stderr);
if (trace_flag & trace_automaton)
{
begin_use_class ("trace0", stderr);
Expand Down Expand Up @@ -614,6 +611,6 @@ void
lalr_free (void)
{
for (state_number s = 0; s < nstates; ++s)
states[s]->reductions->lookahead_tokens = NULL;
states[s]->reductions->lookaheads = NULL;
bitsetv_free (LA);
}
Loading

0 comments on commit 577f594

Please sign in to comment.