14#ifndef LLVM_CLANG_SEMA_SEMAINTERNAL_H
15#define LLVM_CLANG_SEMA_SEMAINTERNAL_H
29 cast<ParmVarDecl>(FTI.
Params[0].
Param)->getType()->isVoidType();
42 if (!LangOpts.CUDA || !
D)
44 bool isDeviceSideDecl =
D->
hasAttr<CUDADeviceAttr>() ||
47 return isDeviceSideDecl == LangOpts.CUDAIsDevice;
53 "A declaration cannot be both dllimport and dllexport.");
54 if (
auto *Import =
D->
getAttr<DLLImportAttr>())
56 if (
auto *Export =
D->
getAttr<DLLExportAttr>())
63 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
64 return std::make_pair(TTP->getDepth(), TTP->getIndex());
66 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
67 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
69 const auto *TTP = cast<TemplateTemplateParmDecl>(ND);
70 return std::make_pair(TTP->getDepth(), TTP->getIndex());
76inline std::optional<std::pair<unsigned, unsigned>>
78 if (
const auto *TTP = dyn_cast<const TemplateTypeParmType *>(UPP.first))
79 return std::make_pair(TTP->getDepth(), TTP->getIndex());
80 if (isa<NamedDecl *>(UPP.first))
89 typedef llvm::StringMap<TypoResultList> TypoResultsMap;
90 typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap;
97 std::unique_ptr<CorrectionCandidateCallback> CCC,
100 : Typo(TypoName.getName().getAsIdentifierInfo()), CurrentTCIndex(0),
101 SavedTCIndex(0), SemaRef(SemaRef), S(S),
103 CorrectionValidator(
std::move(CCC)), MemberContext(MemberContext),
104 Result(SemaRef, TypoName, LookupKind),
105 Namespaces(SemaRef.Context, SemaRef.CurContext, SS),
106 EnteringContext(EnteringContext), SearchNamespaces(
false) {
116 bool InBaseClass)
override;
122 return CorrectionResults.empty() && ValidatedCorrections.size() == 1;
128 return CorrectionResults.begin()->second[Name];
134 if (CorrectionResults.empty())
135 return (std::numeric_limits<unsigned>::max)();
137 unsigned BestED = CorrectionResults.begin()->first;
146 addNamespaces(
const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces);
157 return CurrentTCIndex < ValidatedCorrections.size()
158 ? ValidatedCorrections[CurrentTCIndex]
159 : ValidatedCorrections[0];
167 auto Current = CurrentTCIndex;
169 CurrentTCIndex = Current;
188 return CorrectionResults.empty() &&
189 CurrentTCIndex >= ValidatedCorrections.size();
195 SavedTCIndex = CurrentTCIndex;
200 CurrentTCIndex = SavedTCIndex;
210 return CorrectionValidator.get();
214 class NamespaceSpecifierSet {
215 struct SpecifierInfo {
218 unsigned EditDistance;
221 typedef SmallVector<DeclContext*, 4> DeclContextList;
222 typedef SmallVector<SpecifierInfo, 16> SpecifierInfoList;
225 DeclContextList CurContextChain;
226 std::string CurNameSpecifier;
227 SmallVector<const IdentifierInfo*, 4> CurContextIdentifiers;
228 SmallVector<const IdentifierInfo*, 4> CurNameSpecifierIdentifiers;
230 std::map<unsigned, SpecifierInfoList> DistanceMap;
234 static DeclContextList buildContextChain(DeclContext *Start);
236 unsigned buildNestedNameSpecifier(DeclContextList &DeclChain,
237 NestedNameSpecifier &NNS);
240 NamespaceSpecifierSet(ASTContext &Context, DeclContext *CurContext,
241 CXXScopeSpec *CurScopeSpec);
245 void addNameSpecifier(DeclContext *Ctx);
249 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
252 const std::map<unsigned, SpecifierInfoList>::iterator OuterBack;
254 std::map<unsigned, SpecifierInfoList>::iterator Outer;
256 SpecifierInfoList::iterator Inner;
260 : OuterBack(
std::prev(
Set.DistanceMap.end())),
261 Outer(
Set.DistanceMap.begin()),
262 Inner(!IsAtEnd ? Outer->second.begin() : OuterBack->second.end()) {
263 assert(!
Set.DistanceMap.empty());
268 if (Inner == Outer->second.end() && Outer != OuterBack) {
270 Inner = Outer->second.begin();
279 iterator begin() {
return iterator(*
this,
false); }
280 iterator end() {
return iterator(*
this,
true); }
283 void addName(StringRef Name, NamedDecl *ND,
284 NestedNameSpecifier NNS = std::nullopt,
bool isKeyword =
false);
289 bool resolveCorrection(TypoCorrection &Candidate);
295 void performQualifiedLookups();
298 IdentifierInfo *Typo;
305 TypoEditDistanceMap CorrectionResults;
307 SmallVector<TypoCorrection, 4> ValidatedCorrections;
308 size_t CurrentTCIndex;
313 std::unique_ptr<CXXScopeSpec> SS;
314 std::unique_ptr<CorrectionCandidateCallback> CorrectionValidator;
315 DeclContext *MemberContext;
317 NamespaceSpecifierSet Namespaces;
318 SmallVector<TypoCorrection, 2> QualifiedResults;
319 bool EnteringContext;
320 bool SearchNamespaces;
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ nested-name-specifier or a global scope specifier.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents the results of name lookup.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
This represents a decl that may have a name.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Scope - A scope is a transient data structure that is used while parsing the program.
Sema - This implements semantic analysis and AST building for C.
LookupNameKind
Describes the kind of name lookup to perform.
Represents the result of substituting a builtin template as a pack.
Represents a type template specialization; the template must be a class template, a type alias templa...
Provides flat iteration over specifiers, sorted by distance.
SpecifierInfo & operator*()
iterator(NamespaceSpecifierSet &Set, bool IsAtEnd)
bool operator==(const iterator &RHS) const
void resetCorrectionStream()
Reset the consumer's position in the stream of viable corrections (i.e.
bool isAddressOfOperand() const
void addKeywordResult(StringRef Keyword)
void restoreSavedPosition()
Restore the saved position in the correction stream.
const LookupResult & getLookupResult() const
void addCorrection(TypoCorrection Correction)
const TypoCorrection & getCurrentCorrection()
Get the last correction returned by getNextCorrection().
void saveCurrentPosition()
Save the current position in the correction stream (overwriting any previously saved position).
const CXXScopeSpec * getSS() const
TypoCorrectionConsumer(Sema &SemaRef, const DeclarationNameInfo &TypoName, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, DeclContext *MemberContext, bool EnteringContext)
const TypoCorrection & peekNextCorrection()
Return the next typo correction like getNextCorrection, but keep the internal state pointed to the cu...
bool includeHiddenDecls() const override
Determine whether hidden declarations (from unimported modules) should be given to this consumer.
bool finished()
Return whether the end of the stream of corrections has been reached.
unsigned getBestEditDistance(bool Normalized)
Return the edit distance of the corrections that have the closest/best edit distance from the origina...
bool hasMadeAnyCorrectionProgress() const
In the case of deeply invalid expressions, getNextCorrection() will never be called since the transfo...
const TypoCorrection & getNextCorrection()
Return the next typo correction that passes all internal filters and is deemed valid by the consumer'...
TypoResultList & operator[](StringRef Name)
Return the list of TypoCorrections for the given identifier from the set of corrections that have the...
ASTContext & getContext() const
void FoundName(StringRef Name)
void addNamespaces(const llvm::MapVector< NamespaceDecl *, bool > &KnownNamespaces)
Set-up method to add to the consumer the set of namespaces to use in performing corrections to nested...
CorrectionCandidateCallback * getCorrectionValidator() const
Simple class containing the result of Sema::CorrectTypo.
static unsigned NormalizeEditDistance(unsigned ED)
Consumes visible declarations found when searching for all visible names within a given scope or cont...
The JSON file list parser is used to communicate input to InstallAPI.
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
bool isa(CodeGen::Address addr)
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D)
bool FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI)
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
InheritableAttr * getDLLAttr(Decl *D)
Return a DLL attribute from the declaration.
@ Keyword
The name has been typo-corrected to a keyword.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
unsigned isVariadic
isVariadic - If this function has a prototype, and if that proto ends with ',...)',...
ParamInfo * Params
Params - This is a pointer to a new[]'d array of ParamInfo objects that describe the parameters speci...
unsigned NumParams
NumParams - This is the number of formal parameters specified by the declarator.
const IdentifierInfo * Ident