14 #ifndef LLVM_CLANG_SEMA_TYPOCORRECTION_H 15 #define LLVM_CLANG_SEMA_TYPOCORRECTION_H 23 #include "llvm/ADT/ArrayRef.h" 24 #include "llvm/ADT/SmallVector.h" 25 #include "llvm/Support/Casting.h" 38 class NestedNameSpecifier;
61 unsigned QualifierDistance = 0)
62 : CorrectionName(Name), CorrectionNameSpec(NNS),
63 CharDistance(CharDistance), QualifierDistance(QualifierDistance) {
65 CorrectionDecls.push_back(NameDecl);
69 unsigned CharDistance = 0)
70 : CorrectionName(Name->getDeclName()), CorrectionNameSpec(NNS),
71 CharDistance(CharDistance) {
73 CorrectionDecls.push_back(Name);
77 unsigned CharDistance = 0)
78 : CorrectionName(Name), CorrectionNameSpec(NNS),
79 CharDistance(CharDistance) {}
92 return CorrectionNameSpec;
96 CorrectionNameSpec = NNS;
97 ForceSpecifierReplacement = (NNS !=
nullptr);
101 ForceSpecifierReplacement = ForceReplacement;
105 return ForceSpecifierReplacement;
109 QualifierDistance = ED;
113 CallbackDistance = ED;
120 if (ED > MaximumDistance)
129 if (CharDistance > MaximumDistance || QualifierDistance > MaximumDistance ||
130 CallbackDistance > MaximumDistance)
133 CharDistance * CharDistanceWeight +
134 QualifierDistance * QualifierDistanceWeight +
136 if (ED > MaximumDistance)
147 return hasCorrectionDecl() ? *(CorrectionDecls.begin()) :
nullptr;
153 return D ? D->getUnderlyingDecl() :
nullptr;
155 template <
class DeclClass>
162 CorrectionDecls.clear();
167 CorrectionDecls.clear();
173 CorrectionDecls.clear();
174 CorrectionDecls.insert(CorrectionDecls.begin(), Decls.begin(), Decls.end());
188 explicit operator bool()
const {
return bool(CorrectionName); }
195 CorrectionDecls.clear();
196 CorrectionDecls.push_back(
nullptr);
197 ForceSpecifierReplacement =
true;
203 return !CorrectionDecls.empty() && CorrectionDecls.front() ==
nullptr;
207 template<std::
size_t StrLen>
216 return CorrectionDecls.size() > 1;
222 if (ForceSpecifierReplacement && SS && !SS->
isEmpty())
227 return CorrectionRange;
233 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
241 return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
254 ExtraDiagnostics.push_back(std::move(PD));
257 return ExtraDiagnostics;
261 bool hasCorrectionDecl()
const {
262 return (!
isKeyword() && !CorrectionDecls.empty());
269 unsigned CharDistance = 0;
270 unsigned QualifierDistance = 0;
271 unsigned CallbackDistance = 0;
273 bool ForceSpecifierReplacement =
false;
274 bool RequiresImport =
false;
276 std::vector<PartialDiagnostic> ExtraDiagnostics;
287 : Typo(Typo), TypoNNS(TypoNNS) {}
310 return (!MatchesTypo(candidate) && ValidateCandidate(candidate))
320 virtual std::unique_ptr<CorrectionCandidateCallback> clone() = 0;
328 bool WantTypeSpecifiers =
true;
329 bool WantExpressionKeywords =
true;
330 bool WantCXXNamedCasts =
true;
331 bool WantFunctionLikeCasts =
true;
332 bool WantRemainingKeywords =
true;
333 bool WantObjCSuper =
false;
336 bool IsObjCIvarLookup =
false;
337 bool IsAddressOfOperand =
false;
358 std::unique_ptr<CorrectionCandidateCallback>
clone()
override {
359 return llvm::make_unique<DefaultFilterCCC>(*this);
371 std::unique_ptr<CorrectionCandidateCallback>
clone()
override {
372 return llvm::make_unique<DeclFilterCCC>(*this);
382 bool HasExplicitTemplateArgs,
386 std::unique_ptr<CorrectionCandidateCallback>
clone()
override {
387 return llvm::make_unique<FunctionCallFilterCCC>(*this);
392 bool HasExplicitTemplateArgs;
401 WantTypeSpecifiers =
false;
402 WantExpressionKeywords =
false;
403 WantCXXNamedCasts =
false;
404 WantFunctionLikeCasts =
false;
405 WantRemainingKeywords =
false;
411 std::unique_ptr<CorrectionCandidateCallback>
clone()
override {
412 return llvm::make_unique<NoTypoCorrectionCCC>(*this);
418 #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
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
void makeKeyword()
Mark this TypoCorrection as being a keyword.
void setCorrectionSpecifier(NestedNameSpecifier *NNS)
DefaultFilterCCC(IdentifierInfo *Typo=nullptr, NestedNameSpecifier *TypoNNS=nullptr)
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...
__DEVICE__ int max(int __a, int __b)
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
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
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
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
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
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)
std::unique_ptr< CorrectionCandidateCallback > clone() override
Clone this CorrectionCandidateCallback.
ArrayRef< PartialDiagnostic > getExtraDiagnostics() const