aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/bison/src/AnnotationList.c
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
commitfc7be18c76af2e700641f3598c4856baeef1428e (patch)
tree11dbca45eb321c3a4dd08b12152acc6ef5dd3fa9 /contrib/tools/bison/src/AnnotationList.c
parentec0e7ed6da6fb317741fd8468602949a1362eca5 (diff)
parentc92cb9d3a19331916f0c274d80e67f02a62caa9b (diff)
downloadydb-fc7be18c76af2e700641f3598c4856baeef1428e.tar.gz
Merge branch 'rightlib' into mergelibs-240708-1553
Diffstat (limited to 'contrib/tools/bison/src/AnnotationList.c')
-rw-r--r--contrib/tools/bison/src/AnnotationList.c174
1 files changed, 77 insertions, 97 deletions
diff --git a/contrib/tools/bison/src/AnnotationList.c b/contrib/tools/bison/src/AnnotationList.c
index b14c675b8f..4e29127c57 100644
--- a/contrib/tools/bison/src/AnnotationList.c
+++ b/contrib/tools/bison/src/AnnotationList.c
@@ -1,6 +1,6 @@
/* IELR's inadequacy annotation list.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
+ Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
@@ -168,10 +168,9 @@ AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
bitset conflicted_tokens = bitset_create (ntokens, BITSET_FIXED);
bitset conflicted_tokens_rule = bitset_create (ntokens, BITSET_FIXED);
bitset tokens = bitset_create (ntokens, BITSET_FIXED);
- int i;
bitset_copy (tokens, shift_tokens);
- for (i = 0; i < reds->num; ++i)
+ for (int i = 0; i < reds->num; ++i)
{
bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]);
bitset_or (conflicted_tokens,
@@ -215,20 +214,17 @@ AnnotationList__compute_lhs_contributions (state *s, rule *the_rule,
}
static void
-AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
- bitsetv follow_kernel_items,
- bitsetv always_follows,
- state ***predecessors,
- bitset **item_lookahead_sets,
- AnnotationList
- **annotation_lists,
- AnnotationIndex
- *annotation_counts,
- struct obstack
- *annotations_obstackp)
+AnnotationList__computePredecessorAnnotations (
+ AnnotationList *self, state *s,
+ bitsetv follow_kernel_items,
+ bitsetv always_follows,
+ state ***predecessors,
+ bitset **item_lookahead_sets,
+ AnnotationList **annotation_lists,
+ AnnotationIndex *annotation_counts,
+ struct obstack *annotations_obstackp)
{
- state **predecessor;
- for (predecessor = predecessors[s->number]; *predecessor; ++predecessor)
+ for (state **predecessor = predecessors[s->number]; *predecessor; ++predecessor)
{
AnnotationList *annotation_node =
AnnotationList__alloc_on_obstack (
@@ -237,12 +233,11 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
bool potential_contribution = false;
bitset *lookaheads = NULL;
{
- ContributionIndex ci;
- for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
+ for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
{
symbol_number contribution_token =
InadequacyList__getContributionToken (self->inadequacyNode, ci)
- ->number;
+ ->content->number;
if (AnnotationList__isContributionAlways (self, ci))
{
annotation_node->contributions[ci] = NULL;
@@ -274,12 +269,12 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
if (item_number_is_rule_number (ritem[s->items[self_item]
- 2]))
{
- Sbitset items;
- unsigned int rulei;
+ unsigned rulei;
for (rulei = s->items[self_item];
!item_number_is_rule_number (ritem[rulei]);
++rulei)
- ;
+ continue;
+ Sbitset items;
if (AnnotationList__compute_lhs_contributions (
*predecessor,
&rules[item_number_as_rule_number (ritem[rulei])],
@@ -334,10 +329,9 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
potential_contribution = true;
if (!lookaheads)
{
- size_t j;
lookaheads = xnmalloc ((*predecessor)->nitems,
sizeof *lookaheads);
- for (j = 0; j < (*predecessor)->nitems; ++j)
+ for (size_t j = 0; j < (*predecessor)->nitems; ++j)
lookaheads[j] = NULL;
}
if (!lookaheads[i])
@@ -377,8 +371,7 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
annotation_node = NULL;
}
{
- size_t i;
- for (i = 0; i < (*predecessor)->nitems; ++i)
+ for (size_t i = 0; i < (*predecessor)->nitems; ++i)
if (lookaheads[i])
bitset_free (lookaheads[i]);
free (lookaheads);
@@ -416,23 +409,19 @@ AnnotationList__compute_from_inadequacies (
struct obstack *annotations_obstackp,
InadequacyListNodeCount *inadequacy_list_node_count)
{
- bitsetv all_lookaheads;
- bitset shift_tokens;
- bitset conflicted_tokens;
- bitset_iterator biter_conflict;
- bitset_bindex conflicted_token;
-
/* Return an empty list if s->lookahead_tokens = NULL. */
if (s->consistent)
return;
- all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED);
+ bitsetv all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED);
bitsetv_ones (all_lookaheads);
- shift_tokens = AnnotationList__compute_shift_tokens (s->transitions);
- conflicted_tokens =
+ bitset shift_tokens = AnnotationList__compute_shift_tokens (s->transitions);
+ bitset conflicted_tokens =
AnnotationList__compute_conflicted_tokens (shift_tokens, s->reductions);
/* Add an inadequacy annotation for each conflicted_token. */
+ bitset_iterator biter_conflict;
+ bitset_bindex conflicted_token;
BITSET_FOR_EACH (biter_conflict, conflicted_tokens, conflicted_token, 0)
{
AnnotationList *annotation_node;
@@ -444,8 +433,7 @@ AnnotationList__compute_from_inadequacies (
/* Allocate the annotation node. */
{
- int rule_i;
- for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
+ for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
if (bitset_test (s->reductions->lookahead_tokens[rule_i],
conflicted_token))
++contribution_count;
@@ -461,8 +449,7 @@ AnnotationList__compute_from_inadequacies (
{
ContributionIndex ci = 0;
int item_i = 0;
- int rule_i;
- for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
+ 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],
@@ -541,15 +528,19 @@ AnnotationList__compute_from_inadequacies (
{
InadequacyList__prependTo (conflict_node,
&inadequacy_lists[s->number]);
- aver (AnnotationList__insertInto (
- annotation_node, &annotation_lists[s->number],
- s->nitems));
+ {
+ bool b =
+ AnnotationList__insertInto (annotation_node,
+ &annotation_lists[s->number],
+ s->nitems);
+ aver (b); (void) b;
+ }
/* This aver makes sure the
AnnotationList__computeDominantContribution check above
does discard annotations in the simplest case of a S/R
conflict with no token precedence. */
aver (!bitset_test (shift_tokens, conflicted_token)
- || symbols[conflicted_token]->prec);
+ || symbols[conflicted_token]->content->prec);
++annotation_counts[s->number];
if (contribution_count > *max_contributionsp)
*max_contributionsp = contribution_count;
@@ -580,27 +571,20 @@ AnnotationList__debug (AnnotationList const *self, size_t nitems, int spaces)
AnnotationIndex ai;
for (a = self, ai = 0; a; a = a->next, ++ai)
{
- {
- int j;
- for (j = 0; j < spaces; ++j)
- putc (' ', stderr);
- }
+ for (int j = 0; j < spaces; ++j)
+ putc (' ', stderr);
fprintf (stderr, "Annotation %d (manifesting state %d):\n",
ai, a->inadequacyNode->manifestingState->number);
{
- ContributionIndex ci;
- bitset_bindex rulei = 0; /* init suppresses compiler warning */
- rulei = bitset_first (a->inadequacyNode->inadequacy.conflict.actions);
- for (ci = 0; ci < a->inadequacyNode->contributionCount; ++ci)
+ bitset_bindex rulei
+ = bitset_first (a->inadequacyNode->inadequacy.conflict.actions);
+ for (ContributionIndex ci = 0; ci < a->inadequacyNode->contributionCount; ++ci)
{
symbol_number token =
InadequacyList__getContributionToken (a->inadequacyNode, ci)
- ->number;
- {
- int j;
- for (j = 0; j < spaces+2; ++j)
- putc (' ', stderr);
- }
+ ->content->number;
+ for (int j = 0; j < spaces+2; ++j)
+ putc (' ', stderr);
if (ci == InadequacyList__getShiftContributionIndex (
a->inadequacyNode))
fprintf (stderr, "Contributes shift of token %d.\n", token);
@@ -635,20 +619,17 @@ AnnotationList__computeLookaheadFilter (AnnotationList const *self,
{
bitsetv_zero (lookahead_filter);
for (; self; self = self->next)
- {
- ContributionIndex ci;
- for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
- if (!AnnotationList__isContributionAlways (self, ci))
- {
- Sbitset__Index item;
- Sbitset biter;
- symbol_number token =
- InadequacyList__getContributionToken (self->inadequacyNode, ci)
- ->number;
- SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
- bitset_set (lookahead_filter[item], token);
- }
- }
+ for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
+ if (!AnnotationList__isContributionAlways (self, ci))
+ {
+ symbol_number token =
+ InadequacyList__getContributionToken (self->inadequacyNode, ci)
+ ->content->number;
+ Sbitset__Index item;
+ Sbitset biter;
+ SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
+ bitset_set (lookahead_filter[item], token);
+ }
}
/**
@@ -679,7 +660,8 @@ AnnotationList__stateMakesContribution (AnnotationList const *self,
return false;
{
symbol_number token =
- InadequacyList__getContributionToken (self->inadequacyNode, ci)->number;
+ InadequacyList__getContributionToken (self->inadequacyNode, ci)
+ ->content->number;
Sbitset__Index item;
Sbitset biter;
SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
@@ -694,11 +676,10 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
size_t nitems, bitset *lookaheads,
bool require_split_stable)
{
- symbol *token;
ContributionIndex const ci_shift =
InadequacyList__getShiftContributionIndex (self->inadequacyNode);
- token = self->inadequacyNode->inadequacy.conflict.token;
+ symbol *token = self->inadequacyNode->inadequacy.conflict.token;
/* S/R conflict. */
if (ci_shift != ContributionIndex__none)
@@ -706,10 +687,7 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
bool find_stable_domination_over_shift = false;
bool find_stable_error_action_domination = false;
{
- ContributionIndex ci;
- int actioni;
- ContributionIndex ci_rr_dominator = ContributionIndex__none;
- int shift_precedence = token->prec;
+ int shift_precedence = token->content->prec;
/* If the token has no precedence set, shift is always chosen. */
if (!shift_precedence)
@@ -718,11 +696,16 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
/* Figure out which reductions contribute, which of those would
dominate in a R/R comparison, and whether any reduction dominates
the shift so that the R/R comparison is actually needed. */
- for (ci = 0, actioni = bitset_first (self->inadequacyNode->inadequacy
- .conflict.actions);
+ ContributionIndex ci_rr_dominator = ContributionIndex__none;
+ int actioni;
+ ContributionIndex ci;
+ for (ci = 0,
+ actioni = bitset_first (self->inadequacyNode->inadequacy
+ .conflict.actions);
ci < self->inadequacyNode->contributionCount;
- ++ci, actioni = bitset_next (self->inadequacyNode->inadequacy
- .conflict.actions, actioni+1))
+ ++ci,
+ actioni = bitset_next (self->inadequacyNode->inadequacy
+ .conflict.actions, actioni+1))
{
int reduce_precedence = 0;
if (ci == ci_shift)
@@ -739,7 +722,7 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
if (reduce_precedence
&& (reduce_precedence < shift_precedence
|| (reduce_precedence == shift_precedence
- && token->assoc == right_assoc)))
+ && token->content->assoc == right_assoc)))
continue;
if (!AnnotationList__stateMakesContribution (self, nitems, ci,
lookaheads))
@@ -747,7 +730,7 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
/* This uneliminated reduction contributes, so see if it can cause
an error action. */
if (reduce_precedence == shift_precedence
- && token->assoc == non_assoc)
+ && token->content->assoc == non_assoc)
{
/* It's not possible to find split-stable domination over
shift after a potential %nonassoc. */
@@ -791,17 +774,14 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
/* R/R conflict, so the reduction with the lowest rule number dominates.
Fortunately, contributions are sorted by rule number. */
- {
- ContributionIndex ci;
- for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
- if (AnnotationList__stateMakesContribution (self, nitems, ci,
- lookaheads))
- {
- if (require_split_stable
- && !AnnotationList__isContributionAlways (self, ci))
- return ContributionIndex__none;
- return ci;
- }
- }
+ for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
+ if (AnnotationList__stateMakesContribution (self, nitems, ci,
+ lookaheads))
+ {
+ if (require_split_stable
+ && !AnnotationList__isContributionAlways (self, ci))
+ return ContributionIndex__none;
+ return ci;
+ }
return ContributionIndex__none;
}