Commit Graph

5164 Commits

Author SHA1 Message Date
Akim Demaille
26a4d3c895 tests: enable support for --debug
* tests/c++.at (Variants): Here.
And remove useless clutter when api.token.constructor is enabled.
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
Valentin Tolmer
9e62f1a657 tests: add token declaration order test
* tests/conflicts.at: New test.
2013-01-27 10:43:59 +01:00
Akim Demaille
c6a731eebb regen 2013-01-27 10:41:16 +01:00
Valentin Tolmer
93561c21e8 grammar: preserve token declaration order
In a declaration %token A B, the token A is declared before B, but in %left
A B (or with %precedence or %nonassoc or %right), the token B was declared
before A (tokens were declared in reverse order).

* src/symlist.h, src/symlist.c (symbol_list_append): New.
* src/parse-gram.y: Use it instead of symbol_list_prepend.
* tests/input.at: Adjust expectations.
2013-01-27 10:37:12 +01:00
Akim Demaille
9b3bb25885 tests: improve test group titles
* tests/local.at (AT_SETUP_STRIP): AT_SETUP does not behave properly
with new-lines in its argument.
Remove them.
Fix the handling of %define with quotes.
2013-01-25 16:48:36 +01:00
Akim Demaille
f0f95a50ee c: no longer require stdio.h when locations are enabled
Recent changes (in 2.7) introduced a dependency on both FILE and
fprintf, which are "available" only in %debug mode.  This was to
define yy_location_print_, which is used only in %debug mode by the
parser, but massively used by the test suite to output the locations
in yyerror.

Break this dependency: the test suite should define its own routines
to display the locations.  Eventually Bison will provide the user with
a means to display locations, but not yet.

* data/c.m4 (b4_yy_location_print_define): Use YYFPRINTF instead of
fprintf directly.
* data/yacc.c (b4_yy_location_print_define): Invoke it only in %debug
mode, so that stdio.h is included (needed for FILE*), and YYFPRINTF
is defined.

* tests/local.at (AT_YYERROR_DECLARE, AT_YYERROR_DEFINE): Declare
and define location_print and LOCATION_PRINT.

