Commit Graph

1709 Commits

Author SHA1 Message Date
Akim Demaille
787052f074 style: java: more style fixes
* data/skeletons/lalr1.java, tests/java.at: Avoid space before paren.
And use braces as is customary in the Java.
2020-11-03 08:46:54 +01:00
Akim Demaille
042b916c0e style: comment changes in the skeletons
* data/skeletons/lalr1.cc: Prepare for Java's LAC.
* data/skeletons/lalr1.java: Style fixes.
2020-11-03 08:46:54 +01:00
Adela Vais
0cd16ae964 d: create the Parser.Context class
This will provide the user an interface for creating custom error messages.

* data/skeletons/lalr1.d: Add the Context class.
* doc/bison.texi: Document it.
2020-10-27 07:39:00 +01:00
Adela Vais
7cd195b30a d: change api.token.raw default value to true
Generate consecutive values for enum TokenKind, as D's yylex()
returns TokenKind and collisions can't happen.

* data/skeletons/d.m4: Change default value.
* tests/scanner.at, tests/d.at: Check it.
2020-10-03 17:17:32 +02:00
Akim Demaille
e66673aa64 m4: have b4_percent_define_if_define apply default values lazily
Currently `b4_percent_define_ifdef([foo])` assigns a default value to
`foo` when invoked.  As a consequence, skeletons such as lalr1.d
cannot specify their specific default values: `foo` was defined in
bison.m4.

Instead, provide `foo` with a default value when `b4_foo_if` is
invoked.

I could not measure a runtime difference between both cases.

* data/skeletons/bison.m4 (_b4_percent_define_define): New.
Helps getting rid of spurious indentation that resulted in spurious
white space in the output.
(b4_percent_define_if_define): Move the definition to...
(_b4_percent_define_if_define): when the defined macros is called.
2020-10-03 09:17:53 +02:00
Adela Vais
3829bd6262 d: don't trigger GC in void toString
* data/skeletons/d.m4 (b4_declare_symbol_enum): Here.
2020-10-02 06:48:11 +02:00
Adela Vais
4bbda69f1e d: remove the default prefix for SymbolKind's enum elements
This is not needed in D, since the kinds are "scoped".

* data/skeletons/d.m4: Remove the default prefix.
* doc/bison.text: Document it.
2020-10-02 06:46:32 +02:00
Adela Vais
4855b98554 d: remove the @property attribute from interface Lexer
D best practices is to not use it.

* data/skeletons/lalr1.d: Remove attribute.
2020-10-02 06:35:17 +02:00
Akim Demaille
cd40ec9526 symbols: stop dealing with YYEMPTY as b4_symbol(-2, ...)
* data/skeletons/bison.m4 (b4_symbol): Redirect `b4_symbol(empty,
...)` to `b4_symbol(-2, ...)`.
Change all uses of the latter to the former.
2020-09-29 06:49:31 +02:00
Adela Vais
2e5592b3ab d: support api.symbol.prefix and api.token.prefix
The D skeleton was not properly supporting them.

* data/skeletons/d.m4, data/skeletons/lalr1.d: Fix it.
* tests/calc.at: Check it.
2020-09-28 19:27:19 +02:00
Akim Demaille
9b18cac96b multistart: start more thorough testing
* tests/local.at (AT_MULTISTART_IF): New.
* tests/calc.at: Adjust to check multiple start symbols.
* data/skeletons/yacc.c (yy_parse_impl): Fix.
2020-09-28 19:26:53 +02:00
Akim Demaille
d441a34791 multistart: also give access to yynerrs
This is something that has always bothered me: with pure parsers (and
they all should be) the user does not have an (easy) access to yynerrs
at the end of the parse.  In the case of error recovery, that's the
only direct means to know if there were errors.  The usual approach
being having the user maintain a counter incremented each time yyerror
is called.

So here, also capture yynerrs in the return value of the start-symbol
parsing functions.

* data/skeletons/yacc.c (yy_parse_impl_t): New.
(yy_parse_impl): Use it.
(b4_accept): Fill it.
* examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l: No longer
pass nerrs as lex- and parse-param, just use the resulting yynerrs.
bistromathic and reccalc both demonstrate %param.
2020-09-27 11:58:28 +02:00
Akim Demaille
f4d33ff4b4 yacc.c: also count calls to YYERROR in yynerrs
* data/skeletons/yacc.c: here.
2020-09-27 11:58:27 +02:00
Akim Demaille
d9cf99b6a5 multistart: use b4_accept instead of action post-processing
For each start symbol, generate a parsing function with a richer
return value than the usual of yyparse.  Reserve a place for the
returned semantic value, in order to avoid having to pass a pointer as
argument to "return" that value.  This also makes the call to the
parsing function independent of whether a given start-symbol is typed.

