c++: don't copy the lookahead

The current implementation of parser::context keeps a copy of the
lookahead.  This is troublesome since we support move-only types.
Besides, while GCC is happy with the current implementation, Clang
complains that the ctor it needs to build the copy of the lookahead is
not yet available.

    461. calc.at:1120: testing Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  ...
    calc.at:1120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.cc calc.y
    calc.at:1120: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.cc calc-lex.cc calc-main.cc $LIBS
    stderr:
    In file included from calc-lex.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    In file included from calc-main.cc:7:
    calc.hh:351:12: error: instantiation of function 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' required here, but no definition is available [-Werror,-Wundefined-func-template]
        struct symbol_type : basic_symbol<by_type>
               ^
    calc.hh:273:7: note: forward declaration of template entity is here
          basic_symbol (const basic_symbol& that);
          ^
    calc.hh:351:12: note: add an explicit instantiation declaration to suppress this warning if 'calc::parser::basic_symbol<calc::parser::by_type>::basic_symbol' is explicitly instantiated in another translation unit
        struct symbol_type : basic_symbol<by_type>
               ^
    1 error generated.
    stdout:
    calc.at:1120: exit code was 1, expected 0
    461. calc.at:1120: 461. Calculator C++ %defines %locations parse.error=verbose %name-prefix "calc" %verbose  (calc.at:1120): FAILED (calc.at:1120)

* data/skeletons/lalr1.cc (context::yyla_): Make it a const-ref.
Move the implementation out of the declaration.
This commit is contained in:
Akim Demaille
2020-02-27 21:42:01 +01:00
parent 30d01b21e7
commit b870d5fee4

View File

@@ -239,23 +239,19 @@ m4_define([b4_shared_declarations],
class context
{
public:
context (const ]b4_parser_class[& yyparser, symbol_type yyla)
: yyparser_ (yyparser)
, yyla_ (yyla)
{}
]b4_locations_if([[
context (const ]b4_parser_class[& yyparser, const symbol_type& yyla);]b4_locations_if([[
const location_type& location () const { return yyla_.location; }
]])[
/* Put in YYARG at most YYARGN of the expected tokens, and return the
number of tokens stored in YYARG. If YYARG is null, return the
number of expected tokens (guaranteed to be less than YYNTOKENS). */
/// Put in YYARG at most YYARGN of the expected tokens, and return the
/// number of tokens stored in YYARG. If YYARG is null, return the
/// number of expected tokens (guaranteed to be less than YYNTOKENS).
int yyexpected_tokens (int yyarg[], int yyargn) const;
int yysyntax_error_arguments (int yyarg[], int yyargn) const;
private:
const ]b4_parser_class[& yyparser_;
symbol_type yyla_;
const symbol_type& yyla_;
};
]])[
private:
@@ -1228,6 +1224,12 @@ b4_dollar_popdef])[]dnl
[[yyexc.what ()]])[);
}]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
// ]b4_parser_class[::context.
]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla)
: yyparser_ (yyparser)
, yyla_ (yyla)
{}
int
]b4_parser_class[::context::yyexpected_tokens (int yyarg[], int yyargn) const
{