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>>.
The
Lexerclass provides thesetTokenFactorytemplate function, but its function signature means that its body can't compile. The function is defined as follows:where
this->_factoryis declared as astd::shared_ptr:The function can't work because
std::shared_ptr<T>provides no assignment operator fromT*, nor does it provide an implicitly converting constructor fromT*(i.e., itsT*constructor is markedexplicit).Lexerworks with the defaultCommonTokenFactoryonly because it assigns its_factoryusingCommonTokenFactory::DEFAULT, which is ashared_ptrof the same type as_factory.I believe
setTokenFactoryonLexer,Parser, andTokenSourceshould be changed to the following signature:and the implementation of
Lexer::setTokenFactoryshould be:Because of the declared type of
Lexer::_factory, it's necessary for thefactoryargument here to be convertible to astd::shared_ptr<TokenFactory<CommonToken>>.