15 #ifndef LLVM_CLANG_SEMA_TYPOCORRECTION_H 16 #define LLVM_CLANG_SEMA_TYPOCORRECTION_H 21 #include "llvm/ADT/SmallVector.h" 44 unsigned QualifierDistance = 0)
45 : CorrectionName(Name), CorrectionNameSpec(NNS),
46 CharDistance(CharDistance), QualifierDistance(QualifierDistance),
47 CallbackDistance(0), ForceSpecifierReplacement(
false),
48 RequiresImport(
false) {
50 CorrectionDecls.push_back(NameDecl);
54 unsigned CharDistance = 0)
55 : CorrectionName(Name->getDeclName()), CorrectionNameSpec(NNS),
56 CharDistance(CharDistance), QualifierDistance(0), CallbackDistance(0),
57 ForceSpecifierReplacement(
false), RequiresImport(
false) {
59 CorrectionDecls.push_back(Name);
63 unsigned CharDistance = 0)
64 : CorrectionName(Name), CorrectionNameSpec(NNS),
65 CharDistance(CharDistance), QualifierDistance(0), CallbackDistance(0),
66 ForceSpecifierReplacement(
false), RequiresImport(
false) {}
69 : CorrectionNameSpec(nullptr), CharDistance(0), QualifierDistance(0),
70 CallbackDistance(0), ForceSpecifierReplacement(
false),
71 RequiresImport(
false) {}
81 return CorrectionNameSpec;
84 CorrectionNameSpec = NNS;
85 ForceSpecifierReplacement = (NNS !=
nullptr);
89 ForceSpecifierReplacement = ForceReplacement;
93 return ForceSpecifierReplacement;
97 QualifierDistance = ED;
101 CallbackDistance = ED;
108 if (ED > MaximumDistance)
117 if (CharDistance > MaximumDistance || QualifierDistance > MaximumDistance ||
118 CallbackDistance > MaximumDistance)
121 CharDistance * CharDistanceWeight +
122 QualifierDistance * QualifierDistanceWeight +
124 if (ED > MaximumDistance)
135 return hasCorrectionDecl() ? *(CorrectionDecls.begin()) :
nullptr;
141 return D ? D->getUnderlyingDecl() :
nullptr;
143 template <
class DeclClass>
150 CorrectionDecls.clear();
155 CorrectionDecls.clear();
161 CorrectionDecls.clear();
162 CorrectionDecls.insert(CorrectionDecls.begin(), Decls.begin(), Decls.end());
175 explicit operator bool()
const {
return bool(CorrectionName); }
182 CorrectionDecls.clear();
183 CorrectionDecls.push_back(
nullptr);
184 ForceSpecifierReplacement =
true;
190 return !CorrectionDecls.empty() && CorrectionDecls.front() ==
nullptr;
194 template<std::
size_t StrLen>
203 return CorrectionDecls.size() > 1;
209 if (ForceSpecifierReplacement && SS && !SS->
isEmpty())
214 return CorrectionRange;
219 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
221 decl_iterator
end() {
return CorrectionDecls.end(); }
224 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
226 const_decl_iterator
end()
const {
return CorrectionDecls.end(); }
236 ExtraDiagnostics.push_back(std::move(PD));
239 return ExtraDiagnostics;
243 bool hasCorrectionDecl()
const {
244 return (!
isKeyword() && !CorrectionDecls.empty());
251 unsigned CharDistance;
252 unsigned QualifierDistance;
253 unsigned CallbackDistance;
255 bool ForceSpecifierReplacement;
258 std::vector<PartialDiagnostic> ExtraDiagnostics;
269 : WantTypeSpecifiers(
true), WantExpressionKeywords(
true),
270 WantCXXNamedCasts(
true), WantFunctionLikeCasts(
true),
271 WantRemainingKeywords(
true), WantObjCSuper(
false),
272 IsObjCIvarLookup(
false), IsAddressOfOperand(
false), Typo(Typo),
296 return (!MatchesTypo(candidate) && ValidateCandidate(candidate))
347 bool HasExplicitTemplateArgs,
354 bool HasExplicitTemplateArgs;
363 WantTypeSpecifiers =
false;
364 WantExpressionKeywords =
false;
365 WantCXXNamedCasts =
false;
366 WantFunctionLikeCasts =
false;
367 WantRemainingKeywords =
false;
void setTypoName(IdentifierInfo *II)
SourceRange getCorrectionRange() const
Simple class containing the result of Sema::CorrectTypo.
virtual unsigned RankCandidate(const TypoCorrection &candidate)
Method used by Sema::CorrectTypo to assign an "edit distance" rank to a candidate (where a lower valu...
bool isEmpty() const
No scope specifier.
void makeKeyword()
Mark this TypoCorrection as being a keyword.
void setCorrectionSpecifier(NestedNameSpecifier *NNS)
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
DeclClass * getCorrectionDeclAs() const
bool isOverloaded() const
void setBegin(SourceLocation b)
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
bool WantExpressionKeywords
void setCorrectionDecl(NamedDecl *CDecl)
Clears the list of NamedDecls before adding the new one.
One of these records is kept for each identifier that is lexed.
TypoCorrection(NamedDecl *Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
std::string getQuoted(const LangOptions &LO) const
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
static const unsigned MaximumDistance
void addCorrectionDecl(NamedDecl *CDecl)
Add the given NamedDecl to the list of NamedDecls that are the declarations associated with the Decla...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool requiresImport() const
Returns whether this typo correction is correcting to a declaration that was declared in a module tha...
void setCallbackDistance(unsigned ED)
void setQualifierDistance(unsigned ED)
bool MatchesTypo(const TypoCorrection &candidate)
void setTypoNNS(NestedNameSpecifier *NNS)
static unsigned NormalizeEditDistance(unsigned ED)
Represents a C++ nested-name-specifier or a global scope specifier.
virtual ~CorrectionCandidateCallback()
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
static const unsigned InvalidDistance
SmallVectorImpl< NamedDecl * >::const_iterator const_decl_iterator
bool WantRemainingKeywords
Sema - This implements semantic analysis and AST building for C.
NamedDecl * getFoundDecl() const
Get the correction declaration found by name lookup (before we looked through using shadow declaratio...
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo.
std::string getAsString(const LangOptions &LO) const
void addExtraDiagnostic(PartialDiagnostic PD)
Extra diagnostics are printed after the first diagnostic for the typo.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void setRequiresImport(bool Req)
SourceLocation getBeginLoc() const
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
CorrectionCandidateCallback(IdentifierInfo *Typo=nullptr, NestedNameSpecifier *TypoNNS=nullptr)
static const unsigned CharDistanceWeight
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
TypoCorrection(const DeclarationName &Name, NamedDecl *NameDecl, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0, unsigned QualifierDistance=0)
const_decl_iterator end() const
static const unsigned QualifierDistanceWeight
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
DeclarationName - The name of a declaration.
bool isKeyword(const char(&Str)[StrLen]) const
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool WillReplaceSpecifier() const
IdentifierInfo * getCorrectionAsIdentifierInfo() const
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
void setCorrectionDecls(ArrayRef< NamedDecl *> Decls)
Clears the list of NamedDecls and adds the given set.
const_decl_iterator begin() const
void ClearCorrectionDecls()
Clears the list of NamedDecls.
void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName)
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
NestedNameSpecifier * TypoNNS
static const unsigned CallbackDistanceWeight
TypoCorrection(DeclarationName Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
void WillReplaceSpecifier(bool ForceReplacement)
bool WantFunctionLikeCasts
ArrayRef< PartialDiagnostic > getExtraDiagnostics() const