Skip to content

Commit a28a21b

Browse files
Merge pull request #235 from adrian-prantl/55500457
Cherry-pick FindTypes API modernization
2 parents c6def00 + 0f73abd commit a28a21b

28 files changed

+349
-483
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,7 @@ class Module : public std::enable_shared_from_this<Module>,
447447
/// \param[out] type_list
448448
/// A type list gets populated with any matches.
449449
///
450-
/// \return
451-
/// The number of matches added to \a type_list.
452-
size_t
450+
void
453451
FindTypes(ConstString type_name, bool exact_match, size_t max_matches,
454452
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
455453
TypeList &types);
@@ -459,8 +457,8 @@ class Module : public std::enable_shared_from_this<Module>,
459457
/// This behaves like the other FindTypes method but allows to
460458
/// specify a DeclContext and a language for the type being searched
461459
/// for.
462-
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
463-
LanguageSet languages, bool append, TypeMap &types);
460+
void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
461+
TypeMap &types);
464462

465463
lldb::TypeSP FindFirstType(const SymbolContext &sc,
466464
ConstString type_name, bool exact_match);
@@ -479,11 +477,9 @@ class Module : public std::enable_shared_from_this<Module>,
479477
/// \param[out] type_list
480478
/// A type list gets populated with any matches.
481479
///
482-
/// \return
483-
/// The number of matches added to \a type_list.
484-
size_t FindTypesInNamespace(ConstString type_name,
485-
const CompilerDeclContext *parent_decl_ctx,
486-
size_t max_matches, TypeList &type_list);
480+
void FindTypesInNamespace(ConstString type_name,
481+
const CompilerDeclContext *parent_decl_ctx,
482+
size_t max_matches, TypeList &type_list);
487483

488484
/// Get const accessor for the module architecture.
489485
///
@@ -1074,9 +1070,9 @@ class Module : public std::enable_shared_from_this<Module>,
10741070
private:
10751071
Module(); // Only used internally by CreateJITModule ()
10761072

1077-
size_t FindTypes_Impl(
1073+
void FindTypes_Impl(
10781074
ConstString name, const CompilerDeclContext *parent_decl_ctx,
1079-
bool append, size_t max_matches,
1075+
size_t max_matches,
10801076
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
10811077
TypeMap &types);
10821078

lldb/include/lldb/Core/ModuleList.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,10 @@ class ModuleList {
393393
/// \param[out] type_list
394394
/// A type list gets populated with any matches.
395395
///
396-
/// \return
397-
/// The number of matches added to \a type_list.
398-
size_t FindTypes(Module *search_first, ConstString name,
399-
bool name_is_fully_qualified, size_t max_matches,
400-
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
401-
TypeList &types) const;
396+
void FindTypes(Module *search_first, ConstString name,
397+
bool name_is_fully_qualified, size_t max_matches,
398+
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
399+
TypeList &types) const;
402400

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

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,24 @@ class SymbolFile : public PluginInterface {
185185
virtual uint32_t FindFunctions(const RegularExpression &regex,
186186
bool include_inlines, bool append,
187187
SymbolContextList &sc_list);
188-
virtual uint32_t
188+
virtual void
189189
FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
190-
bool append, uint32_t max_matches,
190+
uint32_t max_matches,
191191
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
192192
TypeMap &types);
193193

194194
/// Find types specified by a CompilerContextPattern.
195195
/// \param languages Only return results in these languages.
196-
virtual size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
197-
LanguageSet languages, bool append,
198-
TypeMap &types);
196+
virtual void FindTypes(llvm::ArrayRef<CompilerContext> pattern,
197+
LanguageSet languages, TypeMap &types);
199198

200199
virtual void
201200
GetMangledNamesForFunction(const std::string &scope_qualified_name,
202201
std::vector<ConstString> &mangled_names);
203202

204-
virtual size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
205-
lldb::TypeClass type_mask,
206-
lldb_private::TypeList &type_list) = 0;
203+
virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope,
204+
lldb::TypeClass type_mask,
205+
lldb_private::TypeList &type_list) = 0;
207206

208207
virtual void PreloadSymbols();
209208

