diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2019-02-03 15:23:54 +0100 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2019-02-03 15:23:54 +0100 |
commit | cf96d1b0afd20ac5c3a7506b020b25d5b299c070 (patch) | |
tree | d8474731a0b579c6bad47fa23e5a21ac0e72d04b /src | |
parent | 56c00ed1ea23178f16f5bbafd7e18233d9c950f9 (diff) | |
parent | 3d25b52a108dc8fbd93040d2fdc6324a8e140fae (diff) | |
download | bison-cf96d1b0afd20ac5c3a7506b020b25d5b299c070.tar.gz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/output.c | 9 | ||||
-rw-r--r-- | src/reduce.c | 25 | ||||
-rw-r--r-- | src/reduce.h | 5 | ||||
-rw-r--r-- | src/scan-code.l | 6 |
4 files changed, 31 insertions, 14 deletions
diff --git a/src/output.c b/src/output.c index 7132b4a9..b674f4ca 100644 --- a/src/output.c +++ b/src/output.c @@ -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]; diff --git a/src/reduce.c b/src/reduce.c index 574e9b07..4408e6a2 100644 --- a/src/reduce.c +++ b/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; } diff --git a/src/reduce.h b/src/reduce.h index c3866fc3..9814962d 100644 --- a/src/reduce.h +++ b/src/reduce.h @@ -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_ */ diff --git a/src/scan-code.l b/src/scan-code.l index 52349ffb..894cc542 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -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, "[], "); |