Commit Graph

1256 Commits

Author SHA1 Message Date
Akim Demaille
98d199ccc8 c++: fix token constructors for types with commas
Bitten by macros, again.
See 680b715518.

* data/variant.hh (_b4_symbol_constructor_declare)
(_b4_symbol_constructor_define): Do not use user types, which can
include commas as in `std::pair<int, int>`, to macros.

* tests/local.at: Adjust the lex related macros to support the
case of token constructors.
* tests/types.at: Also check token constructors on types with commas.
2018-12-19 06:40:28 +01:00
Akim Demaille
25b9eada8c symbols: check the previous commit
* tests/input.at (Symbol declarations): New.
2018-12-16 12:27:28 +01:00
Akim Demaille
d68f05d75c style: s/non-terminal/nonterminal/
I personally prefer 'non terminal', or 'non-terminal', but
'nonterminal' is the common spelling.

* data/glr.c, src/parse-gram.y, src/symtab.c, src/symtab.h,
* tests/input.at, doc/refcard.tex: here.
2018-12-11 06:55:41 +01:00
Akim Demaille
81dbd0d82e C++: support variadic emplace
Suggested by Askar Safin.
http://lists.gnu.org/archive/html/bug-bison/2018-12/msg00006.html

* data/variant.hh: Implement.
* tests/types.at: Check.
* doc/bison.texi: Document.
2018-12-10 17:50:12 +01:00
Akim Demaille
e1a843cc69 d: fix double definition of YYSemanticType
* data/lalr1.d: When moving to b4_user_union_members, it also defines
b4_tag_seen_flag, so we had two definitions.
2018-12-08 08:05:00 +01:00
Akim Demaille
10e3ccac05 d: fix use of b4_union_members
* data/lalr1.d: Use b4_user_union_members instead.
2018-12-06 06:27:33 +01:00
Akim Demaille
3d5059f431 style: comment changes
* data/variant.hh: here.
2018-12-06 06:27:33 +01:00
Akim Demaille
cfd682f46d d, java: compute static subtractions
* data/d.m4, data/java.m4: Use b4_subtract where appropriate.
2018-12-05 06:02:01 +01:00
Akim Demaille
0ebcae4a54 d: update the skeleton
* data/d.m4, data/lalr1.d: Catch up with Bison.
And actually, also catch up with D.
2018-12-04 20:43:01 +01:00
Akim Demaille
4a42a4f911 d: add skeleton for the D language
Contributed by Oliver Mangold.
https://lists.gnu.org/archive/html/help-bison/2012-01/msg00000.html

* README-D.txt, d-skel.m4, d.m4, lalr1.d: New.
2018-12-04 20:29:28 +01:00
Akim Demaille
999277ddd8 skeletons: start some technical documentation
* data/README: Convert to Markdown.
Start documenting some of the macros used in all our skeletons.
Simplify and fix the documentation of the macros in the skeletons.
2018-12-04 08:36:52 +01:00
Akim Demaille
c44a782a4e backend: revamp the handling of symbol types
Currently it is the front end that passes the symbol types to the
backend.  For instance:

  %token <ival> NUM
  %type <ival> exp1 exp2
  exp1: NUM { $$ = $1; }
  exp2: NUM { $<ival>$ = $<ival>1; }

In both cases, $$ and $1 are passed to the backend as having type
'ival' resulting in code like `val.ival`.  This is troublesome in the
case of api.value.type=union, since in that the case the code this:

  %define api.value.type union
  %token <int> NUM
  %type <int> exp1 exp2
  exp1: NUM { $$ = $1; }
  exp2: NUM { $<int>$ = $<int>1; }