* tests/actions.at, tests/existing.at, tests/glr-regression.at,
* tests/input.at, tests/named-refs.at, tests/regression.at: Adjust
to use them.
Fix the expected line numbers (as the prologue's length has changed).
2013-01-25 16:45:17 +01:00
Akim Demaille
d9fa1b7c4f c: minor simplification in the debug code
* data/c.m4 (yy_symbol_print): Minor factoring.
2013-01-25 16:35:52 +01:00
Akim Demaille
aedcb6c095 c++: display locations as C does
See commit 3804aa260b.

* data/location.cc (operator<<): Display location exactly as is
done in C skeletons.
* tests/local.at (AT_LOC_PUSHDEF, AT_LOC_POPDEF): Also define
AT_FIRST_LINE, AT_LAST_LINE, AT_FIRST_COLUMN, AT_LAST_COLUMN.
* tests/actions.at (Location Print): Also check C++ skeletons.
2013-01-25 16:35:52 +01:00
Akim Demaille
c7442984e3 tests: highlight empty right-hand sides
* tests/actions.at, tests/c++.at, tests/headers.at,
* tests/input.at: here.
2013-01-25 16:35:52 +01:00
Akim Demaille
597afd73d7 news: prepare for 2.8
* NEWS: Restructure.
Name contributors.
2013-01-25 16:35:35 +01:00
Akim Demaille
56b91ae0b1 tests: generalize default main for api.namespace
* tests/local.at (AT_NAME_PREFIX): Also match api.namespace.
(AT_MAIN_DEFINE): Take it into account.
* tests/c++.at, tests/headers.at: Use AT_NAME_PREFIX.
(AT_CHECK_NAMESPACE): Rename as...
(AT_TEST): this.
2013-01-21 16:27:46 +01:00
Akim Demaille
f42c012fcf tests: improve factoring of the main function
* tests/local.at (AT_MAIN_DEFINE): If %debug is used, check if
-d/--debug is passed to the generated parser, and enable the traces.
Return exactly the result of yyparse, so that we can check exit code
2 too.
* tests/actions.at, tests/glr-regression.at, tests/regression.at:
Use AT_MAIN_DEFINE, helping AT_BISON_OPTION_PUSHDEFS where needed,
preferably to option -t.
2013-01-21 16:27:46 +01:00
Akim Demaille
3ef9fa8f83 tests: factor the definition of main
With Théophile Ranquet.

* tests/local.at (AT_MAIN_DEFINE): New.
(AT_YYERROR_DEFINE): Improve formatting.
* tests/actions.at, tests/c++.at, tests/conflicts.at,
* tests/glr-regression.at, tests/input.at, tests/regression.at,
* tests/skeletons.at, tests/torture.at: Adjust.
* tests/c++.at: Add missing %skeleton for a PUSHDEFS, and a missing
PUSH/POPDEFS for another test.
2013-01-21 16:27:46 +01:00
Akim Demaille
70b7c35747 tests: minor refactoring
* tests/named-refs.at: Use AT_FULL_COMPILE where applicable.
2013-01-21 16:15:05 +01:00
Akim Demaille
184878b9ca diagnostics: avoid useless caret stuttering
* src/scan-code.l: When reporting a missing ending ';', don't display
the guilty action twice.
2013-01-21 16:15:05 +01:00
Theophile Ranquet
6908c2e1f7 examples: please clang
* doc/bison.texi (calc++-scanner.ll): Don't output useless yyinput function.
2013-01-21 15:54:04 +01:00
Theophile Ranquet
32f4c0a1b2 tests: better silencing of unused argument warnings
input.yy:35:44: error: unused parameter 'msg' [-Werror,-Wunused-parameter]
void yy::parser::error (std::string const& msg)
                                           ^

* tests/c++.at (C++ GLR parser identifier shadowing): Don't name unused
argument, use YYUSE instead of a direct cast to void.
2013-01-21 15:54:04 +01:00
Theophile Ranquet
492dacbc34 bench: compatibility for Bison <= 2.7
There used to be a bug in some skeletons, which caused the expansion of
'yylval' and 'yylloc', generating these errors:

input.cc:547:16: error: expected ',' or '...' before '(' token
 #define yylval (yystackp->yyval)
                ^
input.yy:29:39: note: in expansion of macro 'yylval'
 int yylex (yy::parser::semantic_type *yylval)
                                       ^

This bug is fixed by 'skel: better aliasing of identifiers', but a workaround
is useful when benchmarking against older versions of Bison, which are still
affected by the bug.

* etc/bench.pl.in: Rename yylval to yylvalp and yylloc to yyllocp in base
grammar 'list'.
2013-01-21 15:54:04 +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
Theophile Ranquet
60607adb3c c++: silence warnings
* data/c++.m4 (basic_symbol<Base>::operator=): Unused parameter.
* tests/c++.at (C++ GLR parser identifier shadowing): Here too.
-
2013-01-14 19:25:35 +01:00
Theophile Ranquet
8b4499ad04 news: typos
* NEWS: Fix a typo, use YYSTYPE rather than semantic_type.
2013-01-14 11:02:12 +01:00
Akim Demaille
3f4bc2c1dd regen 2013-01-12 16:23:16 +01:00
Akim Demaille
7d6bad1959 maint: update copyright years
Suggested by Stefano Lattarini.
Run "make update-copyright".
2013-01-12 16:14:16 +01:00
Akim Demaille
f6df83b4e8 build: fix VPATH issue
* Makefile.am (update-b4-copyright, update-package-copyright-year): Fix
path to build-aux.
2013-01-12 16:14:16 +01:00
Theophile Ranquet
016426c195 carets: document default activation
* NEWS: Announce it.
* doc/bison.texi: Adjust.
2013-01-11 19:11:21 +01:00
Theophile Ranquet
0242bf04ac carets: show them in more tests
* tests/input.at, tests/named-refs.at: Here.
2013-01-11 19:11:21 +01:00
Theophile Ranquet
9c4788b7ee carets: activate by default
* src/getargs.c (feature_flag): Here.
* tests/local.at (AT_BISON_CHECK_, AT_BISON_CHECK_NO_XML): Deactivate carets
for the testsuite, by default.
* tests/input.at: Adjust the locations for command line definitions.
2013-01-11 19:11:21 +01:00
Theophile Ranquet
6656c9b52a variants: document move and swap
* data/variant.hh (swap): Doc.
(build): Rename as...
(move): This, more coherent naming with clearer meaning.
* data/c++.m4 (move): Adjust.
2013-01-11 18:57:10 +01:00
Theophile Ranquet
04816a6f32 c++: privatize variant blind copies
* data/variant.hh (variant, operator=): Make private.
* data/c++.m4 (operator=): New, to avoid needing a definition of that operator
for each class member (such as a possible variant).
* data/glr.cc, data/lalr.cc: Add the necessary include for the abort.
2013-01-11 18:57:09 +01:00
Akim Demaille
39ad6cc6ac glr.c: fix an unused argument issue
* data/glr.c (yyuserAction): "Use" yyrhslen, as in variant mode, we might
not use it.
2013-01-11 18:57:09 +01:00
Akim Demaille
bc19eadd65 glr.c: style changes
* data/glr.c (yyuserAction): Use a size_t for sizes.
2013-01-11 18:57:09 +01:00
Akim Demaille
1092d69c34 c.m4: style fix
* data/c.m4 (b4_parse_param_use): Add missing space before paren.
2013-01-11 18:57:09 +01:00
Theophile Ranquet
99d795e8f2 skel: better aliasing of identifiers
* data/glr.c, data/yacc.c: Avoid emitting useless defines.
* data/glr.cc: Restore prefixes for epilogue.
2013-01-11 18:57:09 +01:00
Theophile Ranquet
0707d0c7fa glr.cc: fatal if using api.token.ctor without variants
* data/glr.cc: Here.
2013-01-11 18:57:09 +01:00
Theophile Ranquet
462b243e1d skel: correctly indent switch cases
* data/bison.m4 (b4_type_action_): Here.
2013-01-11 18:57:08 +01:00
Theophile Ranquet
bb1f0f5226 variants: assert changes
* data/variant.hh (swap): More asserts can't hurt. Don't perform useless swaps.
(build): Deactivate problematic asserts, pending further investigation.
(variant): Prohibit copy construction.
2013-01-11 18:57:08 +01:00
Theophile Ranquet
e7b26e942d lalr1.cc: use a vector for the symbol stack
* data/lalr1.cc: Adjust includes.
* data/stack.hh (push, pop): Use push_back and pop_back.
(operator []): Access vector from the end.
2013-01-11 18:57:08 +01:00
Theophile Ranquet
1dbaf37f5c lalr1.cc: change symbols implementation
A "symbol" groups together the symbol type (INT, PLUS, etc.), its
possible semantic value, and its optional location.  The type is
needed to access the value, as it is stored as a variant/union.

There are two kinds of symbols. "symbol_type" are "external symbols":
they have type, value and location, and are returned by yylex.
"stack_symbol_type" are "internal symbols", they group state number,
value and location, and are stored in the parser stack.  The type of
the symbol is computed from the state number.

The class template symbol_base_type<Exact> factors the code common to
stack_symbol_type and symbol_type.  It uses the Curiously Recurring
Template pattern so that we can always (static_) downcast to the exact
type.  symbol_base_type features value and location, and delegates the
handling of the type to its parameter.

When trying to generalize the support for variant, a significant issue
was revealed: because stack_symbol_type and symbol_type _derive_ from
symbol_base_type, the type/state member is defined _after_ the value
and location.  In C++ the order of the definition of the members
defines the order in which they are initialized, things go backward:
the value is initialized _before_ the type.  This is wrong, since the
type is needed to access the value.

Therefore, we need another means to factor the common code, one that
ensures the order of the members.

The idea is simple: define two (base) classes that code the symbol
type ("by_type" codes it by its type, and "by_state" by the state
number).  Define basic_symbol<Base> as the class template that
provides value and location support.  Make it _derive_ from its
parameter, by_type or by_state.  Then define stack_symbol_type and
symbol_type as basic_symbol<by_state>, basic_symbol<by_type>.  The
name basic_symbol was chosen by similarity with basic_string and
basic_ostream.

* data/c++.m4 (symbol_base_type<Exact>): Remove, replace by...
(basic_symbol<Base>): which derives from its parameter, one of...
(by_state, by_type): which provide means to retrieve the actual type of
symbol.
(symbol_type): Is now basic_symbol<by_type>.
(stack_symbol_type): Is now basic_symbol<by_state>.
* data/lalr1.cc: Many adjustments.
2013-01-11 18:57:08 +01:00
Theophile Ranquet
ca42755f13 bench: add %b directive to use a specific Bison
For example,
  $ bench.pl -v '%s lalr1.cc & %d variant & ( %b ~/old-bison/bin/bison
    | %b ~/new-bison/bin/bison )' -g list -i 10000