For instance, if the grammar file contains:

    %type <int> expression
    %start input expression

(so "input" is valueless) we get

    typedef struct
    {
      int yystatus;
    } yyparse_input_t;

    yyparse_input_t yyparse_input (void);

    typedef struct
    {
      int yyvalue;
      int yystatus;
    } yyparse_expression_t;

    yyparse_expression_t yyparse_expression (void);

This commit also changes the implementation of the parser termination:
when there are multiple start symbols, it is the initial rules that
explicitly YYACCEPT.  They do that after having exported the
start-symbol's value (if it is typed):

  switch (yyn)
    {
  case 1: /* $accept: YY_EXPRESSION expression $end  */
  { ((*yyvalue).TOK_expression) = (yyvsp[-1].TOK_expression); YYACCEPT; }
    break;

  case 2: /* $accept: YY_INPUT input $end  */
  { YYACCEPT; }
    break;

I have tried several ways to deal with termination, and this is the
one that appears the best one to me.  It is also the most natural.

* src/scan-code.h, src/scan-code.l (obstack_for_actions): New.
* src/reader.c (grammar_rule_check_and_complete): Generate the actions
of the rules for each start symbol.

* data/skeletons/bison.m4 (b4_symbol_slot): New, with safer semantics
than type and type_tag.
* data/skeletons/yacc.c (b4_accept): New.
Generates the body of the action of the start rules.
(_b4_declare_sub_yyparse): For each start symbol define a dedicated
return type for its parsing function.
Adjust the declaration of its parsing function.
(_b4_define_sub_yyparse): Adjust the definition of the function.

* examples/c/lexcalc/parse.y: Check the case of valueless symbols.
* examples/c/lexcalc/lexcalc.test: Check start symbols.
2020-09-27 09:44:18 +02:00
Akim Demaille
ed324578a2 multistart: equip yacc.c
* data/skeletons/yacc.c: Add support for multiple start symbols.
2020-09-27 09:23:51 +02:00
Akim Demaille
f9b360663b glr2.cc: add an example
Currently this example crashes on input such as "T (x) + y;".
The same example with glr.c works properly.

* examples/c++/glr/Makefile, examples/c++/glr/README.md,
* examples/c++/glr/c++-types.test, examples/c++/glr/c++-types.yy,
* examples/c++/glr/local.mk, examples/c++/local.mk: New.
Based on examples/c/glr/c++-types.y.
2020-09-26 18:33:48 +02:00
Akim Demaille
3add9ffbde glr.cc: fix: use symbol_name
* data/skeletons/glr.cc: here.
2020-09-26 14:33:09 +02:00
Adela Vais
f296669c0f d: change the return value of yylex from int to TokenKind
* data/skeletons/lalr1.d: Change the return value.
* examples/d/calc/calc.y, examples/d/simple/calc.y: Adjust.
* tests/scanner.at: Adjust.
* tests/calc.at (_AT_DATA_CALC_Y(d)): New, extracted from...
(_AT_DATA_CALC_Y(c)): here.
The two grammars have been sufficiently different to be separated.
Still trying to be them together results in a maintenance burden.  For
the same reason, instead of specifying the results for D and for the
rest, compute the expected results with D from the regular case.
2020-09-26 08:08:25 +02:00
Adela Vais
de638df104 d: support api.parser.extends and api.parser.implements
The D skeleton was not properly supporting them.

* data/skeletons/d.m4: Fix it.
* tests/d.at: Check it.
* tests/local.mk, tests/testsuite.at: Adjust.
2020-09-24 09:29:45 +02:00
Akim Demaille
8dc60543c8 glr2.cc: also run all the calculator tests
This revealed issues with yy_symbol_print and yy_reduce_print.
These changes, in turn, reactivated GCC10 warnings:

    559. calc.at:1258: testing Calculator glr2.cc %locations %header parse.error=verbose %debug api.prefix={calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}  ...
    tests/calc.at:1258: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret -Wno-deprecated -o calc.cc calc.y
    tests/calc.at:1258: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.cc calc-lex.cc calc-main.cc $LIBS
    stderr:
    calc.cc: In function 'void glr_stack::yyresolveLocations(glr_state*, int)':
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:1177:10: error: potential null pointer dereference [-Werror=null-dereference]
     1177 |   return yypred ? &(asItem (this) - yypred)->getState () : YY_NULLPTR;
          |          ^~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    calc.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    calc.cc:2623:46: error: potential null pointer dereference [-Werror=null-dereference]
     2623 |                 yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
          |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

* tests/calc.at (AT_CHECK_CALC_GLR_CC): Also check glr2.cc.
* data/skeletons/glr2.cc: Don't pass the user arguments to
yy_symbol_print and yy_reduce_print, since they have it in the parser
object.
(b4_user_formals_no_comma, b4_pure_args, b4_lpure_args)
(b4_locuser_formals, b4_locuser_args): Remove, useless.
(YY_IGNORE_NULL_DEREFERENCE_BEGIN): Enable for GCC >= 10 too.
2020-09-21 06:43:10 +02:00
Akim Demaille
f8cd049ecc tests: check the location of the right-hand side symbols
The D skeleton was not properly supporting @1 etc.
Reported by Adela Vais.
https://lists.gnu.org/r/bison-patches/2020-09/msg00049.html

* data/skeletons/d.m4 (b4_rhs_location): Fix it.
* tests/calc.at: Check the support of @n for all the skeletons.
2020-09-20 17:24:06 +02:00
Akim Demaille
d4ffb69424 glr: support api.header.include
* data/skeletons/glr.c: here.
2020-09-19 17:50:28 +02:00
Akim Demaille
b327f38832 deprecate %defines in favor of %header
This is consistent with --defines being deprecated in favor of
--header.  The directive %defines is also too similar to %define.
And %header matches nicely with api.header.name.

* src/scan-gram.l (%defines): Deprecate to %header.
(%header): Scan it.
* src/parse-gram.y (PERCENT_DEFINES): Replace with...
(PERCENT_HEADER): this.
* data/skeletons/lalr1.java
* doc/bison.texi
* tests/actions.at, tests/c++.at, tests/calc.at, tests/conflicts.at,
* tests/input.at, tests/java.at, tests/local.at, tests/output.at,
* tests/synclines.at, tests/types.at:
Convert most tests to check %header instead of %defines.
2020-09-19 17:49:03 +02:00
Akim Demaille
75c3746ce2 options: rename --defines as --header
The name "defines" is incorrect, the generated file contains far more
than just #defines.

* src/getargs.h, src/getargs.c (-H, --header): New option.
With optional argument, just like --defines, --xml, etc.
(defines_flag): Rename as...
(header_flag): this.
Adjust dependencies.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/glr.c,
* data/skeletons/glr.cc, data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c:
Adjust.
* examples, doc/bison.texi: Adjust.
* tests/headers.at, tests/local.at, tests/output.at: Convert most
tests from using --defines to using --header.
2020-09-19 08:31:49 +02:00
Valentin Tolmer
12a5cc07e0 glr2.cc: replace refs to parser::symbol_kind_type with yysymbol_kind_t
* data/skeletons/glr2.cc: here.
2020-09-17 19:37:05 +02:00
Valentin Tolmer
27b5d92563 glr2.cc: fix container out-of-bounds access
Clang 10 with ASAN enabled reported errors in glr2.cc.

* data/skeletons/glr2.cc: here.
2020-09-17 19:35:47 +02:00
Akim Demaille
34476c449a glr2.cc: disable GCC 4.6 warning
231. conflicts.at:1096: testing Syntax error in consistent error state: glr2.cc ...
    tests/conflicts.at:1096: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    input.cc:2674:36: error: 'yysval' may be used uninitialized in this function [-Werror=uninitialized]

Do not initialize the variable: this way ASAN can really make sure we
do set it to a proper value.
If we initialize it, ASAN would report nothing.

* data/skeletons/c.m4 (YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN): Disable
GCC 4.6's -Wuninitialized.
* data/skeletons/glr2.cc: Disable the warning locally.
2020-09-15 07:27:00 +02:00
Akim Demaille
795a59aba4 glr2.cc: fix warning with GCC 4.7 and 4.8
231. conflicts.at:1096: testing Syntax error in consistent error state: glr2.cc ...
    tests/conflicts.at:1096: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    input.cc: In function 'int yyparse(yy::parser&)':
    input.cc:3147:41: error: 'yyarg' may be used uninitialized in this function [-Werror=maybe-uninitialized]
         return yytnamerr_ (yytname_[yysymbol]);
                                             ^
    input.cc:2058:34: note: 'yyarg' was declared here
         yy::parser::symbol_kind_type yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
                                      ^

* data/skeletons/glr2.cc (yyreportSyntaxError): Initialize yyarg.
2020-09-14 19:53:01 +02:00
Akim Demaille
243fa94ce2 glr2.cc: simplify symbol kinds
We emit code like

    if (yytoken != yy::parser::symbol_kind::symbol_kind::S_YYEMPTY)

* data/skeletons/glr2.cc: Use b4_symbol correctly.
2020-09-14 19:30:48 +02:00
Akim Demaille
11995fec50 glr2.cc: fix warning about local variable vs. member
Fix a warning triggered in GCC (at least from 4.6 to 4.9):

    input.cc: In constructor 'glr_stack_item::glr_stack_item(bool)':
    input.cc:1371:5: error: declaration of 'is_state' shadows a member of 'this' [-Werror=shadow]
         : is_state_(is_state)
         ^

* data/skeletons/glr2.cc (glr_stack_item): Alpha-convert.
2020-09-14 06:34:07 +02:00
Akim Demaille
c654eb481c c++: variants: minor simplification
Do as Valentin Tolmer did in glr2.cc.

* data/skeletons/variant.hh: The union does not need to be named.
2020-09-13 13:47:25 +02:00
Akim Demaille
5c37f5994d glr2.cc: avoid type-punning issues
On the CI, tests fail with GCC 4.6 to GCC 6 as follows:

    tests/synclines.at:440: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret  -o \"\\\"\".cc \"\\\"\".y
    tests/synclines.at:440: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o \"\\\"\" \"\\\"\".cc $LIBS
    stderr:
    "\"".cc: In member function 'glr_state& glr_stack_item::getState()':
    "\"".cc:1404:47: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<glr_state*>(&raw_);
                                                   ^
    "\"".cc: In member function 'const glr_state& glr_stack_item::getState() const':
    "\"".cc:1408:53: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<const glr_state*>(&raw_);
                                                         ^
    "\"".cc: In member function 'semantic_option& glr_stack_item::getOption()':
    "\"".cc:1413:53: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<semantic_option*>(&raw_);
                                                         ^
    "\"".cc: In member function 'const semantic_option& glr_stack_item::getOption() const':
    "\"".cc:1417:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<const semantic_option*>(&raw_);
                                                           ^

See also be6fa942ac.

* data/skeletons/glr2.cc (glr_stack_item): Use a temporary void*
variable to avoid type-punning issues with reinterpret_cast.
2020-09-13 13:45:17 +02:00
Akim Demaille
952a61b62e glr.cc, glr2.cc: don't publish compiler pragmas
Currently the compiler attributes are defined in
b4_shared_declarations (that can in the header if it exists, otherwise
in the implementation file).  This is not needed, only the
implementation file needs them.

Besides, glr2.cc was also defining these macros in the implementation
file, so we had two definitions.

* data/skeletons/glr.cc, data/skeletons/glr2.cc: Define the compiler
attribute macros only in the implementation files.
* tests/regression.at (Lex and parse params): Generate a header, to
make it easy to check that the header is self-sufficient.
2020-09-13 12:23:13 +02:00
Akim Demaille
cf8f805d36 glr2.cc: disable incorrect warnings from GCC6 to 9
For instance with GCC8:

    616. regression.at:1560: testing Lex and parse params: glr2.cc ...
    tests/regression.at:1560: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret  -o input.cc input.y
    tests/regression.at:1560: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    stderr:
    input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    input.cc:1796:10: error: potential null pointer dereference [-Werror=null-dereference]
       return yypred ? &(asItem(this) - yypred)->getState() : YY_NULLPTR;
              ^~~~~~
    input.cc:1796:10: error: potential null pointer dereference [-Werror=null-dereference]
       return yypred ? &(asItem(this) - yypred)->getState() : YY_NULLPTR;
              ^~~~~~
    cc1plus: all warnings being treated as errors

It complains that the implicit this in yypred might be null.  It fears
it because of loops such as

    for (glr_state* yys = firstTopState();
         yys != yystateStack.yysplitPoint;
         yys = yys->pred())
      yyn += 1;

that could possibly set yys to null, since yys->pred might return
null.  However, the warning is incorrect, since in C++ `this` cannot
be null.  GCC 10 no longer emits this warning.

GCC 7 also complains many times about glr_stack::yyresolveLocations
when NDEBUG is enabled (when it is not, YYASSERT (yyoption !=
YY_NULLPTR) is probably enough to pacify GCC):

    616. regression.at:1560: testing Lex and parse params: glr2.cc ...
    tests/regression.at:1560: COLUMNS=1000; export COLUMNS; NO_TERM_HYPERLINKS=1; export NO_TERM_HYPERLINKS;  bison --color=no -fno-caret  -o input.cc input.y
    tests/regression.at:1560: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o input input.cc $LIBS
    stderr:
    input.cc: In member function 'void glr_stack::yyresolveLocations(glr_state*, int)':
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc: In member function 'YYRESULTTAG glr_stack::yyresolveValue(glr_state*)':
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
    input.cc:3061:46: error: potential null pointer dereference [-Werror=null-dereference]
                     yyrhsloc[0].getState().yyloc = yyoption->state()->yyloc;
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

* data/skeletons/glr2.cc (YY_IGNORE_NULL_DEREFERENCE_BEGIN)
(YY_IGNORE_NULL_DEREFERENCE_BEGIN): New.
(glr_state::pred, glr_stack::yyresolveLocations): Use them.
2020-09-13 12:08:28 +02:00
Adela Vais
2bc886dc02 d: make enum SymbolKind idiomatic D
Taking into account comments from H. S. Teoh.
https://lists.gnu.org/r/bison-patches/2020-09/msg00021.html

* data/skeletons/d.m4, data/skeletons/lalr1.d (SymbolKind): Wrap the
enum in a structure that contains its string representation.
2020-09-12 17:09:32 +02:00
Akim Demaille
b5e6d9c4ca glr2.cc: address warnings with G++ 4.8
input.cc: In constructor 'glr_stack_item::glr_stack_item(bool)':
input.cc:1423:5: error: declaration of 'isState' shadows a member of 'this' [-Werror=shadow]
     : isState_(isState) {
     ^
test.cc:1165:45: error: declaration of 'begin' shadows a member of 'this' [-Werror=shadow]
test.cc:1167:45: error: declaration of 'end' shadows a member of 'this' [-Werror=shadow]

* data/skeletons/glr2.cc (isState): Rename as...
(is_state): this.
Formatting changes.
(reduceToOneStack): Rename variables to avoid name clashes.
2020-09-12 15:23:19 +02:00
Akim Demaille
3ae2a22a05 glr2.cc: get rid of the C indirection for yy_symbol_print
* data/skeletons/glr2.cc (yy_symbol_print): Remove.
Just use yyparser.yy_symbol_print_ directly.
2020-09-12 14:49:05 +02:00
Akim Demaille
146a8eb101 glr2.cc: formatting changes
* data/skeletons/glr2.cc: here.
2020-09-12 14:44:29 +02:00
Akim Demaille
4428e8e8b3 glr2.cc: fix GCC10 warning
For instance on test 433: "glr2.cc api.value.type={double}"

    tests/types.at:138: $CXX $CXXFLAGS $CPPFLAGS  $LDFLAGS -o test test.cc $LIBS
    stderr:
    In file included from /opt/local/include/gcc10/c++/bits/stl_tempbuf.h:60,
                     from /opt/local/include/gcc10/c++/bits/stl_algo.h:62,
                     from /opt/local/include/gcc10/c++/algorithm:62,
                     from test.cc:82:
    /opt/local/include/gcc10/c++/bits/stl_construct.h: In instantiation of 'constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = glr_stack_item; _Args = {glr_stack_item}; decltype (::new(void*(0)) _Tp) = glr_stack_item*]':
    /opt/local/include/gcc10/c++/bits/alloc_traits.h:514:21:   required from 'static constexpr void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = glr_stack_item; _Args = {glr_stack_item}; _Tp = glr_stack_item; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<glr_stack_item>]'
    /opt/local/include/gcc10/c++/bits/vector.tcc:115:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {glr_stack_item}; _Tp = glr_stack_item; _Alloc = std::allocator<glr_stack_item>; std::vector<_Tp, _Alloc>::reference = glr_stack_item&]'
    /opt/local/include/gcc10/c++/bits/stl_vector.h:1204:21:   required from 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = glr_stack_item; _Alloc = std::allocator<glr_stack_item>; std::vector<_Tp, _Alloc>::value_type = glr_stack_item]'
    test.cc:1949:48:   required from here
    /opt/local/include/gcc10/c++/bits/stl_construct.h:95:14: error: noexcept-expression evaluates to 'false' because of a call to 'glr_stack_item::glr_stack_item(const glr_stack_item&)' [-Werror=noexcept]
       95 |     noexcept(noexcept(::new((void*)0) _Tp(std::declval<_Args>()...)))
          |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    test.cc:1436:3: note: but 'glr_stack_item::glr_stack_item(const glr_stack_item&)' does not throw; perhaps it should be declared 'noexcept'
     1436 |   glr_stack_item(const glr_stack_item& other)
          |   ^~~~~~~~~~~~~~
    cc1plus: all warnings being treated as errors
    stdout:
    tests/types.at:138: exit code was 1, expected 0
    433. types.at:138: 433. glr2.cc api.value.type={double} (types.at:138): FAILED (types.at:138)

