/* Input parser for Bison
Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002, 2003,
- 2005 Free Software Foundation, Inc.
+ 2005, 2006 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
}
+/*-----------------------------------------------------------------.
+| A symbol is typed if it has a declared %type, or if it is a |
+| mid-rule symbol (i.e., the generated LHS replacing a mid-rule |
+| action) that was assigned to, as in `exp: { $$ = 1; } { $$ = $1; |
+| }'. |
+`-----------------------------------------------------------------*/
+
+static bool
+symbol_typed_p (const symbol_list *s)
+{
+ return (s->sym->type_name
+ || s->midrule && s->midrule->used);
+}
+
/*----------------------------------------------------------------.
| Check that the rule R is properly defined. For instance, there |
| should be no type clash on the default action. |
/* Check that typed symbol values are used. */
{
- symbol_list *l = r;
+ symbol_list const *l = r;
int n = 0;
for (; l && l->sym; l = l->next, ++n)
if (! (l->used
- || !l->sym->type_name
+ || !symbol_typed_p (l)
/* The default action, $$ = $1, `uses' both. */
- || !r->action && (n == 0 || n == 1)))
- if (n)
- warn_at (r->location, _("unused value: $%d"), n);
- else
- warn_at (r->location, _("unset value: $$"));
+ || (!r->action && (n == 0 || n == 1))))
+ {
+ if (n)
+ warn_at (r->location, _("unused value: $%d"), n);
+ else
+ warn_at (r->location, _("unset value: $$"));
+ }
}
}
midrule->action = current_rule->action;
midrule->action_location = dummy_location;
current_rule->action = NULL;
+ /* If $$ was used in the action, the LHS of the enclosing rule was
+ incorrectly flagged as used. */
+ midrule->used = current_rule->used;
+ current_rule->used = false;
if (previous_rule_end)
previous_rule_end->next = midrule;
grammar = midrule;
/* End the dummy's rule. */
- previous_rule_end = symbol_list_new (NULL, dummy_location);
- previous_rule_end->next = current_rule;
+ midrule->next = symbol_list_new (NULL, dummy_location);
+ grammar_rule_check (midrule);
+ midrule->next->next = current_rule;
- midrule->next = previous_rule_end;
+ previous_rule_end = midrule->next;
/* Insert the dummy nonterminal replacing the midrule action into
- the current rule. */
+ the current rule. Bind it to its dedicated rule. */
grammar_current_rule_symbol_append (dummy, dummy_location);
+ grammar_end->midrule = midrule;
}
/* Set the precedence symbol of the current rule to PRECSYM. */