diff options
author | dim <dim@FreeBSD.org> | 2012-05-03 16:53:59 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-05-03 16:53:59 +0000 |
commit | 822bde9df508e0b9afac5e581b0d6ab403417a28 (patch) | |
tree | 2e51705e103e92c7be1b21e8bd8ffd5b5d0e4d52 /lib/Sema/SemaLookup.cpp | |
parent | 50b73317314e889cf39c7b1d6cbf419fa7502f22 (diff) | |
download | FreeBSD-src-822bde9df508e0b9afac5e581b0d6ab403417a28.zip FreeBSD-src-822bde9df508e0b9afac5e581b0d6ab403417a28.tar.gz |
Vendor import of clang release_31 branch r155985:
http://llvm.org/svn/llvm-project/cfe/branches/release_31@155985
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 966eb90..f003bdd 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3165,7 +3165,7 @@ LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc, namespace { typedef llvm::StringMap<TypoCorrection, llvm::BumpPtrAllocator> TypoResultsMap; -typedef std::map<unsigned, TypoResultsMap *> TypoEditDistanceMap; +typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap; static const unsigned MaxTypoDistanceResultSets = 5; @@ -3187,14 +3187,6 @@ public: : Typo(Typo->getName()), SemaRef(SemaRef) { } - ~TypoCorrectionConsumer() { - for (TypoEditDistanceMap::iterator I = BestResults.begin(), - IEnd = BestResults.end(); - I != IEnd; - ++I) - delete I->second; - } - virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass); void FoundName(StringRef Name); @@ -3212,7 +3204,7 @@ public: bool empty() const { return BestResults.empty(); } TypoCorrection &operator[](StringRef Name) { - return (*BestResults.begin()->second)[Name]; + return BestResults.begin()->second[Name]; } unsigned getBestEditDistance(bool Normalized) { @@ -3276,11 +3268,9 @@ void TypoCorrectionConsumer::addName(StringRef Name, void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) { StringRef Name = Correction.getCorrectionAsIdentifierInfo()->getName(); - TypoResultsMap *& Map = BestResults[Correction.getEditDistance(false)]; - if (!Map) - Map = new TypoResultsMap; + TypoResultsMap &Map = BestResults[Correction.getEditDistance(false)]; - TypoCorrection &CurrentCorrection = (*Map)[Name]; + TypoCorrection &CurrentCorrection = Map[Name]; if (!CurrentCorrection || // FIXME: The following should be rolled up into an operator< on // TypoCorrection with a more principled definition. @@ -3289,12 +3279,8 @@ void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) { CurrentCorrection.getAsString(SemaRef.getLangOpts())) CurrentCorrection = Correction; - while (BestResults.size() > MaxTypoDistanceResultSets) { - TypoEditDistanceMap::iterator Last = BestResults.end(); - --Last; - delete Last->second; - BestResults.erase(Last); - } + while (BestResults.size() > MaxTypoDistanceResultSets) + erase(llvm::prior(BestResults.end())); } // Fill the supplied vector with the IdentifierInfo pointers for each piece of @@ -3882,8 +3868,8 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, while (!Consumer.empty()) { TypoCorrectionConsumer::distance_iterator DI = Consumer.begin(); unsigned ED = DI->first; - for (TypoCorrectionConsumer::result_iterator I = DI->second->begin(), - IEnd = DI->second->end(); + for (TypoCorrectionConsumer::result_iterator I = DI->second.begin(), + IEnd = DI->second.end(); I != IEnd; /* Increment in loop. */) { // If the item already has been looked up or is a keyword, keep it. // If a validator callback object was given, drop the correction @@ -3892,7 +3878,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, TypoCorrectionConsumer::result_iterator Prev = I; ++I; if (!isCandidateViable(CCC, Prev->second)) - DI->second->erase(Prev); + DI->second.erase(Prev); continue; } @@ -3911,7 +3897,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, { TypoCorrectionConsumer::result_iterator Next = I; ++Next; - DI->second->erase(I); + DI->second.erase(I); I = Next; } break; @@ -3929,7 +3915,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, I->second.addCorrectionDecl(*TRD); ++I; if (!isCandidateViable(CCC, Prev->second)) - DI->second->erase(Prev); + DI->second.erase(Prev); break; } @@ -3938,14 +3924,14 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, I->second.setCorrectionDecl(TmpRes.getAsSingle<NamedDecl>()); ++I; if (!isCandidateViable(CCC, Prev->second)) - DI->second->erase(Prev); + DI->second.erase(Prev); break; } } } - if (DI->second->empty()) + if (DI->second.empty()) Consumer.erase(DI); else if (!getLangOpts().CPlusPlus || QualifiedResults.empty() || !ED) // If there are results in the closest possible bucket, stop @@ -4009,7 +3995,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, // No corrections remain... if (Consumer.empty()) return TypoCorrection(); - TypoResultsMap &BestResults = *Consumer.begin()->second; + TypoResultsMap &BestResults = Consumer.begin()->second; ED = TypoCorrection::NormalizeEditDistance(Consumer.begin()->first); if (ED > 0 && Typo->getName().size() / ED < 3) { @@ -4083,7 +4069,8 @@ std::string TypoCorrection::getAsString(const LangOptions &LO) const { std::string tmpBuffer; llvm::raw_string_ostream PrefixOStream(tmpBuffer); CorrectionNameSpec->print(PrefixOStream, PrintingPolicy(LO)); - return PrefixOStream.str() + CorrectionName.getAsString(); + CorrectionName.printName(PrefixOStream); + return PrefixOStream.str(); } return CorrectionName.getAsString(); |