LLDB mainline
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
lldb_private::ClangASTSource Class Reference

Provider for named objects defined in the debug info for Clang. More...

#include "lldb/Expression/ClangASTSource.h"

Inheritance diagram for lldb_private::ClangASTSource:
Inheritance graph
[legend]

Classes

class  ClangASTSourceProxy
 "lldb/Expression/ClangASTSource.h" Proxy for ClangASTSource More...
 

Public Member Functions

 ClangASTSource (const lldb::TargetSP &target, const std::shared_ptr< ClangASTImporter > &importer)
 Constructor.
 
 ~ClangASTSource () override
 Destructor.
 
clang::Decl * GetExternalDecl (clang::GlobalDeclID) override
 Interface stubs.
 
clang::Stmt * GetExternalDeclStmt (uint64_t) override
 
clang::Selector GetExternalSelector (uint32_t) override
 
uint32_t GetNumExternalSelectors () override
 
clang::CXXBaseSpecifier * GetExternalCXXBaseSpecifiers (uint64_t Offset) override
 
void MaterializeVisibleDecls (const clang::DeclContext *DC)
 
void InstallASTContext (TypeSystemClang &ast_context)
 
bool FindExternalVisibleDeclsByName (const clang::DeclContext *DC, clang::DeclarationName Name) override
 Look up all Decls that match a particular name.
 
void FindExternalLexicalDecls (const clang::DeclContext *DC, llvm::function_ref< bool(clang::Decl::Kind)> IsKindWeWant, llvm::SmallVectorImpl< clang::Decl * > &Decls) override
 Enumerate all Decls in a given lexical context.
 
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
 Specify the layout of the contents of a RecordDecl.
 
void CompleteType (clang::TagDecl *Tag) override
 Complete a TagDecl.
 
void CompleteType (clang::ObjCInterfaceDecl *Class) override
 Complete an ObjCInterfaceDecl.
 
void StartTranslationUnit (clang::ASTConsumer *Consumer) override
 Called on entering a translation unit.
 
void CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, ConstString name, ClangASTImporter::NamespaceMapSP &parent_map) const override
 Look up the modules containing a given namespace and put the appropriate entries in the namespace map.
 
clang::NamespaceDecl * AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
 
virtual void FindExternalVisibleDecls (NameSearchContext &context)
 The worker function for FindExternalVisibleDeclsByName.
 
clang::Sema * getSema ()
 
void SetLookupsEnabled (bool lookups_enabled)
 
bool GetLookupsEnabled ()
 
clang::ExternalASTSource * CreateProxy ()
 
bool IgnoreName (const ConstString name, bool ignore_all_dollar_names)
 Returns true if a name should be ignored by name lookup.
 
clang::Decl * CopyDecl (clang::Decl *src_decl)
 Copies a single Decl into the parser's AST context.
 
ClangASTImporter::DeclOrigin GetDeclOrigin (const clang::Decl *decl)
 Determined the origin of a single Decl, if it can be found.
 
TypeSystemClangGetTypeSystem () const
 Returns the TypeSystem that uses this ClangASTSource instance as it's ExternalASTSource.
 
- Public Member Functions inherited from lldb_private::ClangASTImporter::MapCompleter
virtual ~MapCompleter ()
 
virtual void CompleteNamespaceMap (NamespaceMapSP &namespace_map, ConstString name, NamespaceMapSP &parent_map) const =0
 

Protected Member Functions

clang::ObjCInterfaceDecl * GetCompleteObjCInterface (const clang::ObjCInterfaceDecl *interface_decl)
 Look for the complete version of an Objective-C interface, and return it if found.
 
void FindExternalVisibleDecls (NameSearchContext &context, lldb::ModuleSP module, CompilerDeclContext &namespace_decl)
 Find all entities matching a given name in a given module, using a NameSearchContext to make Decls for them.
 
void FindObjCMethodDecls (NameSearchContext &context)
 Find all Objective-C methods matching a given selector.
 
void FindObjCPropertyAndIvarDecls (NameSearchContext &context)
 Find all Objective-C properties and ivars with a given name.
 
void LookupInNamespace (NameSearchContext &context)
 Performs lookup into a namespace.
 
CompilerType GuardedCopyType (const CompilerType &src_type)
 A wrapper for TypeSystemClang::CopyType that sets a flag that indicates that we should not respond to queries during import.
 
std::shared_ptr< ClangModulesDeclVendorGetClangModulesDeclVendor ()
 
bool FindObjCMethodDeclsWithOrigin (NameSearchContext &context, clang::ObjCInterfaceDecl *original_interface_decl, const char *log_info)
 
