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:
Akim Demaille
2018-10-16 13:27:55 +02:00
parent a99b4f45bb
commit e3fdc37049
2 changed files with 18 additions and 11 deletions

View File

@@ -51,8 +51,9 @@ int report_flag = report_none;
int trace_flag = trace_none;
static struct bison_language const valid_languages[] = {
{ "c", "c-skel.m4", ".c", ".h", true },
{ "c++", "c++-skel.m4", ".cc", ".hh", true },
/* lang, skeleton, ext, hdr, add_tab */
{ "c", "c-skel.m4", ".c", ".h", true },
{ "c++", "c++-skel.m4", ".cc", ".hh", true },
{ "java", "java-skel.m4", ".java", ".java", false },
{ "", "", "", "", false }
};
@@ -432,8 +433,7 @@ language_argmatch (char const *arg, int prio, location loc)
if (prio < language_prio)
{
int i;
for (i = 0; valid_languages[i].language[0]; i++)
for (int i = 0; valid_languages[i].language[0]; ++i)
if (c_strcasecmp (arg, valid_languages[i].language) == 0)
{
language_prio = prio;

View File

@@ -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. */