-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
The Lexer
class provides the setTokenFactory
template function, but its function signature means that its body can't compile. The function is defined as follows:
template<typename T1>
void setTokenFactory(TokenFactory<T1> * factory) {
this->_factory = factory;
}
where this->_factory
is declared as a std::shared_ptr
:
Ref<TokenFactory<CommonToken>> _factory;
The function can't work because std::shared_ptr<T>
provides no assignment operator from T*
, nor does it provide an implicitly converting constructor from T*
(i.e., its T*
constructor is marked explicit
). Lexer
works with the default CommonTokenFactory
only because it assigns its _factory
using CommonTokenFactory::DEFAULT
, which is a shared_ptr
of the same type as _factory
.
I believe setTokenFactory
on Lexer
, Parser
, and TokenSource
should be changed to the following signature:
template<typename T1>
void setTokenFactory(Ref<TokenFactory<T1>> const& factory);
and the implementation of Lexer::setTokenFactory
should be:
template<typename T1>
void setTokenFactory(Ref<TokenFactory<T1>> const& factory) {
this->_factory = std::static_pointer_cast<TokenFactory<CommonToken>>(factory);
}
Because of the declared type of Lexer::_factory
, it's necessary for the factory
argument here to be convertible to a std::shared_ptr<TokenFactory<CommonToken>>
.