2 smaller changes
- Changed the empty return state PredictionContext to max int (instead fixing it on int 16), like it's done in the Java runtime. - Converted 2 static init lambdas in the Cpp.stg to normal code, as VS doesn't allow us to access private class members in such lambdas.
This commit is contained in:
parent
185e956f9e
commit
c9c294a729
|
@ -70,6 +70,9 @@ ATNConfig::ATNConfig(Ref<ATNConfig> c, ATNState *state, Ref<PredictionContext> c
|
|||
: state(state), alt(c->alt), context(context), semanticContext(semanticContext), reachesIntoOuterContext(c->reachesIntoOuterContext) {
|
||||
}
|
||||
|
||||
ATNConfig::~ATNConfig() {
|
||||
}
|
||||
|
||||
size_t ATNConfig::hashCode() const {
|
||||
size_t hashCode = misc::MurmurHash::initialize(7);
|
||||
hashCode = misc::MurmurHash::update(hashCode, (size_t)state->stateNumber);
|
||||
|
|
|
@ -99,6 +99,8 @@ namespace atn {
|
|||
ATNConfig(Ref<ATNConfig> c, ATNState *state, Ref<PredictionContext> context);
|
||||
ATNConfig(Ref<ATNConfig> c, ATNState *state, Ref<PredictionContext> context, Ref<SemanticContext> semanticContext);
|
||||
|
||||
virtual ~ATNConfig();
|
||||
|
||||
virtual size_t hashCode() const;
|
||||
|
||||
struct ATNConfigHasher
|
||||
|
|
|
@ -414,8 +414,8 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, Ref<L
|
|||
RuleTransition *ruleTransition = static_cast<RuleTransition*>(t);
|
||||
Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, ruleTransition->followState->stateNumber);
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target, newContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Transition::PRECEDENCE:
|
||||
throw UnsupportedOperationException("Precedence predicates are not supported in lexers.");
|
||||
|
@ -447,8 +447,8 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, Ref<L
|
|||
if (evaluatePredicate(input, pt->ruleIndex, pt->predIndex, speculative)) {
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Transition::ACTION:
|
||||
if (config->context == nullptr|| config->context->hasEmptyPath()) {
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace atn {
|
|||
/// Represents $ in an array in full context mode, when $
|
||||
/// doesn't mean wildcard: $ + x = [$,x]. Here,
|
||||
/// $ = EMPTY_RETURN_STATE.
|
||||
static const int EMPTY_RETURN_STATE = INT16_MAX;
|
||||
static const int EMPTY_RETURN_STATE = INT_MAX;
|
||||
|
||||
private:
|
||||
static const int INITIAL_HASH = 1;
|
||||
|
|
|
@ -206,8 +206,10 @@ std::vector\<std::wstring> <lexer.name>::_symbolicNames = {
|
|||
|
||||
Ref\<dfa::Vocabulary> <lexer.name>::_vocabulary = std::make_shared\<dfa::VocabularyImpl>(_literalNames, _symbolicNames);
|
||||
|
||||
std::vector\<std::wstring> <lexer.name>::_tokenNames = []() {
|
||||
std::vector\<std::wstring> result;
|
||||
std::vector\<std::wstring> <lexer.name>::_tokenNames;
|
||||
|
||||
<lexer.name>::Initializer::Initializer() {
|
||||
// This code could be in a static initializer lambda, but VS doesn't allow access to private class members from there.
|
||||
for (size_t i = 0; i \< _symbolicNames.size(); ++i) {
|
||||
std::wstring name = _vocabulary->getLiteralName(i);
|
||||
if (name.empty()) {
|
||||
|
@ -220,10 +222,7 @@ std::vector\<std::wstring> <lexer.name>::_tokenNames = []() {
|
|||
_tokenNames.push_back(name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
|
||||
<lexer.name>::Initializer::Initializer() {
|
||||
|
||||
<atn>
|
||||
}
|
||||
|
||||
|
@ -382,24 +381,23 @@ std::vector\<std::wstring> <parser.name>::_symbolicNames = {
|
|||
|
||||
Ref\<dfa::Vocabulary> <parser.name>::_vocabulary = std::make_shared\<dfa::VocabularyImpl>(_literalNames, _symbolicNames);
|
||||
|
||||
std::vector\<std::wstring> <parser.name>::_tokenNames = []() {
|
||||
std::vector\<std::wstring> result;
|
||||
for (size_t i = 0; i \< <parser.name>::_symbolicNames.size(); ++i) {
|
||||
std::wstring name = <parser.name>::_vocabulary->getLiteralName(i);
|
||||
std::vector\<std::wstring> <parser.name>::_tokenNames;
|
||||
|
||||
<parser.name>::Initializer::Initializer() {
|
||||
// This code could be in a static initializer lambda, but VS doesn't allow access to private class members from there.
|
||||
for (size_t i = 0; i \< _symbolicNames.size(); ++i) {
|
||||
std::wstring name = _vocabulary->getLiteralName(i);
|
||||
if (name.empty()) {
|
||||
name = <parser.name>::_vocabulary->getSymbolicName(i);
|
||||
name = _vocabulary->getSymbolicName(i);
|
||||
}
|
||||
|
||||
if (name.empty()) {
|
||||
result.push_back(L"\<INVALID>");
|
||||
_tokenNames.push_back(L"\<INVALID>");
|
||||
} else {
|
||||
result.push_back(name);
|
||||
_tokenNames.push_back(name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
|
||||
<parser.name>::Initializer::Initializer() {
|
||||
<atn>
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue