Commit Graph

1207 Commits

Author SHA1 Message Date
Akim Demaille
3967e46a2d lalr1.cc: fix stack symbol move
In some casing, once we moved a stack symbol, we forget to mark the
source stack symbol as emptied.  As a consequence, it may be destroyed
a second time.

This happens when the stack has to be resized.

* data/lalr1.cc (stack_symbol_type::stack_symbol_type): Record that
the source was emptied.
(stack_symbol_type::operator=): Likewise.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Force the stack
to be resized.  Check its content.
2018-10-18 07:15:30 +02:00
Akim Demaille
ea31f21fd8 C++: let %require "3.2" disable the generation of obsolete files
The files stack.hh and position.hh are deprecated.  Rather than
devoting specify %define variables to discard them (api.position.file
and api.stack.file), and rather than having to use special rules when
api.location.file is used, let's simply decide that from %require
"3.2" onwards, these files will not be generated.

The only noticeable thing here is that, in order to be able to check
the behavior of %require "3.2", to have this version (which is still
3.1-*) to accept %require "3.2".

* src/gram.h, src/gram.c (required_version): New.
* src/parse-gram.y (version_check): Set it.
* src/output.c (prepare): Pass it m4.
* data/bison.m4 (b4_required_version_if): Receive it and use it.
* data/location.cc, data/stack.hh: Replace the api.*.file with only
required version comparison.
* tests/input.at: No longer check api.stack.file and api.position.file.
* NEWS, doc/bison.texi: Don't mention them.
Document the %require 3.2 behavior.
* tests/output.at: Use %require 3.2 instead.
2018-10-16 13:33:32 +02:00
Jannick
20a6c3175f xml2xhtml.xsl: add UTF-8 encoding
To make arrows appear nicely in the browser. Currently it is shown as
some garbled something in mine (Firefox).

* data/xslt/xml2xhtml.xsl: here.
2018-10-14 18:53:21 +02:00
Akim Demaille
fa386893aa C++: style: add missing space before parens
* data/c++.m4, data/lalr1.cc, data/stack.hh, data/variant.hh,
* examples/variant-11.yy: here.
2018-10-14 15:20:39 +02:00
Akim Demaille
b8351d06f1 C++: issue a better CPP guard and Doxygen file command
Currently we use "<dir><api.location.file>" as \file argument, and as
base for the CPP guard.  This is not nice when <dir> is absolute, in
which case it is expected that the user will use api.location.include
to get something nicer.  If defined, use that name instead.

* data/location.cc (b4_location_path): New.
Use it.
* tests/c++.at (Shared locations): Check the guard and Doxygen doc.
2018-10-09 18:58:50 +02:00
Akim Demaille
67521bc0e8 C++: remove stray empty line
* data/stack.hh: here.
2018-10-09 17:12:29 +02:00
Akim Demaille
5fe636c7ee c++: provide a means to control how location.hh is included
Users may want to generate the location file elsewhere, say
$top_srcdir/include/ast/location.hh.  Yet, we should not generate
`#include "$top_srcdir/include/ast/location.hh"` but probably
something like `#include <ast/location.hh>`, or `#include
"ast/location.hh", or `#include <location.hh>`.  It entirely depends
on the compiler flags (-I/-isystem) that are used.  Bison cannot guess
what is expected, so let's give the user a means to tell how the
location file should be included.

* data/location.cc (b4_location_file): New.
* data/glr.cc, data/lalr1.cc: Use it.
2018-10-06 18:13:48 +02:00
Akim Demaille
50b8d4ba5a c++: support absolute api.location.file names
In the case a user wants to create location.hh elsewhere, it can be
helpful to define api.location.file to some possibly absolute path
such as -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"'.
Currently this does not work with `-o foo/parser.cc`, as we join foo/
and $(top_srcdir) together, the latter starting with slash.

We should not try to do that in m4, manipulating file names is quite
complex when you through Windows file name in.  Let m4 delegate this
to gnulib.

* src/scan-skel.l (at_output): Accept up to two arguments.
* data/bison.m4 (b4_output): Adjust.
* tests/skeletons.at (Fatal errors but M4 continues producing output):
Adjust to keep the error.

