14#ifndef LLVM_CLANG_SEMA_SEMAINTERNAL_H
15#define LLVM_CLANG_SEMA_SEMAINTERNAL_H
32 cast<ParmVarDecl>(FTI.
Params[0].
Param)->getType()->isVoidType();
45 if (!LangOpts.CUDA || !D)
47 bool isDeviceSideDecl = D->
hasAttr<CUDADeviceAttr>() ||
50 return isDeviceSideDecl == LangOpts.CUDAIsDevice;
55 assert(!(D->
hasAttr<DLLImportAttr>() && D->
hasAttr<DLLExportAttr>()) &&
56 "A declaration cannot be both dllimport and dllexport.");
57 if (
auto *Import = D->
getAttr<DLLImportAttr>())
59 if (
auto *Export = D->
getAttr<DLLExportAttr>())
66 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
67 return std::make_pair(TTP->getDepth(), TTP->getIndex());
69 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
70 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
72 const auto *TTP = cast<TemplateTemplateParmDecl>(ND);
73 return std::make_pair(TTP->getDepth(), TTP->getIndex());
77inline std::pair<unsigned, unsigned>
80 return std::make_pair(TTP->getDepth(), TTP->getIndex());
87 typedef llvm::StringMap<TypoResultList> TypoResultsMap;
88 typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap;
95 std::unique_ptr<CorrectionCandidateCallback> CCC,
98 : Typo(TypoName.
getName().getAsIdentifierInfo()), CurrentTCIndex(0),
99 SavedTCIndex(0), SemaRef(SemaRef), S(S),
101 CorrectionValidator(
std::move(CCC)), MemberContext(MemberContext),
102 Result(SemaRef, TypoName, LookupKind),
103 Namespaces(SemaRef.Context, SemaRef.CurContext, SS),
104 EnteringContext(EnteringContext), SearchNamespaces(
false) {
114 bool InBaseClass)
override;
120 return CorrectionResults.empty() && ValidatedCorrections.size() == 1;
126 return CorrectionResults.begin()->second[Name];
132 if (CorrectionResults.empty())
133 return (std::numeric_limits<unsigned>::max)();
135 unsigned BestED = CorrectionResults.begin()->first;
144 addNamespaces(
const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces);
155 return CurrentTCIndex < ValidatedCorrections.size()
156 ? ValidatedCorrections[CurrentTCIndex]
157 : ValidatedCorrections[0];
165 auto Current = CurrentTCIndex;
167 CurrentTCIndex = Current;
186 return CorrectionResults.empty() &&
187 CurrentTCIndex >= ValidatedCorrections.size();
193 SavedTCIndex = CurrentTCIndex;
198 CurrentTCIndex = SavedTCIndex;
208 return CorrectionValidator.get();
212 class NamespaceSpecifierSet {
213 struct SpecifierInfo {
216 unsigned EditDistance;
219 typedef SmallVector<DeclContext*, 4> DeclContextList;
220 typedef SmallVector<SpecifierInfo, 16> SpecifierInfoList;
223 DeclContextList CurContextChain;
224 std::string CurNameSpecifier;
225 SmallVector<const IdentifierInfo*, 4> CurContextIdentifiers;
226 SmallVector<const IdentifierInfo*, 4> CurNameSpecifierIdentifiers;
228 std::map<unsigned, SpecifierInfoList> DistanceMap;
232 static DeclContextList buildContextChain(DeclContext *Start);
234 unsigned buildNestedNameSpecifier(DeclContextList &DeclChain,
235 NestedNameSpecifier *&NNS);
238 NamespaceSpecifierSet(ASTContext &Context, DeclContext *CurContext,
239 CXXScopeSpec *CurScopeSpec);
243 void addNameSpecifier(DeclContext *Ctx);
247 :
public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
250 const std::map<unsigned, SpecifierInfoList>::iterator OuterBack;
252 std::map<unsigned, SpecifierInfoList>::iterator Outer;
254 SpecifierInfoList::iterator Inner;
258 : OuterBack(
std::prev(
Set.DistanceMap.end())),
259 Outer(
Set.DistanceMap.begin()),
260 Inner(!IsAtEnd ? Outer->second.begin() : OuterBack->second.end()) {
261 assert(!
Set.DistanceMap.empty());
266 if (Inner == Outer->second.end() && Outer != OuterBack) {
268 Inner = Outer->second.begin();
277 iterator begin() {
return iterator(*
this,
false); }
278 iterator end() {
return iterator(*
this,
true); }
281 void addName(StringRef Name, NamedDecl *ND,
282 NestedNameSpecifier *NNS =
nullptr,
bool isKeyword =
false);
287 bool resolveCorrection(TypoCorrection &Candidate);
293 void performQualifiedLookups();
296 IdentifierInfo *Typo;
303 TypoEditDistanceMap CorrectionResults;
305 SmallVector<TypoCorrection, 4> ValidatedCorrections;
306 size_t CurrentTCIndex;
311 std::unique_ptr<CXXScopeSpec> SS;
312 std::unique_ptr<CorrectionCandidateCallback> CorrectionValidator;
313 DeclContext *MemberContext;
315 NamespaceSpecifierSet Namespaces;
316 SmallVector<TypoCorrection, 2> QualifiedResults;
317 bool EnteringContext;
318 bool SearchNamespaces;
321inline Sema::TypoExprState::TypoExprState() {}
323inline Sema::TypoExprState::TypoExprState(TypoExprState &&other)
noexcept {
324 *
this = std::move(other);
327inline Sema::TypoExprState &Sema::TypoExprState::
328operator=(Sema::TypoExprState &&other)
noexcept {
329 Consumer = std::move(other.Consumer);
330 DiagHandler = std::move(other.DiagHandler);
331 RecoveryHandler = std::move(other.RecoveryHandler);
Defines the clang::ASTContext interface.
static std::string getName(const CallEvent &Call)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
PartialDiagnostic::DiagStorageAllocator & getDiagAllocator()
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.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
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...
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D)
bool FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI)
InheritableAttr * getDLLAttr(Decl *D)
Return a DLL attribute from the declaration.
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
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.