mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 21:33:04 +00:00
generate the default action only for C++
This commit adds restrictions to what was done in
01898726e2 [1].
Rici Lake [2] has shown that it's risky to disable the pre-action, at
least now. Also, generating the default $$ = $1 action can have bad
effects in some cases [3].
The original change [1] was prompted for C++. Let's try it there
only, for a start. We could restrict it further to lalr1.cc with
variants, but we need to see in the wild how this change behaves. And
it is not unreasonable to expect grammar files in C++ to behave better
wrt types.
See
[1] https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00050.html
[2] https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00061.html
[3] https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00066.html
* src/getargs.c: Style changes.
* src/reader.c (grammar_rule_check_and_complete): Complete only for
C++.
This commit is contained in:
21
src/reader.c
21
src/reader.c
@@ -306,13 +306,20 @@ grammar_rule_check_and_complete (symbol_list *r)
|
||||
lhs_type, rhs_type);
|
||||
else
|
||||
{
|
||||
/* Install the default action. */
|
||||
code_props_rule_action_init (&r->action_props, "{ $$ = $1; }",
|
||||
r->location, r,
|
||||
/* name */ NULL,
|
||||
/* type */ NULL,
|
||||
/* is_predicate */ false);
|
||||
code_props_translate_code (&r->action_props);
|
||||
/* Install the default action only for C++. */
|
||||
bool is_cxx =
|
||||
skeleton
|
||||
? STREQ (skeleton, "glr.cc") || STREQ (skeleton, "lalr1.cc")
|
||||
: STREQ (language->language, "c++");
|
||||
if (is_cxx)
|
||||
{
|
||||
code_props_rule_action_init (&r->action_props, "{ $$ = $1; }",
|
||||
r->location, r,
|
||||
/* name */ NULL,
|
||||
/* type */ NULL,
|
||||
/* is_predicate */ false);
|
||||
code_props_translate_code (&r->action_props);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Warn if there is no default for $$ but we need one. */
|
||||
|
||||
Reference in New Issue
Block a user