* data/location.cc, data/stack.hh: Leave the concatenation to @output.
* tests/output.at: Exercise api.location.file with an absolute path.
2018-10-06 17:17:25 +02:00
Akim Demaille
57d69b04b2 c++: when api.location.file is defined, don't generate stack.hh
Make it easier to have fewer files.

* data/stack.hh: Don't generate stack.hh when api.location.file is
specified.
* tests/calc++.at, tests/output.at: Adjust tests.
2018-10-06 17:17:25 +02:00
Akim Demaille
3e6a075f7f c++: make position.hh completely useless
Let's put the definition of position into location.hh, there's no real
value in keeping them separate: they are small, and share the same
requirements.

To help users transition to this new model, still generate position.hh
by default, but as a simple include to location.hh.

* data/location.cc (api.position.file): Accept only 'none' as possible
value.
(position.hh): Make it a stub.
(location.hh): Adjust.
(b4_position_define): Merge into...
(b4_location_define): this.
* data/glr.cc, data/lalr1.cc, tests/input.at, tests/output.at: Adjust.
2018-10-06 17:17:25 +02:00
Akim Demaille
29b1da4e18 c++: make stack.hh completely useless
Let's completely deprecate stack.hh.  Don't provide a means to give it
a new name, allow only its removal.

See https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00151.html
and https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00182.html.

* data/stack.hh: Reduce stack.hh to a simple comment explaining how to
get rid of it.
* data/lalr1.cc: Adjust
* tests/input.at (%define file variables): Adjust.
* tests/output.at: Remove cases where stack.hh was removed.
2018-10-06 17:17:25 +02:00
Akim Demaille
667588ee8a c++: add support for api.position.file and api.location.file
* data/location.cc: Sort includes.
(b4_position_file, b4_location_file): New.
When there's a file for locations but not for positions, include the
definition of position in the location file.
* data/lalr1.cc (b4_shared_declarations): Include the
position/location file when it exists.
Otherwise, define the class.
* data/glr.cc: Likewise.
* tests/input.at (%define file variables): Check them.
* tests/output.at (C++ output): Check various cases with
api.position.file and api.location.file.
2018-10-06 17:17:25 +02:00
Akim Demaille
b122a71c83 c++: provide control over the stack.hh file name
It was not a good idea to generate the file stack.hh.  It never was.
But now we have to deal with backward compatibility: if we stop
generating it, the build system of some build system will probably
break.

So offer the user a means to (i) decide what the name of the output
file should be, and (ii) not generate this file at all (its content
will be inline where the parser is defined).

* data/lalr1.cc (b4_percent_define_check_file_complain)
(b4_percent_define_check_file): New.
* data/stack.hh: Generate the file only if api.stack.file is not
empty.
In that case, use it as file name.
* data/lalr1.cc: Adjust to include the right file, or to include
the definition of stack.
* tests/calc.at, tests/output.at: Exercise api.stack.file.
2018-10-06 17:17:25 +02:00
Akim Demaille
fd3c17995e c++: style changes
* data/lalr1.cc: Formatting changes.
Remove duplicate definition of YY_NULLPTR.
Add quotes to help Emacs track balanced parens.
2018-10-06 15:45:21 +02:00
Josh Soref
5d4bd04588 spelling: safely 2018-10-05 07:01:05 +02:00
Josh Soref
47f92cb354 spelling: responsibility 2018-10-05 07:01:05 +02:00
Josh Soref
694c6234f9 spelling: namespace 2018-10-05 07:01:05 +02:00
Josh Soref
704a04512c spelling: appropriate 2018-10-05 07:01:03 +02:00
Akim Demaille
4247df921b style: comment changes
* data/glr.cc, data/lalr1.cc: here.
2018-09-29 12:19:33 +02:00
Akim Demaille
8c4a1163ee style: remove useless parens
* data/bison.m4, data/glr.c, data/glr.cc, data/lalr1.cc,
* data/lalr1.java, data/location.cc, data/yacc.c: Call b4_output_end
without parens.
2018-09-24 21:52:55 +02:00
Akim Demaille
2eaa7ed946 style: minor refactoring
* data/bison.m4: Formatting changes.
* src/scan-code.l: Avoid loops, prefer standard string functions.
(find_prefix_end): Be const correct.
Avoid useless intermediate variables.
(variant_add): Be const correct.
(parse_ref): Prefer variable definitions to assignments.
2018-09-24 21:52:55 +02:00
Akim Demaille
3eb9042a30 c++: introduce api.value.automove
Based on work by Frank Heckenbach.
See http://lists.gnu.org/archive/html/bug-bison/2018-04/msg00000.html
and http://lists.gnu.org/archive/html/bug-bison/2018-09/msg00019.html.

