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;
134 return hasCorrectionDecl() ? *(CorrectionDecls.begin()) :
nullptr;
136 template <
class DeclClass>
143 CorrectionDecls.clear();
148 CorrectionDecls.clear();
154 CorrectionDecls.clear();
155 CorrectionDecls.insert(CorrectionDecls.begin(), Decls.begin(), Decls.end());
168 explicit operator bool()
const {
return bool(CorrectionName); }
175 CorrectionDecls.clear();
176 CorrectionDecls.push_back(
nullptr);
177 ForceSpecifierReplacement =
true;
183 return !CorrectionDecls.empty() &&
184 CorrectionDecls.front() ==
nullptr;
188 template<std::
size_t StrLen>
197 return CorrectionDecls.size() > 1;
203 if (ForceSpecifierReplacement && SS && !SS->
isEmpty())
208 return CorrectionRange;
213 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
218 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
228 bool hasCorrectionDecl()
const {
229 return (!
isKeyword() && !CorrectionDecls.empty());
233 DeclarationName CorrectionName;
234 NestedNameSpecifier *CorrectionNameSpec;
235 SmallVector<NamedDecl *, 1> CorrectionDecls;
236 unsigned CharDistance;
237 unsigned QualifierDistance;
238 unsigned CallbackDistance;
239 SourceRange CorrectionRange;
240 bool ForceSpecifierReplacement;
330 bool HasExplicitTemplateArgs,
337 bool HasExplicitTemplateArgs;
void setTypoName(IdentifierInfo *II)
FunctionCallFilterCCC(Sema &SemaRef, unsigned NumArgs, bool HasExplicitTemplateArgs, MemberExpr *ME=nullptr)
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...
IdentifierInfo * getAsIdentifierInfo() const
void makeKeyword()
Mark this TypoCorrection as being a keyword. Since addCorrectionDeclsand setCorrectionDecl don't allo...
void setCorrectionSpecifier(NestedNameSpecifier *NNS)
static const unsigned InvalidDistance
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 isEmpty() const
No scope specifier.
bool WantExpressionKeywords
void setCorrectionDecl(NamedDecl *CDecl)
Clears the list of NamedDecls before adding the new one.
TypoCorrection(NamedDecl *Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
IdentifierInfo * getCorrectionAsIdentifierInfo() const
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
static const unsigned MaximumDistance
bool isOverloaded() const
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...
void setCallbackDistance(unsigned ED)
bool isKeyword(const char(&Str)[StrLen]) const
void setQualifierDistance(unsigned ED)
bool ValidateCandidate(const TypoCorrection &candidate) override
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
bool MatchesTypo(const TypoCorrection &candidate)
void setTypoNNS(NestedNameSpecifier *NNS)
static unsigned NormalizeEditDistance(unsigned ED)
std::string getQuoted(const LangOptions &LO) const
Represents a C++ nested-name-specifier or a global scope specifier.
bool WillReplaceSpecifier() const
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.
virtual bool ValidateCandidate(const TypoCorrection &candidate)
Simple predicate used by the default RankCandidate to determine whether to return an edit distance of...
NestedNameSpecifier * getCorrectionSpecifier() const
Gets the NestedNameSpecifier needed to use the typo correction.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void setRequiresImport(bool Req)
CorrectionCandidateCallback(IdentifierInfo *Typo=nullptr, NestedNameSpecifier *TypoNNS=nullptr)
unsigned getEditDistance(bool Normalized=true) const
Gets the "edit distance" of the typo correction from the typo. If Normalized is true, scale the distance down by the CharDistanceWeight to return the edit distance in terms of single-character edits.
static const unsigned CharDistanceWeight
void setCorrectionDecls(ArrayRef< NamedDecl * > Decls)
Clears the list of NamedDecls and adds the given set.
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)
SourceLocation getBeginLoc() const
static const unsigned QualifierDistanceWeight
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
const_decl_iterator begin() const
DeclClass * getCorrectionDeclAs() const
DeclarationName getCorrection() const
Gets the DeclarationName of the typo correction.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
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...
std::string getAsString(const LangOptions &LO) const
SourceRange getCorrectionRange() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
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
const_decl_iterator end() const
TypoCorrection(DeclarationName Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
A trivial tuple used to represent a source range.
bool requiresImport() const
Returns whether this typo correction is correcting to a declaration that was declared in a module tha...
void WillReplaceSpecifier(bool ForceReplacement)
bool WantFunctionLikeCasts