LLDB mainline
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
lldb_private::ClangASTImporter Class Reference

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, CompilerDeclContextNamespaceMapItem
 
typedef std::vector< NamespaceMapItemNamespaceMap
 
typedef std::shared_ptr< NamespaceMapNamespaceMapSP
 
typedef std::shared_ptr< ASTImporterDelegateImporterDelegateSP
 
typedef llvm::DenseMap< clang::ASTContext *, ImporterDelegateSPDelegateMap
 
typedef llvm::DenseMap< const clang::NamespaceDecl *, NamespaceMapSPNamespaceMetaMap
 
typedef std::shared_ptr< ASTContextMetadataASTContextMetadataSP
 
typedef llvm::DenseMap< const clang::ASTContext *, ASTContextMetadataSPContextMetadataMap
 
typedef llvm::DenseMap< const clang::RecordDecl *, LayoutInfoRecordDeclToLayoutMap
 

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.
 
ClangASTMetadataGetDeclMetadata (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
 

Detailed Description

Manages and observes all Clang AST node importing in LLDB.

The ClangASTImporter takes care of two things:

  1. Keeps track of all ASTImporter instances in LLDB.

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.

  1. Keeps track of from where declarations were imported (origin-tracking). The ASTImporter instances in this class usually only performa a minimal import, i.e., only a shallow copy is made that is filled out on demand when more information is requested later on. This requires record-keeping of where any shallow clone originally came from so that the right original declaration can be found and used as the source of any missing information.

Definition at line 65 of file ClangASTImporter.h.

Member Typedef Documentation

◆ ASTContextMetadataSP

Definition at line 430 of file ClangASTImporter.h.

◆ ContextMetadataMap

typedef llvm::DenseMap<const clang::ASTContext *, ASTContextMetadataSP> lldb_private::ClangASTImporter::ContextMetadataMap

Definition at line 432 of file ClangASTImporter.h.

◆ DelegateMap

typedef llvm::DenseMap<clang::ASTContext *, ImporterDelegateSP> lldb_private::ClangASTImporter::DelegateMap

Definition at line 362 of file ClangASTImporter.h.

◆ ImporterDelegateSP

Definition at line 361 of file ClangASTImporter.h.

◆ NamespaceMap

Definition at line 199 of file ClangASTImporter.h.

◆ NamespaceMapItem

Definition at line 198 of file ClangASTImporter.h.

◆ NamespaceMapSP

Definition at line 200 of file ClangASTImporter.h.

◆ NamespaceMetaMap

typedef llvm::DenseMap<const clang::NamespaceDecl *, NamespaceMapSP> lldb_private::ClangASTImporter::NamespaceMetaMap

Definition at line 364 of file ClangASTImporter.h.

◆ RecordDeclToLayoutMap

typedef llvm::DenseMap<const clang::RecordDecl *, LayoutInfo> lldb_private::ClangASTImporter::RecordDeclToLayoutMap

Definition at line 476 of file ClangASTImporter.h.

Constructor & Destructor Documentation

◆ ClangASTImporter()

lldb_private::ClangASTImporter::ClangASTImporter ( )
inline

Definition at line 79 of file ClangASTImporter.h.

Member Function Documentation

◆ BuildNamespaceMap()

void ClangASTImporter::BuildNamespaceMap ( const clang::NamespaceDecl *  decl)

Definition at line 998 of file ClangASTImporter.cpp.

References GetContextMetadata(), and GetNamespaceMap().

◆ CanImport()

bool ClangASTImporter::CanImport ( const CompilerType type)

◆ CompleteAndFetchChildren()

bool ClangASTImporter::CompleteAndFetchChildren ( clang::QualType  type)

◆ CompleteObjCInterfaceDecl()

bool ClangASTImporter::CompleteObjCInterfaceDecl ( clang::ObjCInterfaceDecl *  interface_decl)

◆ CompleteTagDecl()

bool ClangASTImporter::CompleteTagDecl ( clang::TagDecl *  decl)

◆ CompleteTagDeclWithOrigin()

bool ClangASTImporter::CompleteTagDeclWithOrigin ( clang::TagDecl *  decl,
clang::TagDecl *  origin 
)

◆ CompleteType()

bool ClangASTImporter::CompleteType ( const CompilerType compiler_type)

◆ CopyDecl()

clang::Decl * ClangASTImporter::CopyDecl ( clang::ASTContext *  dst_ctx,
clang::Decl *  decl 
)

◆ CopyType()

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.

See also
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().

◆ DeportDecl()

clang::Decl * ClangASTImporter::DeportDecl ( clang::ASTContext *  dst_ctx,
clang::Decl *  decl 
)

Copies the given decl to the destination type system.

See also
ClangASTImporter::DeportType

Definition at line 331 of file ClangASTImporter.cpp.

References CopyDecl(), lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, and DeclContextOverride::OverrideAllDeclsFromContainingFunction().

◆ DeportType()

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.

See also
ClangASTImporter::CopyType

Definition at line 307 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().

◆ ForgetDestination()

void ClangASTImporter::ForgetDestination ( clang::ASTContext *  dst_ctx)

◆ ForgetSource()

void ClangASTImporter::ForgetSource ( clang::ASTContext *  dst_ctx,
clang::ASTContext *  src_ctx 
)

◆ GetContextMetadata()

ASTContextMetadataSP lldb_private::ClangASTImporter::GetContextMetadata ( clang::ASTContext *  dst_ctx)
inline

◆ GetDeclMetadata()

ClangASTMetadata * ClangASTImporter::GetDeclMetadata ( const clang::Decl *  decl)

◆ GetDeclOrigin()

ClangASTImporter::DeclOrigin ClangASTImporter::GetDeclOrigin ( const clang::Decl *  decl)

◆ GetDelegate()

ImporterDelegateSP lldb_private::ClangASTImporter::GetDelegate ( clang::ASTContext *  dst_ctx,
clang::ASTContext *  src_ctx 
)
inline

◆ GetNamespaceMap()

ClangASTImporter::NamespaceMapSP ClangASTImporter::GetNamespaceMap ( const clang::NamespaceDecl *  decl)

Definition at line 986 of file ClangASTImporter.cpp.

References GetContextMetadata().

Referenced by BuildNamespaceMap().

◆ Import()

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).

