aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaLookup.cpp
diff options
context:
space:
mode:
authorKaelyn Uhrain <rikka@google.com>2012-05-31 23:32:58 +0000
committerKaelyn Uhrain <rikka@google.com>2012-05-31 23:32:58 +0000
commit396e0a8cfa3fbdd5fde83a19cc87b7af62cc1ddd (patch)
tree0e0d6f98f7cdc0080a5572b693f66ce913804e74 /lib/Sema/SemaLookup.cpp
parent3427682d365174f5d69d55e2c6deef49ace0668b (diff)
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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157781 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r--lib/Sema/SemaLookup.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 78a9905155..fb7e463ad9 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -3161,7 +3161,7 @@ class TypoCorrectionConsumer : public VisibleDeclConsumer {
///
/// 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 @@ public:
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::addName(StringRef Name,
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 @@ void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) {
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 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName,
// 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