}
+/*-----------------------------------------------------------------.
+| 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->mid_rule && s->mid_rule->used);
+}
+
/*----------------------------------------------------------------.
| Check that the rule R is properly defined. For instance, there |
| should be no type clash on the default action. |
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))))
{
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->mid_rule = midrule;
}
/* Set the precedence symbol of the current rule to PRECSYM. */
## Unused values. ##
## --------------- ##
-AT_SETUP([Unused values])
+m4_define([AT_CHECK_UNUSED_VALUES],
+[AT_SETUP([Unused values])
AT_DATA([input.y],
[[%token <integer> INT
%type <integer> exp
%%
exp:
- INT { } INT { } INT { }
-/* Ideally we would like to complain also about $2 and $4 here, but
- it's hard to implement. */
-| INT { $$ } INT { $$ } INT { }
-| INT { $1 } INT { } INT { }
-| INT { } INT { $1 } INT { }
-| INT { } INT { } INT { $1 }
-| INT { } INT { } INT { $$ = $1 + $3 + $5; }
+ $1
+| INT
;
]])
AT_CHECK([bison input.y], [], [],
-[[input.y:5.3-25: warning: unset value: $$
+[[$2]])
+
+AT_CLEANUP
+])
+
+AT_CHECK_UNUSED_VALUES([INT { } INT { } INT { }],
+[input.y:5.3-25: warning: unset value: $$
input.y:5.3-25: warning: unused value: $1
input.y:5.3-25: warning: unused value: $3
input.y:5.3-25: warning: unused value: $5
-input.y:8.3-31: warning: unset value: $$
-input.y:8.3-31: warning: unused value: $1
-input.y:8.3-31: warning: unused value: $3
-input.y:8.3-31: warning: unused value: $5
-input.y:9.3-28: warning: unset value: $$
-input.y:9.3-28: warning: unused value: $3
-input.y:9.3-28: warning: unused value: $5
-input.y:10.3-28: warning: unset value: $$
-input.y:10.3-28: warning: unused value: $3
-input.y:10.3-28: warning: unused value: $5
-input.y:11.3-29: warning: unset value: $$
-input.y:11.3-29: warning: unused value: $3
-input.y:11.3-29: warning: unused value: $5
-input.y: conflicts: 1 reduce/reduce
-input.y:8.7-12: warning: rule never reduced because of conflicts: @3: /* empty */
-input.y:9.7-12: warning: rule never reduced because of conflicts: @5: /* empty */
-input.y:10.7-9: warning: rule never reduced because of conflicts: @7: /* empty */
-input.y:11.7-9: warning: rule never reduced because of conflicts: @9: /* empty */
-input.y:12.7-9: warning: rule never reduced because of conflicts: @11: /* empty */
-]])
+])
+
+AT_CHECK_UNUSED_VALUES([INT { $1 } INT { } INT { }],
+[input.y:5.3-28: warning: unset value: $$
+input.y:5.3-28: warning: unused value: $3
+input.y:5.3-28: warning: unused value: $5
+])
+
+AT_CHECK_UNUSED_VALUES([INT { } INT { $1 } INT { }],
+[input.y:5.3-28: warning: unset value: $$
+input.y:5.3-28: warning: unused value: $3
+input.y:5.3-28: warning: unused value: $5
+])
+
+AT_CHECK_UNUSED_VALUES([INT { } INT { } INT { $1 }],
+[input.y:5.3-29: warning: unset value: $$
+input.y:5.3-29: warning: unused value: $3
+input.y:5.3-29: warning: unused value: $5
+])
+
+AT_CHECK_UNUSED_VALUES([INT { } INT { } INT { $$ = $1 + $3 + $5; }])
+
+# Checking mid-rule values.
+AT_CHECK_UNUSED_VALUES([INT { $$ } INT { $$ } INT { }],
+[input.y:5.3-31: warning: unset value: $$
+input.y:5.3-31: warning: unused value: $1
+input.y:5.3-31: warning: unused value: $2
+input.y:5.3-31: warning: unused value: $3
+input.y:5.3-31: warning: unused value: $4
+input.y:5.3-31: warning: unused value: $5
+])
+
+AT_CHECK_UNUSED_VALUES([INT { $$ } INT { $$ = $2 } INT { }],
+[input.y:5.3-36: warning: unset value: $$
+input.y:5.3-36: warning: unused value: $1
+input.y:5.3-36: warning: unused value: $3
+input.y:5.3-36: warning: unused value: $4
+input.y:5.3-36: warning: unused value: $5
+])
+
+# AT_CHECK_UNUSED_VALUES([INT { $$ } { $$ = $2 } { }],
+# [input.y:5.3-36: warning: unset value: $$
+# input.y:5.3-36: warning: unused value: $1
+# input.y:5.3-36: warning: unused value: $3
+# input.y:5.3-36: warning: unused value: $4
+# input.y:5.3-36: warning: unused value: $5
+# ])
+
+AT_CHECK_UNUSED_VALUES([INT { $$ = $1 } INT { $$ = $2 + $3 } INT { $$ = $4 + $5 }])
-AT_CLEANUP
## ---------------------- ##