X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/f6857bbf8c40df05d7c7324cf41ced6d1961ca89..122bea3ab92125b4f3e8a62ea01c237262af7d07:/src/reader.c?ds=sidebyside diff --git a/src/reader.c b/src/reader.c index 4bbed58f..be9f46f6 100644 --- a/src/reader.c +++ b/src/reader.c @@ -69,27 +69,6 @@ grammar_start_symbol_set (symbol *sym, location loc) } } - -/*---------------------------------------------------------------------. -| There are two prologues: one before the first %union and one after. | -| Augment the one specified by POST. | -`---------------------------------------------------------------------*/ - -void -prologue_augment (const char *prologue, location loc, bool post) -{ - struct obstack *oout = - !post ? &pre_prologue_obstack : &post_prologue_obstack; - - obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line); - /* FIXME: Protection of M4 characters missing here. See - output.c:escaped_output. */ - MUSCLE_OBSTACK_SGROW (oout, - quotearg_style (c_quoting_style, loc.start.file)); - obstack_sgrow (oout, "]])[\n"); - obstack_sgrow (oout, prologue); -} - /*------------------------------------------------------------------------. @@ -253,7 +232,7 @@ grammar_current_rule_begin (symbol *lhs, location loc) static bool symbol_should_be_used (symbol_list const *s) { - if (symbol_destructor_get (s->content.sym)) + if (symbol_destructor_get (s->content.sym)->code) return true; if (warnings_flag & warnings_midrule_values) return ((s->midrule && s->midrule->action_props.is_value_used) @@ -465,20 +444,6 @@ packgram (void) rules = xnmalloc (nrules, sizeof *rules); - /* Before invoking grammar_rule_check on any rule, make sure all actions have - already been scanned in order to set `used' flags. Otherwise, checking - that a midrule's $$ should be set will not always work properly because - the check must forward-reference the midrule's parent rule. For the same - reason, all the `used' flags must be set before checking whether to remove - `$' from any midrule symbol name. */ - while (p) - { - code_props_translate_code (&p->action_props); - if (p) - p = p->next; - } - - p = grammar; while (p) { int rule_length = 0; @@ -585,10 +550,6 @@ reader (void) undeftoken->class = token_sym; undeftoken->number = ntokens++; - /* Initialize the obstacks. */ - obstack_init (&pre_prologue_obstack); - obstack_init (&post_prologue_obstack); - gram_in = xfopen (grammar_file, "r"); gram__flex_debug = trace_flag & trace_scan; @@ -668,6 +629,20 @@ check_and_convert_grammar (void) token symbols into FDEFINES if requested. */ symbols_pack (); + /* Scan rule actions after invoking symbol_check_alias_consistency (in + symbols_pack above) so that token types are set correctly before the rule + action type checking. + + Before invoking grammar_rule_check (in packgram below) on any rule, make + sure all actions have already been scanned in order to set `used' flags. + Otherwise, checking that a midrule's $$ should be set will not always work + properly because the check must forward-reference the midrule's parent + rule. For the same reason, all the `used' flags must be set before + checking whether to remove `$' from any midrule symbol name (also in + packgram). */ + for (symbol_list *sym = grammar; sym; sym = sym->next) + code_props_translate_code (&sym->action_props); + /* Convert the grammar into the format described in gram.h. */ packgram ();