LLDB mainline
Public Member Functions | Protected Attributes | List of all members
lldb_private::TypeQuery Class Reference

A class that contains all state required for type lookups. More...

#include <Type.h>

Public Member Functions

 TypeQuery ()=delete
 
 TypeQuery (llvm::StringRef name, TypeQueryOptions options=e_none)
 Construct a type match object using a fully- or partially-qualified name.
 
 TypeQuery (const CompilerDeclContext &decl_ctx, ConstString type_basename, TypeQueryOptions options=e_none)
 Construct a type-match object that matches a type basename that exists in the specified declaration context.
 
 TypeQuery (const CompilerDecl &decl, TypeQueryOptions options=e_none)
 Construct a type-match object using a compiler declaration that specifies a typename and a declaration context to use when doing exact type lookups.
 
 TypeQuery (const llvm::ArrayRef< lldb_private::CompilerContext > &context, TypeQueryOptions options=e_none)
 Construct a type-match object using a CompilerContext array.
 
 TypeQuery (const TypeQuery &rhs)=default
 Construct a type-match object that duplicates all matching criterea, but not any searched symbol files or the type map for matches.
 
TypeQueryoperator= (const TypeQuery &rhs)=default
 Assign a type-match object that duplicates all matching criterea, but not any searched symbol files or the type map for matches.
 
bool ContextMatches (llvm::ArrayRef< lldb_private::CompilerContext > context) const
 Check of a CompilerContext array from matching type from a symbol file matches the m_context.
 
ConstString GetTypeBasename () const
 Get the type basename to use when searching the type indexes in each SymbolFile object.
 
bool HasLanguage () const
 Returns true if any matching languages have been specified in this type matching object.
 
void AddLanguage (lldb::LanguageType language)
 Add a language family to the list of languages that should produce a match.
 
void SetLanguages (LanguageSet languages)
 Set the list of languages that should produce a match to only the ones specified in languages.
 
bool LanguageMatches (lldb::LanguageType language) const
 Check if the language matches any languages that have been added to this match object.
 
bool GetExactMatch () const
 
bool GetModuleSearch () const
 The m_context can be used in two ways: normal types searching with the context containing a stanadard declaration context for a type, or with the context being more complete for exact matches in clang modules.
 
bool GetFindOne () const
 Returns true if the type query is supposed to find only a single matching type.
 
void SetFindOne (bool b)
 
std::vector< lldb_private::CompilerContext > & GetContextRef ()
 Access the internal compiler context array.
 

Protected Attributes

std::vector< lldb_private::CompilerContextm_context
 A full or partial compiler context array where the parent declaration contexts appear at the top of the array starting at index zero and the last entry contains the type and name of the type we are looking for.
 
TypeQueryOptions m_options
 An options bitmask that contains enabled options for the type query.
 
std::optional< LanguageSetm_languages
 If this variable has a value, then the language family must match at least one of the specified languages.
 

Detailed Description

A class that contains all state required for type lookups.

Using a TypeQuery class for matching types simplifies the internal APIs we need to implement type lookups in LLDB. Type lookups can fully specify the exact typename by filling out a complete or partial CompilerContext array. This technique allows for powerful searches and also allows the SymbolFile classes to use the m_context array to lookup types by basename, then eliminate potential matches without having to resolve types into each TypeSystem. This makes type lookups vastly more efficient and allows the SymbolFile objects to stop looking up types when the type matching is complete, like if we are looking for only a single type in our search.

Definition at line 96 of file Type.h.

Constructor & Destructor Documentation

◆ TypeQuery() [1/6]

lldb_private::TypeQuery::TypeQuery ( )
delete

◆ TypeQuery() [2/6]

TypeQuery::TypeQuery ( llvm::StringRef  name,
TypeQueryOptions  options = e_none 
)

Construct a type match object using a fully- or partially-qualified name.

The specified type_name will be chopped up and the m_context will be populated by separating the string by looking for "::". We do this because symbol files have indexes that contain only the type's basename. This also allows symbol files to efficiently not realize types that don't match the specified context. Example of type_name values that can be specified include: "foo": Look for any type whose basename matches "foo". If exact_match is true, then the type can't be contained in any declaration context like a namespace, class, or other containing scope. If exact match is false, then we will find all matches including ones that are contained in other declaration contexts, including top level types. "foo::bar": Look for any type whose basename matches "bar" but make sure its parent declaration context is any named declaration context (namespace, class, struct, etc) whose name matches "foo". If exact_match is true, then the "foo" declaration context must appear at the source file level or inside of a function. If exact match is false, then the "foo" declaration context can be contained in any other declaration contexts. "class foo": Only match types that are classes whose basename matches "foo". "struct foo": Only match types that are structures whose basename matches "foo". "class foo::bar": Only match types that are classes whose basename matches "bar" and that are contained in any named declaration context named "foo".