* data/lalr1.cc (b4_rhs_value): Use YY_MOVE api.rhs.automove is set.
* doc/bison.texi (%define Summary): Document api.rhs.automove.
* examples/variant-11.yy: Use it.

* tests/local.at (AT_AUTOMOVE_IF): New.
* tests/c++.at (Variants): Check move semantics.
2018-09-22 09:49:46 +02:00
Akim Demaille
b7613423ce style: use _foo for private macros, not foo_
We use both styles, let's stick to a single one.  Autoconf uses the
prefix one, let's do the same.

* data/bison.m4, data/c++.m4, data/c-like.m4, data/lalr1.cc,
* data/variant.hh, data/yacc.c: Rename all the b4_*_ macros
as _b4_*.
2018-09-19 20:42:43 +02:00
Akim Demaille
a60a9e3071 glr.c: work around ICC limitations
The CI is littered with

    #                             -*- compilation -*-
    423. regression.at:907: testing Dancer %glr-parser ...
    ./regression.at:907: bison -fno-caret -o dancer.c dancer.y
    ./regression.at:907: $BISON_C_WORKS
    stderr:
    stdout:
    ./regression.at:907: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o dancer dancer.c $LIBS
    stderr:
    icc: command line warning #10006: ignoring unknown option '-Wcast-align'
    icc: command line warning #10006: ignoring unknown option '-fparse-all-comments'
    icc: command line warning #10006: ignoring unknown option '-Wdocumentation'
    icc: command line warning #10006: ignoring unknown option '-Wnull-dereference'
    icc: command line warning #10006: ignoring unknown option '-Wbad-function-cast'
    icc: command line warning #10006: ignoring unknown option '-fno-color-diagnostics'
    icc: command line warning #10006: ignoring unknown option '-Wno-keyword-macro'
    dancer.c(755): error #1628: function declared with "noreturn" does return
      }
      ^

    dancer.c(761): error #1628: function declared with "noreturn" does return
      }
      ^

    compilation aborted for dancer.c (code 2)

ICC sees that `longjmp(buf, 1);` does not return, it sees that
`abort();` does not either, but fails to see it for
`longjmp(buf, 1); abort();`

* data/glr.c (YYLONGJMP): Be even clearer on the fact this does not
return.
2018-09-18 17:21:13 +02:00
Akim Demaille
fb1e27cf47 glr.c: prefer true/false to 1/0 in C++
* data/glr.c: here.
2018-09-18 13:21:38 +02:00
Akim Demaille
7c64b1f4ff tests: fight G++ warnings about zero as null pointer constant
In C++ pre C++11 it is standard practice to use 0 for the null pointer.
But GCC pre 8 -std=c++98 with -Wzero-as-null-pointer-constant warns about
this.

So disable -Wzero-as-null-pointer-constant when compiling C++ pre 11.
Let's do this in AT_DATA_SOURCE_PROLOGUE (which is pasted on top of
all the test grammar files).  Unfortunately, that shifts all the
locations in the expected error messages, which would be too noisy.
Instead, let's introduce testsuite.h, which can vary in length, and
include it in AT_DATA_SOURCE_PROLOGUE.

