diff options
author | Kaelyn Uhrain <rikka@google.com> | 2012-06-06 20:54:51 +0000 |
---|---|---|
committer | Kaelyn Uhrain <rikka@google.com> | 2012-06-06 20:54:51 +0000 |
commit | 8d3607bf22a6a70acce3722a758f02d4ea84fc3a (patch) | |
tree | c9471cc39172eac5648699c3ce71d8d4512cdfb9 /lib/Sema/SemaLookup.cpp | |
parent | 36397dc6c1bf1513a3bac4eabe9209e5b2295a55 (diff) |
Allow CorrectTypo to add/modify nested name qualifiers to typos that
are otherwise too short to try to correct.
The TODOs added to two of the tests are for existing deficiencies in the
typo correction code that could be exposed by using longer identifiers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158109 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 1ee594c2a3..91d76de172 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3795,6 +3795,9 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, bool SearchNamespaces = getLangOpts().CPlusPlus && (IsUnqualifiedLookup || (QualifiedDC && QualifiedDC->isNamespace())); + // In a few cases we *only* want to search for corrections bases on just + // adding or changing the nested name specifier. + bool AllowOnlyNNSChanges = Typo->getName().size() < 3; if (IsUnqualifiedLookup || SearchNamespaces) { // For unqualified lookup, look through all of the names that we have @@ -3831,8 +3834,8 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, return TypoCorrection(); } - // Make sure that the user typed at least 3 characters for each correction - // made. Otherwise, we don't even both looking at the results. + // Make sure the best edit distance (prior to adding any namespace qualifiers) + // is not more that about a third of the length of the typo's identifier. unsigned ED = Consumer.getBestEditDistance(true); if (ED > 0 && Typo->getName().size() / ED < 3) { // If this was an unqualified lookup, note that no correction was found. @@ -3872,6 +3875,16 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, for (TypoCorrectionConsumer::result_iterator I = DI->second.begin(), IEnd = DI->second.end(); I != IEnd; /* Increment in loop. */) { + // If we only want nested name specifier corrections, ignore potential + // corrections that have a different base identifier from the typo. + if (AllowOnlyNNSChanges && + I->second.front().getCorrectionAsIdentifierInfo() != Typo) { + TypoCorrectionConsumer::result_iterator Prev = I; + ++I; + DI->second.erase(Prev); + continue; + } + // If the item already has been looked up or is a keyword, keep it. // If a validator callback object was given, drop the correction // unless it passes validation. @@ -4013,7 +4026,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, TypoResultsMap &BestResults = Consumer.getBestResults(); ED = Consumer.getBestEditDistance(true); - if (ED > 0 && Typo->getName().size() / ED < 3) { + if (!AllowOnlyNNSChanges && ED > 0 && Typo->getName().size() / ED < 3) { // If this was an unqualified lookup and we believe the callback // object wouldn't have filtered out possible corrections, note // that no correction was found. |