lldb/include/lldb/Symbol/TypeList.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ class TypeList {
2828

2929
void Dump(Stream *s, bool show_context);
3030

31-
// lldb::TypeSP
32-
// FindType(lldb::user_id_t uid);
33-
3431
TypeList FindTypes(ConstString name);
3532

3633
void Insert(const lldb::TypeSP &type);
3734

3835
uint32_t GetSize() const;
3936

37+
bool Empty() const { return !GetSize(); }
38+
4039
lldb::TypeSP GetTypeAtIndex(uint32_t idx);
4140

4241
typedef std::vector<lldb::TypeSP> collection;

lldb/source/API/SBModule.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,10 @@ lldb::SBTypeList SBModule::FindTypes(const char *type) {
503503
const bool exact_match = false;
504504
ConstString name(type);
505505
llvm::DenseSet<SymbolFile *> searched_symbol_files;
506-
const uint32_t num_matches = module_sp->FindTypes(
507-
name, exact_match, UINT32_MAX, searched_symbol_files, type_list);
506+
module_sp->FindTypes(name, exact_match, UINT32_MAX, searched_symbol_files,
507+
type_list);
508508

509-
if (num_matches > 0) {
510-
for (size_t idx = 0; idx < num_matches; idx++) {
511-
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
512-
if (type_sp)
513-
retval.Append(SBType(type_sp));
514-
}
515-
} else {
509+
if (type_list.Empty()) {
516510
auto type_system_or_err =
517511
module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
518512
if (auto err = type_system_or_err.takeError()) {
@@ -523,9 +517,14 @@ lldb::SBTypeList SBModule::FindTypes(const char *type) {
523517
if (compiler_type)
524518
retval.Append(SBType(compiler_type));
525519
}
520+
} else {
521+
for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
522+
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
523+
if (type_sp)
524+
retval.Append(SBType(type_sp));
525+
}
526526
}
527527
}
528-
529528
return LLDB_RECORD_RESULT(retval);
530529
}
531530

lldb/source/API/SBTarget.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,16 +1891,13 @@ lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
18911891
bool exact_match = false;
18921892
TypeList type_list;
18931893
llvm::DenseSet<SymbolFile *> searched_symbol_files;
1894-
uint32_t num_matches =
1895-
images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
1896-
searched_symbol_files, type_list);
1894+
images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
1895+
searched_symbol_files, type_list);
18971896

1898-
if (num_matches > 0) {
1899-
for (size_t idx = 0; idx < num_matches; idx++) {
1900-
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1901-
if (type_sp)
1902-
sb_type_list.Append(SBType(type_sp));
1903-
}
1897+
for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
1898+
TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1899+
if (type_sp)
1900+
sb_type_list.Append(SBType(type_sp));
19041901
}
19051902

19061903
// Try the loaded language runtimes

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,75 +1629,30 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter,
16291629
static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm,
16301630
Module *module, const char *name_cstr,
16311631
bool name_is_regex) {
1632+
TypeList type_list;
16321633
if (module && name_cstr && name_cstr[0]) {
1633-
TypeList type_list;
16341634
const uint32_t max_num_matches = UINT32_MAX;
16351635
size_t num_matches = 0;
16361636
bool name_is_fully_qualified = false;
16371637

16381638
ConstString name(name_cstr);
16391639
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
1640-
num_matches =
1641-
module->FindTypes(name, name_is_fully_qualified, max_num_matches,
1642-
searched_symbol_files, type_list);
1643-
1644-
if (num_matches) {
1645-
strm.Indent();
1646-
strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
1647-
num_matches > 1 ? "es" : "");
1648-
DumpFullpath(strm, &module->GetFileSpec(), 0);
1649-
strm.PutCString(":\n");
1650-
for (TypeSP type_sp : type_list.Types()) {
1651-
if (type_sp) {
1652-
// Resolve the clang type so that any forward references to types
1653-
// that haven't yet been parsed will get parsed.
1654-
type_sp->GetFullCompilerType();
1655-
type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
1656-
// Print all typedef chains
1657-
TypeSP typedef_type_sp(type_sp);
1658-
TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1659-
while (typedefed_type_sp) {
1660-
strm.EOL();
1661-
strm.Printf(" typedef '%s': ",
1662-
typedef_type_sp->GetName().GetCString());
1663-
typedefed_type_sp->GetFullCompilerType();
1664-
typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull,
1665-
true);
1666-
typedef_type_sp = typedefed_type_sp;
1667-
typedefed_type_sp = typedef_type_sp->GetTypedefType();
1668-
}
1669-
}
1670-
strm.EOL();
1671-
}
1672-
}
1673-
return num_matches;
1674-
}
1675-
return 0;
1676-
}
1640+
module->FindTypes(name, name_is_fully_qualified, max_num_matches,
1641+
searched_symbol_files, type_list);
16771642

