Commit Graph

118 Commits

Author SHA1 Message Date
Akim Demaille
dee62718ae remove ancient lint directives
* data/c++.m4, data/yacc.c: Remove surprising remains of lint
directives.
2018-11-21 08:59:38 +01:00
Akim Demaille
037eff335b c++: use YY_CPLUSPLUS
* data/c++.m4: here.
2018-11-14 21:25:29 +01:00
Akim Demaille
7adeb80765 c++: factor the handling of __cplusplus into YY_CPLUSPLUS
* data/c++.m4 (b4_cxx_portability): Define it.
Use it.
* data/lalr1.cc, data/variant.hh: Use it.
2018-11-13 07:46:08 +01:00
Akim Demaille
7d1b1133d0 style: comment changes
* data/c++.m4, data/glr.c, data/lalr1.java, data/yacc.c
(yytranslate, YYTRANSLATE): Harmonize comments.
2018-11-11 07:59:55 +01:00
Akim Demaille
eff6739124 c++: workaround portability issue
On some systems (x86_64-pc-solaris2.11), with Developer Studio 12.5's
CC, we get:

    ".../include/CC/Cstd/vector.cc", line 127: Error: Cannot assign const yy::parser::stack_symbol_type to yy::parser::stack_symbol_type without "yy::parser::stack_symbol_type::operator=(const yy::parser::stack_symbol_type&)";.
    ".../include/CC/Cstd/vector", line 475:     Where: While instantiating "std::vector<yy::parser::stack_symbol_type>::__insert_aux(yy::parser::stack_symbol_type*, const yy::parser::stack_symbol_type&)".
    ".../include/CC/Cstd/vector", line 475:     Where: Instantiated from non-template code.
    1 Error(s) detected.

Don't expect __cplusplus to be always defined.  If it's not, consider
this is C++98.

Reported by Nelson H. F. Beebe.

* data/c++.m4, data/lalr1.cc, examples/c++/variant.yy, tests/local.at,
* tests/testsuite.h:
An undefined __cplusplus means pre C++11.
2018-11-04 08:00:01 +01: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
Josh Soref
694c6234f9 spelling: namespace 2018-10-05 07:01:05 +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
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
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
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
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
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
0931d14728 C++: remove useless calls to the base default constructor
* data/c++.m4, data/stack.hh, data/variant.hh: here.
2018-08-14 06:17:21 +02:00
Akim Demaille
928a817418 C++: style: prefer unsigned to unsigned int
* data/c++.m4: here.
2018-05-27 10:04:11 +02:00
Akim Demaille
ae8d777ad6 C++: style: space before paren
* data/c++.m4, data/lalr1.cc: here.
2018-05-27 10:04:11 +02:00
Akim Demaille
d132c2d545 C++: fix uses of inline
Sometimes `inline` would be used in *.cc files on symbols that are not
exported (useless but harmless), and sometimes on exported symbols
such as the constructor of syntax_error (harmful: linking fails).

Reported several times, including:

- by Dennis T
  http://lists.gnu.org/archive/html/bug-bison/2016-03/msg00002.html
- by Frank Heckenbach
  https://savannah.gnu.org/patch/?9616

* data/c++.m4 (b4_inline): New: expands to `inline` or nothing.
Use it where appropriate.
* data/lalr1.cc: Use it where appropriate.

* tests/c++.at (Syntax error as exception): Put the scanner in another
compilation unit to exercise the constructor of syntax_error.
2018-05-10 17:33:18 +02:00
Akim Demaille
0afeaa2ab7 C++: remove useless inline on templates
Templates are implicitly `inline`.

* data/c++.m4, data/lalr1.cc: Remove `inline` from templates.
2018-05-10 16:11:58 +02:00
Akim Demaille
b809770efb c++: style: remove useless "inline" and fix space issues
* data/lalr1.cc, data/c++.m4: Formatting changes.
* data/stack.hh: Remove useless "inline".
Add documentation.
* data/location.cc: Prefer {} for empty bodies.
2015-08-12 13:56:06 +02:00
Akim Demaille
3e82dfaa0d c++: avoid warnings when destructors don't use $$
* data/c++.m4: here.
2015-01-15 14:29:22 +01:00
Akim Demaille
ee028dceff c++: fix the use of destructors when variants are enabled
When using variants, destructors generate invalid code.
<http://lists.gnu.org/archive/html/bug-bison/2014-09/msg00005.html>
Reported by Michael Catanzaro.

