diff options
author | dim <dim@FreeBSD.org> | 2015-01-18 16:23:48 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-01-18 16:23:48 +0000 |
commit | c86b984ea8ecb3e944dc3de48539f4c1f65851ea (patch) | |
tree | 3eb853da77d46cc77c4b017525a422f9ddb1385b /include/clang/Sema/TypoCorrection.h | |
parent | c696171ff15f0ee60dea4abfd99a135473c95656 (diff) | |
download | FreeBSD-src-c86b984ea8ecb3e944dc3de48539f4c1f65851ea.zip FreeBSD-src-c86b984ea8ecb3e944dc3de48539f4c1f65851ea.tar.gz |
Vendor import of clang RELEASE_360/rc1 tag r226102 (effectively, 3.6.0 RC1):
https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_360/rc1@226102
Diffstat (limited to 'include/clang/Sema/TypoCorrection.h')
-rw-r--r-- | include/clang/Sema/TypoCorrection.h | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/include/clang/Sema/TypoCorrection.h b/include/clang/Sema/TypoCorrection.h index 6cab59c..922d0ff 100644 --- a/include/clang/Sema/TypoCorrection.h +++ b/include/clang/Sema/TypoCorrection.h @@ -17,6 +17,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/Sema/DeclSpec.h" +#include "clang/Sema/Ownership.h" #include "llvm/ADT/SmallVector.h" namespace clang { @@ -198,10 +199,9 @@ public: void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName) { - CorrectionRange.setBegin(ForceSpecifierReplacement && SS && !SS->isEmpty() - ? SS->getBeginLoc() - : TypoName.getLoc()); - CorrectionRange.setEnd(TypoName.getLoc()); + CorrectionRange = TypoName.getSourceRange(); + if (ForceSpecifierReplacement && SS && !SS->isEmpty()) + CorrectionRange.setBegin(SS->getBeginLoc()); } SourceRange getCorrectionRange() const { @@ -247,11 +247,13 @@ class CorrectionCandidateCallback { public: static const unsigned InvalidDistance = TypoCorrection::InvalidDistance; - CorrectionCandidateCallback() + explicit CorrectionCandidateCallback(IdentifierInfo *Typo = nullptr, + NestedNameSpecifier *TypoNNS = nullptr) : WantTypeSpecifiers(true), WantExpressionKeywords(true), - WantCXXNamedCasts(true), WantRemainingKeywords(true), - WantObjCSuper(false), IsObjCIvarLookup(false), - IsAddressOfOperand(false) {} + WantCXXNamedCasts(true), WantFunctionLikeCasts(true), + WantRemainingKeywords(true), WantObjCSuper(false), + IsObjCIvarLookup(false), IsAddressOfOperand(false), Typo(Typo), + TypoNNS(TypoNNS) {} virtual ~CorrectionCandidateCallback() {} @@ -274,20 +276,39 @@ public: /// the default RankCandidate returns either 0 or InvalidDistance depending /// whether ValidateCandidate returns true or false. virtual unsigned RankCandidate(const TypoCorrection &candidate) { - return ValidateCandidate(candidate) ? 0 : InvalidDistance; + return (!MatchesTypo(candidate) && ValidateCandidate(candidate)) + ? 0 + : InvalidDistance; } - // Flags for context-dependent keywords. + void setTypoName(IdentifierInfo *II) { Typo = II; } + void setTypoNNS(NestedNameSpecifier *NNS) { TypoNNS = NNS; } + + // Flags for context-dependent keywords. WantFunctionLikeCasts is only + // used/meaningful when WantCXXNamedCasts is false. // TODO: Expand these to apply to non-keywords or possibly remove them. bool WantTypeSpecifiers; bool WantExpressionKeywords; bool WantCXXNamedCasts; + bool WantFunctionLikeCasts; bool WantRemainingKeywords; bool WantObjCSuper; // Temporary hack for the one case where a CorrectTypoContext enum is used // when looking up results. bool IsObjCIvarLookup; bool IsAddressOfOperand; + +protected: + bool MatchesTypo(const TypoCorrection &candidate) { + return Typo && candidate.isResolved() && !candidate.requiresImport() && + candidate.getCorrectionAsIdentifierInfo() == Typo && + // FIXME: This probably does not return true when both + // NestedNameSpecifiers have the same textual representation. + candidate.getCorrectionSpecifier() == TypoNNS; + } + + IdentifierInfo *Typo; + NestedNameSpecifier *TypoNNS; }; /// @brief Simple template class for restricting typo correction candidates @@ -325,6 +346,7 @@ public: WantTypeSpecifiers = false; WantExpressionKeywords = false; WantCXXNamedCasts = false; + WantFunctionLikeCasts = false; WantRemainingKeywords = false; } |