forked from jasder/antlr
Merge pull request #2733 from vinoski/cpp-set-token-factory
Fix #2727: improve setTokenFactory in Cpp target
This commit is contained in:
commit
2d7f727a00
|
@ -11,7 +11,7 @@
|
|||
|
||||
using namespace antlr4;
|
||||
|
||||
const Ref<TokenFactory<CommonToken>> CommonTokenFactory::DEFAULT = std::make_shared<CommonTokenFactory>();
|
||||
const std::unique_ptr<TokenFactory<CommonToken>> CommonTokenFactory::DEFAULT(new CommonTokenFactory);
|
||||
|
||||
CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) {
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace antlr4 {
|
|||
* This token factory does not explicitly copy token text when constructing
|
||||
* tokens.</p>
|
||||
*/
|
||||
static const Ref<TokenFactory<CommonToken>> DEFAULT;
|
||||
static const std::unique_ptr<TokenFactory<CommonToken>> DEFAULT;
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
|
|
@ -136,7 +136,7 @@ size_t Lexer::popMode() {
|
|||
}
|
||||
|
||||
|
||||
Ref<TokenFactory<CommonToken>> Lexer::getTokenFactory() {
|
||||
TokenFactory<CommonToken>* Lexer::getTokenFactory() {
|
||||
return _factory;
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ size_t Lexer::getNumberOfSyntaxErrors() {
|
|||
void Lexer::InitializeInstanceFields() {
|
||||
_syntaxErrors = 0;
|
||||
token = nullptr;
|
||||
_factory = CommonTokenFactory::DEFAULT;
|
||||
_factory = CommonTokenFactory::DEFAULT.get();
|
||||
tokenStartCharIndex = INVALID_INDEX;
|
||||
tokenStartLine = 0;
|
||||
tokenStartCharPositionInLine = 0;
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace antlr4 {
|
|||
|
||||
protected:
|
||||
/// How to create token objects.
|
||||
Ref<TokenFactory<CommonToken>> _factory;
|
||||
TokenFactory<CommonToken> *_factory;
|
||||
|
||||
public:
|
||||
/// The goal of all lexer rules/methods is to create a token object.
|
||||
|
@ -100,7 +100,7 @@ namespace antlr4 {
|
|||
this->_factory = factory;
|
||||
}
|
||||
|
||||
virtual Ref<TokenFactory<CommonToken>> getTokenFactory() override;
|
||||
virtual TokenFactory<CommonToken>* getTokenFactory() override;
|
||||
|
||||
/// Set the char stream and reset the lexer
|
||||
virtual void setInputStream(IntStream *input) override;
|
||||
|
|
|
@ -82,11 +82,11 @@ std::string ListTokenSource::getSourceName() {
|
|||
return "List";
|
||||
}
|
||||
|
||||
Ref<TokenFactory<CommonToken>> ListTokenSource::getTokenFactory() {
|
||||
TokenFactory<CommonToken>* ListTokenSource::getTokenFactory() {
|
||||
return _factory;
|
||||
}
|
||||
|
||||
void ListTokenSource::InitializeInstanceFields() {
|
||||
i = 0;
|
||||
_factory = CommonTokenFactory::DEFAULT;
|
||||
_factory = CommonTokenFactory::DEFAULT.get();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace antlr4 {
|
|||
private:
|
||||
/// This is the backing field for <seealso cref="#getTokenFactory"/> and
|
||||
/// <seealso cref="setTokenFactory"/>.
|
||||
Ref<TokenFactory<CommonToken>> _factory = CommonTokenFactory::DEFAULT;
|
||||
TokenFactory<CommonToken> *_factory = CommonTokenFactory::DEFAULT.get();
|
||||
|
||||
public:
|
||||
/// Constructs a new <seealso cref="ListTokenSource"/> instance from the specified
|
||||
|
@ -79,7 +79,7 @@ namespace antlr4 {
|
|||
this->_factory = factory;
|
||||
}
|
||||
|
||||
virtual Ref<TokenFactory<CommonToken>> getTokenFactory() override;
|
||||
virtual TokenFactory<CommonToken>* getTokenFactory() override;
|
||||
|
||||
private:
|
||||
void InitializeInstanceFields();
|
||||
|
|
|
@ -208,7 +208,7 @@ size_t Parser::getNumberOfSyntaxErrors() {
|
|||
return _syntaxErrors;
|
||||
}
|
||||
|
||||
Ref<TokenFactory<CommonToken>> Parser::getTokenFactory() {
|
||||
TokenFactory<CommonToken>* Parser::getTokenFactory() {
|
||||
return _input->getTokenSource()->getTokenFactory();
|
||||
}
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ namespace antlr4 {
|
|||
/// <seealso cref= #notifyErrorListeners </seealso>
|
||||
virtual size_t getNumberOfSyntaxErrors();
|
||||
|
||||
virtual Ref<TokenFactory<CommonToken>> getTokenFactory() override;
|
||||
virtual TokenFactory<CommonToken>* getTokenFactory() override;
|
||||
|
||||
/// <summary>
|
||||
/// Tell our token source and error strategy about a new way to create tokens. </summary>
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace antlr4 {
|
|||
|
||||
virtual void setInputStream(IntStream *input) = 0;
|
||||
|
||||
virtual Ref<TokenFactory<CommonToken>> getTokenFactory() = 0;
|
||||
virtual TokenFactory<CommonToken>* getTokenFactory() = 0;
|
||||
|
||||
template<typename T1>
|
||||
void setTokenFactory(TokenFactory<T1> *input);
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace antlr4 {
|
|||
/// creating <seealso cref="Token"/> objects from the input.
|
||||
/// </summary>
|
||||
/// <returns> The <seealso cref="TokenFactory"/> currently used by this token source. </returns>
|
||||
virtual Ref<TokenFactory<CommonToken>> getTokenFactory() = 0;
|
||||
virtual TokenFactory<CommonToken>* getTokenFactory() = 0;
|
||||
};
|
||||
|
||||
} // namespace antlr4
|
||||
|
|
Loading…
Reference in New Issue