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;
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();
224 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
234 bool hasCorrectionDecl()
const {
235 return (!
isKeyword() && !CorrectionDecls.empty());
239 DeclarationName CorrectionName;
240 NestedNameSpecifier *CorrectionNameSpec;
241 SmallVector<NamedDecl *, 1> CorrectionDecls;
242 unsigned CharDistance;
243 unsigned QualifierDistance;
244 unsigned CallbackDistance;
245 SourceRange CorrectionRange;
246 bool ForceSpecifierReplacement;
336 bool HasExplicitTemplateArgs,
343 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
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
void makeKeyword()
Mark this TypoCorrection as being a keyword.
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.
One of these records is kept for each identifier that is lexed.
TypoCorrection(NamedDecl *Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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.
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.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclarationName - The name of a declaration.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
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.
NamedDecl * getFoundDecl() const
Get the correction declaration found by name lookup (before we looked through using shadow declaratio...
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).
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
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.
NamedDecl - This represents a decl with a name.
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