1678-
static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm,
1679-
Module &module, const char *name_cstr,
1680-
bool name_is_regex) {
1681-
TypeList type_list;
1682-
const uint32_t max_num_matches = UINT32_MAX;
1683-
size_t num_matches = 1;
1684-
bool name_is_fully_qualified = false;
1643+
if (type_list.Empty())
1644+
return 0;
16851645

1686-
ConstString name(name_cstr);
1687-
llvm::DenseSet<SymbolFile *> searched_symbol_files;
1688-
num_matches = module.FindTypes(name, name_is_fully_qualified, max_num_matches,
1689-
searched_symbol_files, type_list);
1690-
1691-
if (num_matches) {
16921646
strm.Indent();
1693-
strm.PutCString("Best match found in ");
1694-
DumpFullpath(strm, &module.GetFileSpec(), 0);
1647+
strm.Printf("%" PRIu64 " match%s found in ", (uint64_t)num_matches,
1648+
num_matches > 1 ? "es" : "");
1649+
DumpFullpath(strm, &module->GetFileSpec(), 0);
16951650
strm.PutCString(":\n");
1696-
1697-
TypeSP type_sp(type_list.GetTypeAtIndex(0));
1698-
if (type_sp) {
1699-
// Resolve the clang type so that any forward references to types that
1700-
// haven't yet been parsed will get parsed.
1651+
for (TypeSP type_sp : type_list.Types()) {
1652+
if (!type_sp)
1653+
continue;
1654+
// Resolve the clang type so that any forward references to types
1655+
// that haven't yet been parsed will get parsed.
17011656
type_sp->GetFullCompilerType();
17021657
type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
17031658
// Print all typedef chains
@@ -1715,7 +1670,50 @@ static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm,
17151670
}
17161671
strm.EOL();
17171672
}
1718-
return num_matches;
1673+
return type_list.GetSize();
1674+
}
1675+
1676+
static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm,
1677+
Module &module, const char *name_cstr,
1678+
bool name_is_regex) {
1679+
TypeList type_list;
1680+
const uint32_t max_num_matches = UINT32_MAX;
1681+
bool name_is_fully_qualified = false;
1682+
1683+
ConstString name(name_cstr);
1684+
llvm::DenseSet<SymbolFile *> searched_symbol_files;
1685+
module.FindTypes(name, name_is_fully_qualified, max_num_matches,
1686+
searched_symbol_files, type_list);
1687+
1688+
if (type_list.Empty())
1689+
return 0;
1690+
1691+
strm.Indent();
1692+
strm.PutCString("Best match found in ");
1693+
DumpFullpath(strm, &module.GetFileSpec(), 0);
1694+
strm.PutCString(":\n");
1695+
1696+
TypeSP type_sp(type_list.GetTypeAtIndex(0));
1697+
if (type_sp) {
1698+
// Resolve the clang type so that any forward references to types that
1699+
// haven't yet been parsed will get parsed.
1700+
type_sp->GetFullCompilerType();
1701+
type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
1702+
// Print all typedef chains
1703+
TypeSP typedef_type_sp(type_sp);
1704+
TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType());
1705+
while (typedefed_type_sp) {
1706+
strm.EOL();
1707+
strm.Printf(" typedef '%s': ",
1708+
typedef_type_sp->GetName().GetCString());
1709+
typedefed_type_sp->GetFullCompilerType();
1710+
typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true);
1711+
typedef_type_sp = typedefed_type_sp;
1712+
typedefed_type_sp = typedef_type_sp->GetTypedefType();
1713+
}
1714+
}
1715+
strm.EOL();
1716+
return type_list.GetSize();
17191717
}
17201718

17211719
static uint32_t LookupFileAndLineInModule(CommandInterpreter &interpreter,

0 commit comments

Comments
 (0)