* data/skeletons/glr2.cc (glr_stack_item): Use YY_NOEXCEPT/YY_NOTHROW.
2020-09-12 14:44:27 +02:00
Valentin Tolmer
00e47b11d2 glr2.cc: coding style changes
* data/skeletons/glr2.cc: Change some CamlCase to snake_case, and
remove some yy prefixes for classes inside the namespace.
2020-09-12 14:11:58 +02:00
Valentin Tolmer
cf8723de0d glr2.cc: move StrongIndexAlias into the namespace
* data/skeletons/glr2.cc: here.
2020-09-12 14:11:40 +02:00
Valentin Tolmer
8bfc319f8e glr2.cc: remove usage of PTRDIFF_MAX
* data/skeletons/glr2.cc: Use std::ptrdiff_t and numeric_limits.
2020-09-12 14:11:00 +02:00
Valentin Tolmer
1c5b05ad31 glr2.cc: remove C-style casts
* data/skeletons/glr2.cc: here.
2020-09-12 14:10:21 +02:00
Valentin Tolmer
b7e2cac2aa glr2.cc: add copy constructor to yyGLRStackItem
This silences the clang warning -Wdeprecated-copy.

* data/skeletons/glr2.cc: here.
2020-09-12 14:10:02 +02:00
Akim Demaille
1df4b746da glr2.cc: style changes
* data/skeletons/glr2.cc: Remove stray comment.
2020-09-05 07:47:21 +02:00
Akim Demaille
f3f7f6e1dc glr2.cc: get rid of the yyerror scaffolding
The yyerror stand-alone function was used to bounce from glr.c's call
to yyerror to glr.cc's parser.error.  Now that glr.c is out of the
way, just directly use parser.error.