because in this case, since the backend does not know the symbol being
processed, it is forced to generate casts in both cases: *(int*)(&val)`.
This is unfortunate in the first case (exp1) where there is no reason
at all to use a cast instead of `val.NUM` and `val.exp1`.

So instead delegate the computation of the actual value type to the
backend: pass $<ival>$ as `symbol-number, ival` and $$ as
`symbol-number, MULL`, instead of passing `ival` before.

* src/scan-code.l (handle_action_dollar): Find the symbol the action
is about, not just its tyye.  Pass both symbol-number, and explicit
type tag ($<tag>n when there is one) to b4_lhs_value and b4_rhs_value.

* data/bison.m4 (b4_symbol_action): adjust to the new signature to
b4_dollar_pushdef.

* data/c-like.m4 (_b4_dollar_dollar, b4_dollar_pushdef): Accept the
symbol-number as new argument.

* data/c.m4 (b4_symbol_value): Accept the symbol-number as new
argument, and use it.
(b4_symbol_value_union): Accept the symbol-number as new
argument, and use it to prefer ready a union member rather than
casting the union.
* data/yacc.c (b4_lhs_value, b4_rhs_value): Accept the new
symbol-number argument.
Adjust uses of b4_dollar_pushdef.
* data/glr.c (b4_lhs_value, b4_rhs_value): Adjust.

* data/lalr1.cc (b4_symbol_value_template, b4_lhs_value): Adjust
to the new symbol-number argument.
* data/variant.hh (b4_symbol_value, b4_symbol_value_template): Accept
the new symbol-number argument.

* data/java.m4 (b4_symbol_value, b4_rhs_data): New.
(b4_rhs_value): Use them.
* data/lalr1.java: Adjust to b4_dollar_pushdef, and use b4_rhs_data.
2018-12-03 18:40:26 +01:00
Akim Demaille
e40db8976c style: comment and formatting changes
* data/bison.m4, data/c++.m4, data/glr.c, data/java.m4, data/lalr1.cc,
* data/yacc.c, src/scan-code.l:
Fix comments.
Prefer POS to denote the position of a symbol in a rule, since NUM
is also used to denote symbol numbers.
2018-12-03 08:42:26 +01:00
Akim Demaille
e76a934853 c++: don't define variant<S>, directly define semantic_type
Instead of defining yy::variant<S> and then alias
yy::parser::semantic_type to variant<sizeof (union_type)>, directly
define yy::parser::semantic_type.

This model is more appropriate if we want to sit the storage on top of
unions in C++11.

* data/variant.hh (b4_variant_define): Specialize and inline the
definition into...
(b4_value_type_declare): Here.
Define union_type here.
* data/lalr1.cc: Adjust.
2018-12-03 05:40:46 +01:00
Akim Demaille
6ef788f810 C++: use noexcept and constexpr
There are probably more opportunities for them.
So far, I observed no performance improvements.

* data/c++.m4, data/lalr1.cc, data/stack.hh: here.
2018-12-01 12:54:42 +01:00
Akim Demaille
cc050fd321 warning: avoid warnings about unreachable code
Reported by Uxio Prego.
https://lists.gnu.org/archive/html/help-bison/2018-11/msg00031.html

We also need to move the unreachable 'goto' to a reachable place,
otherwise clang complains about the code being unreachable anyway.
See also https://bugs.llvm.org/show_bug.cgi?id=39736.

Interestingly, we don't have to apply that trick to
`#define YYCDEBUG if (false) std::cerr`, clang does not warn when the
code comes from macro expansion.

* configure.ac: Use -Wunreachable-code when supported.
* data/lalr1.cc, data/yacc.c: Pacify clang's warning about `if (0)`
by using a macro.
Another possibility was to move this statement to a reachable place.
* tests/actions.at, tests/c++.at: Avoid generating unreachable code.
2018-11-25 11:22:31 +01:00
Akim Demaille
660811a6c5 yacc.c: avoid generating dead code
We should probably introduce some struct and functions to deal with
stack management, rather than open coding it.  yyparse would be much
nicer to read, and a better model for possible other skeletons.

* data/yacc.c (yyparse::yysetstate): Avoid generating code when
neither yyoverflow nor YYSTACK_RELOCATE is defined.
2018-11-24 13:26:27 +01:00
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
6bc54a934e style: harmonize the labels of yyparse
* data/glr.c, data/lalr1.cc, data/yacc.c: Fix indentation and
other formatting issues.
2018-11-20 20:52:58 +01:00
Akim Demaille
4e510c69b1 c++: using macros around user types breaks when they include comma
We may generate code such as

    basic_symbol (typename Base::kind_type t, YY_RVREF (std::pair<int,int>) v);

which, of course, breaks, because YY_RVREF sees two arguments.  Let's
not play tricks with _VA_ARGS__, I'm unsure about it portability.
Anyway, I plan to change more things in this area.

Reported by Sébastien Villemot.
http://lists.gnu.org/archive/html/bug-bison/2018-11/msg00014.html

* data/variant.hh (b4_basic_symbol_constructor_declare)
(b4_basic_symbol_constructor_define): Don't use macro on user types.
* tests/types.at: Check that we support pairs.
2018-11-20 20:01:50 +01:00
Akim Demaille
8474dbc09e glr.c: fix use of _Noreturn
In C++, [[noreturn]] must not be between "static" and the rest of the
function signature, it must precede it.  C's _Noreturn does not seem
to have such a constraint, but it is therefore compatible with the C++
constraint.  Since we #define _Noreturn as [[noreturn]] is modern C++,
be sure to push the _Noreturn first.

Unfortunately this was not caught by the test suite, because it always
loads config.h first, and config.h contains another definition of
_Noreturn that does not use [[noreturn]], and hides ours.  That's
probably a sign we should avoid always loading config.h.

