[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: generate the default semantic action
From: |
Akim Demaille |
Subject: |
Re: RFC: generate the default semantic action |
Date: |
Tue, 16 Oct 2018 13:41:24 +0200 |
I propose this change. And if people agree with it, then I think we
have 3.2. There are many changes, so I will run a beta release first,
and ask people to try it. Especially people running C++ parsers.
commit e3fdc370495ffdedadd6ac621e32e34a0e1a9de0
Author: Akim Demaille <address@hidden>
Date: Tue Oct 16 13:27:55 2018 +0200
generate the default action only for C++
This commit adds restrictions to what was done in
01898726e27c8cf64f8fcea7f26f8ce62f3f5cf2 [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++.
diff --git a/src/getargs.c b/src/getargs.c
index dfcf5cff..c2f5b032 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -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;
diff --git a/src/reader.c b/src/reader.c
index 516f6aad..c546404f 100644
--- a/src/reader.c
+++ b/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. */
- Re: RFC: generate the default semantic action, (continued)
Re: RFC: generate the default semantic action, Paul Eggert, 2018/10/14
Re: RFC: generate the default semantic action, Rici Lake, 2018/10/15