LLDB  mainline
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | 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]
Collaboration diagram for lldb_private::ClangASTSource:
Collaboration 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. More...
 
 ~ClangASTSource () override
 Destructor. More...
 
clang::Decl * GetExternalDecl (uint32_t) override
 Interface stubs. More...
 
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. More...
 
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. More...
 
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. More...
 
void CompleteType (clang::TagDecl *Tag) override
 Complete a TagDecl. More...
 
void CompleteType (clang::ObjCInterfaceDecl *Class) override
 Complete an ObjCInterfaceDecl. More...
 
void StartTranslationUnit (clang::ASTConsumer *Consumer) override
 Called on entering a translation unit. More...
 
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. More...
 
clang::NamespaceDecl * AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
 
virtual void FindExternalVisibleDecls (NameSearchContext &context)
 The worker function for FindExternalVisibleDeclsByName. More...
 
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. More...
 
clang::Decl * CopyDecl (clang::Decl *src_decl)
 Copies a single Decl into the parser's AST context. More...
 
ClangASTImporter::DeclOrigin GetDeclOrigin (const clang::Decl *decl)
 Determined the origin of a single Decl, if it can be found. More...
 
TypeSystemClangGetTypeSystem () const
 Returns the TypeSystem that uses this ClangASTSource instance as it's ExternalASTSource. More...
 
- Public Member Functions inherited from lldb_private::ClangASTImporter::MapCompleter
virtual ~MapCompleter ()
 

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. More...
 
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. More...
 
void FindObjCMethodDecls (NameSearchContext &context)
 Find all Objective-C methods matching a given selector. More...
 
void FindObjCPropertyAndIvarDecls (NameSearchContext &context)
 Find all Objective-C properties and ivars with a given name. More...
 
void LookupInNamespace (NameSearchContext &context)
 Performs lookup into a namespace. More...
 
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. More...
 
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. More...
 
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. More...
 
clang::ASTContext * m_ast_context
 The AST context requests are coming in for. More...
 
TypeSystemClangm_clang_ast_context
 The TypeSystemClang for m_ast_context. More...
 
clang::FileManager * m_file_manager
 The file manager paired with the AST context. More...
 
std::shared_ptr< ClangASTImporterm_ast_importer_sp
 The target's AST importer. More...
 
std::set< const clang::Decl * > m_active_lexical_decls
 
std::set< const char * > m_active_lookups
 

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 1612 of file ClangASTSource.cpp.