* data/glr.c (yyFail, yyMemoryExhausted): here.
2018-11-16 17:37:47 +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
e4ee138f64 yacc: reduce scope in push mode
* data/yacc.c (yypull_parse): Here.
2018-11-11 08:57:55 +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
2deb687446 c++: simplify a default construction
* data/lalr1.cc (yytnamerr_): here.
2018-11-10 17:03:36 +01:00
Akim Demaille
86efe28222 c++: improve the generated documentation
* data/lalr1.cc, data/location.cc: Improve documenting comments.
* tests/c++.at (Doxygen Documentation): Fix AT_BISON_OPTION_PUSHDEFS,
so that the generated yyerror is correct.
* tests/c++.at, tests/headers.at: Prefer %empty.
2018-11-04 17:56:09 +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
f8cadc731b c: provide a definition of _Noreturn that works for C++
On Solaris, GCC 7.3 defines:

                      -std=c++14  -std=c++17
    __cplusplus       201402L       201703L
    __STDC_VERSION__  199901L       201112L

So the current #definition of _Noreturn sees that 201112 <=
__STDC_VERSION__, i.e., that C11 is supported, so it expects _Noreturn
to be supported.  Apparently it is not.

This is only for C++, the test suite works for C.  However, the test
suite does not try several C standards, maybe we should...

http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00064.html

* data/c.m4 (b4_attribute_define): Define _Noreturn as [[noreturn]] in
modern C++.
2018-10-31 12:06:24 +01:00
Akim Demaille
bd7aebb8b0 c: update the definition of _Noreturn
Does not work on Solaris 11.3 x86/64:

    479. c++.at:1293: testing C++ GLR parser identifier shadowing ...
    ======== Testing with C++ standard flags: '-std=c++17'
    ./c++.at:1332: $BISON_CXX_WORKS
    stderr:
    stdout:
    ./c++.at:1332: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    stderr:
    input.cc:837:8: error: '_Noreturn' does not name a type
     static _Noreturn void
            ^~~~~~~~~
    input.cc:845:8: error: '_Noreturn' does not name a type
     static _Noreturn void
            ^~~~~~~~~

Reported by Kiyoshi Kanazawa.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00051.html

* data/c.m4 (b4_attribute_define): Use the snippet which is currently
in gnulib's m4/gnulib-common.m4 (which seems a little more advanced
than lib/_Noreturn.h).
2018-10-30 19:44:31 +01:00
Akim Demaille
bd0cf11e00 c++: always issue the "generated by" message
Some users rely on this sentence to know that the file can be ignored.
Reported by Alexandre Duret-Lutz.

* data/bison.m4 (b4_generated_by): New.
(b4_copyright): Use it.
* data/location.cc, data/stack.hh: Use it too, for the stub files
(position.hh and stack.hh).
2018-10-29 20:07:21 +01:00
Jannick
01c5b6ab0f xml2dot.xsl: fix typos in comments 2018-10-27 16:43:27 +02:00
Akim Demaille
f9bba892bd c++: make operator() an alias to the parse function
* data/glr.cc, data/lalr1.cc (operator()): New.
* doc/bison.texi: Update.
2018-10-24 06:18:57 +02:00
Akim Demaille
9d8fc7fd3e yacc.c: work around strange typing issues
On the CI, both GCC and Clang report:

    src/parse-gram.c: In function 'yy_lac':
    src/parse-gram.c:1479:29: error: format '%hd' expects argument of type 'int',
       but argument 3 has type 'yytype_int16 {aka long int}' [-Werror=format=]
             YYDPRINTF ((stderr, " G%hd", yystate));
                                 ^

Although yytype_int16 is supposed to be a short int, not a long int.
This must be explored.

* data/yacc.c (yy_lac): Work around typing issue.
2018-10-23 09:08:57 +02:00
Akim Demaille
b5515215c1 yacc.c: don't define _Noreturn uselessly
Clang warns:

     aux/x.h:97:11: error: macro name is a reserved identifier
           [-Werror,-Wreserved-id-macro]
     #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))

Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00024.html

* data/c.m4 (b4_attribute_define): Don't define _Noreturn unconditionally.
* data/glr.c: Ask for _Noreturn.
2018-10-23 09:08:57 +02:00
Akim Demaille
ab3dc5415c pacify ICC 16.0.3 20160415
Found on the CI.

yacc.c:

    error #2259: non-pointer conversion from "int" to "yytype_int16={short}" may lose significant bits
        yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp
                ^

glr.c:

    error #2259: non-pointer conversion from "int" to "yybool={unsigned char}" may lose significant bits
      yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULLPTR);
                                          ^

    error #2259: non-pointer conversion from "int" to "yybool={unsigned char}" may lose significant bits
      return yypact_value_is_default (yypact[yystate]);
             ^

    error #2259: non-pointer conversion from "int" to "yybool={unsigned char}" may lose significant bits
      return 0 < yyaction;
             ^

    error #2259: non-pointer conversion from "int" to "yybool={unsigned char}" may lose significant bits
      return yyaction == 0;
             ^

    error #2259: non-pointer conversion from "int" to "yybool={unsigned char}" may lose significant bits
      yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
                                                     ^

