9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H
10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H
12#include "clang/Basic/ASTSourceDescriptor.h"
13#include "clang/Sema/Lookup.h"
14#include "clang/Sema/MultiplexExternalSemaSource.h"
15#include "clang/Sema/Sema.h"
16#include "clang/Sema/SemaConsumer.h"
17#include "llvm/ADT/IntrusiveRefCntPtr.h"
18#include "llvm/Support/Casting.h"
33 llvm::IntrusiveRefCntPtr<ExternalASTSource>
m_Source;
38 assert(
m_Source &&
"Can't wrap nullptr ExternalASTSource");
52 return m_Source->GetNumExternalSelectors();
56 return m_Source->GetExternalDeclStmt(Offset);
59 clang::CXXCtorInitializer **
61 return m_Source->GetExternalCXXCtorInitializers(Offset);
64 clang::CXXBaseSpecifier *
66 return m_Source->GetExternalCXXBaseSpecifiers(Offset);
70 m_Source->updateOutOfDateIdentifier(II);
74 clang::DeclarationName Name)
override {
75 return m_Source->FindExternalVisibleDeclsByName(DC, Name);
79 m_Source->completeVisibleDeclsMap(DC);
86 std::optional<clang::ASTSourceDescriptor>
92 return m_Source->hasExternalDefinitions(D);
96 const clang::DeclContext *DC,
97 llvm::function_ref<
bool(clang::Decl::Kind)> IsKindWeWant,
99 m_Source->FindExternalLexicalDecls(DC, IsKindWeWant, Result);
105 m_Source->FindFileRegionDecls(
File, Offset, Length, Decls);
127 m_Source->StartTranslationUnit(Consumer);
133 const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
134 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
135 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
137 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
138 &VirtualBaseOffsets)
override {
139 return m_Source->layoutRecordType(Record, Size, Alignment, FieldOffsets,
140 BaseOffsets, VirtualBaseOffsets);
153 llvm::MapVector<clang::NamedDecl *, clang::SourceLocation> &Undefined)
155 Undefined.remove_if([](
auto const &decl_loc_pair) {
156 const clang::NamedDecl *ND = decl_loc_pair.first;
157 return llvm::isa_and_present<clang::FunctionDecl>(ND);
171 m_sc = llvm::dyn_cast<clang::SemaConsumer>(
m_c);
177 m_c->Initialize(Context);
181 return m_c->HandleTopLevelDecl(D);
185 m_c->HandleInlineFunctionDefinition(D);
189 m_c->HandleInterestingDecl(D);
193 m_c->HandleTranslationUnit(Ctx);
197 m_c->HandleTagDeclDefinition(D);
201 m_c->HandleTagDeclRequiredDefinition(D);
205 m_c->HandleCXXImplicitFunctionInstantiation(D);
209 m_c->HandleTopLevelDeclInObjCContainer(D);
213 m_c->HandleImplicitImportDecl(D);
217 m_c->CompleteTentativeDefinition(D);
221 m_c->AssignInheritanceModel(RD);
225 m_c->HandleCXXStaticMemberVarInstantiation(D);
229 m_c->HandleVTable(RD);
233 return m_c->GetASTMutationListener();
237 return m_c->GetASTDeserializationListener();
244 m_sc->InitializeSema(S);
254 return m_c->shouldSkipFunctionBody(D);
275 llvm::SmallVector<clang::ExternalSemaSource *, 2>
Sources;
284 clang::ExternalSemaSource *low_quality_source) {
285 assert(high_quality_source);
286 assert(low_quality_source);
288 high_quality_source->Retain();
289 low_quality_source->Retain();
291 Sources.push_back(high_quality_source);
292 Sources.push_back(low_quality_source);
302 for (
size_t i = 0; i <
Sources.size(); ++i)
309 for (
size_t i = 0; i <
Sources.size(); ++i)
315 for (
size_t i = 0; i <
Sources.size(); ++i) {
316 Sel =
Sources[i]->GetExternalSelector(
ID);
324 for (
size_t i = 0; i <
Sources.size(); ++i)
331 for (
size_t i = 0; i <
Sources.size(); ++i)
337 clang::CXXBaseSpecifier *
339 for (
size_t i = 0; i <
Sources.size(); ++i)
340 if (clang::CXXBaseSpecifier *R =
346 clang::CXXCtorInitializer **
349 if (
auto *R = S->GetExternalCXXCtorInitializers(Offset))
356 if (
auto EK = S->hasExternalDefinitions(D))
357 if (EK != EK_ReplyHazy)
363 clang::DeclarationName Name)
override {
364 for (
size_t i = 0; i <
Sources.size(); ++i)
372 for (
size_t i = 0; i <
Sources.size(); ++i)
377 const clang::DeclContext *DC,
378 llvm::function_ref<
bool(clang::Decl::Kind)> IsKindWeWant,
380 for (
size_t i = 0; i <
Sources.size(); ++i) {
381 Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result);
390 for (
size_t i = 0; i <
Sources.size(); ++i)
395 for (clang::ExternalSemaSource *S :
Sources) {
396 S->CompleteType(Tag);
398 if (Tag->isCompleteDefinition())
404 for (
size_t i = 0; i <
Sources.size(); ++i)
409 for (
size_t i = 0; i <
Sources.size(); ++i)
414 for (
size_t i = 0; i <
Sources.size(); ++i)
419 for (
size_t i = 0; i <
Sources.size(); ++i)
424 for (
size_t i = 0; i <
Sources.size(); ++i)
431 for (
size_t i = 0; i <
Sources.size(); ++i)
438 const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
439 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
440 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
442 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
443 &VirtualBaseOffsets)
override {
444 for (
size_t i = 0; i <
Sources.size(); ++i)
446 BaseOffsets, VirtualBaseOffsets))
453 Source->getMemoryBufferSizes(sizes);
462 Source->InitializeSema(S);
472 Source->ReadMethodPool(Sel);
477 Source->updateOutOfDateSelector(Sel);
483 Source->ReadKnownNamespaces(Namespaces);
487 llvm::MapVector<clang::NamedDecl *, clang::SourceLocation> &Undefined)
490 Source->ReadUndefinedButUsed(Undefined);
494 llvm::MapVector<clang::FieldDecl *,
495 llvm::SmallVector<std::pair<clang::SourceLocation, bool>,
496 4>> &Exprs)
override {
498 Source->ReadMismatchingDeleteExpressions(Exprs);
503 Source->LookupUnqualified(R, S);
514 Source->ReadTentativeDefinitions(Defs);
520 Source->ReadUnusedFileScopedDecls(Decls);
526 Source->ReadDelegatingConstructors(Decls);
532 Source->ReadExtVectorDecls(Decls);
536 llvm::SmallSetVector<const clang::TypedefNameDecl *, 4> &Decls)
override {
538 Source->ReadUnusedLocalTypedefNameCandidates(Decls);
545 Source->ReadReferencedSelectors(Sels);
552 Source->ReadWeakUndeclaredIdentifiers(WI);
558 Source->ReadUsedVTables(VTables);
563 std::pair<clang::ValueDecl *, clang::SourceLocation>> &Pending)
566 Source->ReadPendingInstantiations(Pending);
570 llvm::MapVector<
const clang::FunctionDecl *,
571 std::unique_ptr<clang::LateParsedTemplate>> &LPTMap)
574 Source->ReadLateParsedTemplates(LPTMap);
577 clang::TypoCorrection
578 CorrectTypo(
const clang::DeclarationNameInfo &Typo,
int LookupKind,
579 clang::Scope *S, clang::CXXScopeSpec *SS,
580 clang::CorrectionCandidateCallback &CCC,
581 clang::DeclContext *MemberContext,
bool EnteringContext,
582 const clang::ObjCObjectPointerType *OPT)
override {
584 if (clang::TypoCorrection C =
585 Source->CorrectTypo(Typo, LookupKind, S, SS, CCC,
586 MemberContext, EnteringContext, OPT))
589 return clang::TypoCorrection();
593 clang::QualType T)
override {
595 if (
Source->MaybeDiagnoseMissingCompleteType(Loc, T))
Wraps an ASTConsumer into an SemaConsumer.
void HandleTranslationUnit(clang::ASTContext &Ctx) override
void PrintStats() override
void HandleInlineFunctionDefinition(clang::FunctionDecl *D) override
void InitializeSema(clang::Sema &S) override
void HandleInterestingDecl(clang::DeclGroupRef D) override
ASTConsumerForwarder(clang::ASTConsumer *c)
bool shouldSkipFunctionBody(clang::Decl *D) override
void HandleTagDeclDefinition(clang::TagDecl *D) override
void AssignInheritanceModel(clang::CXXRecordDecl *RD) override
~ASTConsumerForwarder() override
clang::SemaConsumer * m_sc
void HandleTopLevelDeclInObjCContainer(clang::DeclGroupRef D) override
clang::ASTDeserializationListener * GetASTDeserializationListener() override
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
bool HandleTopLevelDecl(clang::DeclGroupRef D) override
void HandleCXXImplicitFunctionInstantiation(clang::FunctionDecl *D) override
void CompleteTentativeDefinition(clang::VarDecl *D) override
void HandleTagDeclRequiredDefinition(const clang::TagDecl *D) override
void HandleVTable(clang::CXXRecordDecl *RD) override
void HandleCXXStaticMemberVarInstantiation(clang::VarDecl *D) override
void Initialize(clang::ASTContext &Context) override
void HandleImplicitImportDecl(clang::ImportDecl *D) override
clang::ASTMutationListener * GetASTMutationListener() override
Wraps an ExternalASTSource into an ExternalSemaSource.
std::optional< clang::ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
~ExternalASTSourceWrapper() override
void ReadUndefinedButUsed(llvm::MapVector< clang::NamedDecl *, clang::SourceLocation > &Undefined) override
This gets called when Sema is reconciling undefined but used decls.
clang::Module * getModule(unsigned ID) override
clang::Selector GetExternalSelector(uint32_t ID) override
ExtKind hasExternalDefinitions(const clang::Decl *D) override
void StartedDeserializing() override
clang::Stmt * GetExternalDeclStmt(uint64_t Offset) override
void completeVisibleDeclsMap(const clang::DeclContext *DC) override
llvm::IntrusiveRefCntPtr< ExternalASTSource > m_Source
ExternalASTSourceWrapper(ExternalASTSource *Source)
void FinishedDeserializing() override
bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override
void FindFileRegionDecls(clang::FileID File, unsigned Offset, unsigned Length, llvm::SmallVectorImpl< clang::Decl * > &Decls) override
void CompleteType(clang::ObjCInterfaceDecl *Class) override
void PrintStats() override
clang::Decl * GetExternalDecl(clang::GlobalDeclID ID) override
uint32_t GetNumExternalSelectors() override
void FindExternalLexicalDecls(const clang::DeclContext *DC, llvm::function_ref< bool(clang::Decl::Kind)> IsKindWeWant, llvm::SmallVectorImpl< clang::Decl * > &Result) override
clang::CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset) override
void ReadComments() override
void StartTranslationUnit(clang::ASTConsumer *Consumer) override
void CompleteRedeclChain(const clang::Decl *D) override
clang::CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
void updateOutOfDateIdentifier(const clang::IdentifierInfo &II) override
bool layoutRecordType(const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &BaseOffsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &VirtualBaseOffsets) override
void CompleteType(clang::TagDecl *Tag) override
An abstract base class for files.
A ExternalSemaSource multiplexer that prioritizes its sources.
void ReadUndefinedButUsed(llvm::MapVector< clang::NamedDecl *, clang::SourceLocation > &Undefined) override
void ReadKnownNamespaces(llvm::SmallVectorImpl< clang::NamespaceDecl * > &Namespaces) override
void ReadExtVectorDecls(llvm::SmallVectorImpl< clang::TypedefNameDecl * > &Decls) override
uint32_t GetNumExternalSelectors() override
bool MaybeDiagnoseMissingCompleteType(clang::SourceLocation Loc, clang::QualType T) override
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const clang::TypedefNameDecl *, 4 > &Decls) override
clang::Selector GetExternalSelector(uint32_t ID) override
void StartedDeserializing() override
clang::Module * getModule(unsigned ID) override
void FindExternalLexicalDecls(const clang::DeclContext *DC, llvm::function_ref< bool(clang::Decl::Kind)> IsKindWeWant, llvm::SmallVectorImpl< clang::Decl * > &Result) override
void FinishedDeserializing() override
bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override
void ReadUsedVTables(llvm::SmallVectorImpl< clang::ExternalVTableUse > &VTables) override
clang::TypoCorrection CorrectTypo(const clang::DeclarationNameInfo &Typo, int LookupKind, clang::Scope *S, clang::CXXScopeSpec *SS, clang::CorrectionCandidateCallback &CCC, clang::DeclContext *MemberContext, bool EnteringContext, const clang::ObjCObjectPointerType *OPT) override
SemaSourceWithPriorities(clang::ExternalSemaSource *high_quality_source, clang::ExternalSemaSource *low_quality_source)
Construct a SemaSourceWithPriorities with a 'high quality' source that has the higher priority and a ...
void CompleteRedeclChain(const clang::Decl *D) override
clang::Stmt * GetExternalDeclStmt(uint64_t Offset) override
void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override
clang::Decl * GetExternalDecl(clang::GlobalDeclID ID) override
void StartTranslationUnit(clang::ASTConsumer *Consumer) override
clang::CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
void ReadTentativeDefinitions(llvm::SmallVectorImpl< clang::VarDecl * > &Defs) override
void ReadReferencedSelectors(llvm::SmallVectorImpl< std::pair< clang::Selector, clang::SourceLocation > > &Sels) override
void ReadLateParsedTemplates(llvm::MapVector< const clang::FunctionDecl *, std::unique_ptr< clang::LateParsedTemplate > > &LPTMap) override
bool layoutRecordType(const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &BaseOffsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &VirtualBaseOffsets) override
void ReadMethodPool(clang::Selector Sel) override
clang::CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset) override
void PrintStats() override
void CompleteType(clang::TagDecl *Tag) override
void ForgetSema() override
llvm::SmallVector< clang::ExternalSemaSource *, 2 > Sources
The sources ordered in decreasing priority.
void FindFileRegionDecls(clang::FileID File, unsigned Offset, unsigned Length, llvm::SmallVectorImpl< clang::Decl * > &Decls) override
void ReadUnusedFileScopedDecls(llvm::SmallVectorImpl< const clang::DeclaratorDecl * > &Decls) override
void CompleteType(clang::ObjCInterfaceDecl *Class) override
void completeVisibleDeclsMap(const clang::DeclContext *DC) override
void ReadPendingInstantiations(llvm::SmallVectorImpl< std::pair< clang::ValueDecl *, clang::SourceLocation > > &Pending) override
void ReadDelegatingConstructors(llvm::SmallVectorImpl< clang::CXXConstructorDecl * > &Decls) override
bool LookupUnqualified(clang::LookupResult &R, clang::Scope *S) override
void updateOutOfDateSelector(clang::Selector Sel) override
void ReadComments() override
void ReadWeakUndeclaredIdentifiers(llvm::SmallVectorImpl< std::pair< clang::IdentifierInfo *, clang::WeakInfo > > &WI) override
void ReadMismatchingDeleteExpressions(llvm::MapVector< clang::FieldDecl *, llvm::SmallVector< std::pair< clang::SourceLocation, bool >, 4 > > &Exprs) override
ExtKind hasExternalDefinitions(const clang::Decl *D) override
~SemaSourceWithPriorities() override
void InitializeSema(clang::Sema &S) override
A class that represents a running process on the host machine.