We spend a lot of time in quotearg, in particular when --verbose.

* src/symtab.c (symbol_get): Store a quoted version of the key.
(symbol_tag_get, symbol_tag_get_n, symbol_tag_print): Remove.
Adjust all callers.
This commit is contained in:
Akim Demaille
2002-06-30 17:34:52 +00:00
parent d257636504
commit 97650f4efc
15 changed files with 74 additions and 109 deletions

View File

@@ -1,3 +1,12 @@
2002-06-30 Akim Demaille <akim@epita.fr>
We spend a lot of time in quotearg, in particular when --verbose.
* src/symtab.c (symbol_get): Store a quoted version of the key.
(symbol_tag_get, symbol_tag_get_n, symbol_tag_print): Remove.
Adjust all callers.
2002-06-30 Akim Demaille <akim@epita.fr> 2002-06-30 Akim Demaille <akim@epita.fr>
* src/state.h (reductions_t): Rename member `nreds' as num. * src/state.h (reductions_t): Rename member `nreds' as num.

View File

@@ -196,7 +196,7 @@ new_state (symbol_number_t symbol, size_t core_size, item_number_t *core)
if (trace_flag) if (trace_flag)
fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n", fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n",
nstates, symbol, symbol_tag_get (symbols[symbol])); nstates, symbol, symbols[symbol]->tag);
res = state_new (symbol, core_size, core); res = state_new (symbol, core_size, core);
state_hash_insert (res); state_hash_insert (res);
@@ -224,7 +224,7 @@ get_state (symbol_number_t symbol, size_t core_size, item_number_t *core)
if (trace_flag) if (trace_flag)
fprintf (stderr, "Entering get_state, symbol = %d (%s)\n", fprintf (stderr, "Entering get_state, symbol = %d (%s)\n",
symbol, symbol_tag_get (symbols[symbol])); symbol, symbols[symbol]->tag);
sp = state_hash_lookup (core_size, core); sp = state_hash_lookup (core_size, core);
if (!sp) if (!sp)
@@ -372,7 +372,7 @@ generate_states (void)
if (trace_flag) if (trace_flag)
fprintf (stderr, "Processing state %d (reached by %s)\n", fprintf (stderr, "Processing state %d (reached by %s)\n",
state->number, state->number,
symbol_tag_get (symbols[state->accessing_symbol])); symbols[state->accessing_symbol]->tag);
/* Set up ruleset and itemset for the transitions out of this /* Set up ruleset and itemset for the transitions out of this
state. ruleset gets a 1 bit for each rule that could reduce state. ruleset gets a 1 bit for each rule that could reduce
now. itemset gets a vector of all the items that could be now. itemset gets a vector of all the items that could be

View File

@@ -59,7 +59,7 @@ print_closure (const char *title, item_number_t *array, size_t size)
item_number_t *rp; item_number_t *rp;
fprintf (stderr, " %2d: .", array[i]); fprintf (stderr, " %2d: .", array[i]);
for (rp = &ritem[array[i]]; *rp >= 0; ++rp) for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
fprintf (stderr, " %s", symbol_tag_get (symbols[*rp])); fprintf (stderr, " %s", symbols[*rp]->tag);
fprintf (stderr, " (rule %d)\n", -*rp - 1); fprintf (stderr, " (rule %d)\n", -*rp - 1);
} }
fputs ("\n\n", stderr); fputs ("\n\n", stderr);
@@ -74,11 +74,11 @@ print_firsts (void)
fprintf (stderr, "FIRSTS\n"); fprintf (stderr, "FIRSTS\n");
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
fprintf (stderr, "\t%s firsts\n", symbol_tag_get (symbols[i])); fprintf (stderr, "\t%s firsts\n", symbols[i]->tag);
BITSET_EXECUTE (FIRSTS (i), 0, j, BITSET_EXECUTE (FIRSTS (i), 0, j,
{ {
fprintf (stderr, "\t\t%s\n", fprintf (stderr, "\t\t%s\n",
symbol_tag_get (symbols[j + ntokens])); symbols[j + ntokens]->tag);
}); });
} }
fprintf (stderr, "\n\n"); fprintf (stderr, "\n\n");
@@ -94,13 +94,13 @@ print_fderives (void)
fprintf (stderr, "FDERIVES\n"); fprintf (stderr, "FDERIVES\n");
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
fprintf (stderr, "\t%s derives\n", symbol_tag_get (symbols[i])); fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
BITSET_EXECUTE (FDERIVES (i), 0, r, BITSET_EXECUTE (FDERIVES (i), 0, r,
{ {
item_number_t *rhsp = NULL; item_number_t *rhsp = NULL;
fprintf (stderr, "\t\t%d:", r - 1); fprintf (stderr, "\t\t%d:", r - 1);
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
fprintf (stderr, " %s", symbol_tag_get (symbols[*rhsp])); fprintf (stderr, " %s", symbols[*rhsp]->tag);
fputc ('\n', stderr); fputc ('\n', stderr);
}); });
} }

View File

@@ -45,7 +45,7 @@ print_derives (void)
item_number_t *rhsp; item_number_t *rhsp;
fprintf (stderr, "\t\t%d:", *rp); fprintf (stderr, "\t\t%d:", *rp);
for (rhsp = rules[*rp].rhs; *rhsp >= 0; ++rhsp) for (rhsp = rules[*rp].rhs; *rhsp >= 0; ++rhsp)
fprintf (stderr, " %s", symbol_tag_get (symbols[*rhsp])); fprintf (stderr, " %s", symbols[*rhsp]->tag);
fprintf (stderr, " (rule %d)\n", fprintf (stderr, " (rule %d)\n",
rule_number_of_item_number (*rhsp) - 1); rule_number_of_item_number (*rhsp) - 1);
} }

View File

@@ -59,12 +59,12 @@ rule_lhs_print (rule_t *rule, symbol_t *previous_lhs, FILE *out)
fprintf (out, " %3d ", rule->number - 1); fprintf (out, " %3d ", rule->number - 1);
if (previous_lhs != rule->lhs) if (previous_lhs != rule->lhs)
{ {
fprintf (out, "%s:", symbol_tag_get (rule->lhs)); fprintf (out, "%s:", rule->lhs->tag);
} }
else else
{ {
int n; int n;
for (n = strlen (symbol_tag_get (previous_lhs)); n > 0; --n) for (n = strlen (previous_lhs->tag); n > 0; --n)
fputc (' ', out); fputc (' ', out);
fputc ('|', out); fputc ('|', out);
} }
@@ -97,7 +97,7 @@ rule_rhs_print (rule_t *rule, FILE *out)
{ {
item_number_t *r; item_number_t *r;
for (r = rule->rhs; *r >= 0; r++) for (r = rule->rhs; *r >= 0; r++)
fprintf (out, " %s", symbol_tag_get (symbols[*r])); fprintf (out, " %s", symbols[*r]->tag);
fputc ('\n', out); fputc ('\n', out);
} }
else else
@@ -114,7 +114,7 @@ rule_rhs_print (rule_t *rule, FILE *out)
void void
rule_print (rule_t *rule, FILE *out) rule_print (rule_t *rule, FILE *out)
{ {
fprintf (out, "%s:", symbol_tag_get (rule->lhs)); fprintf (out, "%s:", rule->lhs->tag);
rule_rhs_print (rule, out); rule_rhs_print (rule, out);
} }
@@ -130,7 +130,7 @@ ritem_print (FILE *out)
fputs ("RITEM\n", out); fputs ("RITEM\n", out);
for (i = 0; i < nritems; ++i) for (i = 0; i < nritems; ++i)
if (ritem[i] >= 0) if (ritem[i] >= 0)
fprintf (out, " %s", symbol_tag_get (symbols[ritem[i]])); fprintf (out, " %s", symbols[ritem[i]]->tag);
else else
fprintf (out, " (rule %d)\n", -ritem[i] - 1); fprintf (out, " (rule %d)\n", -ritem[i] - 1);
fputs ("\n\n", out); fputs ("\n\n", out);
@@ -217,7 +217,7 @@ grammar_dump (FILE *out, const char *title)
fprintf (out, "%5d %5d %5d %s\n", fprintf (out, "%5d %5d %5d %s\n",
i, i,
symbols[i]->prec, symbols[i]->assoc, symbols[i]->prec, symbols[i]->assoc,
symbol_tag_get (symbols[i])); symbols[i]->tag);
fprintf (out, "\n\n"); fprintf (out, "\n\n");
} }

View File

@@ -427,7 +427,7 @@ lookaheads_print (FILE *out)
BITSET_EXECUTE (states[i]->lookaheads[j], 0, k, BITSET_EXECUTE (states[i]->lookaheads[j], 0, k,
{ {
fprintf (out, " on %d (%s) -> rule %d\n", fprintf (out, " on %d (%s) -> rule %d\n",
k, symbol_tag_get (symbols[k]), k, symbols[k]->tag,
states[i]->lookaheads_rule[j]->number - 1); states[i]->lookaheads_rule[j]->number - 1);
}); });
} }

View File

@@ -249,7 +249,7 @@ prepare_tokens (void)
SYMBOL_TAG_GET uses slot 0. */ SYMBOL_TAG_GET uses slot 0. */
const char *cp = const char *cp =
quotearg_n_style (1, c_quoting_style, quotearg_n_style (1, c_quoting_style,
symbol_tag_get (symbols[i])); symbols[i]->tag);
/* Width of the next token, including the two quotes, the coma /* Width of the next token, including the two quotes, the coma
and the space. */ and the space. */
int strsize = strlen (cp) + 2; int strsize = strlen (cp) + 2;
@@ -745,7 +745,7 @@ symbol_destructors_output (FILE *out)
fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]", fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
first ? "" : ",\n", first ? "" : ",\n",
infile, symbol->destructor_location.first_line, infile, symbol->destructor_location.first_line,
symbol_tag_get (symbol), symbol->tag,
symbol->number, symbol->number,
symbol->destructor, symbol->destructor,
symbol->type_name); symbol->type_name);
@@ -778,7 +778,7 @@ symbol_printers_output (FILE *out)
fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]", fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
first ? "" : ",\n", first ? "" : ",\n",
infile, symbol->printer_location.first_line, infile, symbol->printer_location.first_line,
symbol_tag_get (symbol), symbol->tag,
symbol->number, symbol->number,
symbol->printer, symbol->printer,
symbol->type_name); symbol->type_name);
@@ -1196,9 +1196,9 @@ m4_invoke (const char *definitions)
if (!skel_in) if (!skel_in)
error (EXIT_FAILURE, errno, "cannot run m4"); error (EXIT_FAILURE, errno, "cannot run m4");
skel_lex (); skel_lex ();
} }
/*---------------------------. /*---------------------------.
| Call the skeleton parser. | | Call the skeleton parser. |
`---------------------------*/ `---------------------------*/

View File

@@ -103,10 +103,10 @@ print_core (FILE *out, state_t *state)
previous_lhs = rules[rule].lhs; previous_lhs = rules[rule].lhs;
for (sp = rules[rule].rhs; sp < sp1; sp++) for (sp = rules[rule].rhs; sp < sp1; sp++)
fprintf (out, " %s", symbol_tag_get (symbols[*sp])); fprintf (out, " %s", symbols[*sp]->tag);
fputs (" .", out); fputs (" .", out);
for (/* Nothing */; *sp >= 0; ++sp) for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", symbol_tag_get (symbols[*sp])); fprintf (out, " %s", symbols[*sp]->tag);
/* Display the lookaheads? */ /* Display the lookaheads? */
if (report_flag & report_lookaheads) if (report_flag & report_lookaheads)
@@ -135,7 +135,7 @@ print_transitions (state_t *state, FILE *out, bool display_transitions_p)
&& TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p) && TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p)
{ {
symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)]; symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)];
max_length (&width, symbol_tag_get (symbol)); max_length (&width, symbol->tag);
} }
/* Nothing to report. */ /* Nothing to report. */
@@ -151,7 +151,7 @@ print_transitions (state_t *state, FILE *out, bool display_transitions_p)
&& TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p) && TRANSITION_IS_SHIFT (transitions, i) == display_transitions_p)
{ {
symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)]; symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)];
const char *tag = symbol_tag_get (symbol); const char *tag = symbol->tag;
state_number_t state1 = transitions->states[i]; state_number_t state1 = transitions->states[i];
int j; int j;
@@ -180,7 +180,7 @@ print_errs (FILE *out, state_t *state)
/* Compute the width of the lookaheads column. */ /* Compute the width of the lookaheads column. */
for (i = 0; i < errp->num; ++i) for (i = 0; i < errp->num; ++i)
if (errp->symbols[i]) if (errp->symbols[i])
max_length (&width, symbol_tag_get (symbols[errp->symbols[i]])); max_length (&width, symbols[errp->symbols[i]]->tag);
/* Nothing to report. */ /* Nothing to report. */
if (!width) if (!width)
@@ -193,7 +193,7 @@ print_errs (FILE *out, state_t *state)
for (i = 0; i < errp->num; ++i) for (i = 0; i < errp->num; ++i)
if (errp->symbols[i]) if (errp->symbols[i])
{ {
const char *tag = symbol_tag_get (symbols[errp->symbols[i]]); const char *tag = symbols[errp->symbols[i]]->tag;
int j; int j;
fprintf (out, " %s", tag); fprintf (out, " %s", tag);
for (j = width - strlen (tag); j > 0; --j) for (j = width - strlen (tag); j > 0; --j)
@@ -288,7 +288,7 @@ print_reduction (FILE *out, size_t width,
if (!enabled) if (!enabled)
fputc ('[', out); fputc ('[', out);
fprintf (out, _("reduce using rule %d (%s)"), fprintf (out, _("reduce using rule %d (%s)"),
rule->number - 1, symbol_tag_get (rule->lhs)); rule->number - 1, rule->lhs->tag);
if (!enabled) if (!enabled)
fputc (']', out); fputc (']', out);
fputc ('\n', out); fputc ('\n', out);
@@ -331,12 +331,12 @@ print_reductions (FILE *out, state_t *state)
if (count == 0) if (count == 0)
{ {
if (state->lookaheads_rule[j] != default_rule) if (state->lookaheads_rule[j] != default_rule)
max_length (&width, symbol_tag_get (symbols[i])); max_length (&width, symbols[i]->tag);
count++; count++;
} }
else else
{ {
max_length (&width, symbol_tag_get (symbols[i])); max_length (&width, symbols[i]->tag);
} }
} }
} }
@@ -361,7 +361,7 @@ print_reductions (FILE *out, state_t *state)
{ {
if (state->lookaheads_rule[j] != default_rule) if (state->lookaheads_rule[j] != default_rule)
print_reduction (out, width, print_reduction (out, width,
symbol_tag_get (symbols[i]), symbols[i]->tag,
state->lookaheads_rule[j], TRUE); state->lookaheads_rule[j], TRUE);
else else
defaulted = 1; defaulted = 1;
@@ -371,11 +371,11 @@ print_reductions (FILE *out, state_t *state)
{ {
if (defaulted) if (defaulted)
print_reduction (out, width, print_reduction (out, width,
symbol_tag_get (symbols[i]), symbols[i]->tag,
default_rule, TRUE); default_rule, TRUE);
defaulted = 0; defaulted = 0;
print_reduction (out, width, print_reduction (out, width,
symbol_tag_get (symbols[i]), symbols[i]->tag,
state->lookaheads_rule[j], FALSE); state->lookaheads_rule[j], FALSE);
} }
} }
@@ -463,7 +463,7 @@ print_grammar (FILE *out)
for (i = 0; i < max_user_token_number + 1; i++) for (i = 0; i < max_user_token_number + 1; i++)
if (token_translations[i] != undeftoken->number) if (token_translations[i] != undeftoken->number)
{ {
const char *tag = symbol_tag_get (symbols[token_translations[i]]); const char *tag = symbols[token_translations[i]]->tag;
rule_number_t r; rule_number_t r;
item_number_t *rhsp; item_number_t *rhsp;
@@ -491,7 +491,7 @@ print_grammar (FILE *out)
{ {
int left_count = 0, right_count = 0; int left_count = 0, right_count = 0;
rule_number_t r; rule_number_t r;
const char *tag = symbol_tag_get (symbols[i]); const char *tag = symbols[i]->tag;
for (r = 1; r < nrules + 1; r++) for (r = 1; r < nrules + 1; r++)
{ {

View File

@@ -75,15 +75,15 @@ print_core (struct obstack *oout, state_t *state)
if (i) if (i)
obstack_1grow (oout, '\n'); obstack_1grow (oout, '\n');
obstack_fgrow1 (oout, " %s -> ", obstack_fgrow1 (oout, " %s -> ",
symbol_tag_get (rules[rule].lhs)); rules[rule].lhs->tag);
for (sp = rules[rule].rhs; sp < sp1; sp++) for (sp = rules[rule].rhs; sp < sp1; sp++)
obstack_fgrow1 (oout, "%s ", symbol_tag_get (symbols[*sp])); obstack_fgrow1 (oout, "%s ", symbols[*sp]->tag);
obstack_1grow (oout, '.'); obstack_1grow (oout, '.');
for (/* Nothing */; *sp >= 0; ++sp) for (/* Nothing */; *sp >= 0; ++sp)
obstack_fgrow1 (oout, " %s", symbol_tag_get (symbols[*sp])); obstack_fgrow1 (oout, " %s", symbols[*sp]->tag);
/* Experimental feature: display the lookaheads. */ /* Experimental feature: display the lookaheads. */
if ((report_flag & report_lookaheads) if ((report_flag & report_lookaheads)
@@ -107,7 +107,7 @@ print_core (struct obstack *oout, state_t *state)
{ {
if (state->lookaheads_rule[j]->number == rule) if (state->lookaheads_rule[j]->number == rule)
obstack_fgrow2 (oout, "%s%s", obstack_fgrow2 (oout, "%s%s",
symbol_tag_get (symbols[k]), symbols[k]->tag,
--nlookaheads ? ", " : ""); --nlookaheads ? ", " : "");
}); });
obstack_sgrow (oout, "]"); obstack_sgrow (oout, "]");
@@ -156,7 +156,7 @@ print_actions (state_t *state, const char *node_name)
edge.color = red; edge.color = red;
else else
edge.color = TRANSITION_IS_SHIFT(transitions, i) ? blue : green; edge.color = TRANSITION_IS_SHIFT(transitions, i) ? blue : green;
edge.label = symbol_tag_get (symbols[symbol]); edge.label = symbols[symbol]->tag;
output_edge (&edge, fgraph); output_edge (&edge, fgraph);
close_edge (fgraph); close_edge (fgraph);
} }

View File

@@ -307,7 +307,7 @@ nonterminals_reduce (void)
LOCATION_PRINT (stderr, symbols[i]->location); LOCATION_PRINT (stderr, symbols[i]->location);
fprintf (stderr, ": %s: %s: %s\n", fprintf (stderr, ": %s: %s: %s\n",
_("warning"), _("useless nonterminal"), _("warning"), _("useless nonterminal"),
symbol_tag_get (symbols[i])); symbols[i]->tag);
} }
@@ -355,7 +355,7 @@ reduce_output (FILE *out)
int i; int i;
fprintf (out, "%s\n\n", _("Useless nonterminals:")); fprintf (out, "%s\n\n", _("Useless nonterminals:"));
for (i = 0; i < nuseless_nonterminals; ++i) for (i = 0; i < nuseless_nonterminals; ++i)
fprintf (out, " %s\n", symbol_tag_get (symbols[nsyms + i])); fprintf (out, " %s\n", symbols[nsyms + i]->tag);
fputs ("\n\n", out); fputs ("\n\n", out);
} }
@@ -368,7 +368,7 @@ reduce_output (FILE *out)
if (!b) if (!b)
fprintf (out, "%s\n\n", _("Terminals which are not used:")); fprintf (out, "%s\n\n", _("Terminals which are not used:"));
b = TRUE; b = TRUE;
fprintf (out, " %s\n", symbol_tag_get (symbols[i])); fprintf (out, " %s\n", symbols[i]->tag);
} }
if (b) if (b)
fputs ("\n\n", out); fputs ("\n\n", out);
@@ -440,7 +440,7 @@ reduce_grammar (void)
if (!bitset_test (N, axiom->number - ntokens)) if (!bitset_test (N, axiom->number - ntokens))
fatal (_("Start symbol %s does not derive any sentence"), fatal (_("Start symbol %s does not derive any sentence"),
symbol_tag_get (symbols[axiom->number])); symbols[axiom->number]->tag);
/* First reduce the nonterminals, as they renumber themselves in the /* First reduce the nonterminals, as they renumber themselves in the
whole grammar. If you change the order, nonterms would be whole grammar. If you change the order, nonterms would be

View File

@@ -2793,7 +2793,7 @@ handle_action_dollar (char *text, location_t location)
type_name = symbol_list_n_type_name_get (current_rule, location, 0); type_name = symbol_list_n_type_name_get (current_rule, location, 0);
if (!type_name && typed) if (!type_name && typed)
complain_at (location, _("$$ of `%s' has no declared type"), complain_at (location, _("$$ of `%s' has no declared type"),
symbol_tag_get (current_rule->sym)); current_rule->sym->tag);
if (!type_name) if (!type_name)
type_name = ""; type_name = "";
obstack_fgrow1 (&string_obstack, obstack_fgrow1 (&string_obstack,
@@ -2817,7 +2817,7 @@ handle_action_dollar (char *text, location_t location)
n); n);
if (!type_name && typed) if (!type_name && typed)
complain_at (location, _("$%d of `%s' has no declared type"), complain_at (location, _("$%d of `%s' has no declared type"),
n, symbol_tag_get (current_rule->sym)); n, current_rule->sym->tag);
if (!type_name) if (!type_name)
type_name = ""; type_name = "";
obstack_fgrow3 (&string_obstack, obstack_fgrow3 (&string_obstack,

View File

@@ -557,7 +557,7 @@ handle_action_dollar (char *text, location_t location)
type_name = symbol_list_n_type_name_get (current_rule, location, 0); type_name = symbol_list_n_type_name_get (current_rule, location, 0);
if (!type_name && typed) if (!type_name && typed)
complain_at (location, _("$$ of `%s' has no declared type"), complain_at (location, _("$$ of `%s' has no declared type"),
symbol_tag_get (current_rule->sym)); current_rule->sym->tag);
if (!type_name) if (!type_name)
type_name = ""; type_name = "";
obstack_fgrow1 (&string_obstack, obstack_fgrow1 (&string_obstack,
@@ -581,7 +581,7 @@ handle_action_dollar (char *text, location_t location)
n); n);
if (!type_name && typed) if (!type_name && typed)
complain_at (location, _("$%d of `%s' has no declared type"), complain_at (location, _("$%d of `%s' has no declared type"),
n, symbol_tag_get (current_rule->sym)); n, current_rule->sym->tag);
if (!type_name) if (!type_name)
type_name = ""; type_name = "";
obstack_fgrow3 (&string_obstack, obstack_fgrow3 (&string_obstack,

View File

@@ -213,7 +213,7 @@ state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out)
{ {
if (state->lookaheads_rule[j]->number == rule->number) if (state->lookaheads_rule[j]->number == rule->number)
fprintf (out, "%s%s", fprintf (out, "%s%s",
symbol_tag_get (symbols[k]), symbols[k]->tag,
--nlookaheads ? ", " : ""); --nlookaheads ? ", " : "");
}); });
fprintf (out, "]"); fprintf (out, "]");

View File

@@ -66,41 +66,6 @@ symbol_new (const char *tag, location_t location)
} }
/*-----------------------------------------------------------------.
| Return the tag of this SYMBOL in a printable form. Warning: use |
| the first QUOTEARG slot: 0. |
`-----------------------------------------------------------------*/
const char *
symbol_tag_get (symbol_t *symbol)
{
return quotearg_style (escape_quoting_style, symbol->tag);
}
/*------------------------------------------------------------.
| Return the tag of this SYMBOL in a printable form. Use the |
| QUOTEARG slot number N. |
`------------------------------------------------------------*/
const char *
symbol_tag_get_n (symbol_t *symbol, int n)
{
return quotearg_n_style (n, escape_quoting_style, symbol->tag);
}
/*-------------------------------.
| Print the tag of this SYMBOL. |
`-------------------------------*/
void
symbol_tag_print (symbol_t *symbol, FILE *out)
{
fputs (symbol_tag_get (symbol), out);
}
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| Set the TYPE_NAME associated to SYMBOL. Does nothing if passed 0 | | Set the TYPE_NAME associated to SYMBOL. Does nothing if passed 0 |
| as TYPE_NAME. | | as TYPE_NAME. |
@@ -113,7 +78,7 @@ symbol_type_set (symbol_t *symbol, char *type_name, location_t location)
{ {
if (symbol->type_name) if (symbol->type_name)
complain_at (location, complain_at (location,
_("type redeclaration for %s"), symbol_tag_get (symbol)); _("type redeclaration for %s"), symbol->tag);
symbol->type_name = type_name; symbol->type_name = type_name;
} }
} }
@@ -131,7 +96,7 @@ symbol_destructor_set (symbol_t *symbol, char *destructor, location_t location)
if (symbol->destructor) if (symbol->destructor)
complain_at (location, complain_at (location,
_("%s redeclaration for %s"), _("%s redeclaration for %s"),
"%destructor", symbol_tag_get (symbol)); "%destructor", symbol->tag);
symbol->destructor = destructor; symbol->destructor = destructor;
symbol->destructor_location = location; symbol->destructor_location = location;
} }
@@ -150,7 +115,7 @@ symbol_printer_set (symbol_t *symbol, char *printer, location_t location)
if (symbol->printer) if (symbol->printer)
complain_at (location, complain_at (location,
_("%s redeclaration for %s"), _("%s redeclaration for %s"),
"%printer", symbol_tag_get (symbol)); "%printer", symbol->tag);
symbol->printer = printer; symbol->printer = printer;
symbol->printer_location = location; symbol->printer_location = location;
} }
@@ -171,7 +136,7 @@ symbol_precedence_set (symbol_t *symbol,
if (symbol->prec != 0) if (symbol->prec != 0)
complain_at (location, complain_at (location,
_("redefining precedence of %s"), _("redefining precedence of %s"),
symbol_tag_get (symbol)); symbol->tag);
symbol->prec = prec; symbol->prec = prec;
symbol->assoc = assoc; symbol->assoc = assoc;
} }
@@ -189,7 +154,7 @@ void
symbol_class_set (symbol_t *symbol, symbol_class class, location_t location) symbol_class_set (symbol_t *symbol, symbol_class class, location_t location)
{ {
if (symbol->class != unknown_sym && symbol->class != class) if (symbol->class != unknown_sym && symbol->class != class)
complain_at (location, _("symbol %s redefined"), symbol_tag_get (symbol)); complain_at (location, _("symbol %s redefined"), symbol->tag);
if (class == nterm_sym && symbol->class != nterm_sym) if (class == nterm_sym && symbol->class != nterm_sym)
symbol->number = nvars++; symbol->number = nvars++;
@@ -213,7 +178,7 @@ symbol_user_token_number_set (symbol_t *symbol,
if (symbol->user_token_number != USER_NUMBER_UNDEFINED if (symbol->user_token_number != USER_NUMBER_UNDEFINED
&& symbol->user_token_number != user_token_number) && symbol->user_token_number != user_token_number)
complain_at (location, _("redefining user token number of %s"), complain_at (location, _("redefining user token number of %s"),
symbol_tag_get (symbol)); symbol->tag);
symbol->user_token_number = user_token_number; symbol->user_token_number = user_token_number;
/* User defined EOF token? */ /* User defined EOF token? */
@@ -258,7 +223,7 @@ symbol_check_defined (symbol_t *this)
complain_at complain_at
(this->location, (this->location,
_("symbol %s is used, but is not defined as a token and has no rules"), _("symbol %s is used, but is not defined as a token and has no rules"),
symbol_tag_get (this)); this->tag);
this->class = nterm_sym; this->class = nterm_sym;
this->number = nvars++; this->number = nvars++;
} }
@@ -277,10 +242,10 @@ symbol_make_alias (symbol_t *symbol, symbol_t *symval)
{ {
if (symval->alias) if (symval->alias)
warn (_("symbol `%s' used more than once as a literal string"), warn (_("symbol `%s' used more than once as a literal string"),
symbol_tag_get (symval)); symval->tag);
else if (symbol->alias) else if (symbol->alias)
warn (_("symbol `%s' given more than one literal string"), warn (_("symbol `%s' given more than one literal string"),
symbol_tag_get (symbol)); symbol->tag);
else else
{ {
symval->class = token_sym; symval->class = token_sym;
@@ -313,7 +278,7 @@ symbol_check_alias_consistence (symbol_t *this)
{ {
if (this->prec != 0 && this->alias->prec != 0) if (this->prec != 0 && this->alias->prec != 0)
complain (_("conflicting precedences for %s and %s"), complain (_("conflicting precedences for %s and %s"),
symbol_tag_get (this), symbol_tag_get (this->alias)); this->tag, this->alias->tag);
if (this->prec != 0) if (this->prec != 0)
this->alias->prec = this->prec; this->alias->prec = this->prec;
else else
@@ -328,7 +293,7 @@ symbol_check_alias_consistence (symbol_t *this)
if (this->assoc != right_assoc if (this->assoc != right_assoc
&& this->alias->assoc != right_assoc) && this->alias->assoc != right_assoc)
complain (_("conflicting associativities for %s and %s"), complain (_("conflicting associativities for %s and %s"),
symbol_tag_get (this), symbol_tag_get (this->alias)); this->tag, this->alias->tag);
if (this->assoc != 0) if (this->assoc != 0)
this->alias->assoc = this->assoc; this->alias->assoc = this->assoc;
else else
@@ -396,8 +361,8 @@ symbol_translation (symbol_t *this)
/* A token which translation has already been set? */ /* A token which translation has already been set? */
if (token_translations[this->user_token_number] != undeftoken->number) if (token_translations[this->user_token_number] != undeftoken->number)
complain (_("tokens %s and %s both assigned number %d"), complain (_("tokens %s and %s both assigned number %d"),
symbol_tag_get (symbols[token_translations[this->user_token_number]]), symbols[token_translations[this->user_token_number]]->tag,
symbol_tag_get (this), this->user_token_number); this->tag, this->user_token_number);
token_translations[this->user_token_number] = this->number; token_translations[this->user_token_number] = this->number;
} }
@@ -454,6 +419,8 @@ symbol_get (const char *key, location_t location)
symbol_t probe; symbol_t probe;
symbol_t *entry; symbol_t *entry;
/* Keep the symbol in a printable form. */
key = quotearg_style (escape_quoting_style, key);
(const char *) probe.tag = key; (const char *) probe.tag = key;
entry = hash_lookup (symbol_table, &probe); entry = hash_lookup (symbol_table, &probe);
@@ -598,9 +565,9 @@ symbols_pack (void)
if (startsymbol->class == unknown_sym) if (startsymbol->class == unknown_sym)
fatal_at (startsymbol_location, fatal_at (startsymbol_location,
_("the start symbol %s is undefined"), _("the start symbol %s is undefined"),
symbol_tag_get (startsymbol)); startsymbol->tag);
else if (startsymbol->class == token_sym) else if (startsymbol->class == token_sym)
fatal_at (startsymbol_location, fatal_at (startsymbol_location,
_("the start symbol %s is a token"), _("the start symbol %s is a token"),
symbol_tag_get (startsymbol)); startsymbol->tag);
} }

View File

@@ -91,17 +91,6 @@ struct symbol_s
#define NUMBER_UNDEFINED ((symbol_number_t) -1) #define NUMBER_UNDEFINED ((symbol_number_t) -1)
/* Return the tag of this SYMBOL in a printable form. Warning: uses
the QUOTEARG slot 0. */
const char *symbol_tag_get PARAMS ((symbol_t *symbol));
/* Return the tag of this SYMBOL in a printable form. Use the
QUOTEARG slot number N. */
const char *symbol_tag_get_n PARAMS ((symbol_t *symbol, int n));
/* Print the tag of this SYMBOL. */
void symbol_tag_print PARAMS ((symbol_t *symbol, FILE *out));
/* Fetch (or create) the symbol associated to KEY. */ /* Fetch (or create) the symbol associated to KEY. */
symbol_t *symbol_get PARAMS ((const char *key, location_t location)); symbol_t *symbol_get PARAMS ((const char *key, location_t location));