mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 14:23:04 +00:00
Merge branch maint
* maint: maint: post-release administrivia version 3.3.2 style: minor fixes NEWS: named constructors are preferable to symbol_type ctors gram: fix handling of nterms in actions when some are unused style: rename local variable CI: update the ICC serial number for travis-ci.org
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include "muscle-tab.h"
|
||||
#include "output.h"
|
||||
#include "reader.h"
|
||||
#include "reduce.h"
|
||||
#include "scan-code.h" /* max_left_semantic_context */
|
||||
#include "scan-skel.h"
|
||||
#include "symtab.h"
|
||||
@@ -413,6 +414,14 @@ merger_output (FILE *out)
|
||||
static void
|
||||
prepare_symbol_definitions (void)
|
||||
{
|
||||
/* Map "orig NUM" to new numbers. See data/README. */
|
||||
for (symbol_number i = ntokens; i < nsyms + nuseless_nonterminals; ++i)
|
||||
{
|
||||
obstack_printf (&format_obstack, "symbol(orig %d, number)", i);
|
||||
const char *key = obstack_finish0 (&format_obstack);
|
||||
MUSCLE_INSERT_INT (key, nterm_map ? nterm_map[i - ntokens] : i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nsyms; ++i)
|
||||
{
|
||||
symbol *sym = symbols[i];
|
||||
|
||||
25
src/reduce.c
25
src/reduce.c
@@ -258,22 +258,23 @@ reduce_grammar_tables (void)
|
||||
| Remove useless nonterminals. |
|
||||
`------------------------------*/
|
||||
|
||||
symbol_number *nterm_map = NULL;
|
||||
|
||||
static void
|
||||
nonterminals_reduce (void)
|
||||
{
|
||||
nterm_map = xnmalloc (nvars, sizeof *nterm_map);
|
||||
/* Map the nonterminals to their new index: useful first, useless
|
||||
afterwards. Kept for later report. */
|
||||
|
||||
symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap);
|
||||
{
|
||||
symbol_number n = ntokens;
|
||||
for (symbol_number i = ntokens; i < nsyms; ++i)
|
||||
if (bitset_test (V, i))
|
||||
nontermmap[i - ntokens] = n++;
|
||||
nterm_map[i - ntokens] = n++;
|
||||
for (symbol_number i = ntokens; i < nsyms; ++i)
|
||||
if (!bitset_test (V, i))
|
||||
{
|
||||
nontermmap[i - ntokens] = n++;
|
||||
nterm_map[i - ntokens] = n++;
|
||||
if (symbols[i]->content->status != used)
|
||||
complain (&symbols[i]->location, Wother,
|
||||
_("nonterminal useless in grammar: %s"),
|
||||
@@ -281,32 +282,30 @@ nonterminals_reduce (void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Shuffle elements of tables indexed by symbol number. */
|
||||
{
|
||||
symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted);
|
||||
for (symbol_number i = ntokens; i < nsyms; ++i)
|
||||
symbols[i]->content->number = nontermmap[i - ntokens];
|
||||
symbols[i]->content->number = nterm_map[i - ntokens];
|
||||
for (symbol_number i = ntokens; i < nsyms; ++i)
|
||||
symbols_sorted[nontermmap[i - ntokens] - ntokens] = symbols[i];
|
||||
symbols_sorted[nterm_map[i - ntokens] - ntokens] = symbols[i];
|
||||
for (symbol_number i = ntokens; i < nsyms; ++i)
|
||||
symbols[i] = symbols_sorted[i - ntokens];
|
||||
free (symbols_sorted);
|
||||
}
|
||||
|
||||
/* Update nonterminal numbers in the RHS of the rules. LHS are
|
||||
pointers to the symbol structure, they don't need renumbering. */
|
||||
{
|
||||
for (rule_number r = 0; r < nrules; ++r)
|
||||
for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp)
|
||||
if (ISVAR (*rhsp))
|
||||
*rhsp = symbol_number_as_item_number (nontermmap[*rhsp
|
||||
- ntokens]);
|
||||
accept->content->number = nontermmap[accept->content->number - ntokens];
|
||||
*rhsp = symbol_number_as_item_number (nterm_map[*rhsp - ntokens]);
|
||||
accept->content->number = nterm_map[accept->content->number - ntokens];
|
||||
}
|
||||
|
||||
nsyms -= nuseless_nonterminals;
|
||||
nvars -= nuseless_nonterminals;
|
||||
|
||||
free (nontermmap);
|
||||
}
|
||||
|
||||
|
||||
@@ -432,4 +431,6 @@ reduce_free (void)
|
||||
bitset_free (V);
|
||||
bitset_free (V1);
|
||||
bitset_free (P);
|
||||
free (nterm_map);
|
||||
nterm_map = NULL;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ bool reduce_nonterminal_useless_in_grammar (const sym_content *sym);
|
||||
|
||||
void reduce_free (void);
|
||||
|
||||
/** Map initial nterm numbers to the new ones. Built by
|
||||
* reduce_grammar. Size nvars + nuseless_nonterminals. */
|
||||
extern symbol_number *nterm_map;
|
||||
|
||||
extern unsigned nuseless_nonterminals;
|
||||
extern unsigned nuseless_productions;
|
||||
|
||||
#endif /* !REDUCE_H_ */
|
||||
|
||||
@@ -648,7 +648,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
|
||||
untyped_var_seen = true;
|
||||
}
|
||||
|
||||
obstack_printf (&obstack_for_string, "]b4_lhs_value(%d, ",
|
||||
obstack_printf (&obstack_for_string, "]b4_lhs_value(orig %d, ",
|
||||
sym->content.sym->content->number);
|
||||
obstack_quote (&obstack_for_string, type_name);
|
||||
obstack_sgrow (&obstack_for_string, ")[");
|
||||
@@ -677,7 +677,9 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
|
||||
"]b4_rhs_value(%d, %d, ",
|
||||
effective_rule_length, n);
|
||||
if (sym)
|
||||
obstack_printf (&obstack_for_string, "%d, ", sym->content.sym->content->number);
|
||||
obstack_printf (&obstack_for_string, "%s%d, ",
|
||||
sym->content.sym->content->class == nterm_sym ? "orig " : "",
|
||||
sym->content.sym->content->number);
|
||||
else
|
||||
obstack_sgrow (&obstack_for_string, "[], ");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user