References lldb_private::SymbolFile::FindNamespace(), lldb_private::TypeSystemClang::getDisplayName(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::ModuleList::GetModuleAtIndexUnlocked(), lldb_private::ModuleList::GetMutex(), lldb_private::ModuleList::GetSize(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_ast_context, m_clang_ast_context, and m_target.

Referenced by MaterializeVisibleDecls().

◆ CompleteType() [1/2]

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

◆ CompleteType() [2/2]

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

◆ 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 655 of file ClangASTSource.cpp.

References lldb_private::SymbolFile::FindNamespace(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::ModuleList::GetModuleAtIndexUnlocked(), lldb_private::ModuleList::GetMutex(), lldb_private::ModuleList::GetSize(), IgnoreName(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, lldb_private::NameSearchContext::m_decl_name, lldb_private::NameSearchContext::m_namespace_map, and m_target.

Referenced by FindExternalVisibleDecls(), and GetTypeSystem().

◆ 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 383 of file ClangASTSource.cpp.

References CopyDecl(), lldb_private::ClangUtil::DumpDecl(), GetCompleteObjCInterface(), lldb_private::TypeSystemClang::getDisplayName(), lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_active_lexical_decls, m_ast_context, m_ast_importer_sp, and m_clang_ast_context.

Referenced by lldb_private::ClangASTSource::ClangASTSourceProxy::FindExternalLexicalDecls(), and MaterializeVisibleDecls().

◆ 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 586 of file ClangASTSource.cpp.

References lldb_private::NameSearchContext::AddTypeDecl(), FillNamespaceMap(), FindDeclInModules(), FindDeclInObjCRuntime(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::TypeList::GetSize(), lldb_private::TypeList::GetTypeAtIndex(), GuardedCopyType(), IgnoreName(), LIBLLDB_LOG_EXPRESSIONS, 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 99 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(), and MaterializeVisibleDecls().

◆ FindObjCMethodDecls()

void ClangASTSource::FindObjCMethodDecls ( NameSearchContext context)
protected

Find all Objective-C methods matching a given selector.

Parameters
[in]contextThe NameSearchContext that can construct Decls for this name. Its m_decl_name contains the selector and its m_decl_context is the containing object.

Definition at line 926 of file ClangASTSource.cpp.

References lldb_private::NameSearchContext::AddNamedDecl(), lldb_private::ConstString::AsCString(), lldb_private::StreamString::Clear(), lldb_private::ConstString::Clear(), CopyDecl(), lldb_private::ClangASTImporter::DeclOrigin::decl, lldb_private::TypeSystemClang::DeclContextGetAsObjCMethodDecl(), lldb_private::ClangUtil::DumpDecl(), FindObjCMethodDeclsWithOrigin(), lldb_private::StreamString::Flush(), lldb_private::SymbolContext::function, lldb_private::ObjCLanguageRuntime::Get(), GetCompleteObjCInterface(), lldb_private::SymbolContextList::GetContextAtIndex(), lldb_private::Function::GetDeclContext(), lldb_private::LanguageRuntime::GetDeclVendor(), lldb_private::TypeSystemClang::getDisplayName(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::Function::GetName(), lldb_private::SymbolContextList::GetSize(), lldb_private::StreamString::GetString(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_ast_context, m_ast_importer_sp, m_clang_ast_context, lldb_private::NameSearchContext::m_decl_context, lldb_private::NameSearchContext::m_decl_name, m_target, lldb_private::Stream::Printf(), and lldb_private::ClangASTImporter::DeclOrigin::Valid().

Referenced by CreateProxy(), and FindExternalVisibleDeclsByName().

◆ FindObjCMethodDeclsWithOrigin()

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

◆ FindObjCPropertyAndIvarDecls()

void ClangASTSource::FindObjCPropertyAndIvarDecls ( NameSearchContext context)
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 342 of file ClangASTSource.cpp.

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

Referenced by CompleteType(), CreateProxy(), 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 1732 of file ClangASTSource.cpp.

References m_ast_importer_sp.

Referenced by CreateProxy(), and DeclFromParser< D >::GetOrigin().

◆ 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 ( uint32_t  )
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

◆ 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 569 of file ClangASTSource.cpp.

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

Referenced by CreateProxy(), FillNamespaceMap(), lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(), and 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 1490 of file ClangASTSource.cpp.

References lldb_private::TypeSystemClang::GetCompleteDecl(), lldb_private::TypeSystemClang::getDisplayName(), lldb_private::GetLogIfAllCategoriesSet(), ImportOffsetMap(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, lldbassert, m_ast_context, and m_clang_ast_context.

Referenced by lldb_private::ClangASTSource::ClangASTSourceProxy::layoutRecordType(), and MaterializeVisibleDecls().

◆ LookupInNamespace()

void ClangASTSource::LookupInNamespace ( NameSearchContext context)
protected

Performs lookup into a namespace.

Parameters
contextThe NameSearchContext for a lookup inside a namespace.

Definition at line 1385 of file ClangASTSource.cpp.

References FindExternalVisibleDecls(), lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, LLDB_LOGV, m_ast_importer_sp, and lldb_private::NameSearchContext::m_decl_context.

Referenced by CreateProxy(), and FindExternalVisibleDecls().

◆ MaterializeVisibleDecls()

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

◆ 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 90 of file ClangASTSource.cpp.

References m_ast_context.

Referenced by MaterializeVisibleDecls(), and lldb_private::ClangASTSource::ClangASTSourceProxy::StartTranslationUnit().

Friends And Related Function Documentation

◆ NameSearchContext

friend struct NameSearchContext
friend

Definition at line 372 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 386 of file ClangASTSource.h.

Referenced by FindCompleteType(), and FindExternalLexicalDecls().

◆ m_active_lookups

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

Definition at line 387 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 383 of file ClangASTSource.h.

Referenced by InstallASTContext().

◆ m_lookups_enabled

bool lldb_private::ClangASTSource::m_lookups_enabled
protected

Definition at line 374 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: