A few more places that no longer pass a shared_ptr around.
This commit is contained in:
parent
dcb0d4aa62
commit
728af59528
|
@ -70,12 +70,12 @@
|
|||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/csharp/Test*.java</include>
|
||||
<!-- include>**/csharp/Test*.java</include -->
|
||||
<include>**/cpp/Test*.java</include>
|
||||
<include>**/java/Test*.java</include>
|
||||
<!-- include>**/java/Test*.java</include>
|
||||
<include>**/javascript/node/Test*.java</include>
|
||||
<include>**/python2/Test*.java</include>
|
||||
<include>**/python3/Test*.java</include>
|
||||
<include>**/python3/Test*.java</include -->
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -102,8 +102,7 @@ antlrcpp::BitSet DiagnosticErrorListener::getConflictingAlts(const antlrcpp::Bit
|
|||
}
|
||||
|
||||
antlrcpp::BitSet result;
|
||||
for (size_t i = 0; i < configs->size(); i++) {
|
||||
Ref<atn::ATNConfig> config = configs->get(i);
|
||||
for (auto &config : configs->configs) {
|
||||
result.set((size_t)config->alt);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,25 +48,25 @@ ATNConfig::ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& con
|
|||
reachesIntoOuterContext = 0;
|
||||
}
|
||||
|
||||
ATNConfig::ATNConfig(Ref<ATNConfig> const& c) : ATNConfig(c, c->state, c->context, c->semanticContext) {
|
||||
ATNConfig::ATNConfig(ATNConfig *c) : ATNConfig(c, c->state, c->context, c->semanticContext) {
|
||||
}
|
||||
|
||||
ATNConfig::ATNConfig(Ref<ATNConfig> const& c, ATNState *state) : ATNConfig(c, state, c->context, c->semanticContext) {
|
||||
ATNConfig::ATNConfig(ATNConfig *c, ATNState *state) : ATNConfig(c, state, c->context, c->semanticContext) {
|
||||
}
|
||||
|
||||
ATNConfig::ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<SemanticContext> const& semanticContext)
|
||||
ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, Ref<SemanticContext> const& semanticContext)
|
||||
: ATNConfig(c, state, c->context, semanticContext) {
|
||||
}
|
||||
|
||||
ATNConfig::ATNConfig(Ref<ATNConfig> const& c, Ref<SemanticContext> const& semanticContext)
|
||||
ATNConfig::ATNConfig(ATNConfig *c, Ref<SemanticContext> const& semanticContext)
|
||||
: ATNConfig(c, c->state, c->context, semanticContext) {
|
||||
}
|
||||
|
||||
ATNConfig::ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context)
|
||||
ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context)
|
||||
: ATNConfig(c, state, context, c->semanticContext) {
|
||||
}
|
||||
|
||||
ATNConfig::ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context,
|
||||
ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context,
|
||||
Ref<SemanticContext> const& semanticContext)
|
||||
: state(state), alt(c->alt), context(context), reachesIntoOuterContext(c->reachesIntoOuterContext),
|
||||
semanticContext(semanticContext) {
|
||||
|
|
|
@ -46,13 +46,13 @@ namespace atn {
|
|||
public:
|
||||
struct Hasher
|
||||
{
|
||||
size_t operator()(ATNConfig const& k) const {
|
||||
return k.hashCode();
|
||||
size_t operator()(Ref<ATNConfig> const& k) const {
|
||||
return k->hashCode();
|
||||
}
|
||||
};
|
||||
|
||||
struct Comparer {
|
||||
bool operator()(ATNConfig const& lhs, ATNConfig const& rhs) const {
|
||||
bool operator()(Ref<ATNConfig> const& lhs, Ref<ATNConfig> const& rhs) const {
|
||||
return lhs == rhs;
|
||||
}
|
||||
};
|
||||
|
@ -105,12 +105,12 @@ namespace atn {
|
|||
ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context);
|
||||
ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext);
|
||||
|
||||
ATNConfig(Ref<ATNConfig> const& c); // dup
|
||||
ATNConfig(Ref<ATNConfig> const& c, ATNState *state);
|
||||
ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<SemanticContext> const& semanticContext);
|
||||
ATNConfig(Ref<ATNConfig> const& c, Ref<SemanticContext> const& semanticContext);
|
||||
ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context);
|
||||
ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext);
|
||||
ATNConfig(ATNConfig *c); // dup
|
||||
ATNConfig(ATNConfig *c, ATNState *state);
|
||||
ATNConfig(ATNConfig *c, ATNState *state, Ref<SemanticContext> const& semanticContext);
|
||||
ATNConfig(ATNConfig *c, Ref<SemanticContext> const& semanticContext);
|
||||
ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context);
|
||||
ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext);
|
||||
|
||||
virtual ~ATNConfig();
|
||||
|
||||
|
|
|
@ -55,11 +55,11 @@ ATNConfigSet::ATNConfigSet(const Ref<ATNConfigSet> &old) : ATNConfigSet(old->ful
|
|||
ATNConfigSet::~ATNConfigSet() {
|
||||
}
|
||||
|
||||
bool ATNConfigSet::add(const Ref<ATNConfig> &config) {
|
||||
bool ATNConfigSet::add(Ref<ATNConfig> const& config) {
|
||||
return add(config, nullptr);
|
||||
}
|
||||
|
||||
bool ATNConfigSet::add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache) {
|
||||
bool ATNConfigSet::add(Ref<ATNConfig> const& config, PredictionContextMergeCache *mergeCache) {
|
||||
if (_readonly) {
|
||||
throw IllegalStateException("This set is readonly");
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ bool ATNConfigSet::addAll(const Ref<ATNConfigSet> &other) {
|
|||
|
||||
std::vector<ATNState*> ATNConfigSet::getStates() {
|
||||
std::vector<ATNState*> states;
|
||||
for (auto c : configs) {
|
||||
for (auto &c : configs) {
|
||||
states.push_back(c->state);
|
||||
}
|
||||
return states;
|
||||
|
@ -124,15 +124,15 @@ std::vector<ATNState*> ATNConfigSet::getStates() {
|
|||
|
||||
BitSet ATNConfigSet::getAlts() {
|
||||
BitSet alts;
|
||||
for (ATNConfig config : configs) {
|
||||
alts.set(config.alt);
|
||||
for (auto &config : configs) {
|
||||
alts.set(config->alt);
|
||||
}
|
||||
return alts;
|
||||
}
|
||||
|
||||
std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() {
|
||||
std::vector<Ref<SemanticContext>> preds;
|
||||
for (auto c : configs) {
|
||||
for (auto &c : configs) {
|
||||
if (c->semanticContext != SemanticContext::NONE) {
|
||||
preds.push_back(c->semanticContext);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() {
|
|||
return preds;
|
||||
}
|
||||
|
||||
Ref<ATNConfig> ATNConfigSet::get(size_t i) const {
|
||||
Ref<ATNConfig> const& ATNConfigSet::get(size_t i) const {
|
||||
return configs[i];
|
||||
}
|
||||
|
||||
|
@ -217,8 +217,8 @@ void ATNConfigSet::setReadonly(bool readonly) {
|
|||
std::string ATNConfigSet::toString() {
|
||||
std::stringstream ss;
|
||||
ss << "[";
|
||||
for (size_t i = 0; i < configs.size(); i++) {
|
||||
ss << configs[i]->toString();
|
||||
for (auto &config : configs) {
|
||||
ss << config->toString();
|
||||
}
|
||||
ss << "]";
|
||||
|
||||
|
|
|
@ -68,11 +68,11 @@ namespace atn {
|
|||
const bool fullCtx;
|
||||
|
||||
ATNConfigSet(bool fullCtx = true);
|
||||
ATNConfigSet(const Ref<ATNConfigSet> &old);
|
||||
ATNConfigSet(Ref<ATNConfigSet> const& old);
|
||||
|
||||
virtual ~ATNConfigSet();
|
||||
|
||||
virtual bool add(const Ref<ATNConfig> &config);
|
||||
virtual bool add(Ref<ATNConfig> const& config);
|
||||
|
||||
/// <summary>
|
||||
/// Adding a new config means merging contexts with existing configs for
|
||||
|
@ -84,7 +84,7 @@ namespace atn {
|
|||
/// This method updates <seealso cref="#dipsIntoOuterContext"/> and
|
||||
/// <seealso cref="#hasSemanticContext"/> when necessary.
|
||||
/// </summary>
|
||||
virtual bool add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache);
|
||||
virtual bool add(Ref<ATNConfig> const& config, PredictionContextMergeCache *mergeCache);
|
||||
|
||||
virtual std::vector<ATNState *> getStates();
|
||||
|
||||
|
@ -99,7 +99,7 @@ namespace atn {
|
|||
antlrcpp::BitSet getAlts();
|
||||
virtual std::vector<Ref<SemanticContext>> getPredicates();
|
||||
|
||||
virtual Ref<ATNConfig> get(size_t i) const;
|
||||
virtual Ref<ATNConfig> const& get(size_t i) const;
|
||||
|
||||
virtual void optimizeConfigs(ATNSimulator *interpreter);
|
||||
|
||||
|
|
|
@ -52,17 +52,17 @@ LexerATNConfig::LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext>
|
|||
_passedThroughNonGreedyDecision(false) {
|
||||
}
|
||||
|
||||
LexerATNConfig::LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state)
|
||||
LexerATNConfig::LexerATNConfig(LexerATNConfig *c, ATNState *state)
|
||||
: ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor),
|
||||
_passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) {
|
||||
}
|
||||
|
||||
LexerATNConfig::LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor)
|
||||
LexerATNConfig::LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor)
|
||||
: ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(lexerActionExecutor),
|
||||
_passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) {
|
||||
}
|
||||
|
||||
LexerATNConfig::LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context)
|
||||
LexerATNConfig::LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<PredictionContext> const& context)
|
||||
: ATNConfig(c, state, context, c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor),
|
||||
_passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) {
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ bool LexerATNConfig::operator == (const LexerATNConfig& other) const
|
|||
return ATNConfig::operator == (other);
|
||||
}
|
||||
|
||||
bool LexerATNConfig::checkNonGreedyDecision(Ref<LexerATNConfig> const& source, ATNState *target) {
|
||||
bool LexerATNConfig::checkNonGreedyDecision(LexerATNConfig *source, ATNState *target) {
|
||||
return source->_passedThroughNonGreedyDecision ||
|
||||
(is<DecisionState*>(target) && (static_cast<DecisionState*>(target))->nonGreedy);
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ namespace atn {
|
|||
LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context);
|
||||
LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<LexerActionExecutor> const& lexerActionExecutor);
|
||||
|
||||
LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state);
|
||||
LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor);
|
||||
LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context);
|
||||
LexerATNConfig(LexerATNConfig *c, ATNState *state);
|
||||
LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor);
|
||||
LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<PredictionContext> const& context);
|
||||
|
||||
/**
|
||||
* Gets the {@link LexerActionExecutor} capable of executing the embedded
|
||||
|
@ -63,7 +63,7 @@ namespace atn {
|
|||
const Ref<LexerActionExecutor> _lexerActionExecutor;
|
||||
const bool _passedThroughNonGreedyDecision;
|
||||
|
||||
static bool checkNonGreedyDecision(Ref<LexerATNConfig> const& source, ATNState *target);
|
||||
static bool checkNonGreedyDecision(LexerATNConfig *source, ATNState *target);
|
||||
};
|
||||
|
||||
} // namespace atn
|
||||
|
|
|
@ -279,7 +279,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
|
|||
}
|
||||
|
||||
bool treatEofAsEpsilon = t == Token::EOF;
|
||||
Ref<LexerATNConfig> config = std::make_shared<LexerATNConfig>(std::static_pointer_cast<LexerATNConfig>(c),
|
||||
Ref<LexerATNConfig> config = std::make_shared<LexerATNConfig>(std::static_pointer_cast<LexerATNConfig>(c).get(),
|
||||
target, lexerActionExecutor);
|
||||
|
||||
if (closure(input, config, reach, currentAltReachedAcceptState, true, treatEofAsEpsilon)) {
|
||||
|
@ -350,7 +350,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
|
|||
configs->add(config);
|
||||
return true;
|
||||
} else {
|
||||
configs->add(std::make_shared<LexerATNConfig>(config, config->state, PredictionContext::EMPTY));
|
||||
configs->add(std::make_shared<LexerATNConfig>(config.get(), config->state, PredictionContext::EMPTY));
|
||||
currentAltReachedAcceptState = true;
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
|
|||
if (config->context->getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE) {
|
||||
std::weak_ptr<PredictionContext> newContext = config->context->getParent(i); // "pop" return state
|
||||
ATNState *returnState = atn.states[(size_t)config->context->getReturnState(i)];
|
||||
Ref<LexerATNConfig> c = std::make_shared<LexerATNConfig>(config, returnState, newContext.lock());
|
||||
Ref<LexerATNConfig> c = std::make_shared<LexerATNConfig>(config.get(), returnState, newContext.lock());
|
||||
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon);
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
|
|||
ATNState *p = config->state;
|
||||
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
|
||||
Transition *t = p->transition(i);
|
||||
Ref<LexerATNConfig> c = getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon);
|
||||
Ref<LexerATNConfig> c = getEpsilonTarget(input, config.get(), t, configs, speculative, treatEofAsEpsilon);
|
||||
if (c != nullptr) {
|
||||
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon);
|
||||
}
|
||||
|
@ -388,16 +388,14 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
|
|||
return currentAltReachedAcceptState;
|
||||
}
|
||||
|
||||
Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, Transition *t,
|
||||
Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, LexerATNConfig *config, Transition *t,
|
||||
ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon) {
|
||||
|
||||
Ref<LexerATNConfig> c = nullptr;
|
||||
switch (t->getSerializationType()) {
|
||||
case Transition::RULE: {
|
||||
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;
|
||||
return std::make_shared<LexerATNConfig>(config, t->target, newContext);
|
||||
}
|
||||
|
||||
case Transition::PRECEDENCE:
|
||||
|
@ -423,12 +421,9 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const
|
|||
test them, we cannot cash the DFA state target of ID.
|
||||
*/
|
||||
PredicateTransition *pt = static_cast<PredicateTransition*>(t);
|
||||
if (debug) {
|
||||
std::cout << "EVAL rule " << pt->ruleIndex << ":" << pt->predIndex << std::endl;
|
||||
}
|
||||
configs->hasSemanticContext = true;
|
||||
if (evaluatePredicate(input, pt->ruleIndex, pt->predIndex, speculative)) {
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target);
|
||||
return std::make_shared<LexerATNConfig>(config, t->target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -449,33 +444,28 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const
|
|||
// the split operation.
|
||||
Ref<LexerActionExecutor> lexerActionExecutor = LexerActionExecutor::append(config->getLexerActionExecutor(),
|
||||
atn.lexerActions[static_cast<ActionTransition *>(t)->actionIndex]);
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target, lexerActionExecutor);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
return std::make_shared<LexerATNConfig>(config, t->target, lexerActionExecutor);
|
||||
} else {
|
||||
// ignore actions in referenced rules
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target);
|
||||
break;
|
||||
return std::make_shared<LexerATNConfig>(config, t->target);
|
||||
}
|
||||
|
||||
case Transition::EPSILON:
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target);
|
||||
break;
|
||||
return std::make_shared<LexerATNConfig>(config, t->target);
|
||||
|
||||
case Transition::ATOM:
|
||||
case Transition::RANGE:
|
||||
case Transition::SET:
|
||||
if (treatEofAsEpsilon) {
|
||||
if (t->matches(Token::EOF, Lexer::MIN_CHAR_VALUE, Lexer::MAX_CHAR_VALUE)) {
|
||||
c = std::make_shared<LexerATNConfig>(config, t->target);
|
||||
break;
|
||||
return std::make_shared<LexerATNConfig>(config, t->target);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return c;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int predIndex, bool speculative) {
|
||||
|
|
|
@ -187,7 +187,7 @@ namespace atn {
|
|||
bool currentAltReachedAcceptState, bool speculative, bool treatEofAsEpsilon);
|
||||
|
||||
// side-effect: can alter configs.hasSemanticContext
|
||||
virtual Ref<LexerATNConfig> getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, Transition *t,
|
||||
virtual Ref<LexerATNConfig> getEpsilonTarget(CharStream *input, LexerATNConfig *config, Transition *t,
|
||||
ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -471,7 +471,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
|
|||
Transition *trans = c->state->transition(ti);
|
||||
ATNState *target = getReachableTarget(trans, (int)t);
|
||||
if (target != nullptr) {
|
||||
intermediate->add(std::make_shared<ATNConfig>(c, target), &mergeCache);
|
||||
intermediate->add(std::make_shared<ATNConfig>(c.get(), target), &mergeCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
|
|||
ATNConfig::Set closureBusy;
|
||||
|
||||
bool treatEofAsEpsilon = t == Token::EOF;
|
||||
for (auto c : intermediate->configs) {
|
||||
for (auto &c : intermediate->configs) {
|
||||
closure(c, reach.get(), closureBusy, false, fullCtx, treatEofAsEpsilon);
|
||||
}
|
||||
}
|
||||
|
@ -578,7 +578,7 @@ ATNConfigSet* ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNConfigSe
|
|||
misc::IntervalSet nextTokens = atn.nextTokens(config->state);
|
||||
if (nextTokens.contains(Token::EPSILON)) {
|
||||
ATNState *endOfRuleState = atn.ruleToStopState[(size_t)config->state->ruleIndex];
|
||||
result->add(std::make_shared<ATNConfig>(config, endOfRuleState), &mergeCache);
|
||||
result->add(std::make_shared<ATNConfig>(config.get(), endOfRuleState), &mergeCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -618,7 +618,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfi
|
|||
|
||||
statesFromAlt1[config->state->stateNumber] = config->context;
|
||||
if (updatedContext != config->semanticContext) {
|
||||
configSet->add(std::make_shared<ATNConfig>(config, updatedContext), &mergeCache);
|
||||
configSet->add(std::make_shared<ATNConfig>(config.get(), updatedContext), &mergeCache);
|
||||
}
|
||||
else {
|
||||
configSet->add(config, &mergeCache);
|
||||
|
@ -837,7 +837,7 @@ void ParserATNSimulator::closureCheckingStopState(Ref<ATNConfig> const& config,
|
|||
for (size_t i = 0; i < config->context->size(); i++) {
|
||||
if (config->context->getReturnState(i) == PredictionContext::EMPTY_RETURN_STATE) {
|
||||
if (fullCtx) {
|
||||
configs->add(std::make_shared<ATNConfig>(config, config->state, PredictionContext::EMPTY), &mergeCache);
|
||||
configs->add(std::make_shared<ATNConfig>(config.get(), config->state, PredictionContext::EMPTY), &mergeCache);
|
||||
continue;
|
||||
} else {
|
||||
// we have no context info, just chase follow links (if greedy)
|
||||
|
@ -966,7 +966,7 @@ Ref<ATNConfig> ParserATNSimulator::getEpsilonTarget(Ref<ATNConfig> const& config
|
|||
return actionTransition(config, static_cast<ActionTransition*>(t));
|
||||
|
||||
case Transition::EPSILON:
|
||||
return std::make_shared<ATNConfig>(config, t->target);
|
||||
return std::make_shared<ATNConfig>(config.get(), t->target);
|
||||
|
||||
case Transition::ATOM:
|
||||
case Transition::RANGE:
|
||||
|
@ -975,7 +975,7 @@ Ref<ATNConfig> ParserATNSimulator::getEpsilonTarget(Ref<ATNConfig> const& config
|
|||
// transition is traversed
|
||||
if (treatEofAsEpsilon) {
|
||||
if (t->matches(Token::EOF, 0, 1)) {
|
||||
return std::make_shared<ATNConfig>(config, t->target);
|
||||
return std::make_shared<ATNConfig>(config.get(), t->target);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -990,7 +990,7 @@ Ref<ATNConfig> ParserATNSimulator::actionTransition(Ref<ATNConfig> const& config
|
|||
if (debug) {
|
||||
std::cout << "ACTION edge " << t->ruleIndex << ":" << t->actionIndex << std::endl;
|
||||
}
|
||||
return std::make_shared<ATNConfig>(config, t->target);
|
||||
return std::make_shared<ATNConfig>(config.get(), t->target);
|
||||
}
|
||||
|
||||
Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& config, PrecedencePredicateTransition *pt,
|
||||
|
@ -1016,14 +1016,14 @@ Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& co
|
|||
bool predSucceeds = evalSemanticContext(pt->getPredicate(), _outerContext, config->alt, fullCtx);
|
||||
_input->seek(currentPosition);
|
||||
if (predSucceeds) {
|
||||
c = std::make_shared<ATNConfig>(config, pt->target); // no pred context
|
||||
c = std::make_shared<ATNConfig>(config.get(), pt->target); // no pred context
|
||||
}
|
||||
} else {
|
||||
Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
|
||||
c = std::make_shared<ATNConfig>(config, pt->target, newSemCtx);
|
||||
c = std::make_shared<ATNConfig>(config.get(), pt->target, newSemCtx);
|
||||
}
|
||||
} else {
|
||||
c = std::make_shared<ATNConfig>(config, pt->target);
|
||||
c = std::make_shared<ATNConfig>(config.get(), pt->target);
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
|
@ -1054,14 +1054,14 @@ Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config,
|
|||
bool predSucceeds = evalSemanticContext(pt->getPredicate(), _outerContext, config->alt, fullCtx);
|
||||
_input->seek(currentPosition);
|
||||
if (predSucceeds) {
|
||||
c = std::make_shared<ATNConfig>(config, pt->target); // no pred context
|
||||
c = std::make_shared<ATNConfig>(config.get(), pt->target); // no pred context
|
||||
}
|
||||
} else {
|
||||
Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
|
||||
c = std::make_shared<ATNConfig>(config, pt->target, newSemCtx);
|
||||
c = std::make_shared<ATNConfig>(config.get(), pt->target, newSemCtx);
|
||||
}
|
||||
} else {
|
||||
c = std::make_shared<ATNConfig>(config, pt->target);
|
||||
c = std::make_shared<ATNConfig>(config.get(), pt->target);
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
|
@ -1077,7 +1077,7 @@ Ref<ATNConfig> ParserATNSimulator::ruleTransition(Ref<ATNConfig> const& config,
|
|||
|
||||
atn::ATNState *returnState = t->followState;
|
||||
Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, returnState->stateNumber);
|
||||
return std::make_shared<ATNConfig>(config, t->target, newContext);
|
||||
return std::make_shared<ATNConfig>(config.get(), t->target, newContext);
|
||||
}
|
||||
|
||||
BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {
|
||||
|
|
|
@ -714,17 +714,17 @@ namespace atn {
|
|||
virtual std::string getRuleName(size_t index);
|
||||
|
||||
protected:
|
||||
virtual Ref<ATNConfig> getEpsilonTarget(Ref<ATNConfig> const& config, Transition *t, bool collectPredicates,
|
||||
bool inContext, bool fullCtx, bool treatEofAsEpsilon);
|
||||
virtual Ref<ATNConfig> getEpsilonTarget(Ref<ATNConfig> const& config, Transition *t,
|
||||
bool collectPredicates, bool inContext, bool fullCtx, bool treatEofAsEpsilon);
|
||||
virtual Ref<ATNConfig> actionTransition(Ref<ATNConfig> const& config, ActionTransition *t);
|
||||
|
||||
public:
|
||||
virtual Ref<ATNConfig> precedenceTransition(Ref<ATNConfig> const& config, PrecedencePredicateTransition *pt,
|
||||
bool collectPredicates, bool inContext, bool fullCtx);
|
||||
virtual Ref<ATNConfig> precedenceTransition(Ref<ATNConfig> const& config,
|
||||
PrecedencePredicateTransition *pt, bool collectPredicates, bool inContext, bool fullCtx);
|
||||
|
||||
protected:
|
||||
virtual Ref<ATNConfig> predTransition(Ref<ATNConfig> const& config, PredicateTransition *pt, bool collectPredicates,
|
||||
bool inContext, bool fullCtx);
|
||||
virtual Ref<ATNConfig> predTransition(Ref<ATNConfig> const& config, PredicateTransition *pt,
|
||||
bool collectPredicates, bool inContext, bool fullCtx);
|
||||
|
||||
virtual Ref<ATNConfig> ruleTransition(Ref<ATNConfig> const& config, RuleTransition *t);
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ struct AltAndContextConfigHasher
|
|||
};
|
||||
|
||||
struct AltAndContextConfigComparer {
|
||||
bool operator()(const ATNConfig &a, const ATNConfig &b) const
|
||||
bool operator() (const ATNConfig &a, const ATNConfig &b) const
|
||||
{
|
||||
if (&a == &b) {
|
||||
return true;
|
||||
|
@ -88,7 +88,7 @@ bool PredictionModeClass::hasSLLConflictTerminatingPrediction(PredictionMode mod
|
|||
// dup configs, tossing out semantic predicates
|
||||
ATNConfigSet dup(true);
|
||||
for (auto &config : configs->configs) {
|
||||
Ref<ATNConfig> c = std::make_shared<ATNConfig>(config, SemanticContext::NONE);
|
||||
Ref<ATNConfig> c = std::make_shared<ATNConfig>(config.get(), SemanticContext::NONE);
|
||||
dup.add(c);
|
||||
}
|
||||
std::vector<antlrcpp::BitSet> altsets = getConflictingAltSubsets(&dup);
|
||||
|
@ -184,9 +184,9 @@ antlrcpp::BitSet PredictionModeClass::getAlts(ATNConfigSet *configs) {
|
|||
}
|
||||
|
||||
std::vector<antlrcpp::BitSet> PredictionModeClass::getConflictingAltSubsets(ATNConfigSet *configs) {
|
||||
std::unordered_map<Ref<ATNConfig>, antlrcpp::BitSet, AltAndContextConfigHasher, AltAndContextConfigComparer> configToAlts;
|
||||
std::unordered_map<ATNConfig *, antlrcpp::BitSet, AltAndContextConfigHasher, AltAndContextConfigComparer> configToAlts;
|
||||
for (auto &config : configs->configs) {
|
||||
configToAlts[config].set(config->alt);
|
||||
configToAlts[config.get()].set(config->alt);
|
||||
}
|
||||
std::vector<antlrcpp::BitSet> values;
|
||||
for (auto it : configToAlts) {
|
||||
|
|
Loading…
Reference in New Issue