Skip to content

Make only one function that needs to be implemented when searching for types #74786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 10 additions & 67 deletions lldb/include/lldb/Core/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,70 +415,19 @@ class Module : public std::enable_shared_from_this<Module>,
void FindGlobalVariables(const RegularExpression &regex, size_t max_matches,
VariableList &variable_list);

/// Find types by name.
///
/// Type lookups in modules go through the SymbolFile. The SymbolFile needs to
/// be able to lookup types by basename and not the fully qualified typename.
/// This allows the type accelerator tables to stay small, even with heavily
/// templatized C++. The type search will then narrow down the search
/// results. If "exact_match" is true, then the type search will only match
/// exact type name matches. If "exact_match" is false, the type will match
/// as long as the base typename matches and as long as any immediate
/// containing namespaces/class scopes that are specified match. So to
/// search for a type "d" in "b::c", the name "b::c::d" can be specified and
/// it will match any class/namespace "b" which contains a class/namespace
/// "c" which contains type "d". We do this to allow users to not always
/// have to specify complete scoping on all expressions, but it also allows
/// for exact matching when required.
///
/// \param[in] type_name
/// The name of the type we are looking for that is a fully
/// or partially qualified type name.
///
/// \param[in] exact_match
/// If \b true, \a type_name is fully qualified and must match
/// exactly. If \b false, \a type_name is a partially qualified
/// name where the leading namespaces or classes can be
/// omitted to make finding types that a user may type
/// easier.
///
/// \param[out] types
/// A type list gets populated with any matches.
/// Find types using a type-matching object that contains all search
/// parameters.
///
void
FindTypes(ConstString type_name, bool exact_match, size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeList &types);

/// Find types by name.
///
/// This behaves like the other FindTypes method but allows to
/// specify a DeclContext and a language for the type being searched
/// for.
///
/// \param searched_symbol_files
/// Prevents one file from being visited multiple times.
void
FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types);

lldb::TypeSP FindFirstType(const SymbolContext &sc, ConstString type_name,
bool exact_match);

/// Find types by name that are in a namespace. This function is used by the
/// expression parser when searches need to happen in an exact namespace
/// scope.
/// \see lldb_private::TypeQuery
///
/// \param[in] type_name
/// The name of a type within a namespace that should not include
/// any qualifying namespaces (just a type basename).
/// \param[in] query
/// A type matching object that contains all of the details of the type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A type matching object that contains all of the details of the type
/// A type-matching object that contains all of the details of the type

/// search.
///
/// \param[out] type_list
/// A type list gets populated with any matches.
void FindTypesInNamespace(ConstString type_name,
const CompilerDeclContext &parent_decl_ctx,
size_t max_matches, TypeList &type_list);
/// \param[in] results
/// Any matching types will be populated into the \a results object using
/// TypeMap::InsertUnique(...).
void FindTypes(const TypeQuery &query, TypeResults &results);

/// Get const accessor for the module architecture.
///
Expand Down Expand Up @@ -1122,12 +1071,6 @@ class Module : public std::enable_shared_from_this<Module>,
private:
Module(); // Only used internally by CreateJITModule ()

void FindTypes_Impl(
ConstString name, const CompilerDeclContext &parent_decl_ctx,
size_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types);

Module(const Module &) = delete;
const Module &operator=(const Module &) = delete;

Expand Down
24 changes: 10 additions & 14 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,22 @@ class ModuleList {
lldb::SymbolType symbol_type,
SymbolContextList &sc_list) const;

/// Find types by name.
/// Find types using a type-matching object that contains all search
/// parameters.
///
/// \param[in] search_first
/// If non-null, this module will be searched before any other
/// modules.
///
/// \param[in] name
/// The name of the type we are looking for.
///
/// \param[in] max_matches
/// Allow the number of matches to be limited to \a
/// max_matches. Specify UINT32_MAX to get all possible matches.
///
/// \param[out] types
/// A type list gets populated with any matches.
/// \param[in] query
/// A type matching object that contains all of the details of the type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A type matching object that contains all of the details of the type
/// A type-matching object that contains all of the details of the type

