bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 7/7] c++: don't copy the lookahead


From: Akim Demaille
Subject: [PATCH 7/7] c++: don't copy the lookahead
Date: Fri, 28 Feb 2020 06:32:19 +0100

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.
---
 data/skeletons/lalr1.cc | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 91b08a12..2c50cdd7 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -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
   {
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]