diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2018-10-16 13:27:55 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2018-10-16 13:41:09 +0200 |
commit | e3fdc370495ffdedadd6ac621e32e34a0e1a9de0 (patch) | |
tree | 07b44c796248203edcf116e2569c045a1bf9c628 | |
parent | a99b4f45bb2a9a5d5629720b845bf7d99831ec94 (diff) | |
download | bison-e3fdc370495ffdedadd6ac621e32e34a0e1a9de0.tar.gz |
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++.
-rw-r--r-- | src/getargs.c | 8 | ||||
-rw-r--r-- | src/reader.c | 21 |
2 files changed, 18 insertions, 11 deletions
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. */ |