Parameters
[in]type_nameA fully- or partially-qualified type name. This name will be parsed and broken up and the m_context will be populated with the various parts of the name. This typename can be prefixed with "struct ", "class ", "union", "enum " or "typedef " before the actual type name to limit the results of the types that match. The declaration context can be specified with the "::" string. For example, "a::b::my_type".
[in]optionsA set of boolean enumeration flags from the TypeQueryOptions enumerations.
See also
TypeQueryOptions.

Definition at line 86 of file Type.cpp.

References lldb_private::AnyDeclContext, lldb_private::AnyType, ConvertTypeClass(), lldb_private::Type::GetTypeScopeAndBasename(), m_context, and m_options.

◆ TypeQuery() [3/6]

TypeQuery::TypeQuery ( const CompilerDeclContext decl_ctx,
ConstString  type_basename,
TypeQueryOptions  options = e_none 
)

Construct a type-match object that matches a type basename that exists in the specified declaration context.

This allows the m_context to be first populated using a declaration context to exactly identify the containing declaration context of a type. This can be used when you have a forward declaration to a type and you need to search for its complete type.

Parameters
[in]decl_ctxA declaration context object that comes from a TypeSystem plug-in. This object will be asked to populate the array of CompilerContext objects by adding the top most declaration context first into the array and then adding any containing declaration contexts.
[in]type_basenameThe basename of the type to lookup in the specified declaration context.
[in]optionsA set of boolean enumeration flags from the TypeQueryOptions enumerations.
See also
TypeQueryOptions.

Definition at line 112 of file Type.cpp.

References lldb_private::AnyType, lldb_private::CompilerDeclContext::GetCompilerContext(), m_context, and m_options.

◆ TypeQuery() [4/6]

TypeQuery::TypeQuery ( const CompilerDecl decl,
TypeQueryOptions  options = e_none 
)

Construct a type-match object using a compiler declaration that specifies a typename and a declaration context to use when doing exact type lookups.

This allows the m_context to be first populated using a type declaration. The type declaration might have a declaration context and each TypeSystem plug-in can populate the declaration context needed to perform an exact lookup for a type. This can be used when you have a forward declaration to a type and you need to search for its complete type.

Parameters
[in]declA type declaration context object that comes from a TypeSystem plug-in. This object will be asked to full the array of CompilerContext objects by adding the top most declaration context first into the array and then adding any containing declaration contexts, and ending with the exact typename and the kind of type it is (class, struct, union, enum, etc).
[in]optionsA set of boolean enumeration flags from the TypeQueryOptions enumerations.
See also
TypeQueryOptions.

Definition at line 129 of file Type.cpp.

References lldb_private::CompilerDecl::GetCompilerContext(), m_context, and m_options.

◆ TypeQuery() [5/6]

TypeQuery::TypeQuery ( const llvm::ArrayRef< lldb_private::CompilerContext > &  context,
TypeQueryOptions  options = e_none 
)

Construct a type-match object using a CompilerContext array.

Clients can manually create compiler contexts and use these to find matches when searching for types. There are two types of contexts that are supported when doing type searchs: type contexts and clang module contexts. Type contexts have contexts that specify the type and its containing declaration context like namespaces and classes. Clang module contexts specify contexts more completely to find exact matches within clang module debug information. They will include the modules that the type is included in and any functions that the type might be defined in. This allows very fine-grained type resolution.

Parameters
[in]contextThe compiler context to use when doing the search.
[in]optionsA set of boolean enumeration flags from the TypeQueryOptions enumerations.
See also
TypeQueryOptions.

Definition at line 121 of file Type.cpp.

References m_options.

◆ TypeQuery() [6/6]

lldb_private::TypeQuery::TypeQuery ( const TypeQuery rhs)
default

Construct a type-match object that duplicates all matching criterea, but not any searched symbol files or the type map for matches.

This allows the m_context to be modified prior to performing another search.

Member Function Documentation

◆ AddLanguage()

void TypeQuery::AddLanguage ( lldb::LanguageType  language)

Add a language family to the list of languages that should produce a match.

Definition at line 142 of file Type.cpp.

References m_languages.

Referenced by DWARFASTParserClang::ParseTypeFromClangModule().

◆ ContextMatches()

bool TypeQuery::ContextMatches ( llvm::ArrayRef< lldb_private::CompilerContext context) const

Check of a CompilerContext array from matching type from a symbol file matches the m_context.

Parameters
[in]contextA fully qualified CompilerContext array for a potential match that is created by the symbol file prior to trying to actually resolve a type.
Returns
True if the context matches, false if it doesn't. If e_exact_match is set in m_options, then context must exactly match m_context. If e_exact_match is not set, then the bottom m_context.size() objects in context must match. This allows SymbolFile objects the fill in a potential type basename match from the index into context, and see if it matches prior to having to resolve a lldb_private::Type object for the type from the index. This allows type parsing to be as efficient as possible and only realize the types that match the query.