void FindDeclInModules (NameSearchContext &context, ConstString name)
 
void FindDeclInObjCRuntime (NameSearchContext &context, ConstString name)
 
void FillNamespaceMap (NameSearchContext &context, lldb::ModuleSP module_sp, const CompilerDeclContext &namespace_decl)
 Fills the namespace map of the given NameSearchContext.
 
clang::TagDecl * FindCompleteType (const clang::TagDecl *decl)
 

Protected Attributes

bool m_lookups_enabled
 
const lldb::TargetSP m_target
 The target to use in finding variables and types.
 
clang::ASTContext * m_ast_context
 The AST context requests are coming in for.
 
TypeSystemClangm_clang_ast_context
 The TypeSystemClang for m_ast_context.
 
clang::FileManager * m_file_manager
 The file manager paired with the AST context.
 
std::shared_ptr< ClangASTImporterm_ast_importer_sp
 The target's AST importer.
 
std::set< const clang::Decl * > m_active_lexical_decls
 
std::set< const char * > m_active_lookups
 

Private Member Functions

bool FindObjCPropertyAndIvarDeclsWithOrigin (NameSearchContext &context, DeclFromUser< const clang::ObjCInterfaceDecl > &origin_iface_decl)
 

Friends

struct NameSearchContext
 

Detailed Description

Provider for named objects defined in the debug info for Clang.

As Clang parses an expression, it may encounter names that are not defined inside the expression, including variables, functions, and types. Clang knows the name it is looking for, but nothing else. The ExternalSemaSource class provides Decls (VarDecl, FunDecl, TypeDecl) to Clang for these names, consulting the ClangExpressionDeclMap to do the actual lookups.

Definition at line 33 of file ClangASTSource.h.

Constructor & Destructor Documentation

◆ ClangASTSource()

ClangASTSource::ClangASTSource ( const lldb::TargetSP target,
const std::shared_ptr< ClangASTImporter > &  importer 
)

Constructor.

Initializes class variables.

Parameters
[in]targetA reference to the target containing debug information to use.
[in]importerThe ClangASTImporter to use.

Definition at line 53 of file ClangASTSource.cpp.

References m_ast_importer_sp.

◆ ~ClangASTSource()

ClangASTSource::~ClangASTSource ( )
override

Member Function Documentation

◆ AddNamespace()

NamespaceDecl * ClangASTSource::AddNamespace ( NameSearchContext context,
ClangASTImporter::NamespaceMapSP namespace_decls 
)

◆ CompleteNamespaceMap()

void ClangASTSource::CompleteNamespaceMap ( ClangASTImporter::NamespaceMapSP namespace_map,
ConstString  name,
ClangASTImporter::NamespaceMapSP parent_map 
) const
overridevirtual

Look up the modules containing a given namespace and put the appropriate entries in the namespace map.

Parameters
[in]namespace_mapThe map to be completed.
[in]nameThe name of the namespace to be found.
[in]parent_mapThe map for the namespace's parent namespace, if there is one.

Implements lldb_private::ClangASTImporter::MapCompleter.

Definition at line 1360 of file ClangASTSource.cpp.

References lldb_private::Expressions, lldb_private::SymbolFile::FindNamespace(), lldb_private::TypeSystemClang::getDisplayName(), lldb_private::GetLog(), LLDB_LOG, m_ast_context, m_clang_ast_context, and m_target.

◆ CompleteType() [1/2]

void ClangASTSource::CompleteType ( clang::ObjCInterfaceDecl *  Class)
override

◆ CompleteType() [2/2]

void lldb_private::ClangASTSource::CompleteType ( clang::TagDecl *  Tag)
override

Complete a TagDecl.

Parameters
[in]TagThe Decl to be completed in place.

Referenced by lldb_private::ClangExpressionDeclMap::AddExpressionVariable(), CompleteType(), and lldb_private::ClangASTSource::ClangASTSourceProxy::CompleteType().

◆ CopyDecl()

clang::Decl * ClangASTSource::CopyDecl ( clang::Decl *  src_decl)

◆ CreateProxy()

clang::ExternalASTSource * lldb_private::ClangASTSource::CreateProxy ( )
inline

◆ FillNamespaceMap()

void ClangASTSource::FillNamespaceMap ( NameSearchContext context,
lldb::ModuleSP  module_sp,
const CompilerDeclContext namespace_decl 
)
protected

Fills the namespace map of the given NameSearchContext.

