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>
* 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)
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);
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)
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);
if (!sp)
@@ -372,7 +372,7 @@ generate_states (void)
if (trace_flag)
fprintf (stderr, "Processing state %d (reached by %s)\n",
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
state. ruleset gets a 1 bit for each rule that could reduce
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;
fprintf (stderr, " %2d: .", array[i]);
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);
}
fputs ("\n\n", stderr);
@@ -74,11 +74,11 @@ print_firsts (void)
fprintf (stderr, "FIRSTS\n");
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,
{
fprintf (stderr, "\t\t%s\n",
symbol_tag_get (symbols[j + ntokens]));
symbols[j + ntokens]->tag);
});
}
fprintf (stderr, "\n\n");
@@ -94,13 +94,13 @@ print_fderives (void)
fprintf (stderr, "FDERIVES\n");
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,
{
item_number_t *rhsp = NULL;
fprintf (stderr, "\t\t%d:", r - 1);
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);
});
}

View File

@@ -45,7 +45,7 @@ print_derives (void)
item_number_t *rhsp;
fprintf (stderr, "\t\t%d:", *rp);
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",
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);
if (previous_lhs != rule->lhs)
{
fprintf (out, "%s:", symbol_tag_get (rule->lhs));
fprintf (out, "%s:", rule->lhs->tag);
}
else
{
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);
}
@@ -97,7 +97,7 @@ rule_rhs_print (rule_t *rule, FILE *out)
{
item_number_t *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);
}
else
@@ -114,7 +114,7 @@ rule_rhs_print (rule_t *rule, FILE *out)
void
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);
}
@@ -130,7 +130,7 @@ ritem_print (FILE *out)
fputs ("RITEM\n", out);
for (i = 0; i < nritems; ++i)
if (ritem[i] >= 0)
fprintf (out, " %s", symbol_tag_get (symbols[ritem[i]]));
fprintf (out, " %s", symbols[ritem[i]]->tag);
else
fprintf (out, " (rule %d)\n", -ritem[i] - 1);
fputs ("\n\n", out);
@@ -217,7 +217,7 @@ grammar_dump (FILE *out, const char *title)
fprintf (out, "%5d %5d %5d %s\n",
i,
symbols[i]->prec, symbols[i]->assoc,
symbol_tag_get (symbols[i]));
symbols[i]->tag);
fprintf (out, "\n\n");
}

View File

@@ -427,7 +427,7 @@ lookaheads_print (FILE *out)
BITSET_EXECUTE (states[i]->lookaheads[j], 0, k,
{
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);
});
}

View File

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

View File

