LLDB mainline
|
Manages and observes all Clang AST node importing in LLDB. More...
#include <ClangASTImporter.h>
Classes | |
class | ASTContextMetadata |
struct | ASTImporterDelegate |
ASTImporter that intercepts and records the import process of the underlying ASTImporter. More... | |
struct | DeclOrigin |
struct | LayoutInfo |
class | MapCompleter |
struct | NewDeclListener |
Listener interface used by the ASTImporterDelegate to inform other code about decls that have been imported the first time. More... | |
Public Types | |
typedef std::pair< lldb::ModuleSP, CompilerDeclContext > | NamespaceMapItem |
typedef std::vector< NamespaceMapItem > | NamespaceMap |
typedef std::shared_ptr< NamespaceMap > | NamespaceMapSP |
typedef std::shared_ptr< ASTImporterDelegate > | ImporterDelegateSP |
typedef llvm::DenseMap< clang::ASTContext *, ImporterDelegateSP > | DelegateMap |
typedef llvm::DenseMap< const clang::NamespaceDecl *, NamespaceMapSP > | NamespaceMetaMap |
typedef std::shared_ptr< ASTContextMetadata > | ASTContextMetadataSP |
typedef llvm::DenseMap< const clang::ASTContext *, ASTContextMetadataSP > | ContextMetadataMap |
typedef llvm::DenseMap< const clang::RecordDecl *, LayoutInfo > | RecordDeclToLayoutMap |
Public Member Functions | |
ClangASTImporter () | |
CompilerType | CopyType (TypeSystemClang &dst, const CompilerType &src_type) |
Copies the given type and the respective declarations to the destination type system. | |
clang::Decl * | CopyDecl (clang::ASTContext *dst_ctx, clang::Decl *decl) |
CompilerType | DeportType (TypeSystemClang &dst, const CompilerType &src_type) |
Copies the given type and the respective declarations to the destination type system. | |
clang::Decl * | DeportDecl (clang::ASTContext *dst_ctx, clang::Decl *decl) |
Copies the given decl to the destination type system. | |
void | SetRecordLayout (clang::RecordDecl *decl, const LayoutInfo &layout) |
Sets the layout for the given RecordDecl. | |
bool | LayoutRecordType (const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets) |
bool | importRecordLayoutFromOrigin (const clang::RecordDecl *record, uint64_t &size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets) |
If record has a valid origin, this function copies that origin's layout into this ClangASTImporter instance. | |
bool | CanImport (const CompilerType &type) |
Returns true iff the given type was copied from another TypeSystemClang and the original type in this other TypeSystemClang might contain additional information (e.g., the definition of a 'class' type) that could be imported. | |
bool | Import (const CompilerType &type) |
If the given type was copied from another TypeSystemClang then copy over all missing information (e.g., the definition of a 'class' type). | |
bool | CompleteType (const CompilerType &compiler_type) |
bool | CompleteTagDecl (clang::TagDecl *decl) |
bool | CompleteTagDeclWithOrigin (clang::TagDecl *decl, clang::TagDecl *origin) |
bool | CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl) |
bool | CompleteAndFetchChildren (clang::QualType type) |
bool | RequireCompleteType (clang::QualType type) |
void | SetDeclOrigin (const clang::Decl *decl, clang::Decl *original_decl) |
Updates the internal origin-tracking information so that the given 'original' decl is from now on used to import additional information into the given decl. | |
std::optional< ClangASTMetadata > | GetDeclMetadata (const clang::Decl *decl) |
void | RegisterNamespaceMap (const clang::NamespaceDecl *decl, NamespaceMapSP &namespace_map) |
NamespaceMapSP | GetNamespaceMap (const clang::NamespaceDecl *decl) |
void | BuildNamespaceMap (const clang::NamespaceDecl *decl) |
void | InstallMapCompleter (clang::ASTContext *dst_ctx, MapCompleter &completer) |
void | ForgetDestination (clang::ASTContext *dst_ctx) |
void | ForgetSource (clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx) |
ASTContextMetadataSP | GetContextMetadata (clang::ASTContext *dst_ctx) |
ASTContextMetadataSP | MaybeGetContextMetadata (clang::ASTContext *dst_ctx) |
ImporterDelegateSP | GetDelegate (clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx) |
DeclOrigin | GetDeclOrigin (const clang::Decl *decl) |
Public Attributes | |
ContextMetadataMap | m_metadata_map |
clang::FileManager | m_file_manager |
RecordDeclToLayoutMap | m_record_decl_to_layout_map |
Manages and observes all Clang AST node importing in LLDB.
The ClangASTImporter takes care of two things:
Clang's ASTImporter takes care of importing types from one ASTContext to another. This class expands this concept by allowing copying from several ASTContext instances to several other ASTContext instances. Instead of constructing a new ASTImporter manually to copy over a type/decl, this class can be asked to do this. It will construct a ASTImporter for the caller (and will cache the ASTImporter instance for later use) and then perform the import.
This mainly prevents that a caller might construct several ASTImporter instances for the same source/target ASTContext combination. As the ASTImporter has an internal state that keeps track of already imported declarations and so on, using only one ASTImporter instance is more efficient and less error-prone than using multiple.
Definition at line 65 of file ClangASTImporter.h.
typedef std::shared_ptr<ASTContextMetadata> lldb_private::ClangASTImporter::ASTContextMetadataSP |
Definition at line 430 of file ClangASTImporter.h.
typedef llvm::DenseMap<const clang::ASTContext *, ASTContextMetadataSP> lldb_private::ClangASTImporter::ContextMetadataMap |
Definition at line 432 of file ClangASTImporter.h.
typedef llvm::DenseMap<clang::ASTContext *, ImporterDelegateSP> lldb_private::ClangASTImporter::DelegateMap |
Definition at line 362 of file ClangASTImporter.h.
typedef std::shared_ptr<ASTImporterDelegate> lldb_private::ClangASTImporter::ImporterDelegateSP |
Definition at line 361 of file ClangASTImporter.h.
typedef std::vector<NamespaceMapItem> lldb_private::ClangASTImporter::NamespaceMap |
Definition at line 199 of file ClangASTImporter.h.
typedef std::pair<lldb::ModuleSP, CompilerDeclContext> lldb_private::ClangASTImporter::NamespaceMapItem |
Definition at line 198 of file ClangASTImporter.h.
typedef std::shared_ptr<NamespaceMap> lldb_private::ClangASTImporter::NamespaceMapSP |
Definition at line 200 of file ClangASTImporter.h.
typedef llvm::DenseMap<const clang::NamespaceDecl *, NamespaceMapSP> lldb_private::ClangASTImporter::NamespaceMetaMap |
Definition at line 364 of file ClangASTImporter.h.
typedef llvm::DenseMap<const clang::RecordDecl *, LayoutInfo> lldb_private::ClangASTImporter::RecordDeclToLayoutMap |
Definition at line 476 of file ClangASTImporter.h.
|
inline |
Definition at line 79 of file ClangASTImporter.h.
void ClangASTImporter::BuildNamespaceMap | ( | const clang::NamespaceDecl * | decl | ) |
Definition at line 998 of file ClangASTImporter.cpp.
References GetContextMetadata(), and GetNamespaceMap().
bool ClangASTImporter::CanImport | ( | const CompilerType & | type | ) |
Returns true iff the given type was copied from another TypeSystemClang and the original type in this other TypeSystemClang might contain additional information (e.g., the definition of a 'class' type) that could be imported.
Definition at line 361 of file ClangASTImporter.cpp.
References CanImport(), lldb_private::ClangUtil::GetCanonicalQualType(), GetDeclOrigin(), lldb_private::CompilerType::GetTypeSystem(), lldb_private::ClangUtil::IsClangType(), and lldb_private::ClangUtil::RemoveFastQualifiers().
Referenced by CanImport(), lldb_private::plugin::dwarf::SymbolFileDWARF::CompleteType(), lldb_private::npdb::SymbolFileNativePDB::CompleteType(), CompleteType(), lldb_private::plugin::dwarf::SymbolFileDWARF::HasForwardDeclForCompilerType(), and PrepareContextToReceiveMembers().
bool ClangASTImporter::CompleteAndFetchChildren | ( | clang::QualType | type | ) |
Definition at line 856 of file ClangASTImporter.cpp.
References lldb_private::ClangASTImporter::DeclOrigin::ctx, lldb_private::ClangASTImporter::DeclOrigin::decl, lldb_private::Expressions, GetDeclOrigin(), GetDelegate(), lldb_private::GetLog(), LLDB_LOG_ERROR, RequireCompleteType(), and lldb_private::ClangASTImporter::DeclOrigin::Valid().
Referenced by Import().
bool ClangASTImporter::CompleteObjCInterfaceDecl | ( | clang::ObjCInterfaceDecl * | interface_decl | ) |
Definition at line 834 of file ClangASTImporter.cpp.
References lldb_private::ClangASTImporter::DeclOrigin::ctx, lldb_private::ClangASTImporter::DeclOrigin::decl, lldb_private::TypeSystemClang::GetCompleteDecl(), GetDeclOrigin(), GetDelegate(), RequireCompleteType(), and lldb_private::ClangASTImporter::DeclOrigin::Valid().
Referenced by RequireCompleteType().
bool ClangASTImporter::CompleteTagDecl | ( | clang::TagDecl * | decl | ) |
Definition at line 795 of file ClangASTImporter.cpp.
References lldb_private::ClangASTImporter::DeclOrigin::ctx, lldb_private::ClangASTImporter::DeclOrigin::decl, lldb_private::TypeSystemClang::GetCompleteDecl(), GetDeclOrigin(), GetDelegate(), and lldb_private::ClangASTImporter::DeclOrigin::Valid().
Referenced by MaybeCompleteReturnType(), and RequireCompleteType().
bool ClangASTImporter::CompleteTagDeclWithOrigin | ( | clang::TagDecl * | decl, |
clang::TagDecl * | origin | ||
) |
Definition at line 815 of file ClangASTImporter.cpp.
References lldb_private::TypeSystemClang::GetCompleteDecl(), GetContextMetadata(), and GetDelegate().
bool ClangASTImporter::CompleteType | ( | const CompilerType & | compiler_type | ) |
Definition at line 508 of file ClangASTImporter.cpp.
References CanImport(), lldb_private::TypeSystemClang::CompleteTagDeclarationDefinition(), lldb_private::CompilerType::GetOpaqueQualType(), Import(), and lldb_private::TypeSystemClang::SetHasExternalStorage().
Referenced by lldb_private::plugin::dwarf::SymbolFileDWARF::CompleteType(), lldb_private::npdb::SymbolFileNativePDB::CompleteType(), and PDBASTParser::CompleteTypeFromPDB().
clang::Decl * ClangASTImporter::CopyDecl | ( | clang::ASTContext * | dst_ctx, |
clang::Decl * | decl | ||
) |
Definition at line 69 of file ClangASTImporter.cpp.
References lldb_private::Expressions, GetDeclMetadata(), GetDelegate(), lldb_private::GetLog(), LLDB_INVALID_UID, LLDB_LOG, and LLDB_LOG_ERROR.
Referenced by DeportDecl(), lldb_private::DeclFromUser< D >::Import(), and lldb_private::ClangASTImporter::ASTImporterDelegate::ImportImpl().
CompilerType ClangASTImporter::CopyType | ( | TypeSystemClang & | dst, |
const CompilerType & | src_type | ||
) |
Copies the given type and the respective declarations to the destination type system.
This function does a shallow copy and requires that the target AST has an ExternalASTSource which queries this ClangASTImporter instance for any additional information that is maybe lacking in the shallow copy. This also means that the type system of src_type can not be deleted after this function has been called. If you need to delete the source type system you either need to delete the destination type system first or use ClangASTImporter::DeportType.
Definition at line 36 of file ClangASTImporter.cpp.
References lldb_private::CompilerType::TypeSystemSPWrapper::dyn_cast_or_null(), lldb_private::Expressions, lldb_private::TypeSystemClang::getASTContext(), GetDelegate(), lldb_private::GetLog(), lldb_private::ClangUtil::GetQualType(), lldb_private::CompilerType::GetTypeSystem(), and LLDB_LOG_ERROR.
Referenced by DeportType(), and DWARFASTParserClang::ParseTypeFromClangModule().
clang::Decl * ClangASTImporter::DeportDecl | ( | clang::ASTContext * | dst_ctx, |
clang::Decl * | decl | ||
) |
Copies the given decl to the destination type system.
Definition at line 330 of file ClangASTImporter.cpp.
References CopyDecl(), lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, and DeclContextOverride::OverrideAllDeclsFromContainingFunction().
CompilerType ClangASTImporter::DeportType | ( | TypeSystemClang & | dst, |
const CompilerType & | src_type | ||
) |
Copies the given type and the respective declarations to the destination type system.
Unlike CopyType this function ensures that types/declarations which are originally from the AST of src_type are fully copied over. The type system of src_type can safely be deleted after calling this function.
Definition at line 306 of file ClangASTImporter.cpp.
References CopyType(), lldb_private::CompilerType::TypeSystemSPWrapper::dyn_cast_or_null(), lldb_private::Expressions, lldb_private::TypeSystemClang::getASTContext(), lldb_private::GetLog(), lldb_private::CompilerType::GetOpaqueQualType(), lldb_private::ClangUtil::GetQualType(), lldb_private::CompilerType::GetTypeName(), lldb_private::CompilerType::GetTypeSystem(), LLDB_LOG, and DeclContextOverride::OverrideAllDeclsFromContainingFunction().
void ClangASTImporter::ForgetDestination | ( | clang::ASTContext * | dst_ctx | ) |
Definition at line 1024 of file ClangASTImporter.cpp.
References lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, and m_metadata_map.
void ClangASTImporter::ForgetSource | ( | clang::ASTContext * | dst_ctx, |
clang::ASTContext * | src_ctx | ||
) |
Definition at line 1034 of file ClangASTImporter.cpp.
References lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, and MaybeGetContextMetadata().
Referenced by lldb_private::ScratchTypeSystemClang::ForgetSource().
|
inline |
Definition at line 436 of file ClangASTImporter.h.
References m_metadata_map.
Referenced by BuildNamespaceMap(), CompleteTagDeclWithOrigin(), GetDeclOrigin(), GetDelegate(), GetNamespaceMap(), RegisterNamespaceMap(), and SetDeclOrigin().
std::optional< ClangASTMetadata > ClangASTImporter::GetDeclMetadata | ( | const clang::Decl * | decl | ) |
Definition at line 953 of file ClangASTImporter.cpp.
References lldb_private::ClangASTImporter::DeclOrigin::ctx, lldb_private::ClangASTImporter::DeclOrigin::decl, lldb_private::TypeSystemClang::GetASTContext(), GetDeclOrigin(), lldb_private::TypeSystemClang::GetMetadata(), and lldb_private::ClangASTImporter::DeclOrigin::Valid().
Referenced by CopyDecl(), and lldb_private::ClangASTImporter::ASTImporterDelegate::ImportImpl().
ClangASTImporter::DeclOrigin ClangASTImporter::GetDeclOrigin | ( | const clang::Decl * | decl | ) |
Definition at line 965 of file ClangASTImporter.cpp.
References GetContextMetadata().
Referenced by CanImport(), CompleteAndFetchChildren(), CompleteObjCInterfaceDecl(), CompleteTagDecl(), GetDeclMetadata(), lldb_private::DeclFromParser< D >::GetOrigin(), Import(), lldb_private::ClangASTImporter::ASTImporterDelegate::ImportImpl(), and LayoutRecordType().
|
inline |
Definition at line 456 of file ClangASTImporter.h.
References GetContextMetadata().
Referenced by CompleteAndFetchChildren(), CompleteObjCInterfaceDecl(), CompleteTagDecl(), CompleteTagDeclWithOrigin(), CopyDecl(), and CopyType().
ClangASTImporter::NamespaceMapSP ClangASTImporter::GetNamespaceMap | ( | const clang::NamespaceDecl * | decl | ) |
Definition at line 986 of file ClangASTImporter.cpp.
References GetContextMetadata().
Referenced by BuildNamespaceMap().
bool ClangASTImporter::Import | ( | const CompilerType & | type | ) |
If the given type was copied from another TypeSystemClang then copy over all missing information (e.g., the definition of a 'class' type).
Definition at line 435 of file ClangASTImporter.cpp.
References CompleteAndFetchChildren(), lldb_private::ClangUtil::GetCanonicalQualType(), GetDeclOrigin(), lldb_private::CompilerType::GetTypeSystem(), Import(), lldb_private::ClangUtil::IsClangType(), and lldb_private::ClangUtil::RemoveFastQualifiers().
Referenced by CompleteType(), Import(), lldb_private::ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(), and lldb_private::ClangASTImporter::ASTImporterDelegate::ImportImpl().
bool ClangASTImporter::importRecordLayoutFromOrigin | ( | const clang::RecordDecl * | record, |
uint64_t & | size, | ||
uint64_t & | alignment, | ||
llvm::DenseMap< const clang::FieldDecl *, uint64_t > & | field_offsets, | ||
llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > & | base_offsets, | ||
llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > & | vbase_offsets | ||
) |
If record has a valid origin, this function copies that origin's layout into this ClangASTImporter instance.
[in] | record | The decl whose layout we're calculating. |
[out] | size | Size of record in bytes. |
[out] | alignment | Alignment of record in bytes. |
[out] | field_offsets | Offsets of fields of record. |
[out] | base_offsets | Offsets of base classes of record. |
[out] | vbase_offsets | Offsets of virtual base classes of record. |
Definition at line 627 of file ClangASTImporter.cpp.
References lldb_private::TaggedASTDecl< D >::decl, lldb_private::Expressions, lldb_private::TypeSystemClang::GetASTContext(), lldb_private::TypeSystemClang::GetCompleteDecl(), lldb_private::GetLog(), lldb_private::DeclFromParser< D >::GetOrigin(), ImportOffsetMap(), lldb_private::TaggedASTDecl< D >::IsInvalid(), lldb_private::TaggedASTDecl< D >::IsValid(), and LLDB_LOG.
Referenced by LayoutRecordType().
|
inline |
Definition at line 222 of file ClangASTImporter.h.
References m_metadata_map.
bool ClangASTImporter::LayoutRecordType | ( | const clang::RecordDecl * | record_decl, |
uint64_t & | bit_size, | ||
uint64_t & | alignment, | ||
llvm::DenseMap< const clang::FieldDecl *, uint64_t > & | field_offsets, | ||
llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > & | base_offsets, | ||
llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > & | vbase_offsets | ||
) |
Definition at line 752 of file ClangASTImporter.cpp.
References GetDeclOrigin(), importRecordLayoutFromOrigin(), m_record_decl_to_layout_map, and lldb_private::ClangASTImporter::DeclOrigin::Valid().
Referenced by lldb_private::TypeSystemClang::LayoutRecordType().
|
inline |
Definition at line 448 of file ClangASTImporter.h.
References m_metadata_map.
Referenced by ForgetSource().
void ClangASTImporter::RegisterNamespaceMap | ( | const clang::NamespaceDecl * | decl, |
NamespaceMapSP & | namespace_map | ||
) |
Definition at line 978 of file ClangASTImporter.cpp.
References GetContextMetadata().
bool ClangASTImporter::RequireCompleteType | ( | clang::QualType | type | ) |
Definition at line 926 of file ClangASTImporter.cpp.
References CompleteObjCInterfaceDecl(), CompleteTagDecl(), and RequireCompleteType().
Referenced by CompleteAndFetchChildren(), CompleteObjCInterfaceDecl(), DWARFASTParserClang::ParseTypeFromClangModule(), PrepareContextToReceiveMembers(), and RequireCompleteType().
void ClangASTImporter::SetDeclOrigin | ( | const clang::Decl * | decl, |
clang::Decl * | original_decl | ||
) |
Updates the internal origin-tracking information so that the given 'original' decl is from now on used to import additional information into the given decl.
Usually the origin-tracking in the ClangASTImporter is automatically updated when a declaration is imported, so the only valid reason to ever call this is if there is a 'better' original decl and the target decl is only a shallow clone that lacks any contents.
Definition at line 971 of file ClangASTImporter.cpp.
References GetContextMetadata().
void ClangASTImporter::SetRecordLayout | ( | clang::RecordDecl * | decl, |
const LayoutInfo & | layout | ||
) |
Sets the layout for the given RecordDecl.
The layout will later be used by Clang's during code generation. Not calling this function for a RecordDecl will cause that Clang's codegen tries to layout the record by itself.
decl | The RecordDecl to set the layout for. |
layout | The layout for the record. |
Definition at line 790 of file ClangASTImporter.cpp.
References m_record_decl_to_layout_map.
Referenced by lldb_private::npdb::UdtRecordCompleter::AddMember(), lldb_private::npdb::UdtRecordCompleter::complete(), DWARFASTParserClang::CompleteRecordType(), and PDBASTParser::CompleteTypeFromUDT().
clang::FileManager lldb_private::ClangASTImporter::m_file_manager |
Definition at line 474 of file ClangASTImporter.h.
ContextMetadataMap lldb_private::ClangASTImporter::m_metadata_map |
Definition at line 434 of file ClangASTImporter.h.
Referenced by ForgetDestination(), GetContextMetadata(), InstallMapCompleter(), and MaybeGetContextMetadata().
RecordDeclToLayoutMap lldb_private::ClangASTImporter::m_record_decl_to_layout_map |
Definition at line 478 of file ClangASTImporter.h.
Referenced by LayoutRecordType(), and SetRecordLayout().