/// search.
///
void FindTypes(Module *search_first, ConstString name,
bool name_is_fully_qualified, size_t max_matches,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeList &types) const;
/// \param[in] results
/// Any matching types will be populated into the \a results object using
/// TypeMap::InsertUnique(...).
void FindTypes(Module *search_first, const TypeQuery &query,
lldb_private::TypeResults &results) const;

bool FindSourceFile(const FileSpec &orig_spec, FileSpec &new_spec) const;

Expand Down
7 changes: 7 additions & 0 deletions lldb/include/lldb/Symbol/CompilerDecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class CompilerDecl {
// based argument index
CompilerType GetFunctionArgumentType(size_t arg_idx) const;

/// Populate a valid compiler context from the current declaration.
///
/// \returns A valid vector of CompilerContext entries that describes
/// this declaration. The first entry in the vector is the parent of
/// the subsequent entry, so the topmost entry is the global namespace.
std::vector<lldb_private::CompilerContext> GetCompilerContext() const;

private:
TypeSystem *m_type_system = nullptr;
void *m_opaque_decl = nullptr;
Expand Down
8 changes: 8 additions & 0 deletions lldb/include/lldb/Symbol/CompilerDeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <vector>

#include "lldb/Symbol/Type.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/lldb-private.h"

Expand Down Expand Up @@ -56,6 +57,13 @@ class CompilerDeclContext {
return m_type_system != nullptr && m_opaque_decl_ctx != nullptr;
}

/// Populate a valid compiler context from the current decl context.
///
/// \returns A valid vector of CompilerContext entries that describes
/// this declaration context. The first entry in the vector is the parent of
/// the subsequent entry, so the topmost entry is the global namespace.
std::vector<lldb_private::CompilerContext> GetCompilerContext() const;

std::vector<CompilerDecl> FindDeclByName(ConstString name,
const bool ignore_using_decls);

Expand Down
29 changes: 14 additions & 15 deletions lldb/include/lldb/Symbol/SymbolFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,20 @@ class SymbolFile : public PluginInterface {
bool include_inlines, SymbolContextList &sc_list);
virtual void FindFunctions(const RegularExpression &regex,
bool include_inlines, SymbolContextList &sc_list);
virtual void
FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types);

/// Find types specified by a CompilerContextPattern.
/// \param languages
/// Only return results in these languages.
/// \param searched_symbol_files
/// Prevents one file from being visited multiple times.
virtual void
FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
TypeMap &types);

/// Find types using a type-matching object that contains all search
/// parameters.
///
/// \see lldb_private::TypeQuery
///
/// \param[in] query
/// A type matching object that contains all of the details of the type
/// search.
///
/// \param[in] results
/// Any matching types will be populated into the \a results object using
/// TypeMap::InsertUnique(...).
virtual void FindTypes(const TypeQuery &query, TypeResults &results) {}

virtual void
GetMangledNamesForFunction(const std::string &scope_qualified_name,
Expand Down
13 changes: 2 additions & 11 deletions lldb/include/lldb/Symbol/SymbolFileOnDemand.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,8 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile {
const std::string &scope_qualified_name,
std::vector<lldb_private::ConstString> &mangled_names) override;

void
FindTypes(lldb_private::ConstString name,
const lldb_private::CompilerDeclContext &parent_decl_ctx,
uint32_t max_matches,
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
lldb_private::TypeMap &types) override;

void FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern,
lldb_private::LanguageSet languages,
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
lldb_private::TypeMap &types) override;
void FindTypes(const lldb_private::TypeQuery &query,
lldb_private::TypeResults &results) override;

void GetTypes(lldb_private::SymbolContextScope *sc_scope,
lldb::TypeClass type_mask,
Expand Down
Loading