15 #ifndef LLVM_CLANG_SEMA_TYPOCORRECTION_H 16 #define LLVM_CLANG_SEMA_TYPOCORRECTION_H 24 #include "llvm/ADT/ArrayRef.h" 25 #include "llvm/ADT/SmallVector.h" 26 #include "llvm/Support/Casting.h" 39 class NestedNameSpecifier;
62 unsigned QualifierDistance = 0)
63 : CorrectionName(Name), CorrectionNameSpec(NNS),
64 CharDistance(CharDistance), QualifierDistance(QualifierDistance) {
66 CorrectionDecls.push_back(NameDecl);
70 unsigned CharDistance = 0)
71 : CorrectionName(Name->getDeclName()), CorrectionNameSpec(NNS),
72 CharDistance(CharDistance) {
74 CorrectionDecls.push_back(Name);
78 unsigned CharDistance = 0)
79 : CorrectionName(Name), CorrectionNameSpec(NNS),
80 CharDistance(CharDistance) {}
93 return CorrectionNameSpec;
97 CorrectionNameSpec = NNS;
98 ForceSpecifierReplacement = (NNS !=
nullptr);
102 ForceSpecifierReplacement = ForceReplacement;
106 return ForceSpecifierReplacement;
110 QualifierDistance = ED;
114 CallbackDistance = ED;
121 if (ED > MaximumDistance)
130 if (CharDistance > MaximumDistance || QualifierDistance > MaximumDistance ||
131 CallbackDistance > MaximumDistance)
134 CharDistance * CharDistanceWeight +
135 QualifierDistance * QualifierDistanceWeight +
137 if (ED > MaximumDistance)
148 return hasCorrectionDecl() ? *(CorrectionDecls.begin()) :
nullptr;
154 return D ? D->getUnderlyingDecl() :
nullptr;
156 template <
class DeclClass>
163 CorrectionDecls.clear();
168 CorrectionDecls.clear();
174 CorrectionDecls.clear();
175 CorrectionDecls.insert(CorrectionDecls.begin(), Decls.begin(), Decls.end());
189 explicit operator bool()
const {
return bool(CorrectionName); }
196 CorrectionDecls.clear();
197 CorrectionDecls.push_back(
nullptr);
198 ForceSpecifierReplacement =
true;
204 return !CorrectionDecls.empty() && CorrectionDecls.front() ==
nullptr;
208 template<std::
size_t StrLen>
217 return CorrectionDecls.size() > 1;
223 if (ForceSpecifierReplacement && SS && !SS->
isEmpty())
228 return CorrectionRange;
234 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
242 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
255 ExtraDiagnostics.push_back(std::move(PD));
258 return ExtraDiagnostics;
262 bool hasCorrectionDecl()
const {
263 return (!
isKeyword() && !CorrectionDecls.empty());
270 unsigned CharDistance = 0;
271 unsigned QualifierDistance = 0;
272 unsigned CallbackDistance = 0;
274 bool ForceSpecifierReplacement =
false;
275 bool RequiresImport =
false;
277 std::vector<PartialDiagnostic> ExtraDiagnostics;
288 : Typo(Typo), TypoNNS(TypoNNS) {}
311 return (!MatchesTypo(candidate) && ValidateCandidate(candidate))
322 bool WantTypeSpecifiers =
true;
323 bool WantExpressionKeywords =
true;
324 bool WantCXXNamedCasts =
true;
325 bool WantFunctionLikeCasts =
true;
326 bool WantRemainingKeywords =
true;
327 bool WantObjCSuper =
false;
330 bool IsObjCIvarLookup =
false;
331 bool IsAddressOfOperand =
false;
362 bool HasExplicitTemplateArgs,
369 bool HasExplicitTemplateArgs;
378 WantTypeSpecifiers =
false;
379 WantExpressionKeywords =
false;
380 WantCXXNamedCasts =
false;
381 WantFunctionLikeCasts =
false;
382 WantRemainingKeywords =
false;
392 #endif // LLVM_CLANG_SEMA_TYPOCORRECTION_H 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.
SmallVectorImpl< NamedDecl * >::const_iterator const_decl_iterator
SmallVectorImpl< NamedDecl * >::iterator decl_iterator
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...
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)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
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.
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
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
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
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.
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...
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
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.
Defines the clang::SourceLocation class and associated facilities.
const_decl_iterator begin() const
void ClearCorrectionDecls()
Clears the list of NamedDecls.
void setCorrectionRange(CXXScopeSpec *SS, const DeclarationNameInfo &TypoName)
NestedNameSpecifier * TypoNNS
static const unsigned CallbackDistanceWeight
__DEVICE__ int max(int __a, int __b)
TypoCorrection(DeclarationName Name, NestedNameSpecifier *NNS=nullptr, unsigned CharDistance=0)
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
void WillReplaceSpecifier(bool ForceReplacement)
ArrayRef< PartialDiagnostic > getExtraDiagnostics() const