* etc/bench.pl.in: Here.
2013-01-11 18:57:08 +01:00
Akim Demaille
bcf54c336e regen 2013-01-09 16:41:16 +01:00
Akim Demaille
19b1b96f87 gnulib: update 2013-01-04 16:26:14 +01:00
Akim Demaille
dbf3962c35 doc: use deffn to declare the list of %define variables
* doc/bison.texi (%define Summary): Use @deffn instead of @table, it
spares a lot of width, especially in PDF, and looks nicer in the other
formats too.
It is also more consistent with the rest of the document.
2012-12-31 16:33:44 +01:00
Akim Demaille
a256496a3a doc: minor completion and fixes
* doc/bison.texi (%define Summary): Provide more history to some
variables.
2012-12-31 16:32:12 +01:00
Akim Demaille
4119d1ea60 java: stype is obsoleted by api.value.type
This is consistent with the other %define variable names.

* data/java.m4: Use api.value.type instead of stype.
* doc/bison.texi, NEWS: Document that change.
* src/muscle-tab.c (muscle_percent_variable_update): Provide backward
compatibility.
* tests/java.at: Adjust.
2012-12-31 16:32:12 +01:00
Akim Demaille
bdcbadbe37 doc: fix html build
* doc/local.mk (bison.html): Fix dependencies.
2012-12-31 16:32:12 +01:00
Akim Demaille
b8a8cc42c6 todo: remove erroneous task
* tests/input.at: Check that there are no warnings about stray $ and @
in the epilogue.
* TODO: Remove the correponding task.
2012-12-31 16:32:12 +01:00
Akim Demaille
a565e60eef gnulib: update 2012-12-31 16:32:12 +01:00