* data/c++.m4 (~basic_symbol): b4_symbol_foreach works on yysym:
define it.
* tests/c++.at (Variants): Check it.
2015-01-09 13:54:58 +01:00
Akim Demaille
ee2f433512 c++: provide a means to clear symbols
The symbol destructor is currently the only means to clear a symbol.
Unfortunately during error recovery we might have to clear the
lookahead, which is a local variable (yyla) that has not yet reached
its end of scope.

Rather that duplicating the code to destroy a symbol, or rather than
destroying and recreating yyla, let's provide a means to clear a
symbol.

Reported by Antonio Silva Correia, with an analysis from Michel d'Hooge.
<http://savannah.gnu.org/support/?108481>

* data/c++.m4, data/lalr1.cc (basis_symbol::clear, by_state::clear)
(by_type::clear): New.
(basic_symbol::~basic_symbol): Use clear.
2015-01-08 16:07:59 +01:00
Akim Demaille
5422471cbb c++: clean up the handling of empty symbols
* data/c++.m4, data/lalr1.cc (yyempty_): Remove, replaced by...
(empty_symbol, by_state::empty_state): these.
(basic_symbol::empty): New.
2015-01-08 14:45:42 +01:00
Akim Demaille
8a4ec3595b c++: comment and style changes
* data/c++.m4, data/lalr1.cc: More documentation.
Tidy.
* tests/c++.at (string_cast): Rename as...
(to_string): this C++11 name.
2015-01-08 11:25:07 +01:00
Akim Demaille
827bc59ca1 %union: fix the support for named %union
Bison supports a union tag, for obscure reasons.  But it does a poor
job at it, especially since Bison 3.0.
Reported by Stephen Cameron and Tobias Frost.

It did not ensure that the name was not given several times.  An easy
way to do this is to make the %union tag be handled as a %define
variable, as they cannot be defined several times.

Since Bison 3.0, the synclines were wrongly placed, resulting in
invalid code.  Addressing this issue, because of the way the union tag
was stored (as a code muscle), would have been tedious.  Unless we
rather define the %union tag as a %percent variable, whose synclines
are easier to manipulate.

So replace the b4_union_name muscle by the api.value.union.name
%define variable, document, and check.

* data/bison.m4: Make sure that api.value.union.name has a keyword value.
* data/c++.m4: Make sure that api.value.union.name is not defined.
* data/c.m4 (b4_union_name): No longer use it, use api.value.union.name.
* doc/bison.texi (%define Summary): Document it.
* src/parse-gram.y (union_name): No longer define b4_uion_name, but
api.value.union.name.
* tests/input.at (Redefined %union name): New.
* tests/synclines.at (%union name syncline): New.
* tests/types.at: Check named %unions.
2015-01-04 18:00:51 +01:00
Akim Demaille
3209eb1c4c package: bump to 2015
Which also requires:

