Merge pull request #2176 from niccroad/atnsimulator_memleak

This resolves the recently opened issue 2175 (a memory leak).
This commit is contained in:
Terence Parr 2018-12-21 12:00:36 -07:00 committed by GitHub
commit ce3b5a4cb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -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;
}

View File

@ -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