@@ -103,10 +103,10 @@ print_core (FILE *out, state_t *state)
previous_lhs = rules[rule].lhs;
for (sp = rules[rule].rhs; sp < sp1; sp++)
fprintf (out, " %s", symbol_tag_get (symbols[*sp]));
fprintf (out, " %s", symbols[*sp]->tag);
fputs (" .", out);
for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", symbol_tag_get (symbols[*sp]));
fprintf (out, " %s", symbols[*sp]->tag);
/* Display the 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)
{
symbol_t *symbol = symbols[TRANSITION_SYMBOL (transitions, i)];
max_length (&width, symbol_tag_get (symbol));
max_length (&width, symbol->tag);
}
/* 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)
{
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];
int j;
@@ -180,7 +180,7 @@ print_errs (FILE *out, state_t *state)
/* Compute the width of the lookaheads column. */
for (i = 0; i < errp->num; ++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. */
if (!width)
@@ -193,7 +193,7 @@ print_errs (FILE *out, state_t *state)
for (i = 0; i < errp->num; ++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;
fprintf (out, " %s", tag);
for (j = width - strlen (tag); j > 0; --j)
@@ -288,7 +288,7 @@ print_reduction (FILE *out, size_t width,
if (!enabled)
fputc ('[', out);
fprintf (out, _("reduce using rule %d (%s)"),
rule->number - 1, symbol_tag_get (rule->lhs));
rule->number - 1, rule->lhs->tag);
if (!enabled)
fputc (']', out);
fputc ('\n', out);
@@ -331,12 +331,12 @@ print_reductions (FILE *out, state_t *state)
if (count == 0)
{
if (state->lookaheads_rule[j] != default_rule)
max_length (&width, symbol_tag_get (symbols[i]));
max_length (&width, symbols[i]->tag);
count++;
}
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)
print_reduction (out, width,
symbol_tag_get (symbols[i]),
symbols[i]->tag,
state->lookaheads_rule[j], TRUE);
else
defaulted = 1;
@@ -371,11 +371,11 @@ print_reductions (FILE *out, state_t *state)
{
if (defaulted)
print_reduction (out, width,
symbol_tag_get (symbols[i]),
symbols[i]->tag,
default_rule, TRUE);
defaulted = 0;
print_reduction (out, width,
symbol_tag_get (symbols[i]),
symbols[i]->tag,
state->lookaheads_rule[j], FALSE);
}
}
@@ -463,7 +463,7 @@ print_grammar (FILE *out)
for (i = 0; i < max_user_token_number + 1; i++)
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;
item_number_t *rhsp;
@@ -491,7 +491,7 @@ print_grammar (FILE *out)
{
int left_count = 0, right_count = 0;
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++)
{

View File

@@ -75,15 +75,15 @@ print_core (struct obstack *oout, state_t *state)
if (i)
obstack_1grow (oout, '\n');
obstack_fgrow1 (oout, " %s -> ",
symbol_tag_get (rules[rule].lhs));
rules[rule].lhs->tag);
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, '.');
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. */
if ((report_flag & report_lookaheads)
@@ -107,7 +107,7 @@ print_core (struct obstack *oout, state_t *state)
{
if (state->lookaheads_rule[j]->number == rule)
obstack_fgrow2 (oout, "%s%s",
symbol_tag_get (symbols[k]),
symbols[k]->tag,
--nlookaheads ? ", " : "");
});
obstack_sgrow (oout, "]");
@@ -156,7 +156,7 @@ print_actions (state_t *state, const char *node_name)
edge.color = red;
else
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);
close_edge (fgraph);
}

View File