Parameters
contextThe NameSearchContext with the namespace map to fill.
module_spThe module to search for namespaces or a nullptr if the current target should be searched.
namespace_declThe DeclContext in which to search for namespaces.

Definition at line 645 of file ClangASTSource.cpp.

References lldb_private::Expressions, lldb_private::SymbolFile::FindNamespace(), lldb_private::GetLog(), IgnoreName(), LLDB_LOG, lldb_private::NameSearchContext::m_decl_context, lldb_private::NameSearchContext::m_decl_name, lldb_private::NameSearchContext::m_namespace_map, and m_target.

Referenced by FindExternalVisibleDecls().

◆ FindCompleteType()

TagDecl * ClangASTSource::FindCompleteType ( const clang::TagDecl *  decl)
protected

◆ FindDeclInModules()

void ClangASTSource::FindDeclInModules ( NameSearchContext context,
ConstString  name 
)
protected

◆ FindDeclInObjCRuntime()

void ClangASTSource::FindDeclInObjCRuntime ( NameSearchContext context,
ConstString  name 
)
protected

◆ FindExternalLexicalDecls()

void ClangASTSource::FindExternalLexicalDecls ( const clang::DeclContext *  DC,
llvm::function_ref< bool(clang::Decl::Kind)>  IsKindWeWant,
llvm::SmallVectorImpl< clang::Decl * > &  Decls 
)
override

Enumerate all Decls in a given lexical context.

Parameters
[in]DCThe DeclContext being searched.
[in]IsKindWeWantA callback function that returns true given the DeclKinds of desired Decls, and false otherwise.
[in]DeclsA vector that is filled in with matching Decls.

Definition at line 367 of file ClangASTSource.cpp.

References CopyDecl(), lldb_private::ClangASTImporter::DeclOrigin::ctx, lldb_private::ClangASTImporter::DeclOrigin::decl, lldb_private::ClangUtil::DumpDecl(), lldb_private::Expressions, GetCompleteObjCInterface(), lldb_private::TypeSystemClang::getDisplayName(), lldb_private::GetLog(), LLDB_LOG, m_active_lexical_decls, m_ast_context, m_ast_importer_sp, m_clang_ast_context, and lldb_private::ClangASTImporter::DeclOrigin::Valid().

Referenced by lldb_private::ClangASTSource::ClangASTSourceProxy::FindExternalLexicalDecls().

◆ FindExternalVisibleDecls() [1/2]

void ClangASTSource::FindExternalVisibleDecls ( NameSearchContext context)
virtual

◆ FindExternalVisibleDecls() [2/2]

void ClangASTSource::FindExternalVisibleDecls ( NameSearchContext context,
lldb::ModuleSP  module,
CompilerDeclContext namespace_decl 
)
protected

Find all entities matching a given name in a given module, using a NameSearchContext to make Decls for them.

Parameters
[in]contextThe NameSearchContext that can construct Decls for this name.
[in]moduleIf non-NULL, the module to query.
[in]namespace_declIf valid and module is non-NULL, the parent namespace.

Definition at line 577 of file ClangASTSource.cpp.

References lldb_private::NameSearchContext::AddTypeDecl(), lldb_private::Expressions, FillNamespaceMap(), FindDeclInModules(), FindDeclInObjCRuntime(), lldb_private::TypeResults::GetFirstType(), lldb_private::GetLog(), lldb_private::ConstString::GetStringRef(), GuardedCopyType(), IgnoreName(), LLDB_LOG, m_ast_context, lldb_private::NameSearchContext::m_decl_name, lldb_private::NameSearchContext::m_found_type, and m_target.

◆ FindExternalVisibleDeclsByName()

bool ClangASTSource::FindExternalVisibleDeclsByName ( const clang::DeclContext *  DC,
clang::DeclarationName  Name 
)
override

Look up all Decls that match a particular name.

Only handles Identifiers and DeclContexts that are either NamespaceDecls or TranslationUnitDecls. Calls SetExternalVisibleDeclsForName with the result.

The work for this function is done by void FindExternalVisibleDecls (NameSearchContext &);

Parameters
[in]DCThe DeclContext to register the found Decls in.
[in]NameThe name to find entries for.
Returns
Whatever SetExternalVisibleDeclsForName returns.

Definition at line 101 of file ClangASTSource.cpp.

References FindExternalVisibleDecls(), FindObjCMethodDecls(), lldb_private::ConstString::GetCString(), GetLookupsEnabled(), m_active_lookups, m_ast_context, m_clang_ast_context, and SetLookupsEnabled().

Referenced by lldb_private::ClangASTSource::ClangASTSourceProxy::FindExternalVisibleDeclsByName().

