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.
This commit is contained in:
Akim Demaille
2015-01-08 10:19:10 +01:00
parent 5422471cbb
commit ee2f433512
3 changed files with 36 additions and 2 deletions

View File

@@ -288,6 +288,9 @@ b4_location_define])])[
/// Copy constructor.
by_state (const by_state& other);
/// Record that this symbol is empty.
void clear ();
/// Steal the symbol type from \a that.
void move (by_state& that);
@@ -542,12 +545,19 @@ m4_if(b4_prefix, [yy], [],
: state (other.state)
{}
inline
void
]b4_parser_class_name[::by_state::clear ()
{
state = empty_state;
}
inline
void
]b4_parser_class_name[::by_state::move (by_state& that)
{
state = that.state;
that.state = empty_state;
that.clear ();
}
inline