Commit Graph

18 Commits

Author SHA1 Message Date
Akim Demaille
2d32fc9fe2 Add "%define assert" to variants.
This is used to help the user catch cases where some value gets
ovewritten by a new one.  This should not happen, as this will
probably leak.

Unfortunately this uncovered a bug in the C++ parser itself: the
lookahead value was not destroyed between two calls to yylex.  For
instance if the previous lookahead was a std::string, and then an int,
then the value of the std::string was correctly taken (i.e., the
lookahead was now an empty string), but std::string structure itself
was not reclaimed.

This is now done in variant::build(other&) (which is used to take the
value of the lookahead): other is not only stolen from its value, it
is also destroyed.  This incurs a new performance penalty of a few
percent, and union becomes faster again.

	* data/lalr1-fusion.cc (variant::build(other&)): Destroy other.
	(b4_variant_if): New.
	(variant::built): New.
	Use it whereever the status of the variant changes.
	* etc/bench.pl.in: Check the penalty of %define assert.
2008-11-07 21:38:06 +01:00
Akim Demaille
3c26260608 Formatting changes.
* data/lalr1-fusion.cc, src/parse-gram.y: here.
2008-11-04 21:43:51 +01:00
Akim Demaille
a2b93d5278 Formatting changes.
* data/lalr1-fusion.cc: here.
2008-11-04 21:43:46 +01:00
Akim Demaille
4af4348a3f Don't memcpy C++ structures.
* data/lalr1-fusion.cc (b4_symbol_variant): Adjust additional
	arguments.
	(variant::build): New overload for
	copy-construction-that-destroys.
	(variant::swap): New.
	(parser::yypush_): Use it in variant mode.
2008-11-04 21:43:28 +01:00
Akim Demaille
006a030300 Sort methods.
* data/lalr1-fusion.cc (destroy): Use as() in its definition.
	Define it after as().
2008-11-04 21:21:56 +01:00
Akim Demaille
faef34664a Useless parens.
* data/lalr1-fusion.cc (b4_rhs_location): Remove useless parens.
2008-11-04 21:21:51 +01:00
Akim Demaille
e426d17bc5 Remove trailing empty line.
* data/lalr1-fusion.cc: Don't add an empty line after the user's
	epilogue.
2008-11-04 21:21:43 +01:00
Akim Demaille
a9ce3f5413 Fix output of copyright years.
* data/bison.m4 (b4_copyright): Fix the indentation of the
	copyright year paragraph.
	Use b4_copyright_years when no years are given.
	* data/lalr1.cc, data/lalr1-fusion.cc, data/location.cc
	(b4_copyright_years): New.
	Use it.
2008-11-04 21:21:38 +01:00
Akim Demaille
59c544c268 Avoid the spurious initial empty line.
* data/lalr1-fusion.cc, data/location.cc: Put a trailing "@" at
	the end of @output request to suppress the empty line that
	results.
2008-11-04 21:21:34 +01:00
Akim Demaille
96b15448b9 Remove parser::rhs_number_type.
* data/lalr1-fusion.cc (rhs_number_type): No longer define it.
	(yyrhs_): Use b4_table_define.
2008-11-04 21:21:30 +01:00
Akim Demaille
f063317430 Fix iteration type.
* data/lalr1-fusion.cc: Use an int to iterate up to an int.
2008-11-04 21:21:25 +01:00
Akim Demaille
417b80040b Factor the declaration of the integer tables.
* data/lalr1-fusion.cc (b4_table_define): New.
	Use it.
2008-11-04 21:21:20 +01:00
Akim Demaille
1a5246c66f Fix indentation of tables in lalr1.cc
* data/lalr1-fusion.cc: Fix the indentation.
2008-11-03 22:01:27 +01:00
Akim Demaille
f8a95c9c12 Destroy the lhs symbols after reduction.
* data/lalr1-fusion.cc (parse): After the user action, when in
	variant mode, destroy the lhs symbols.
2008-11-03 22:01:22 +01:00
Akim Demaille
d7f4d82382 Simplify yysyntax_error_ use.
* data/lalr1-fusion.cc (yysyntax_error_): Always pass it the token
	type, but make it unnamed in the declaration when it is not used.
2008-11-03 22:01:18 +01:00
Akim Demaille
8b9c89fb65 Let yy::variant::build return an lvalue.
* data/lalr1-fusion.cc (variant::build): Return a reference to the
	object.
2008-11-03 22:01:14 +01:00
Akim Demaille
83243c24ba Define yy::variant only when needed.
* data/lalr1-fusion.cc (yy::variant): Define only if variants are
	used.
2008-11-03 22:01:10 +01:00
Akim Demaille
0e0ed236ab Fuse the three stacks into a single one.
In order to make it easy to perform benchmarks to ensure that there are no
performance loss, lalr1.cc is forked into lalr1-fusion.cc.  Eventually,
lalr1-fusion.cc will replace lalr1.cc.

Meanwhile, to make sure that lalr1-fusion.cc is correctly exercized by the
test suite, the user must install a symbolic link from lalr1.cc to it.

Instead of having three stacks (state, value, location), use a stack
of triples.  This considerably simplifies the code (and it will be
easier not to require locations as currently does the C++ parser),
and also gives a 10% speedup according to etc/bench (probably mainly since
memory allocation is done once instead of three times).

Another motivation is to make it easier to destruct properly
semantic values: now that they are bound to their state (hence
symbol type) it will be easier to call the appropriate destructor.

These changes should probably benefit the C parser too.

	* data/lalr1.cc: Copy as...  * data/lalr1-fusion.cc: this new
	file.
	(b4_rhs_value, b4_rhs_location): New definitions overriding those
	from c++.m4.
	(state_stack_type, semantic_stack_type, location_stack_type)
	(yystate_stack_, yysemantic_stack_, yylocation_stack_): Remove.
	(data_type, stack_type, yystack_): New.
	(YYLLOC_DEFAULT, yypush_): Adjust.
	(yyerror_range): Now based on data_type, not location_type.
2008-11-03 21:59:59 +01:00