* tests/testsuite.h: New.
Disable -Wzero-as-null-pointer-constant's warning with GCC pre 8,
C++ pre 11.
* tests/local.at (AT_DATA_SOURCE_PROLOGUE): Use it.
* tests/atlocal.in (CPPFLAGS): Find it.
* tests/local.mk: Ship it.
* data/c.m4 (YY_NULLPTR): Prefer ((void*)0) to 0 in C.
2018-09-18 13:21:38 +02:00
Akim Demaille
09bc1b99c9 lalr1.cc: modern C++ no longer needs an assignment for symbols
Reported by Frank Heckenbach.
http://lists.gnu.org/archive/html/bug-bison/2018-03/msg00002.html

Actually the assignment operator should never be needed: the C++98
requirements for vector::push_back is CopyInsertable, which does not require
an assignment operator.  However, libstdc++ shipped with GCC up to (and
including) 6 uses the assignment operator (which affects Clang on top of
libstdc++, but also ICC).  So let's keep it for legacy C++.

See https://gcc.godbolt.org/z/q0XXmC.

* data/lalr1.cc (stack_symbol_type::operator=): Remove.
* data/c++.m4 (basic_symbol::operator=): Ditto.
* tests/c++.at (C++ Variant-based Symbols Unit Tests): Adjust.
2018-09-13 19:01:42 +02:00
Akim Demaille
f19ecae3b2 lalr1.cc: support move semantics
Modern C++ (i.e., C++11 and later) introduced "move only" types: types such
as std::unique_ptr<T> that can never be duplicated.  They must never be
copied (by assignments and constructors), they must be "moved".  The
implementation of lalr1.cc used to copy symbols (including their semantic
values).  This commit ensures that values are only moved in modern C++, yet
remain compatible with C++98/C++03.

Suggested by Frank Heckenbach, who provided a full implementation on
top of C++17's std::variant.
See http://lists.gnu.org/archive/html/bug-bison/2018-03/msg00002.html,
and https://lists.gnu.org/archive/html/bison-patches/2018-04/msg00002.html.

Symbols (terminal/non terminal) are handled by several functions that used
to take const-refs, which resulted eventually in a copy pushed on the stack.
With modern C++ (C++11 and later) the callers must use std::move, and the
callees must take their arguments as rvalue refs (foo&&).  In order to avoid
duplicating these functions to support both legacy C++ and modern C++, let's
introduce macros (YY_MOVE, YY_RVREF, etc.)  that rely on copy-semantics for
C++98/03, and move-semantics for modern C++.

That's easy for inner types, when the parser's functions pass arguments to
each other.  Functions facing the user (make_NUMBER, make_STRING, etc.)
should support both rvalue-refs (for instance to support move-only types:
make_INT (std::make_unique<int> (1))), and lvalue-refs (so that we can pass
a variable: make_INT (my_int)).  To avoid the multiplication of the
signatures (there is also the location), let's take the argument by value.

See:
https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00024.html.

* data/c++.m4 (b4_cxx_portability): New.
(basic_symbol): In C++11, replace copy-ctors with move-ctors.
In C++11, replace copies with moves.
* data/lalr1.cc (stack_symbol_type, yypush_): Likewise.
Use YY_MOVE to avoid useless copies.
* data/variant.hh (variant): Support move-semantics.
(make_SYMBOL): In C++11, in order to support both read-only lvalues,
and rvalues, take the argument as a copy.
* data/stack.hh (yypush_): Use rvalue-refs in C++11.
* tests/c++.at: Use move semantics.

* tests/headers.at: Adjust to the new macros (YY_MOVE, etc.).

* configure.ac (CXX98_CXXFLAGS, CXX11_CXXFLAGS, CXX14_CXXFLAGS)
(CXX17_CXXFLAGS, ENABLE_CXX11): New.
* tests/atlocal.in: Receive them.

* examples/variant.yy: Don't define things in std.
* examples/variant-11.test, examples/variant-11.yy: New.
Check the support of move-only types.
* examples/README, examples/local.mk: Adjust.
2018-09-13 19:01:33 +02:00
Akim Demaille
493182f70e build: use -fparse-all-comments with -Wdocumentation
Clang checks only /** ... */ comments without this flag.

