forked from jasder/antlr
LexerAction instances shared_ptr fix
This commit is contained in:
parent
6de938dbf7
commit
027dde5e3e
|
@ -392,7 +392,9 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
|
|||
data2 = -1;
|
||||
}
|
||||
|
||||
atn.lexerActions[i] = lexerActionFactory(actionType, data1, data2);
|
||||
auto la = lexerActionFactory(actionType, data1, data2);
|
||||
assert(la != nullptr);
|
||||
atn.lexerActions[i] = la;
|
||||
}
|
||||
} else {
|
||||
// for compatibility with older serialized ATNs, convert the old
|
||||
|
@ -718,16 +720,16 @@ Ref<LexerAction> ATNDeserializer::lexerActionFactory(LexerActionType type, int d
|
|||
return std::make_shared< LexerModeAction>(data1);
|
||||
|
||||
case LexerActionType::MORE:
|
||||
return LexerMoreAction::INSTANCE;
|
||||
return LexerMoreAction::getInstance();
|
||||
|
||||
case LexerActionType::POP_MODE:
|
||||
return LexerPopModeAction::INSTANCE;
|
||||
return LexerPopModeAction::getInstance();
|
||||
|
||||
case LexerActionType::PUSH_MODE:
|
||||
return std::make_shared<LexerPushModeAction>(data1);
|
||||
|
||||
case LexerActionType::SKIP:
|
||||
return LexerSkipAction::INSTANCE;
|
||||
return LexerSkipAction::getInstance();
|
||||
|
||||
case LexerActionType::TYPE:
|
||||
return std::make_shared<LexerTypeAction>(data1);
|
||||
|
|
|
@ -38,7 +38,11 @@ using namespace antlr4;
|
|||
using namespace antlr4::atn;
|
||||
using namespace antlr4::misc;
|
||||
|
||||
const Ref<LexerMoreAction> LexerMoreAction::INSTANCE { new LexerMoreAction() };
|
||||
const Ref<LexerMoreAction> LexerMoreAction::getInstance() {
|
||||
static Ref<LexerMoreAction> instance = std::shared_ptr<LexerMoreAction>(
|
||||
new LexerMoreAction());
|
||||
return instance;
|
||||
}
|
||||
|
||||
LexerMoreAction::LexerMoreAction() {
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace atn {
|
|||
/// <summary>
|
||||
/// Provides a singleton instance of this parameterless lexer action.
|
||||
/// </summary>
|
||||
static const Ref<LexerMoreAction> INSTANCE;
|
||||
static const Ref<LexerMoreAction> getInstance();
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc} </summary>
|
||||
|
|
|
@ -38,13 +38,17 @@ using namespace antlr4;
|
|||
using namespace antlr4::atn;
|
||||
using namespace antlr4::misc;
|
||||
|
||||
const Ref<LexerPopModeAction> LexerPopModeAction::INSTANCE { new LexerPopModeAction() };
|
||||
const Ref<LexerPopModeAction> LexerPopModeAction::getInstance() {
|
||||
static Ref<LexerPopModeAction> instance = std::shared_ptr<LexerPopModeAction>(
|
||||
new LexerPopModeAction());
|
||||
return instance;
|
||||
}
|
||||
|
||||
LexerPopModeAction::LexerPopModeAction() {
|
||||
}
|
||||
|
||||
LexerActionType LexerPopModeAction::getActionType() const {
|
||||
return LexerActionType::POP_MODE;
|
||||
return LexerActionType::POP_MODE;
|
||||
}
|
||||
|
||||
bool LexerPopModeAction::isPositionDependent() const {
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include "atn/LexerAction.h"
|
||||
#include "atn/LexerActionType.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace antlr4 {
|
||||
namespace atn {
|
||||
|
||||
|
@ -51,7 +53,7 @@ namespace atn {
|
|||
/// <summary>
|
||||
/// Provides a singleton instance of this parameterless lexer action.
|
||||
/// </summary>
|
||||
static const Ref<LexerPopModeAction> INSTANCE;
|
||||
static const Ref<LexerPopModeAction> getInstance();
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc} </summary>
|
||||
|
|
|
@ -38,33 +38,37 @@ using namespace antlr4;
|
|||
using namespace antlr4::atn;
|
||||
using namespace antlr4::misc;
|
||||
|
||||
const Ref<LexerSkipAction> LexerSkipAction::INSTANCE { new LexerSkipAction() };
|
||||
const Ref<LexerSkipAction> LexerSkipAction::getInstance() {
|
||||
static Ref<LexerSkipAction> instance = std::shared_ptr<LexerSkipAction>(
|
||||
new LexerSkipAction());
|
||||
return instance;
|
||||
}
|
||||
|
||||
LexerSkipAction::LexerSkipAction() {
|
||||
}
|
||||
|
||||
LexerActionType LexerSkipAction::getActionType() const {
|
||||
return LexerActionType::SKIP;
|
||||
return LexerActionType::SKIP;
|
||||
}
|
||||
|
||||
bool LexerSkipAction::isPositionDependent() const {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void LexerSkipAction::execute(Lexer *lexer) {
|
||||
lexer->skip();
|
||||
lexer->skip();
|
||||
}
|
||||
|
||||
size_t LexerSkipAction::hashCode() const {
|
||||
size_t hash = MurmurHash::initialize();
|
||||
hash = MurmurHash::update(hash, (size_t)getActionType());
|
||||
return MurmurHash::finish(hash, 1);
|
||||
size_t hash = MurmurHash::initialize();
|
||||
hash = MurmurHash::update(hash, (size_t) getActionType());
|
||||
return MurmurHash::finish(hash, 1);
|
||||
}
|
||||
|
||||
bool LexerSkipAction::operator == (const LexerAction &obj) const {
|
||||
return &obj == this;
|
||||
bool LexerSkipAction::operator ==(const LexerAction &obj) const {
|
||||
return &obj == this;
|
||||
}
|
||||
|
||||
std::string LexerSkipAction::toString() const {
|
||||
return "skip";
|
||||
return "skip";
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "atn/LexerAction.h"
|
||||
#include "atn/LexerActionType.h"
|
||||
#include <memory>
|
||||
|
||||
namespace antlr4 {
|
||||
namespace atn {
|
||||
|
@ -49,7 +50,7 @@ namespace atn {
|
|||
class ANTLR4CPP_PUBLIC LexerSkipAction final : public LexerAction {
|
||||
public:
|
||||
/// Provides a singleton instance of this parameterless lexer action.
|
||||
static const Ref<LexerSkipAction> INSTANCE;
|
||||
static const Ref<LexerSkipAction> getInstance();
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc} </summary>
|
||||
|
|
Loading…
Reference in New Issue