◆ FindObjCMethodDecls()

void ClangASTSource::FindObjCMethodDecls ( NameSearchContext context)
protected

◆ FindObjCMethodDeclsWithOrigin()

bool ClangASTSource::FindObjCMethodDeclsWithOrigin ( NameSearchContext context,
clang::ObjCInterfaceDecl *  original_interface_decl,
const char *  log_info 
)
protected

◆ FindObjCPropertyAndIvarDecls()

void ClangASTSource::FindObjCPropertyAndIvarDecls ( NameSearchContext context)
protected

◆ FindObjCPropertyAndIvarDeclsWithOrigin()

bool ClangASTSource::FindObjCPropertyAndIvarDeclsWithOrigin ( NameSearchContext context,
DeclFromUser< const clang::ObjCInterfaceDecl > &  origin_iface_decl 
)
private

◆ GetClangModulesDeclVendor()

std::shared_ptr< ClangModulesDeclVendor > ClangASTSource::GetClangModulesDeclVendor ( )
protected

◆ GetCompleteObjCInterface()

clang::ObjCInterfaceDecl * ClangASTSource::GetCompleteObjCInterface ( const clang::ObjCInterfaceDecl *  interface_decl)
protected

Look for the complete version of an Objective-C interface, and return it if found.

Parameters
[in]interface_declAn ObjCInterfaceDecl that may not be the complete one.
Returns
NULL if the complete interface couldn't be found; the complete interface otherwise.

Definition at line 326 of file ClangASTSource.cpp.

References lldb_private::ObjCLanguageRuntime::Get(), lldb_private::CompilerType::GetOpaqueQualType(), lldb_private::ObjCLanguageRuntime::LookupInCompleteClassCache(), and m_target.

Referenced by CompleteType(), FindExternalLexicalDecls(), FindObjCMethodDecls(), and FindObjCPropertyAndIvarDecls().

◆ GetDeclOrigin()

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

Determined the origin of a single Decl, if it can be found.

Parameters
[in]declThe Decl whose origin is to be found.
Returns
True if lookup succeeded; false otherwise.

Definition at line 1474 of file ClangASTSource.cpp.

References m_ast_importer_sp.

◆ GetExternalCXXBaseSpecifiers()

clang::CXXBaseSpecifier * lldb_private::ClangASTSource::GetExternalCXXBaseSpecifiers ( uint64_t  Offset)
inlineoverride

Definition at line 59 of file ClangASTSource.h.

◆ GetExternalDecl()

clang::Decl * lldb_private::ClangASTSource::GetExternalDecl ( clang::GlobalDeclID  )
inlineoverride

Interface stubs.

Definition at line 52 of file ClangASTSource.h.

◆ GetExternalDeclStmt()

clang::Stmt * lldb_private::ClangASTSource::GetExternalDeclStmt ( uint64_t  )
inlineoverride

Definition at line 53 of file ClangASTSource.h.

◆ GetExternalSelector()

clang::Selector lldb_private::ClangASTSource::GetExternalSelector ( uint32_t  )
inlineoverride

Definition at line 54 of file ClangASTSource.h.

◆ GetLookupsEnabled()

bool lldb_private::ClangASTSource::GetLookupsEnabled ( )
inline

Definition at line 203 of file ClangASTSource.h.

References m_lookups_enabled.

Referenced by FindExternalVisibleDeclsByName().

◆ GetNumExternalSelectors()

uint32_t lldb_private::ClangASTSource::GetNumExternalSelectors ( )
inlineoverride

Definition at line 57 of file ClangASTSource.h.

◆ getSema()

clang::Sema * ClangASTSource::getSema ( )

◆ GetTypeSystem()

TypeSystemClang * lldb_private::ClangASTSource::GetTypeSystem ( ) const
inline

Returns the TypeSystem that uses this ClangASTSource instance as it's ExternalASTSource.

Definition at line 353 of file ClangASTSource.h.

References m_clang_ast_context.

Referenced by IRForTarget::CreateResultVariable(), IRForTarget::MaybeHandleVariable(), and IRForTarget::RewritePersistentAlloc().

◆ GuardedCopyType()

CompilerType ClangASTSource::GuardedCopyType ( const CompilerType src_type)
protected

◆ IgnoreName()

bool ClangASTSource::IgnoreName ( const ConstString  name,
bool  ignore_all_dollar_names 
)

Returns true if a name should be ignored by name lookup.