* configure.ac (warn_common): Also check -fparse-all-comments.
2018-09-10 06:31:56 +02:00
Akim Demaille
79331541ae skeletons: style/comment changes
* data/c++.m4, data/c.m4, data/glr.c: Here.
2018-09-09 13:50:00 +02:00
Akim Demaille
d6fb1813ee variant: indent better the generated code
* data/variant.hh (b4_basic_symbol_constructor_declare)
(b4_basic_symbol_constructor_define): here.
2018-09-09 11:40:23 +02:00
Akim Demaille
7194099027 lalr1.cc: don't generate useless constructors when variant is used
This generates less code, which is nicer to read, but also takes less
chances with compilers such as G++ 4.8 that are too strict and check
"dead code" (templated code that is not instantiated).

* data/c++.m4 (b4_symbol_type_declare, b4_symbol_type_define): When
variants are used, don't generate code meant for non variants.
2018-09-09 11:40:23 +02:00
Akim Demaille
a7e46f6e41 C++: don't issue the definition of symbol_type when not used
Currently, in glr.cc, we emit the definitions of basic_symbol and
symbol_type, although there are not used.

* data/c++.m4 (b4_public_types_declare): Extract these definitions from
here, and move them...
(b4_symbol_type_declare): here.
(b4_public_types_declare): Also remove the definition of the symbol
constructors.
* data/lalr1.cc (b4_shared_declarations): Adjust: call
b4_symbol_type_declare and b4_symbol_constructor_declare.
2018-09-02 11:25:28 +02:00
Akim Demaille
50fb434689 C++: leave 'inline' on the definition, not the declaration
This is for consistency with the other uses of 'inline' in the C++
skeletons.  On examples/variant.yy, this change gives:

    --- examples/variant.hh	2018-08-31 07:16:57.214222580 +0200
    +++ examples/variant.hh	2018-08-31 07:19:52.285431997 +0200
    @@ -444,15 +444,15 @@
         typedef basic_symbol<by_type> symbol_type;

         // Symbol constructors declarations.
    -    static inline
    +    static
         symbol_type
         make_END_OF_FILE (const location_type& l);

    -    static inline
    +    static
         symbol_type
         make_TEXT (const ::std::string& v, const location_type& l);

    -    static inline
    +    static
         symbol_type
         make_NUMBER (const int& v, const location_type& l);

    @@ -945,19 +945,23 @@
         };
         return static_cast<token_type> (yytoken_number_[type]);
       }
    +
       // Implementation of make_symbol for each symbol type.
    +  inline
       parser::symbol_type
       parser::make_END_OF_FILE (const location_type& l)
       {
         return symbol_type (token::END_OF_FILE, l);
       }

    +  inline
       parser::symbol_type
       parser::make_TEXT (const ::std::string& v, const location_type& l)
       {
         return symbol_type (token::TEXT, v, l);
       }

    +  inline
       parser::symbol_type
       parser::make_NUMBER (const int& v, const location_type& l)
       {
    @@ -967,7 +971,7 @@

     } // yy
    -#line 971 "examples/variant.hh" // lalr1.cc:380
    +#line 975 "examples/variant.hh" // lalr1.cc:380

and no changes on variant.cc.

* data/c++.m4 (b4_public_types_define): Formatting changes.
* data/variant.hh (b4_symbol_value_template_, b4_symbol_constructor_declare_):
Move the 'inline' from declaration to implementation.
2018-08-31 07:25:57 +02:00
Akim Demaille
b5d4eb8913 c++: style changes
Instead of

    parser::stack_symbol_type::stack_symbol_type (const stack_symbol_type& that)
      : super_type (that.state, that.location)
    {
      value = that.value;
    }

generate

    parser::stack_symbol_type::stack_symbol_type (const stack_symbol_type& that)
      : super_type (that.state, that.value, that.location)
    {}

* data/lalr1.cc (stack_symbol_type): Improve the copy ctor, when not
using the variants.
(yypush_): Rename arguments for clarity.
2018-08-30 08:14:33 +02:00
Akim Demaille
2116ad3a28 c++: the assignment operator does not have to be const
* data/lalr1.cc (stack_symbol_type::operator=): Don't copy the
argument, move it.
2018-08-30 08:14:33 +02:00
Akim Demaille
33e523878b C++: make sure the generated header is self container
See the previous commit.