* gnulib: Update.
2015-01-04 17:49:13 +01:00
Akim Demaille
fc51acddb4 package: bump to 2014
* AUTHORS, ChangeLog-2012, Makefile.am, NEWS, PACKAGING, README,
* README-alpha, README-hacking, THANKS, TODO, bootstrap.conf,
* build-aux/darwin11.4.0.valgrind, build-aux/local.mk,
* build-aux/update-b4-copyright,
* build-aux/update-package-copyright-year, cfg.mk, configure.ac,
* data/README, data/bison.m4, data/c++-skel.m4, data/c++.m4,
* data/c-like.m4, data/c-skel.m4, data/c.m4, data/glr.c, data/glr.cc,
* data/java-skel.m4, data/java.m4, data/lalr1.cc, data/lalr1.java,
* data/local.mk, data/location.cc, data/stack.hh, data/variant.hh,
* data/xslt/bison.xsl, data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl,
* data/xslt/xml2xhtml.xsl, data/yacc.c, djgpp/Makefile.maint,
* djgpp/README.in, djgpp/config.bat, djgpp/config.sed,
* djgpp/config.site, djgpp/config_h.sed, djgpp/djunpack.bat,
* djgpp/local.mk, djgpp/subpipe.c, djgpp/subpipe.h,
* djgpp/testsuite.sed, doc/bison.texi, doc/local.mk, doc/refcard.tex,
* etc/README, etc/bench.pl.in, etc/local.mk,
* examples/calc++/calc++.test, examples/calc++/local.mk,
* examples/extexi, examples/local.mk, examples/mfcalc/local.mk,
* examples/mfcalc/mfcalc.test, examples/rpcalc/local.mk,
* examples/rpcalc/rpcalc.test, examples/test, examples/variant.yy,
* lib/abitset.c, lib/abitset.h, lib/bbitset.h, lib/bitset.c,
* lib/bitset.h, lib/bitset_stats.c, lib/bitset_stats.h,
* lib/bitsetv-print.c, lib/bitsetv-print.h, lib/bitsetv.c,
* lib/bitsetv.h, lib/ebitset.c, lib/ebitset.h, lib/get-errno.c,
* lib/get-errno.h, lib/lbitset.c, lib/lbitset.h, lib/libiberty.h,
* lib/local.mk, lib/main.c, lib/timevar.c, lib/timevar.def,
* lib/timevar.h, lib/vbitset.c, lib/vbitset.h, lib/yyerror.c,
* m4/bison-i18n.m4, m4/c-working.m4, m4/cxx.m4, m4/flex.m4,
* m4/timevar.m4, src/AnnotationList.c, src/AnnotationList.h,
* src/InadequacyList.c, src/InadequacyList.h, src/LR0.c, src/LR0.h,
* src/Sbitset.c, src/Sbitset.h, src/assoc.c, src/assoc.h,
* src/closure.c, src/closure.h, src/complain.c, src/complain.h,
* src/conflicts.c, src/conflicts.h, src/derives.c, src/derives.h,
* src/files.c, src/files.h, src/flex-scanner.h, src/getargs.c,
* src/getargs.h, src/gram.c, src/gram.h, src/graphviz.c,
* src/graphviz.h, src/ielr.c, src/ielr.h, src/lalr.c, src/lalr.h,
* src/local.mk, src/location.c, src/location.h, src/main.c,
* src/muscle-tab.c, src/muscle-tab.h, src/named-ref.c,
* src/named-ref.h, src/nullable.c, src/nullable.h, src/output.c,
* src/output.h, src/parse-gram.c, src/parse-gram.y, src/print-xml.c,
* src/print-xml.h, src/print.c, src/print.h, src/print_graph.c,
* src/print_graph.h, src/reader.c, src/reader.h, src/reduce.c,
* src/reduce.h, src/relation.c, src/relation.h, src/scan-code.h,
* src/scan-code.l, src/scan-gram.h, src/scan-gram.l, src/scan-skel.h,
* src/scan-skel.l, src/state.c, src/state.h, src/symlist.c,
* src/symlist.h, src/symtab.c, src/symtab.h, src/system.h,
* src/tables.c, src/tables.h, src/uniqstr.c, src/uniqstr.h,
* tests/actions.at, tests/atlocal.in, tests/bison.in, tests/c++.at,
* tests/calc.at, tests/conflicts.at, tests/cxx-type.at,
* tests/existing.at, tests/glr-regression.at, tests/headers.at,
* tests/input.at, tests/java.at, tests/javapush.at, tests/local.at,
* tests/local.mk, tests/named-refs.at, tests/output.at, tests/push.at,
* tests/reduce.at, tests/regression.at, tests/sets.at,
* tests/skeletons.at, tests/synclines.at, tests/testsuite.at,
* tests/torture.at, tests/types.at:
here.
2014-02-03 15:27:02 +01:00
Akim Demaille
6ce4b4ff1b muscle: check more cases of %define variables with code values
* data/bison.m4 (b4_percent_define_check_kind): Fix overquotation.
(api.location.type, api.position.type): Check they have code values here.
* data/c++.m4 (api.location.type): No longer checked here.
(parser_class_name): Check it here.
* data/java.m4 (api.value.type, init_throws, lex_throws, parser_class_name)
(throws, annotations, extends, implements): Check they have code values.
* doc/bison.texi: Fix every incorrect occurrence of %define.
Document the additional syntax for %define: code values.
Document the additional syntax for -D/-F: string and code values.
* tests/calc.at, tests/headers.at, tests/input.at, tests/java.at,
* tests/local.at: Fix dependencies.
2013-04-18 17:19:30 +02:00
Akim Demaille
aba47f5624 muscle: check the kind of api.prefix, api.location.type
* data/bison.m4: Check api.prefix.
* data/c++.m4: Check api.location.type.
* doc/bison.texi: Fix uses of api.value.type, api.prefix, api.location.type.
Document {...} values for %define.
* src/parse-gram.y: Fix use of api.prefix.
* tests/calc.at: Fix uses of api.location.type.
* tests/input.at: Check api.prefix, and api.location.type.
2013-04-16 17:42:43 +02:00
Akim Demaille
07e65a77aa muscle: factor the kind check in M4
* data/bison.m4 (b4_percent_define_check_kind): New.
Use it to check api.token.prefix.
* data/c++.m4: Check the kind of api.namespace.
* doc/bison.texi: Update a reference to former 'namespace' variable.
* tests/input.at ("%define" code variables): Check api.namespace.
2013-04-15 10:37:00 +02:00
Akim Demaille
435575cb5e api.value.type: use keyword/brace values
Suggested by Joel E. Denny.
http://lists.gnu.org/archive/html/bison-patches/2013-03/msg00016.html