Returns
True iff an original type in another TypeSystemClang was found. Note: Does not return false if an original type was found but no information was imported over.
See also
ClangASTImporter::Import

Definition at line 436 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().

◆ importRecordLayoutFromOrigin()

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.

Parameters
[in]recordThe decl whose layout we're calculating.
[out]sizeSize of record in bytes.
[out]alignmentAlignment of record in bytes.
[out]field_offsetsOffsets of fields of record.
[out]base_offsetsOffsets of base classes of record.
[out]vbase_offsetsOffsets of virtual base classes of record.
Returns
Returns 'false' if no valid origin was found for record or this function failed to import the layout from the origin. Otherwise, returns 'true' and the offsets/size/alignment are valid for use.

Definition at line 628 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().

◆ InstallMapCompleter()

void lldb_private::ClangASTImporter::InstallMapCompleter ( clang::ASTContext *  dst_ctx,
MapCompleter completer 
)
inline

Definition at line 222 of file ClangASTImporter.h.

References m_metadata_map.

◆ LayoutRecordType()

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 
)

◆ MaybeGetContextMetadata()

ASTContextMetadataSP lldb_private::ClangASTImporter::MaybeGetContextMetadata ( clang::ASTContext *  dst_ctx)
inline

Definition at line 448 of file ClangASTImporter.h.

References m_metadata_map.

Referenced by ForgetSource().

◆ RegisterNamespaceMap()

void ClangASTImporter::RegisterNamespaceMap ( const clang::NamespaceDecl *  decl,
NamespaceMapSP namespace_map 
)

Definition at line 978 of file ClangASTImporter.cpp.

References GetContextMetadata().

◆ RequireCompleteType()

bool ClangASTImporter::RequireCompleteType ( clang::QualType  type)

◆ SetDeclOrigin()

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().

◆ SetRecordLayout()

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.

Parameters
declThe RecordDecl to set the layout for.
layoutThe layout for the record.

Definition at line 791 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(), PDBASTParser::CompleteTypeFromUDT(), and DWARFASTParserClang::ParseStructureLikeDIE().

Member Data Documentation

◆ m_file_manager

clang::FileManager lldb_private::ClangASTImporter::m_file_manager

Definition at line 474 of file ClangASTImporter.h.

◆ m_metadata_map

ContextMetadataMap lldb_private::ClangASTImporter::m_metadata_map

◆ m_record_decl_to_layout_map

RecordDeclToLayoutMap lldb_private::ClangASTImporter::m_record_decl_to_layout_map

Definition at line 478 of file ClangASTImporter.h.

Referenced by LayoutRecordType(), and SetRecordLayout().


The documentation for this class was generated from the following files: