[cfe-commits] r157781 - /cfe/trunk/lib/Sema/SemaLookup.cpp
Kaelyn Uhrain
rikka at google.com
Thu May 31 16:32:58 PDT 2012
Author: rikka
Date: Thu May 31 18:32:58 2012
New Revision: 157781
URL: http://llvm.org/viewvc/llvm-project?rev=157781&view=rev
Log:
In TypoCorrectionConsumer, BestResults to CorrectionResults to lessen
the confusion among all of the uses of Best* in relation to the set of
possible typo correction results. Also add a method to return the set of
typo corrections that have the single best edit distance--it returns the
second half of the first pair in TypoEditDistanceMap (with
getBestEditDistance already returning the first half).
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=157781&r1=157780&r2=157781&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Thu May 31 18:32:58 2012
@@ -3161,7 +3161,7 @@
///
/// The pointer value being set to the current DeclContext indicates
/// whether there is a keyword with this name.
- TypoEditDistanceMap BestResults;
+ TypoEditDistanceMap CorrectionResults;
Sema &SemaRef;
@@ -3180,23 +3180,28 @@
typedef TypoResultsMap::iterator result_iterator;
typedef TypoEditDistanceMap::iterator distance_iterator;
- distance_iterator begin() { return BestResults.begin(); }
- distance_iterator end() { return BestResults.end(); }
- void erase(distance_iterator I) { BestResults.erase(I); }
- unsigned size() const { return BestResults.size(); }
- bool empty() const { return BestResults.empty(); }
+ distance_iterator begin() { return CorrectionResults.begin(); }
+ distance_iterator end() { return CorrectionResults.end(); }
+ void erase(distance_iterator I) { CorrectionResults.erase(I); }
+ unsigned size() const { return CorrectionResults.size(); }
+ bool empty() const { return CorrectionResults.empty(); }
TypoCorrection &operator[](StringRef Name) {
- return BestResults.begin()->second[Name];
+ return CorrectionResults.begin()->second[Name];
}
unsigned getBestEditDistance(bool Normalized) {
- if (BestResults.empty())
+ if (CorrectionResults.empty())
return (std::numeric_limits<unsigned>::max)();
- unsigned BestED = BestResults.begin()->first;
+ unsigned BestED = CorrectionResults.begin()->first;
return Normalized ? TypoCorrection::NormalizeEditDistance(BestED) : BestED;
}
+
+ TypoResultsMap &getBestResults() {
+ return CorrectionResults.begin()->second;
+ }
+
};
}
@@ -3251,7 +3256,7 @@
void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) {
StringRef Name = Correction.getCorrectionAsIdentifierInfo()->getName();
- TypoResultsMap &Map = BestResults[Correction.getEditDistance(false)];
+ TypoResultsMap &Map = CorrectionResults[Correction.getEditDistance(false)];
TypoCorrection &CurrentCorrection = Map[Name];
if (!CurrentCorrection ||
@@ -3262,8 +3267,8 @@
CurrentCorrection.getAsString(SemaRef.getLangOpts()))
CurrentCorrection = Correction;
- while (BestResults.size() > MaxTypoDistanceResultSets)
- erase(llvm::prior(BestResults.end()));
+ while (CorrectionResults.size() > MaxTypoDistanceResultSets)
+ erase(llvm::prior(CorrectionResults.end()));
}
// Fill the supplied vector with the IdentifierInfo pointers for each piece of
@@ -3978,8 +3983,8 @@
// No corrections remain...
if (Consumer.empty()) return TypoCorrection();
- TypoResultsMap &BestResults = Consumer.begin()->second;
- ED = TypoCorrection::NormalizeEditDistance(Consumer.begin()->first);
+ TypoResultsMap &BestResults = Consumer.getBestResults();
+ ED = Consumer.getBestEditDistance(true);
if (ED > 0 && Typo->getName().size() / ED < 3) {
// If this was an unqualified lookup and we believe the callback
More information about the cfe-commits
mailing list