* data/lalr1.cc: Be sure to define YY_NULLPTR.
* tests/headers.at: Check the case that was failing.
2018-08-26 18:54:42 +02:00
Akim Demaille
10082ac068 "C++: restore copy-constructor for stack_symbol_type
Benchmarks show that it is more efficient to keep this copy
constructor, rather than forcing the use of the default constructor
and then assignment.

This reverts commit 7ab25ad020.
2018-08-25 11:05:53 +02:00
Jiahao Li
c1cf82f9c8 variant: fix uninitialized memory access in variant<>
Currently, in bison's C++ parser template (`lalr.cc`), the `variant<>`
struct's `build()` method uses placement-new in the form `new (...) T`
to initialize a variant type.  However, for POD variant types, this
will leave the memory space uninitialized.  If we subsequently tries
to `::move` into a variant object in such state, the call can trigger
clang's undefined behavior sanitizer due to accessing the
uninitialized memory.

https://lists.gnu.org/archive/html/bison-patches/2018-08/msg00098.html

* data/variant.hh (build): Always initialize the stored value.

Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
2018-08-25 07:25:05 +02:00
Akim Demaille
44e76d801f lalr1.cc: support compilation with disabled support for exceptions
Reported by Brooks Moses <bmoses@google.com>
http://lists.gnu.org/archive/html/bison-patches/2018-02/msg00000.html

* data/lalr1.cc (YY_EXCEPTIONS): New.
Use it to disable try/catch clauses.

* doc/bison.texi (C++ Parser Interface): Document it.

* configure.ac (CXXFLAGS_NO_EXCEPTIONS): New.
* tests/atlocal.in: Receive it.
* tests/local.at (AT_FULL_COMPILE, AT_LANG_COMPILE):
Accept a new argument, extra compiler flags.
* tests/calc.at: Run the C++ calculator with exception support disabled.
2018-08-19 17:47:59 +02:00
Akim Demaille
f348522005 C++: fix portability issue with MSVC 2017
Visual Studio issues a C4146 warning on '-static_cast<unsigned>(rhs)'.
The code is weird, probably to cope with INT_MIN.  Let's go back to
using std::max (whose header is still included in position.hh...) like
originally, but with the needed casts.

Reported by 長田偉伸, and with help from Rici Lake.

See also
http://lists.gnu.org/archive/html/bug-bison/2013-02/msg00000.html
and commit 75ae829984.

