Merge pull request #2176 from niccroad/atnsimulator_memleak
This resolves the recently opened issue 2175 (a memory leak).
This commit is contained in:
commit
ce3b5a4cb4
|
@ -698,27 +698,22 @@ std::vector<Ref<SemanticContext>> ParserATNSimulator::getPredsForAmbigAlts(const
|
|||
}
|
||||
|
||||
std::vector<dfa::DFAState::PredPrediction *> ParserATNSimulator::getPredicatePredictions(const antlrcpp::BitSet &ambigAlts,
|
||||
std::vector<Ref<SemanticContext>> altToPred) {
|
||||
std::vector<dfa::DFAState::PredPrediction*> pairs;
|
||||
bool containsPredicate = false;
|
||||
for (size_t i = 1; i < altToPred.size(); i++) {
|
||||
Ref<SemanticContext> pred = altToPred[i];
|
||||
std::vector<Ref<SemanticContext>> const& altToPred) {
|
||||
bool containsPredicate = std::find_if(altToPred.begin(), altToPred.end(), [](Ref<SemanticContext> const context) {
|
||||
return context != SemanticContext::NONE;
|
||||
}) != altToPred.end();
|
||||
if (!containsPredicate)
|
||||
return {};
|
||||
|
||||
// unpredicted is indicated by SemanticContext.NONE
|
||||
assert(pred != nullptr);
|
||||
std::vector<dfa::DFAState::PredPrediction*> pairs;
|
||||
for (size_t i = 1; i < altToPred.size(); ++i) {
|
||||
Ref<SemanticContext> const& pred = altToPred[i];
|
||||
assert(pred != nullptr); // unpredicted is indicated by SemanticContext.NONE
|
||||
|
||||
if (ambigAlts.test(i)) {
|
||||
pairs.push_back(new dfa::DFAState::PredPrediction(pred, (int)i)); /* mem-check: managed by the DFAState it will be assigned to after return */
|
||||
}
|
||||
if (pred != SemanticContext::NONE) {
|
||||
containsPredicate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!containsPredicate) {
|
||||
pairs.clear();
|
||||
}
|
||||
|
||||
return pairs;
|
||||
}
|
||||
|
||||
|
|
|
@ -652,7 +652,7 @@ namespace atn {
|
|||
ATNConfigSet *configs, size_t nalts);
|
||||
|
||||
virtual std::vector<dfa::DFAState::PredPrediction*> getPredicatePredictions(const antlrcpp::BitSet &ambigAlts,
|
||||
std::vector<Ref<SemanticContext>> altToPred);
|
||||
std::vector<Ref<SemanticContext>> const& altToPred);
|
||||
|
||||
/**
|
||||
* This method is used to improve the localization of error messages by
|
||||
|
|
Loading…
Reference in New Issue