Parameters
[in]nameThe name to be considered.
[in]ignore_all_dollar_namesTrue if $-names of all sorts should be ignored.
Returns
True if the name is one of a class of names that are ignored by global lookup for performance reasons.

Definition at line 560 of file ClangASTSource.cpp.

References lldb_private::ConstString::GetStringRef(), and m_ast_context.

Referenced by FillNamespaceMap(), FindExternalVisibleDecls(), and lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls().

◆ InstallASTContext()

void ClangASTSource::InstallASTContext ( TypeSystemClang ast_context)

◆ layoutRecordType()

bool ClangASTSource::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

Specify the layout of the contents of a RecordDecl.

Parameters
[in]RecordThe record (in the parser's AST context) that needs to be laid out.
[out]SizeThe total size of the record in bits.
[out]AlignmentThe alignment of the record in bits.
[in]FieldOffsetsA map that must be populated with pairs of the record's fields (in the parser's AST context) and their offsets (measured in bits).
[in]BaseOffsetsA map that must be populated with pairs of the record's C++ concrete base classes (in the parser's AST context, and only if the record is a CXXRecordDecl and has base classes) and their offsets (measured in bytes).
[in]VirtualBaseOffsetsA map that must be populated with pairs of the record's C++ virtual base classes (in the parser's AST context, and only if the record is a CXXRecordDecl and has base classes) and their offsets (measured in bytes).
Returns
True <=> the layout is valid.

Definition at line 1348 of file ClangASTSource.cpp.

References m_ast_importer_sp.

Referenced by lldb_private::ClangASTSource::ClangASTSourceProxy::layoutRecordType().

◆ LookupInNamespace()

void ClangASTSource::LookupInNamespace ( NameSearchContext context)
protected

Performs lookup into a namespace.

Parameters
contextThe NameSearchContext for a lookup inside a namespace.

Definition at line 1323 of file ClangASTSource.cpp.

References lldb_private::Expressions, FindExternalVisibleDecls(), lldb_private::GetLog(), LLDB_LOG, LLDB_LOGV, m_ast_importer_sp, and lldb_private::NameSearchContext::m_decl_context.

Referenced by FindExternalVisibleDecls().

◆ MaterializeVisibleDecls()

void lldb_private::ClangASTSource::MaterializeVisibleDecls ( const clang::DeclContext *  DC)
inline

Definition at line 62 of file ClangASTSource.h.

◆ SetLookupsEnabled()

void lldb_private::ClangASTSource::SetLookupsEnabled ( bool  lookups_enabled)
inline

◆ StartTranslationUnit()

void ClangASTSource::StartTranslationUnit ( clang::ASTConsumer *  Consumer)
override

Called on entering a translation unit.

Tells Clang by calling setHasExternalVisibleStorage() and setHasExternalLexicalStorage() that this object has something to say about undefined names.

Parameters
[in]ConsumerUnused.

Definition at line 92 of file ClangASTSource.cpp.

References m_ast_context.

Referenced by lldb_private::ClangASTSource::ClangASTSourceProxy::StartTranslationUnit().

Friends And Related Function Documentation

◆ NameSearchContext

friend struct NameSearchContext
friend

Definition at line 379 of file ClangASTSource.h.

Member Data Documentation

◆ m_active_lexical_decls

std::set<const clang::Decl *> lldb_private::ClangASTSource::m_active_lexical_decls
protected

Definition at line 393 of file ClangASTSource.h.

Referenced by FindExternalLexicalDecls().

◆ m_active_lookups

std::set<const char *> lldb_private::ClangASTSource::m_active_lookups
protected

Definition at line 394 of file ClangASTSource.h.

Referenced by FindExternalVisibleDeclsByName().

◆ m_ast_context

clang::ASTContext* lldb_private::ClangASTSource::m_ast_context
protected

◆ m_ast_importer_sp

std::shared_ptr<ClangASTImporter> lldb_private::ClangASTSource::m_ast_importer_sp
protected

◆ m_clang_ast_context

TypeSystemClang* lldb_private::ClangASTSource::m_clang_ast_context
protected

◆ m_file_manager

clang::FileManager* lldb_private::ClangASTSource::m_file_manager
protected

The file manager paired with the AST context.

Definition at line 390 of file ClangASTSource.h.

Referenced by InstallASTContext().

◆ m_lookups_enabled

bool lldb_private::ClangASTSource::m_lookups_enabled
protected

Definition at line 381 of file ClangASTSource.h.

Referenced by GetLookupsEnabled(), and SetLookupsEnabled().

◆ m_target

const lldb::TargetSP lldb_private::ClangASTSource::m_target
protected

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