@@ -307,7 +307,7 @@ nonterminals_reduce (void)
LOCATION_PRINT (stderr, symbols[i]->location);
fprintf (stderr, ": %s: %s: %s\n",
_("warning"), _("useless nonterminal"),
symbol_tag_get (symbols[i]));
symbols[i]->tag);
}
@@ -355,7 +355,7 @@ reduce_output (FILE *out)
int i;
fprintf (out, "%s\n\n", _("Useless nonterminals:"));
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);
}
@@ -368,7 +368,7 @@ reduce_output (FILE *out)
if (!b)
fprintf (out, "%s\n\n", _("Terminals which are not used:"));
b = TRUE;
fprintf (out, " %s\n", symbol_tag_get (symbols[i]));
fprintf (out, " %s\n", symbols[i]->tag);
}
if (b)
fputs ("\n\n", out);
@@ -440,7 +440,7 @@ reduce_grammar (void)
if (!bitset_test (N, axiom->number - ntokens))
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
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);
if (!type_name && typed)
complain_at (location, _("$$ of `%s' has no declared type"),
symbol_tag_get (current_rule->sym));
current_rule->sym->tag);
if (!type_name)
type_name = "";
obstack_fgrow1 (&string_obstack,
@@ -2817,7 +2817,7 @@ handle_action_dollar (char *text, location_t location)
n);
if (!type_name && typed)
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)
type_name = "";
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);
if (!type_name && typed)
complain_at (location, _("$$ of `%s' has no declared type"),
symbol_tag_get (current_rule->sym));
current_rule->sym->tag);
if (!type_name)
type_name = "";
obstack_fgrow1 (&string_obstack,
@@ -581,7 +581,7 @@ handle_action_dollar (char *text, location_t location)
n);
if (!type_name && typed)
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)
type_name = "";
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)
fprintf (out, "%s%s",
symbol_tag_get (symbols[k]),
symbols[k]->tag,
--nlookaheads ? ", " : "");
});
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 |
| as TYPE_NAME. |
@@ -113,7 +78,7 @@ symbol_type_set (symbol_t *symbol, char *type_name, location_t location)
{
if (symbol->type_name)
complain_at (location,
_("type redeclaration for %s"), symbol_tag_get (symbol));
_("type redeclaration for %s"), symbol->tag);
symbol->type_name = type_name;
}
}
@@ -131,7 +96,7 @@ symbol_destructor_set (symbol_t *symbol, char *destructor, location_t location)
if (symbol->destructor)
complain_at (location,
_("%s redeclaration for %s"),
"%destructor", symbol_tag_get (symbol));
"%destructor", symbol->tag);
symbol->destructor = destructor;
symbol->destructor_location = location;
}
@@ -150,7 +115,7 @@ symbol_printer_set (symbol_t *symbol, char *printer, location_t location)
if (symbol->printer)
complain_at (location,
_("%s redeclaration for %s"),
"%printer", symbol_tag_get (symbol));
"%printer", symbol->tag);
symbol->printer = printer;
symbol->printer_location = location;
}
@@ -171,7 +136,7 @@ symbol_precedence_set (symbol_t *symbol,
if (symbol->prec != 0)
complain_at (location,
_("redefining precedence of %s"),
symbol_tag_get (symbol));
symbol->tag);
symbol->prec = prec;
symbol->assoc = assoc;
}
@@ -189,7 +154,7 @@ void
symbol_class_set (symbol_t *symbol, symbol_class class, location_t location)
{
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)
symbol->number = nvars++;
@@ -213,7 +178,7 @@ symbol_user_token_number_set (symbol_t *symbol,
if (symbol->user_token_number != USER_NUMBER_UNDEFINED
&& symbol->user_token_number != user_token_number)
complain_at (location, _("redefining user token number of %s"),
symbol_tag_get (symbol));
symbol->tag);
symbol->user_token_number = user_token_number;
/* User defined EOF token? */
@@ -258,7 +223,7 @@ symbol_check_defined (symbol_t *this)
complain_at
(this->location,
_("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->number = nvars++;
}
@@ -277,10 +242,10 @@ symbol_make_alias (symbol_t *symbol, symbol_t *symval)
{
if (symval->alias)
warn (_("symbol `%s' used more than once as a literal string"),
symbol_tag_get (symval));
symval->tag);
else if (symbol->alias)
warn (_("symbol `%s' given more than one literal string"),
symbol_tag_get (symbol));
symbol->tag);
else
{
symval->class = token_sym;
@@ -313,7 +278,7 @@ symbol_check_alias_consistence (symbol_t *this)
{
if (this->prec != 0 && this->alias->prec != 0)
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)
this->alias->prec = this->prec;
else
@@ -328,7 +293,7 @@ symbol_check_alias_consistence (symbol_t *this)
if (this->assoc != right_assoc
&& this->alias->assoc != right_assoc)
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)
this->alias->assoc = this->assoc;
else
@@ -396,8 +361,8 @@ symbol_translation (symbol_t *this)
/* A token which translation has already been set? */
if (token_translations[this->user_token_number] != undeftoken->number)
complain (_("tokens %s and %s both assigned number %d"),
symbol_tag_get (symbols[token_translations[this->user_token_number]]),
symbol_tag_get (this), this->user_token_number);
symbols[token_translations[this->user_token_number]]->tag,
this->tag, this->user_token_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 *entry;
/* Keep the symbol in a printable form. */
key = quotearg_style (escape_quoting_style, key);
(const char *) probe.tag = key;
entry = hash_lookup (symbol_table, &probe);
@@ -598,9 +565,9 @@ symbols_pack (void)
if (startsymbol->class == unknown_sym)
fatal_at (startsymbol_location,
_("the start symbol %s is undefined"),
symbol_tag_get (startsymbol));
startsymbol->tag);
else if (startsymbol->class == token_sym)
fatal_at (startsymbol_location,
_("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)
/* 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. */
symbol_t *symbol_get PARAMS ((const char *key, location_t location));