Revert "A few more places that no longer pass a shared_ptr around."

This reverts commit 728af59528.
This commit is contained in:
Mike Lischke 2016-06-15 13:30:37 +02:00
parent 728af59528
commit 4a8010b4eb
13 changed files with 90 additions and 79 deletions

View File

@ -70,12 +70,12 @@
<version>2.12.4</version> <version>2.12.4</version>
<configuration> <configuration>
<includes> <includes>
<!-- include>**/csharp/Test*.java</include --> <include>**/csharp/Test*.java</include>
<include>**/cpp/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>**/javascript/node/Test*.java</include>
<include>**/python2/Test*.java</include> <include>**/python2/Test*.java</include>
<include>**/python3/Test*.java</include --> <include>**/python3/Test*.java</include>
</includes> </includes>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -102,7 +102,8 @@ antlrcpp::BitSet DiagnosticErrorListener::getConflictingAlts(const antlrcpp::Bit
} }
antlrcpp::BitSet result; antlrcpp::BitSet result;
for (auto &config : configs->configs) { for (size_t i = 0; i < configs->size(); i++) {
Ref<atn::ATNConfig> config = configs->get(i);
result.set((size_t)config->alt); result.set((size_t)config->alt);
} }

View File

@ -48,25 +48,25 @@ ATNConfig::ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& con
reachesIntoOuterContext = 0; reachesIntoOuterContext = 0;
} }
ATNConfig::ATNConfig(ATNConfig *c) : ATNConfig(c, c->state, c->context, c->semanticContext) { ATNConfig::ATNConfig(Ref<ATNConfig> const& c) : ATNConfig(c, 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) : ATNConfig(c, state, c->context, c->semanticContext) {
} }
ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, Ref<SemanticContext> const& semanticContext) ATNConfig::ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<SemanticContext> const& semanticContext)
: ATNConfig(c, state, c->context, semanticContext) { : ATNConfig(c, state, c->context, semanticContext) {
} }
ATNConfig::ATNConfig(ATNConfig *c, Ref<SemanticContext> const& semanticContext) ATNConfig::ATNConfig(Ref<ATNConfig> const& c, Ref<SemanticContext> const& semanticContext)
: ATNConfig(c, c->state, c->context, semanticContext) { : ATNConfig(c, c->state, c->context, semanticContext) {
} }
ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context) ATNConfig::ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context)
: ATNConfig(c, state, context, c->semanticContext) { : ATNConfig(c, state, context, c->semanticContext) {
} }
ATNConfig::ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context, ATNConfig::ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context,
Ref<SemanticContext> const& semanticContext) Ref<SemanticContext> const& semanticContext)
: state(state), alt(c->alt), context(context), reachesIntoOuterContext(c->reachesIntoOuterContext), : state(state), alt(c->alt), context(context), reachesIntoOuterContext(c->reachesIntoOuterContext),
semanticContext(semanticContext) { semanticContext(semanticContext) {

View File

@ -46,13 +46,13 @@ namespace atn {
public: public:
struct Hasher struct Hasher
{ {
size_t operator()(Ref<ATNConfig> const& k) const { size_t operator()(ATNConfig const& k) const {
return k->hashCode(); return k.hashCode();
} }
}; };
struct Comparer { struct Comparer {
bool operator()(Ref<ATNConfig> const& lhs, Ref<ATNConfig> const& rhs) const { bool operator()(ATNConfig const& lhs, ATNConfig const& rhs) const {
return lhs == rhs; 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);
ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext); ATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext);
ATNConfig(ATNConfig *c); // dup ATNConfig(Ref<ATNConfig> const& c); // dup
ATNConfig(ATNConfig *c, ATNState *state); ATNConfig(Ref<ATNConfig> const& c, ATNState *state);
ATNConfig(ATNConfig *c, ATNState *state, Ref<SemanticContext> const& semanticContext); ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<SemanticContext> const& semanticContext);
ATNConfig(ATNConfig *c, Ref<SemanticContext> const& semanticContext); ATNConfig(Ref<ATNConfig> const& c, Ref<SemanticContext> const& semanticContext);
ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context); ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context);
ATNConfig(ATNConfig *c, ATNState *state, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext); ATNConfig(Ref<ATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context, Ref<SemanticContext> const& semanticContext);
virtual ~ATNConfig(); virtual ~ATNConfig();

View File

@ -55,11 +55,11 @@ ATNConfigSet::ATNConfigSet(const Ref<ATNConfigSet> &old) : ATNConfigSet(old->ful
ATNConfigSet::~ATNConfigSet() { ATNConfigSet::~ATNConfigSet() {
} }
bool ATNConfigSet::add(Ref<ATNConfig> const& config) { bool ATNConfigSet::add(const Ref<ATNConfig> &config) {
return add(config, nullptr); return add(config, nullptr);
} }
bool ATNConfigSet::add(Ref<ATNConfig> const& config, PredictionContextMergeCache *mergeCache) { bool ATNConfigSet::add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache) {
if (_readonly) { if (_readonly) {
throw IllegalStateException("This set is 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*> ATNConfigSet::getStates() {
std::vector<ATNState*> states; std::vector<ATNState*> states;
for (auto &c : configs) { for (auto c : configs) {
states.push_back(c->state); states.push_back(c->state);
} }
return states; return states;
@ -124,15 +124,15 @@ std::vector<ATNState*> ATNConfigSet::getStates() {
BitSet ATNConfigSet::getAlts() { BitSet ATNConfigSet::getAlts() {
BitSet alts; BitSet alts;
for (auto &config : configs) { for (ATNConfig config : configs) {
alts.set(config->alt); alts.set(config.alt);
} }
return alts; return alts;
} }
std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() { std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() {
std::vector<Ref<SemanticContext>> preds; std::vector<Ref<SemanticContext>> preds;
for (auto &c : configs) { for (auto c : configs) {
if (c->semanticContext != SemanticContext::NONE) { if (c->semanticContext != SemanticContext::NONE) {
preds.push_back(c->semanticContext); preds.push_back(c->semanticContext);
} }
@ -140,7 +140,7 @@ std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() {
return preds; return preds;
} }
Ref<ATNConfig> const& ATNConfigSet::get(size_t i) const { Ref<ATNConfig> ATNConfigSet::get(size_t i) const {
return configs[i]; return configs[i];
} }
@ -217,8 +217,8 @@ void ATNConfigSet::setReadonly(bool readonly) {
std::string ATNConfigSet::toString() { std::string ATNConfigSet::toString() {
std::stringstream ss; std::stringstream ss;
ss << "["; ss << "[";
for (auto &config : configs) { for (size_t i = 0; i < configs.size(); i++) {
ss << config->toString(); ss << configs[i]->toString();
} }
ss << "]"; ss << "]";

View File

@ -68,11 +68,11 @@ namespace atn {
const bool fullCtx; const bool fullCtx;
ATNConfigSet(bool fullCtx = true); ATNConfigSet(bool fullCtx = true);
ATNConfigSet(Ref<ATNConfigSet> const& old); ATNConfigSet(const Ref<ATNConfigSet> &old);
virtual ~ATNConfigSet(); virtual ~ATNConfigSet();
virtual bool add(Ref<ATNConfig> const& config); virtual bool add(const Ref<ATNConfig> &config);
/// <summary> /// <summary>
/// Adding a new config means merging contexts with existing configs for /// Adding a new config means merging contexts with existing configs for
@ -84,7 +84,7 @@ namespace atn {
/// This method updates <seealso cref="#dipsIntoOuterContext"/> and /// This method updates <seealso cref="#dipsIntoOuterContext"/> and
/// <seealso cref="#hasSemanticContext"/> when necessary. /// <seealso cref="#hasSemanticContext"/> when necessary.
/// </summary> /// </summary>
virtual bool add(Ref<ATNConfig> const& config, PredictionContextMergeCache *mergeCache); virtual bool add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache);
virtual std::vector<ATNState *> getStates(); virtual std::vector<ATNState *> getStates();
@ -99,7 +99,7 @@ namespace atn {
antlrcpp::BitSet getAlts(); antlrcpp::BitSet getAlts();
virtual std::vector<Ref<SemanticContext>> getPredicates(); virtual std::vector<Ref<SemanticContext>> getPredicates();
virtual Ref<ATNConfig> const& get(size_t i) const; virtual Ref<ATNConfig> get(size_t i) const;
virtual void optimizeConfigs(ATNSimulator *interpreter); virtual void optimizeConfigs(ATNSimulator *interpreter);

View File

@ -52,17 +52,17 @@ LexerATNConfig::LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext>
_passedThroughNonGreedyDecision(false) { _passedThroughNonGreedyDecision(false) {
} }
LexerATNConfig::LexerATNConfig(LexerATNConfig *c, ATNState *state) LexerATNConfig::LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state)
: ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor), : ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor),
_passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) { _passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) {
} }
LexerATNConfig::LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor) LexerATNConfig::LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor)
: ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(lexerActionExecutor), : ATNConfig(c, state, c->context, c->semanticContext), _lexerActionExecutor(lexerActionExecutor),
_passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) { _passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) {
} }
LexerATNConfig::LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<PredictionContext> const& context) LexerATNConfig::LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context)
: ATNConfig(c, state, context, c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor), : ATNConfig(c, state, context, c->semanticContext), _lexerActionExecutor(c->_lexerActionExecutor),
_passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) { _passedThroughNonGreedyDecision(checkNonGreedyDecision(c, state)) {
} }
@ -99,7 +99,7 @@ bool LexerATNConfig::operator == (const LexerATNConfig& other) const
return ATNConfig::operator == (other); return ATNConfig::operator == (other);
} }
bool LexerATNConfig::checkNonGreedyDecision(LexerATNConfig *source, ATNState *target) { bool LexerATNConfig::checkNonGreedyDecision(Ref<LexerATNConfig> const& source, ATNState *target) {
return source->_passedThroughNonGreedyDecision || return source->_passedThroughNonGreedyDecision ||
(is<DecisionState*>(target) && (static_cast<DecisionState*>(target))->nonGreedy); (is<DecisionState*>(target) && (static_cast<DecisionState*>(target))->nonGreedy);
} }

View File

@ -41,9 +41,9 @@ namespace atn {
LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context); LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context);
LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<LexerActionExecutor> const& lexerActionExecutor); LexerATNConfig(ATNState *state, int alt, Ref<PredictionContext> const& context, Ref<LexerActionExecutor> const& lexerActionExecutor);
LexerATNConfig(LexerATNConfig *c, ATNState *state); LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state);
LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor); LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<LexerActionExecutor> const& lexerActionExecutor);
LexerATNConfig(LexerATNConfig *c, ATNState *state, Ref<PredictionContext> const& context); LexerATNConfig(Ref<LexerATNConfig> const& c, ATNState *state, Ref<PredictionContext> const& context);
/** /**
* Gets the {@link LexerActionExecutor} capable of executing the embedded * Gets the {@link LexerActionExecutor} capable of executing the embedded
@ -63,7 +63,7 @@ namespace atn {
const Ref<LexerActionExecutor> _lexerActionExecutor; const Ref<LexerActionExecutor> _lexerActionExecutor;
const bool _passedThroughNonGreedyDecision; const bool _passedThroughNonGreedyDecision;
static bool checkNonGreedyDecision(LexerATNConfig *source, ATNState *target); static bool checkNonGreedyDecision(Ref<LexerATNConfig> const& source, ATNState *target);
}; };
} // namespace atn } // namespace atn

View File

@ -279,7 +279,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, ATNConfigSet *c
} }
bool treatEofAsEpsilon = t == Token::EOF; bool treatEofAsEpsilon = t == Token::EOF;
Ref<LexerATNConfig> config = std::make_shared<LexerATNConfig>(std::static_pointer_cast<LexerATNConfig>(c).get(), Ref<LexerATNConfig> config = std::make_shared<LexerATNConfig>(std::static_pointer_cast<LexerATNConfig>(c),
target, lexerActionExecutor); target, lexerActionExecutor);
if (closure(input, config, reach, currentAltReachedAcceptState, true, treatEofAsEpsilon)) { if (closure(input, config, reach, currentAltReachedAcceptState, true, treatEofAsEpsilon)) {
@ -350,7 +350,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
configs->add(config); configs->add(config);
return true; return true;
} else { } else {
configs->add(std::make_shared<LexerATNConfig>(config.get(), config->state, PredictionContext::EMPTY)); configs->add(std::make_shared<LexerATNConfig>(config, config->state, PredictionContext::EMPTY));
currentAltReachedAcceptState = true; currentAltReachedAcceptState = true;
} }
} }
@ -360,7 +360,7 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
if (config->context->getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE) { if (config->context->getReturnState(i) != PredictionContext::EMPTY_RETURN_STATE) {
std::weak_ptr<PredictionContext> newContext = config->context->getParent(i); // "pop" return state std::weak_ptr<PredictionContext> newContext = config->context->getParent(i); // "pop" return state
ATNState *returnState = atn.states[(size_t)config->context->getReturnState(i)]; ATNState *returnState = atn.states[(size_t)config->context->getReturnState(i)];
Ref<LexerATNConfig> c = std::make_shared<LexerATNConfig>(config.get(), returnState, newContext.lock()); Ref<LexerATNConfig> c = std::make_shared<LexerATNConfig>(config, returnState, newContext.lock());
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon); 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; ATNState *p = config->state;
for (size_t i = 0; i < p->getNumberOfTransitions(); i++) { for (size_t i = 0; i < p->getNumberOfTransitions(); i++) {
Transition *t = p->transition(i); Transition *t = p->transition(i);
Ref<LexerATNConfig> c = getEpsilonTarget(input, config.get(), t, configs, speculative, treatEofAsEpsilon); Ref<LexerATNConfig> c = getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon);
if (c != nullptr) { if (c != nullptr) {
currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon); currentAltReachedAcceptState = closure(input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon);
} }
@ -388,14 +388,16 @@ bool LexerATNSimulator::closure(CharStream *input, const Ref<LexerATNConfig> &co
return currentAltReachedAcceptState; return currentAltReachedAcceptState;
} }
Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, LexerATNConfig *config, Transition *t, Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, Transition *t,
ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon) { ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon) {
Ref<LexerATNConfig> c = nullptr;
switch (t->getSerializationType()) { switch (t->getSerializationType()) {
case Transition::RULE: { case Transition::RULE: {
RuleTransition *ruleTransition = static_cast<RuleTransition*>(t); RuleTransition *ruleTransition = static_cast<RuleTransition*>(t);
Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, ruleTransition->followState->stateNumber); Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, ruleTransition->followState->stateNumber);
return std::make_shared<LexerATNConfig>(config, t->target, newContext); c = std::make_shared<LexerATNConfig>(config, t->target, newContext);
break;
} }
case Transition::PRECEDENCE: case Transition::PRECEDENCE:
@ -421,9 +423,12 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, Lexer
test them, we cannot cash the DFA state target of ID. test them, we cannot cash the DFA state target of ID.
*/ */
PredicateTransition *pt = static_cast<PredicateTransition*>(t); PredicateTransition *pt = static_cast<PredicateTransition*>(t);
if (debug) {
std::cout << "EVAL rule " << pt->ruleIndex << ":" << pt->predIndex << std::endl;
}
configs->hasSemanticContext = true; configs->hasSemanticContext = true;
if (evaluatePredicate(input, pt->ruleIndex, pt->predIndex, speculative)) { if (evaluatePredicate(input, pt->ruleIndex, pt->predIndex, speculative)) {
return std::make_shared<LexerATNConfig>(config, t->target); c = std::make_shared<LexerATNConfig>(config, t->target);
} }
break; break;
} }
@ -444,28 +449,33 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, Lexer
// the split operation. // the split operation.
Ref<LexerActionExecutor> lexerActionExecutor = LexerActionExecutor::append(config->getLexerActionExecutor(), Ref<LexerActionExecutor> lexerActionExecutor = LexerActionExecutor::append(config->getLexerActionExecutor(),
atn.lexerActions[static_cast<ActionTransition *>(t)->actionIndex]); atn.lexerActions[static_cast<ActionTransition *>(t)->actionIndex]);
return std::make_shared<LexerATNConfig>(config, t->target, lexerActionExecutor); c = std::make_shared<LexerATNConfig>(config, t->target, lexerActionExecutor);
} else { break;
}
else {
// ignore actions in referenced rules // ignore actions in referenced rules
return std::make_shared<LexerATNConfig>(config, t->target); c = std::make_shared<LexerATNConfig>(config, t->target);
break;
} }
case Transition::EPSILON: case Transition::EPSILON:
return std::make_shared<LexerATNConfig>(config, t->target); c = std::make_shared<LexerATNConfig>(config, t->target);
break;
case Transition::ATOM: case Transition::ATOM:
case Transition::RANGE: case Transition::RANGE:
case Transition::SET: case Transition::SET:
if (treatEofAsEpsilon) { if (treatEofAsEpsilon) {
if (t->matches(Token::EOF, Lexer::MIN_CHAR_VALUE, Lexer::MAX_CHAR_VALUE)) { if (t->matches(Token::EOF, Lexer::MIN_CHAR_VALUE, Lexer::MAX_CHAR_VALUE)) {
return std::make_shared<LexerATNConfig>(config, t->target); c = std::make_shared<LexerATNConfig>(config, t->target);
break;
} }
} }
break; break;
} }
return nullptr; return c;
} }
bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int predIndex, bool speculative) { bool LexerATNSimulator::evaluatePredicate(CharStream *input, int ruleIndex, int predIndex, bool speculative) {

View File

@ -187,7 +187,7 @@ namespace atn {
bool currentAltReachedAcceptState, bool speculative, bool treatEofAsEpsilon); bool currentAltReachedAcceptState, bool speculative, bool treatEofAsEpsilon);
// side-effect: can alter configs.hasSemanticContext // side-effect: can alter configs.hasSemanticContext
virtual Ref<LexerATNConfig> getEpsilonTarget(CharStream *input, LexerATNConfig *config, Transition *t, virtual Ref<LexerATNConfig> getEpsilonTarget(CharStream *input, const Ref<LexerATNConfig> &config, Transition *t,
ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon); ATNConfigSet *configs, bool speculative, bool treatEofAsEpsilon);
/// <summary> /// <summary>

View File

@ -471,7 +471,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
Transition *trans = c->state->transition(ti); Transition *trans = c->state->transition(ti);
ATNState *target = getReachableTarget(trans, (int)t); ATNState *target = getReachableTarget(trans, (int)t);
if (target != nullptr) { if (target != nullptr) {
intermediate->add(std::make_shared<ATNConfig>(c.get(), target), &mergeCache); intermediate->add(std::make_shared<ATNConfig>(c, target), &mergeCache);
} }
} }
} }
@ -510,7 +510,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::computeReachSet(ATNConfigSet *
ATNConfig::Set closureBusy; ATNConfig::Set closureBusy;
bool treatEofAsEpsilon = t == Token::EOF; bool treatEofAsEpsilon = t == Token::EOF;
for (auto &c : intermediate->configs) { for (auto c : intermediate->configs) {
closure(c, reach.get(), closureBusy, false, fullCtx, treatEofAsEpsilon); closure(c, reach.get(), closureBusy, false, fullCtx, treatEofAsEpsilon);
} }
} }
@ -578,7 +578,7 @@ ATNConfigSet* ParserATNSimulator::removeAllConfigsNotInRuleStopState(ATNConfigSe
misc::IntervalSet nextTokens = atn.nextTokens(config->state); misc::IntervalSet nextTokens = atn.nextTokens(config->state);
if (nextTokens.contains(Token::EPSILON)) { if (nextTokens.contains(Token::EPSILON)) {
ATNState *endOfRuleState = atn.ruleToStopState[(size_t)config->state->ruleIndex]; ATNState *endOfRuleState = atn.ruleToStopState[(size_t)config->state->ruleIndex];
result->add(std::make_shared<ATNConfig>(config.get(), endOfRuleState), &mergeCache); result->add(std::make_shared<ATNConfig>(config, endOfRuleState), &mergeCache);
} }
} }
} }
@ -618,7 +618,7 @@ std::unique_ptr<ATNConfigSet> ParserATNSimulator::applyPrecedenceFilter(ATNConfi
statesFromAlt1[config->state->stateNumber] = config->context; statesFromAlt1[config->state->stateNumber] = config->context;
if (updatedContext != config->semanticContext) { if (updatedContext != config->semanticContext) {
configSet->add(std::make_shared<ATNConfig>(config.get(), updatedContext), &mergeCache); configSet->add(std::make_shared<ATNConfig>(config, updatedContext), &mergeCache);
} }
else { else {
configSet->add(config, &mergeCache); 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++) { for (size_t i = 0; i < config->context->size(); i++) {
if (config->context->getReturnState(i) == PredictionContext::EMPTY_RETURN_STATE) { if (config->context->getReturnState(i) == PredictionContext::EMPTY_RETURN_STATE) {
if (fullCtx) { if (fullCtx) {
configs->add(std::make_shared<ATNConfig>(config.get(), config->state, PredictionContext::EMPTY), &mergeCache); configs->add(std::make_shared<ATNConfig>(config, config->state, PredictionContext::EMPTY), &mergeCache);
continue; continue;
} else { } else {
// we have no context info, just chase follow links (if greedy) // 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)); return actionTransition(config, static_cast<ActionTransition*>(t));
case Transition::EPSILON: case Transition::EPSILON:
return std::make_shared<ATNConfig>(config.get(), t->target); return std::make_shared<ATNConfig>(config, t->target);
case Transition::ATOM: case Transition::ATOM:
case Transition::RANGE: case Transition::RANGE:
@ -975,7 +975,7 @@ Ref<ATNConfig> ParserATNSimulator::getEpsilonTarget(Ref<ATNConfig> const& config
// transition is traversed // transition is traversed
if (treatEofAsEpsilon) { if (treatEofAsEpsilon) {
if (t->matches(Token::EOF, 0, 1)) { if (t->matches(Token::EOF, 0, 1)) {
return std::make_shared<ATNConfig>(config.get(), t->target); return std::make_shared<ATNConfig>(config, t->target);
} }
} }
@ -990,7 +990,7 @@ Ref<ATNConfig> ParserATNSimulator::actionTransition(Ref<ATNConfig> const& config
if (debug) { if (debug) {
std::cout << "ACTION edge " << t->ruleIndex << ":" << t->actionIndex << std::endl; std::cout << "ACTION edge " << t->ruleIndex << ":" << t->actionIndex << std::endl;
} }
return std::make_shared<ATNConfig>(config.get(), t->target); return std::make_shared<ATNConfig>(config, t->target);
} }
Ref<ATNConfig> ParserATNSimulator::precedenceTransition(Ref<ATNConfig> const& config, PrecedencePredicateTransition *pt, 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); bool predSucceeds = evalSemanticContext(pt->getPredicate(), _outerContext, config->alt, fullCtx);
_input->seek(currentPosition); _input->seek(currentPosition);
if (predSucceeds) { if (predSucceeds) {
c = std::make_shared<ATNConfig>(config.get(), pt->target); // no pred context c = std::make_shared<ATNConfig>(config, pt->target); // no pred context
} }
} else { } else {
Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate); Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
c = std::make_shared<ATNConfig>(config.get(), pt->target, newSemCtx); c = std::make_shared<ATNConfig>(config, pt->target, newSemCtx);
} }
} else { } else {
c = std::make_shared<ATNConfig>(config.get(), pt->target); c = std::make_shared<ATNConfig>(config, pt->target);
} }
if (debug) { if (debug) {
@ -1054,14 +1054,14 @@ Ref<ATNConfig> ParserATNSimulator::predTransition(Ref<ATNConfig> const& config,
bool predSucceeds = evalSemanticContext(pt->getPredicate(), _outerContext, config->alt, fullCtx); bool predSucceeds = evalSemanticContext(pt->getPredicate(), _outerContext, config->alt, fullCtx);
_input->seek(currentPosition); _input->seek(currentPosition);
if (predSucceeds) { if (predSucceeds) {
c = std::make_shared<ATNConfig>(config.get(), pt->target); // no pred context c = std::make_shared<ATNConfig>(config, pt->target); // no pred context
} }
} else { } else {
Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate); Ref<SemanticContext> newSemCtx = SemanticContext::And(config->semanticContext, predicate);
c = std::make_shared<ATNConfig>(config.get(), pt->target, newSemCtx); c = std::make_shared<ATNConfig>(config, pt->target, newSemCtx);
} }
} else { } else {
c = std::make_shared<ATNConfig>(config.get(), pt->target); c = std::make_shared<ATNConfig>(config, pt->target);
} }
if (debug) { if (debug) {
@ -1077,7 +1077,7 @@ Ref<ATNConfig> ParserATNSimulator::ruleTransition(Ref<ATNConfig> const& config,
atn::ATNState *returnState = t->followState; atn::ATNState *returnState = t->followState;
Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, returnState->stateNumber); Ref<PredictionContext> newContext = SingletonPredictionContext::create(config->context, returnState->stateNumber);
return std::make_shared<ATNConfig>(config.get(), t->target, newContext); return std::make_shared<ATNConfig>(config, t->target, newContext);
} }
BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) { BitSet ParserATNSimulator::getConflictingAlts(ATNConfigSet *configs) {

View File

@ -714,17 +714,17 @@ namespace atn {
virtual std::string getRuleName(size_t index); virtual std::string getRuleName(size_t index);
protected: protected:
virtual Ref<ATNConfig> getEpsilonTarget(Ref<ATNConfig> const& config, Transition *t, virtual Ref<ATNConfig> getEpsilonTarget(Ref<ATNConfig> const& config, Transition *t, bool collectPredicates,
bool collectPredicates, bool inContext, bool fullCtx, bool treatEofAsEpsilon); bool inContext, bool fullCtx, bool treatEofAsEpsilon);
virtual Ref<ATNConfig> actionTransition(Ref<ATNConfig> const& config, ActionTransition *t); virtual Ref<ATNConfig> actionTransition(Ref<ATNConfig> const& config, ActionTransition *t);
public: public:
virtual Ref<ATNConfig> precedenceTransition(Ref<ATNConfig> const& config, virtual Ref<ATNConfig> precedenceTransition(Ref<ATNConfig> const& config, PrecedencePredicateTransition *pt,
PrecedencePredicateTransition *pt, bool collectPredicates, bool inContext, bool fullCtx); bool collectPredicates, bool inContext, bool fullCtx);
protected: protected:
virtual Ref<ATNConfig> predTransition(Ref<ATNConfig> const& config, PredicateTransition *pt, virtual Ref<ATNConfig> predTransition(Ref<ATNConfig> const& config, PredicateTransition *pt, bool collectPredicates,
bool collectPredicates, bool inContext, bool fullCtx); bool inContext, bool fullCtx);
virtual Ref<ATNConfig> ruleTransition(Ref<ATNConfig> const& config, RuleTransition *t); virtual Ref<ATNConfig> ruleTransition(Ref<ATNConfig> const& config, RuleTransition *t);

View File

@ -88,7 +88,7 @@ bool PredictionModeClass::hasSLLConflictTerminatingPrediction(PredictionMode mod
// dup configs, tossing out semantic predicates // dup configs, tossing out semantic predicates
ATNConfigSet dup(true); ATNConfigSet dup(true);
for (auto &config : configs->configs) { for (auto &config : configs->configs) {
Ref<ATNConfig> c = std::make_shared<ATNConfig>(config.get(), SemanticContext::NONE); Ref<ATNConfig> c = std::make_shared<ATNConfig>(config, SemanticContext::NONE);
dup.add(c); dup.add(c);
} }
std::vector<antlrcpp::BitSet> altsets = getConflictingAltSubsets(&dup); 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::vector<antlrcpp::BitSet> PredictionModeClass::getConflictingAltSubsets(ATNConfigSet *configs) {
std::unordered_map<ATNConfig *, antlrcpp::BitSet, AltAndContextConfigHasher, AltAndContextConfigComparer> configToAlts; std::unordered_map<Ref<ATNConfig>, antlrcpp::BitSet, AltAndContextConfigHasher, AltAndContextConfigComparer> configToAlts;
for (auto &config : configs->configs) { for (auto &config : configs->configs) {
configToAlts[config.get()].set(config->alt); configToAlts[config].set(config->alt);
} }
std::vector<antlrcpp::BitSet> values; std::vector<antlrcpp::BitSet> values;
for (auto it : configToAlts) { for (auto it : configToAlts) {