Definition at line 152 of file Type.cpp.

References GetExactMatch(), and m_context.

Referenced by lldb_private::plugin::dwarf::SymbolFileDWARF::FindTypes(), lldb_private::npdb::SymbolFileNativePDB::FindTypes(), and SymbolFilePDB::FindTypes().

◆ GetContextRef()

std::vector< lldb_private::CompilerContext > & lldb_private::TypeQuery::GetContextRef ( )
inline

Access the internal compiler context array.

Clients can use this to populate the context manually.

Definition at line 282 of file Type.h.

Referenced by lldb_private::npdb::SymbolFileNativePDB::FindTypes(), SymbolFilePDB::FindTypes(), and UpdateCompilerContextForSimpleTemplateNames().

◆ GetExactMatch()

bool lldb_private::TypeQuery::GetExactMatch ( ) const
inline

Definition at line 262 of file Type.h.

Referenced by ContextMatches().

◆ GetFindOne()

bool lldb_private::TypeQuery::GetFindOne ( ) const
inline

Returns true if the type query is supposed to find only a single matching type.

Returns false if the type query should find all matches.

Definition at line 271 of file Type.h.

Referenced by lldb_private::TypeResults::Done().

◆ GetModuleSearch()

bool lldb_private::TypeQuery::GetModuleSearch ( ) const
inline

The m_context can be used in two ways: normal types searching with the context containing a stanadard declaration context for a type, or with the context being more complete for exact matches in clang modules.

Set this to true if you wish to search for a type in clang module.

Definition at line 267 of file Type.h.

Referenced by lldb_private::plugin::dwarf::SymbolFileDWARF::FindTypes().

◆ GetTypeBasename()

ConstString TypeQuery::GetTypeBasename ( ) const

Get the type basename to use when searching the type indexes in each SymbolFile object.

Debug information indexes often contain indexes that track the basename of types only, not a fully qualified path. This allows the indexes to be smaller and allows for efficient lookups.

Returns
The type basename to use when doing lookups as a constant string.

Definition at line 136 of file Type.cpp.

References m_context.

Referenced by lldb_private::SymbolFileCTF::FindTypes(), lldb_private::plugin::dwarf::SymbolFileDWARF::FindTypes(), lldb_private::npdb::SymbolFileNativePDB::FindTypes(), and SymbolFilePDB::FindTypes().

◆ HasLanguage()

bool lldb_private::TypeQuery::HasLanguage ( ) const
inline

Returns true if any matching languages have been specified in this type matching object.

Definition at line 244 of file Type.h.

◆ LanguageMatches()

bool TypeQuery::LanguageMatches ( lldb::LanguageType  language) const

Check if the language matches any languages that have been added to this match object.

Returns
True if no language have been specified, or if some language have been added using AddLanguage(...) and they match. False otherwise.

Definition at line 169 of file Type.cpp.

References m_languages.

◆ operator=()

TypeQuery & lldb_private::TypeQuery::operator= ( const TypeQuery rhs)
default

Assign a type-match object that duplicates all matching criterea, but not any searched symbol files or the type map for matches.

This allows the m_context to be modified prior to performing another search.

◆ SetFindOne()

void lldb_private::TypeQuery::SetFindOne ( bool  b)
inline

Definition at line 272 of file Type.h.

Referenced by lldb_private::ItaniumABILanguageRuntime::GetTypeInfo().

◆ SetLanguages()

void TypeQuery::SetLanguages ( LanguageSet  languages)

Set the list of languages that should produce a match to only the ones specified in languages.

Definition at line 148 of file Type.cpp.

References m_languages.

Member Data Documentation

◆ m_context

std::vector<lldb_private::CompilerContext> lldb_private::TypeQuery::m_context
protected

A full or partial compiler context array where the parent declaration contexts appear at the top of the array starting at index zero and the last entry contains the type and name of the type we are looking for.

Definition at line 290 of file Type.h.

Referenced by ContextMatches(), GetTypeBasename(), and TypeQuery().

◆ m_languages

std::optional<LanguageSet> lldb_private::TypeQuery::m_languages
protected

If this variable has a value, then the language family must match at least one of the specified languages.

If this variable has no value, then the language of the type doesn't need to match any types that are searched.

Definition at line 297 of file Type.h.

Referenced by AddLanguage(), LanguageMatches(), and SetLanguages().

◆ m_options

TypeQueryOptions lldb_private::TypeQuery::m_options
protected

An options bitmask that contains enabled options for the type query.

See also
TypeQueryOptions.

Definition at line 293 of file Type.h.

Referenced by TypeQuery().


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