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>

Collaboration diagram for lldb_private::ClangASTImporter:
Collaboration graph
[legend]

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. More...
 
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. More...
 
clang::Decl * DeportDecl (clang::ASTContext *dst_ctx, clang::Decl *decl)
 Copies the given decl to the destination type system. More...
 
void SetRecordLayout (clang::RecordDecl *decl, const LayoutInfo &layout)
 Sets the layout for the given RecordDecl. More...
 
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 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. More...
 
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). More...
 
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. More...
 
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 64 of file ClangASTImporter.h.

Member Typedef Documentation

◆ ASTContextMetadataSP

Definition at line 408 of file ClangASTImporter.h.

◆ ContextMetadataMap

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

Definition at line 410 of file ClangASTImporter.h.

◆ DelegateMap

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

Definition at line 340 of file ClangASTImporter.h.

◆ ImporterDelegateSP

Definition at line 339 of file ClangASTImporter.h.

◆ NamespaceMap

Definition at line 177 of file ClangASTImporter.h.

◆ NamespaceMapItem

Definition at line 176 of file ClangASTImporter.h.

◆ NamespaceMapSP

Definition at line 178 of file ClangASTImporter.h.

◆ NamespaceMetaMap

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

Definition at line 342 of file ClangASTImporter.h.

◆ RecordDeclToLayoutMap

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

Definition at line 454 of file ClangASTImporter.h.

Constructor & Destructor Documentation

◆ ClangASTImporter()

lldb_private::ClangASTImporter::ClangASTImporter ( )
inline

Definition at line 78 of file ClangASTImporter.h.

Member Function Documentation

◆ BuildNamespaceMap()

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

Definition at line 755 of file ClangASTImporter.cpp.

References string().

◆ CanImport()

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.

See also
ClangASTImporter::Import

Definition at line 358 of file ClangASTImporter.cpp.

References lldb_private::ClangUtil::GetCanonicalQualType(), lldb_private::CompilerType::GetTypeSystem(), lldb_private::ClangUtil::IsClangType(), and lldb_private::ClangUtil::RemoveFastQualifiers().

Referenced by SymbolFileDWARF::CompleteType(), SymbolFileDWARF::HasForwardDeclForClangType(), and PrepareContextToReceiveMembers().

◆ 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 31 of file ClangASTImporter.cpp.

References lldb_private::TypeSystemClang::getASTContext(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::ClangUtil::GetQualType(), lldb_private::CompilerType::GetTypeSystem(), LIBLLDB_LOG_EXPRESSIONS, and LLDB_LOG_ERROR.

Referenced by DWARFASTParserClang::ParseTypeFromClangModule().

◆ DeportDecl()

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

◆ 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 304 of file ClangASTImporter.cpp.

References lldb_private::TypeSystemClang::getASTContext(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::CompilerType::GetOpaqueQualType(), lldb_private::ClangUtil::GetQualType(), lldb_private::CompilerType::GetTypeName(), lldb_private::CompilerType::GetTypeSystem(), LIBLLDB_LOG_EXPRESSIONS, 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

Definition at line 414 of file ClangASTImporter.h.

References m_metadata_map.

Referenced by GetDelegate().

◆ GetDeclMetadata()

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

◆ GetDeclOrigin()

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

Definition at line 722 of file ClangASTImporter.cpp.

◆ GetDelegate()

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

Definition at line 434 of file ClangASTImporter.h.

References GetContextMetadata().

◆ GetNamespaceMap()

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

Definition at line 743 of file ClangASTImporter.cpp.

◆ 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 432 of file ClangASTImporter.cpp.

References lldb_private::ClangUtil::GetCanonicalQualType(), lldb_private::CompilerType::GetTypeSystem(), lldb_private::ClangUtil::IsClangType(), and lldb_private::ClangUtil::RemoveFastQualifiers().

◆ InstallMapCompleter()

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

Definition at line 200 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 426 of file ClangASTImporter.h.

References m_metadata_map.

◆ RegisterNamespaceMap()

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

Definition at line 735 of file ClangASTImporter.cpp.

◆ 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 728 of file ClangASTImporter.cpp.

◆ 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 548 of file ClangASTImporter.cpp.

Referenced by 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 452 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 456 of file ClangASTImporter.h.


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