* data/bison.m4 (b4_percent_define_get_kind): New.
(b4_variant_flag): Check that api.value.type is defined as the 'variant'
keyword value.
* data/c.m4 (_b4_value_type_setup_keyword): New.
(b4_value_type_setup): Use it to simplify reading.
Use b4_define_silent.
Decode api.value.type, including its type.
(b4_value_type_define): Likewise.
* data/c++.m4 (b4_value_type_declare): Adjust the decoding of api.value.type,
taking its kind into account.
* doc/bison.texi: Adjust all the examples to the new syntax.
* NEWS: Ditto.
* tests/types.at: Adjust
2013-04-09 16:59:06 +02:00
Akim Demaille
6574576cfb api.value.type: implement proper support, check, and document
* data/c.m4 (b4_symbol_type_register, b4_type_define_tag)
(b4_symbol_value_union, b4_value_type_setup_union)
(b4_value_type_setup_variant, b4_value_type_setup):
New.
(b4_value_type_define): Use it to set up properly the type.
Handle the various possible values of api.value.type.
* data/c++.m4 (b4_value_type_declare): Likewise.
* data/lalr1.cc (b4_value_type_setup_variant): Redefine.

* tests/types.at: New.
Exercise all the C/C++ skeletons with different types of
api.value.type values.
* tests/local.mk, tests/testsuite.at: Use it.

* doc/bison.texi (%define Summary): Document api.value.type.
* NEWS: Advertise it, together with api.token.constructor.
2013-04-09 14:07:51 +02:00
Akim Demaille
7601a471f5 c++: rename b4_semantic_type_declare as b4_value_type_declare
This is to match the names used in C and api.value.type, even if the
parser actually defines semantic_type.