* data/location.cc (position::add_): Take min as an int.
Use std::max.
While here, get rid of a couple of useless inlines.
2018-08-18 18:07:43 +02:00
Akim Demaille
72252aaa97 lalr1.cc: remove debug comment
* data/lalr1.cc: Remove a comment about indentation.
I'm not sure it would be nice to indent even more, it's already quite
of the right.
2018-08-18 14:46:17 +02:00
Akim Demaille
5010af94d0 portability: don't use _Pragma with ICC
ICC defines __GNUC__ [1], but does not support GCC's _Pragma for
diagnostics.  As a matter of fact, I believe it does not support
_Pragma at all (only #pragma) [2].

Reported by Maxim Prohorenko.
https://savannah.gnu.org/support/index.php?108339

[1] https://software.intel.com/en-us/cpp-compiler-18.0-developer-guide-and-reference-gcc-compatibility-and-interoperability
[2] https://software.intel.com/en-us/cpp-compiler-18.0-developer-guide-and-reference-pragmas

* data/c.m4 (YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN): Exclude ICC from
the club.
2018-08-18 14:15:13 +02:00
Akim Demaille
adf0425d11 escape properly the file names in #line for printer/destructor
Reported by Jannick.
http://lists.gnu.org/archive/html/bug-bison/2017-05/msg00001.html

"Amusingly" enough, we have the same problem with %defines when the
parser file name has backslashes or quotes: we generate #includes with
an incorrect C string.

* src/output.c (prepare_symbol_definitions): Escape properly the file
names before passing them to M4.
* data/bison.m4, data/lalr1.cc: Don't simply put the file name between
two quotes (that should have been strong enough a smell...), expect
the string to be properly quoted.
* tests/synclines.at: New tests to check this.
2018-08-18 10:04:50 +02:00
Akim Demaille
1113522acb c++: fix GCC8 warnings about uninitialized values
In 0931d14728 I removed too many
initializations from some ctors: some were not about base ctors, but
about member variables.  In fact, more of them were missing to please
GCC 8.

While at it, generate more natural code for C++ without variant:
instead of

    template <typename Base>
    parser::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
      : Base (other)
      , value ()
    {
      value = other.value
    }

generate

    template <typename Base>
    parser::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
      : Base (other)
      , value (other.value)
    {}

* data/c++.m4 (basic_symbol::basic_symbol): Always initialize 'value',
it might be a POD without a ctor.
* data/lalr1.cc (stack_symbol_type::stack_symbol_type): Likewise.
* data/variant.hh (variant::variant): Default initialize the buffer too.
2018-08-15 20:24:16 +02:00
Akim Demaille
b01b80836d tests: fix warnings in push mode
Fix warning with GCC 8, -DNDEBUG.

    422. push.at:83: testing Multiple impure instances ...
    input.y: In function 'main':
    input.c:1022:12: error: potential null pointer dereference [-Werror=null-dereference]
       if (!yyps->yynew && yyps->yyss != yyps->yyssa)
            ~~~~^~~~~~~

* data/yacc.c (pstate_delete): Do nothing if called on null pointer.
2018-08-15 19:40:15 +02:00
Akim Demaille
bd07c76b0a c++: avoid GCC 8 warnings
GCC 8 issues warnings whose root cause was a bit hard to find.

    calc.cc: In member function 'virtual int yy::parser::parse()':
    calc.cc:810:18: warning: '*((void*)&<anonymous> +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         , location (l)
                      ^
    calc.cc: In member function 'void yy::parser::yypush_(const char*, yy::parser::stack_symbol_type&)':
    calc.cc:810:18: warning: '*((void*)&<anonymous> +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         , location (l)
                      ^
    calc.cc: In member function 'void yy::parser::yypush_(const char*, yy::parser::state_type, yy::parser::symbol_type&)':
    calc.cc:810:18: warning: '*((void*)&<anonymous> +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         , location (l)
                      ^

The problem is with locations that don't have a constructor, such as
Span (in calc.cc) which is POD.  It is POD on purpose: so that we can
use that structure to test glr.cc which cannot use non POD in its
(C) stacks.

* data/c++.m4 (basic_symbol): Also ensure that 'location' is
initialized.
2018-08-15 19:23:00 +02:00
Akim Demaille
30c179fee8 examples: ship and install variant.yy
This file was meant to be shown as an example.  Install it.

* README, data/README: Put Emacs metadata in the final section.
* examples/README: New.
* examples/variant.yy: Use %empty.
* examples/local.mk: Install both these files.
2018-08-14 13:36:47 +02:00
Akim Demaille
7ab25ad020 C++: remove useless copy-constructor
We currently generate copy constructors such as the following
one (taken from examples/variant.yy):

    parser::stack_symbol_type::stack_symbol_type (const stack_symbol_type& that)
      : super_type (that.state, that.location)
    {
      switch (that.type_get ())
      {
        case 3: // TEXT
        case 8: // item
          value.copy< ::std::string > (that.value);
          break;

        case 7: // list
          value.copy< ::std::vector<std::string> > (that.value);
          break;

        case 4: // NUMBER
          value.copy< int > (that.value);
          break;

        default:
          break;
      }
    }

they are actually useless: we never need it.

* data/lalr1.cc: Don't generate the stack_symbol_type copy ctor.
2018-08-14 06:17:21 +02:00
Akim Demaille
e555fb5e55 C++: symbol constructors: add a missing reference
Fix a typo so that instead of

    basic_symbol::basic_symbol (typename Base::kind_type t, const int v)

we now generate

    basic_symbol::basic_symbol (typename Base::kind_type t, const int& v)

* data/variant.hh (b4_basic_symbol_constructor_declare)
(b4_basic_symbol_constructor_define): Add missing reference.
2018-08-14 06:17:21 +02:00