* data/glr.c, data/yacc.c: Avoid these warnings.
2018-10-23 09:08:57 +02:00
Akim Demaille
121da2cbdb glr.c: be strict about types
* data/glr.c: Don't use `foo |= bar` with foo and bar being yybool:
the result appears to be an int, not a yybool.
Use yybool where appropriate.
Add casts where needed.
2018-10-23 09:08:57 +02:00
Akim Demaille
7a45fc35bf yacc.c: fix warnings about integral types
Reported by Derek Clegg.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00018.html

Rather than adding casts, we should be more careful with types.  For
instance yystate should be a yytype_int16.  But currently we can't: it
is also used sometimes for storing other things that state numbers.

* data/yacc.c (yyparse): Add missing casts.
2018-10-23 09:08:57 +02:00
Akim Demaille
ae1e65a285 yacc.c: clarify the computation of yystate
The yacc.c skeleton is old, and was using many tricks to save
registers.  Today's register allocators can do this themselves.  Let's
keep the code simpler to read and let compilers do their job.

* data/yacc.c: Avoid using yystate for different types of content.
An inline function would be better, but doing this portably will be
a problem.
2018-10-22 17:49:08 +02:00
Akim Demaille
ba9db64745 printf returns a signed int
* tests/local.at: Adjust location_print's signature.
2018-10-22 17:49:08 +02:00
Akim Demaille
0021bc3e28 c++: fix signedness issues
* data/lalr1.cc, data/stack.hh: The callers of stack use int, while
stack is based on size_type.  Add overloads to avoid warnings.
2018-10-22 08:40:39 +02:00
Akim Demaille
4b0efdeb28 c++: minor changes
* data/lalr1.cc: Fix oldish comment.
* data/stack.hh: Prefer typename for type names.
Use size() instead of duplicating it.
* examples/variant-11.yy, examples/variant.yy (yylex): Use int,
as this is the type of the semantic value.
2018-10-22 08:40:39 +02:00
Akim Demaille
73917e9e6f all: display a clear warning about private macros
* data/bison.m4 (b4_disclaimer): New.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it.
2018-10-22 07:28:54 +02:00
Akim Demaille
ba29791773 c++: minor simplification
* data/stack.hh: Prefer a default argument value to two constructors.
2018-10-21 19:09:53 +02:00
Akim Demaille
81a9580622 all: avoid useless comments and #lines
Currently we emit useless code for places where we might issue user
content, but there is none.  This commit avoids this.  Besides, some
of the comments looked like implementation details ("Copy the first
part of user declarations"), rather than made for the reader of the
result ("First part of user prologue").

On Bison's parse-gram.c we get:

    @@ -76,10 +76,6 @@
     #define yynerrs         gram_nerrs

    -/* Copy the first part of user declarations.  */
    -
    -#line 82 "src/parse-gram.c" /* yacc.c:339  */
    -

* data/bison.m4 (b4_define_user_code): Accept a comment to document
the section.
Do not emit any code if the content is empty.
Adjust callers to not emit the comment.
Do not
* data/glr.c, data/glr.cc, data/lalr1.cc, data/lalr1.java, data/yacc.c:
Adjust.
2018-10-21 09:58:44 +02:00
Akim Demaille
3ead69b1c1 c++: prefer a perfect forwarding version of variant's emplace
* data/variant.hh (emplace): In modern C++, use only a perfect
forwarding version.
And use it.
* doc/bison.texi: Document it.
2018-10-20 19:03:01 +02:00
Akim Demaille
42f0b949ec c++: prefer 'emplace' to 'build'
When we introduced variants in Bison, C++ did not have the 'emplace'
functions, and we chose 'build'.  Let's align with modern C++ and
promote 'emplace' rather than 'build'.

* data/lalr1.cc, data/variant.hh (emplace): New.
(build): Deprecate in favor of emplace.
* doc/bison.texi: Adjust.
2018-10-20 19:03:01 +02:00
Akim Demaille
e7b709ab0b %printer: promote yyo rather than yyoutput
* doc/bison.texi: Promote yyo rather than yyoutput.

* data/c.m4, data/glr.cc, tests/types.at, tests/calc.at,
tests/regression.at: Adjust.
2018-10-20 19:03:01 +02:00
Akim Demaille
ace93397c1 c++: don't obfuscate std::move when not needed
* data/lalr1.cc, data/variant.hh: Avoid macros that depend on the
version of C++ when not needed.
2018-10-20 09:18:40 +02:00
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