* data/c++.m4 (b4_semantic_type_declare): Rename as...
(b4_value_type_declare): this.
* data/variant.hh: Likewise.
2013-02-23 16:16:15 +01:00
Akim Demaille
45eebca42d style: no longer use backquotes
* README, REFERENCES, TODO, configure.ac, data/README, data/bison.m4,
* data/c++.m4, data/c.m4, data/java.m4, data/lalr1.cc,
* data/lalr1.java, data/yacc.c, doc/local.mk, etc/bench.pl.in,
* src/conflicts.c, src/files.c, src/getargs.c, src/gram.h, src/lalr.c,
* src/location.c, src/location.h, src/muscle-tab.c, src/muscle-tab.h,
* src/output.c, src/parse-gram.c, src/parse-gram.y, src/print-xml.c,
* src/print.c, src/reader.c, src/reduce.c, src/scan-skel.l,
* src/symtab.h, src/system.h, src/tables.c:
Use single quotes, as currently recommended by the GNU Coding Standards.
2013-02-18 10:01:28 +01:00
Akim Demaille
1dce289a00 c++: api.token.constructor requires api.value.type=variant
Eventually it should also support "union".

* data/glr.cc: Move this check to...
* data/c++.m4: here, as lalr1.cc is affected too.
2013-02-08 17:28:02 +01:00
Akim Demaille
c5dbd909d0 style: rename internal "stype" as "union_members" for clarity
"stype" is quite unclear, and it also collides with the former %define
variable that had the same name (replaced by api.value.type).

* src/parse-gram.y (stype): Rename as...
(union_members): this.
* data/bison.m4: Adjust.
(b4_user_stype): Rename as...
(b4_user_union_members): this.
* data/c++.m4, data/c.m4: Adjust.
* src/parse-gram.c: regen.
2013-02-04 18:45:21 +01:00
Theophile Ranquet
ee9cf8c4a6 m4: generate a basic_symbol constructor for each symbol type
Recently, there was a slightly vicious bug hidden in the make_ functions:

  parser::symbol_type
  parser::make_TEXT (const ::std::string& v)
  {
    return symbol_type (token::TOK_TEXT, v);
  }

The constructor for symbol_type doesn't take an ::std::string& as
argument, but a constant variant.  However, because there is a variant
constructor which takes an ::std::string&, this caused the implicit
construction of a built variant.  Considering that the variant argument
for the symbol_type constructor was cv-qualified, this temporary variant
was never destroyed.

As a temporary solution, the symbol was built in two stages:

  symbol_type res (token::TOK_TEXT);
  res.value.build< ::std::string&> (v);
  return res;

However, the solution introduced in this patch contributes to letting
the symbols handle themselves, by supplying them with constructors that
take a non-variant value and build the symbol's own variant with that
value.

* data/variant.hh (b4_symbol_constructor_define_): Use the new
constructors rather than building in a temporary symbol.
(b4_basic_symbol_constructor_declare,
b4_basic_symbol_constructor_define): New macros generating the
constructors.
* data/c++.m4 (basic_symbol): Invoke the macros here.
2013-01-29 11:37:04 +01:00
Theophile Ranquet
858666c443 c++: minor stylistic changes
* data/c++m4: Remove useless comment lines.
* data/variant.hh (self_type): Use this typedef instead of variant<S>.
(b4_symbol_constructor_define_): Remove commented-out line, and stylistic
change (avoid blank line).
2013-01-29 11:32:38 +01:00
Akim Demaille
675d9fe489 c++: please G++ 4.8 with -O3: array bounds
* data/c++.m4, data/lalr1.cc (by_state, by_type): Do not use -1 to
denote the absence of value, as GCC then fears that this -1 might
be used to dereference arrays (such as yytname).
Use 0, which corresponds to $accept, which is valueless (the needed
property: the symbol destructor must not try to reclaim the memory
associated with the symbol).
2013-01-29 09:04:08 +01:00
Akim Demaille
26f95f5f35 c++: use more explicit types than int
* data/c++.m4 (b4_public_types_declare): Declare token_number_type soon.
Introduce symbol_number_type (wider than token_number_type).
Clarify the requirement that kind_type from by_state and by_type
denote the _input_ type (required by the constructor), not the stored type.
Use symbol_number_type and token_number_type where appropriate, instead
of int.
* data/lalr1.cc: Adjust to these changes.
Propagate "symbol_number_type".
Invoke "type_get ()" instead of read "type" directly.
2013-01-29 09:04:08 +01:00
Akim Demaille
7fc7df7a38 c++: value_type -> kind_type
* data/c++.m4, data/lalr1.cc (by_type, by_state): Rename 'value_type'
as 'kind_type', as it is clearer.
2013-01-29 09:04:08 +01:00
Theophile Ranquet
b20e797a71 c++: better inline expansion
Many 'inline' keywords were in the declarations.  They rather belong in
definitions, so move them.