* data/skeletons/glr2.cc (yyerror): Remove.
Adjust callers.
(b4_yyerror_args, b4_lyyerror_args, b4_pure_formals): Remove.
Now unused.
2020-09-05 07:44:23 +02:00
Valentin Tolmer
38abe1e1b7 glr2.cc: avoid warnings about printf and shadowing
* data/skeletons/glr2.cc: Migrate from using printf to std::cerr & co.
Since the yyGLRStack has the user params, no need to pass them around.
2020-09-04 06:47:10 +02:00
Akim Demaille
82d913741b glr2.cc: avoid warnings about long long
* data/skeletons/glr2.cc: Disable the warning before triggering it.
2020-08-30 20:05:34 +02:00
Akim Demaille
b63e3a3352 glr2.cc: fix a few warnings
* data/skeletons/glr2.cc: Fix some documentation.
Be consistent between class/struct.
(yydoAction, yyresolveAction): Avoid passing yyparser where useless.
2020-08-30 12:58:27 +02:00
Valentin Tolmer
ef09bf065a glr2.cc: fork glr.cc to a c++ version
This is a fork of glr.cc to be c++-first instead of a wrapper around
glr.c.

* data/skeletons/glr2.cc: New.
* data/skeletons/bison.m4, data/skeletons/c++.m4: Adjust.
* data/skeletons/c.m4 (b4_user_args_no_comma): New.
* src/reader.c (grammar_rule_check_and_complete): glr2.cc is C++.
* tests/actions.at, tests/c++.at, tests/calc.at, tests/conflicts.at,
* tests/input.at, tests/local.at, tests/regression.at, tests/scanner.at,
* tests/synclines.at, tests/types.at: Also check glr2.cc.
2020-08-30 10:45:21 +02:00