style: reduce scopes in graphviz.c

This commit is contained in:
Akim Demaille
2018-09-15 07:18:45 +02:00
parent 46532a9d3b
commit 6cc69f4d14

View File

@@ -87,12 +87,14 @@ escape (char const *name)
static void static void
no_reduce_bitset_init (state const *s, bitset *no_reduce_set) no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
{ {
int n;
*no_reduce_set = bitset_create (ntokens, BITSET_FIXED); *no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
bitset_zero (*no_reduce_set); bitset_zero (*no_reduce_set);
FOR_EACH_SHIFT (s->transitions, n) {
bitset_set (*no_reduce_set, TRANSITION_SYMBOL (s->transitions, n)); int n;
for (n = 0; n < s->errs->num; ++n) FOR_EACH_SHIFT (s->transitions, n)
bitset_set (*no_reduce_set, TRANSITION_SYMBOL (s->transitions, n));
}
for (int n = 0; n < s->errs->num; ++n)
if (s->errs->symbols[n]) if (s->errs->symbols[n])
bitset_set (*no_reduce_set, s->errs->symbols[n]->content->number); bitset_set (*no_reduce_set, s->errs->symbols[n]->content->number);
} }
@@ -145,11 +147,9 @@ conclude_red (struct obstack *out, int source, rule_number ruleno,
static bool static bool
print_token (struct obstack *out, bool first, char const *tok) print_token (struct obstack *out, bool first, char const *tok)
{ {
char const *q = escape (tok);
if (! first) if (! first)
obstack_sgrow (out, ", "); obstack_sgrow (out, ", ");
obstack_sgrow (out, q); obstack_sgrow (out, escape (tok));
return false; return false;
} }
@@ -157,8 +157,7 @@ void
output_red (state const *s, reductions const *reds, FILE *fout) output_red (state const *s, reductions const *reds, FILE *fout)
{ {
bitset no_reduce_set; bitset no_reduce_set;
int j; no_reduce_bitset_init (s, &no_reduce_set);
int source = s->number;
/* Two obstacks are needed: one for the enabled reductions, and one /* Two obstacks are needed: one for the enabled reductions, and one
for the disabled reductions, because in the end we want two for the disabled reductions, because in the end we want two
@@ -166,42 +165,38 @@ output_red (state const *s, reductions const *reds, FILE *fout)
be printed. */ be printed. */
struct obstack dout; struct obstack dout;
struct obstack eout; struct obstack eout;
no_reduce_bitset_init (s, &no_reduce_set);
obstack_init (&dout); obstack_init (&dout);
obstack_init (&eout); obstack_init (&eout);
for (j = 0; j < reds->num; ++j) const int source = s->number;
for (int j = 0; j < reds->num; ++j)
{ {
bool defaulted = false; rule *default_reduction =
bool firstd = true; yydefact[s->number]
bool firste = true; ? &rules[yydefact[s->number] - 1]
rule_number ruleno = reds->rules[j]->number; : NULL;
rule *default_reduction = NULL;
if (yydefact[s->number] != 0) bool defaulted = default_reduction && default_reduction == reds->rules[j];
default_reduction = &rules[yydefact[s->number] - 1];
/* Build the lookahead tokens lists, one for enabled transitions and one /* Build the lookahead tokens lists, one for enabled transitions and one
for disabled transistions. */ for disabled transistions. */
if (default_reduction && default_reduction == reds->rules[j]) bool firstd = true;
defaulted = true; bool firste = true;
rule_number ruleno = reds->rules[j]->number;
if (reds->lookahead_tokens) if (reds->lookahead_tokens)
{ for (int i = 0; i < ntokens; i++)
int i; if (bitset_test (reds->lookahead_tokens[j], i))
for (i = 0; i < ntokens; i++) {
if (bitset_test (reds->lookahead_tokens[j], i)) if (bitset_test (no_reduce_set, i))
{ firstd = print_token (&dout, firstd, symbols[i]->tag);
if (bitset_test (no_reduce_set, i)) else
firstd = print_token (&dout, firstd, symbols[i]->tag); {
else if (! defaulted)
{ firste = print_token (&eout, firste, symbols[i]->tag);
if (! defaulted) bitset_set (no_reduce_set, i);
firste = print_token (&eout, firste, symbols[i]->tag); }
bitset_set (no_reduce_set, i); }
}
}
}
/* Do the actual output. */ /* Do the actual output. */
conclude_red (&dout, source, ruleno, false, firstd, fout); conclude_red (&dout, source, ruleno, false, firstd, fout);