* data/c++.m4 (basic_symbol, by_type): Many inlines here.
* data/lalr1.cc (yytranslate_, yy_destroy_, by_state, yypush_, yypop_): Inline
these as well.
(move): Move the definition outside the struct, where it belongs.
2013-01-28 18:26:49 +01:00
Akim Demaille
7d1aa2d636 c++: remove now-useless operators
Now that symbols behaves properly, we can eliminate special routines
that are no longer needed.

* data/c++.m4, data/glr.cc, data/lalr1.cc, data/variant.hh:
Remove useless assignment operators and copy constructors.
As a consequence, remove useless includes for "abort".
2013-01-28 15:00:23 +01:00
Akim Demaille
97ae878ec3 c++: revamp the support for variants
The current approach was too adhoc: the symbols were not sufficiently
self-contained, in particular wrt memory management.  The "new"
guideline is the one that should have been followed from the start:
let the symbols handle themslves, instead of leaving their users to
it.  It was justified by the will to avoid gratuitious moves and
copies, but the current approach does not seem to be slower, yet it
will probably be simpler to adjust to support move semantics from
C++11.

The documentation says that the %parse-param are available from the
%destructor.  In retrospect, that was a silly design decision, which
we can break for variants, as its a new feature.  It should be phased
out for non-variants too.

* data/variant.hh: A variant never knows if it stores something or
not, it is up to its users to store this information.
Yet, in parse.assert mode, make sure the empty/filled variants
are properly used.
(b4_symbol_constructor_define_): Don't call directly the symbol
constructor, to save a useless temporary.
* data/stack.hh (push): Steal the pushed value instead of duplicating
it.
This will simplify the callers of push, who handled this "move"
approach themselves.
* data/c++.m4 (basic_symbol): Let -1, as kind, denote the fact that
a symbol is empty.
This is needed for instance when shifting the lookahead: yyla
is given as argument to "push", and its value is then moved on
the stack.  But then yyla must be declared "empty" so that its
destructor won't be called.
(basic_symbol::move): New.
Move the responsibility of calling the destructor from yy_destroy
to ~basic_symbol in the case of variants.
* data/lalr1.cc (stack_symbol_type): Now a derived class from its
previous value, so that we can add a constructor from a symbol_type.
(by_state): State -1 means empty.
(yypush_): Factor, by calling one overload from the other one, and
using the new semantics of stack::push.
No longer reclaim by hand the memory from rhs symbols, since now
that we store objects with proper destructors, they will be reclaimed
automatically.
Conversely, be sure to delete yylhs.
* tests/c++.at (C++ Variant-based Symbols): New "unit" test for
symbols.
2013-01-28 15:00:22 +01:00
Akim Demaille
5f87211cb4 c++: formatting and comment changes
* data/c++.m4, data/lalr1.cc, data/stack.hh, data/variant.hh:
Fix indentation.
Fix some comments.
2013-01-28 14:22:51 +01:00
Theophile Ranquet
733fb7c593 c++: remove useless inlines
* data/c++.m4 (basic_symbol): Keep 'inline' in the prototypes, but don't
duplicate it in the implementation.
* data/variant.hh (variant): 'inline' is not needed when the implementation is
provided in the class definition.
2013-01-15 15:36:24 +01:00
Theophile Ranquet
403febcac5 c++: m4 stylistic change
* data/c++.m4 (syntax_error): Fix the indentation of 'inline'.
2013-01-15 15:36:24 +01:00