Skip to content

Commit d4d428e

Browse files
committed
Remove unused "append" parameter from FindTypes API
I noticed that SymbolFileDWARFDebugMap::FindTypes was implementing it incorrectly (passing append=false in a for-loop to recursive calls to FindTypes would yield only the very last set of results), but instead of fixing it, removing it seemed like an even better option. rdar://problem/54412692 Differential Revision: https://reviews.llvm.org/D68171 llvm-svn: 373224
1 parent 09025ca commit d4d428e

16 files changed

+87
-131
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ class Module : public std::enable_shared_from_this<Module>,
460460
/// specify a DeclContext and a language for the type being searched
461461
/// for.
462462
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
463-
LanguageSet languages, bool append, TypeMap &types);
463+
LanguageSet languages, TypeMap &types);
464464

465465
lldb::TypeSP FindFirstType(const SymbolContext &sc,
466466
ConstString type_name, bool exact_match);
@@ -1076,7 +1076,7 @@ class Module : public std::enable_shared_from_this<Module>,
10761076

10771077
size_t FindTypes_Impl(
10781078
ConstString name, const CompilerDeclContext *parent_decl_ctx,
1079-
bool append, size_t max_matches,
1079+
size_t max_matches,
10801080
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
10811081
TypeMap &types);
10821082

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,14 @@ class SymbolFile : public PluginInterface {
190190
SymbolContextList &sc_list);
191191
virtual uint32_t
192192
FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx,
193-
bool append, uint32_t max_matches,
193+
uint32_t max_matches,
194194
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
195195
TypeMap &types);
196196

197197
/// Find types specified by a CompilerContextPattern.
198198
/// \param languages Only return results in these languages.
199199
virtual size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
200-
LanguageSet languages, bool append,
201-
TypeMap &types);
200+
LanguageSet languages, TypeMap &types);
202201

203202
virtual void
204203
GetMangledNamesForFunction(const std::string &scope_qualified_name,

lldb/source/Core/Module.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -941,26 +941,24 @@ void Module::FindAddressesForLine(const lldb::TargetSP target_sp,
941941

942942
size_t Module::FindTypes_Impl(
943943
ConstString name, const CompilerDeclContext *parent_decl_ctx,
944-
bool append, size_t max_matches,
944+
size_t max_matches,
945945
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
946946
TypeMap &types) {
947947
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
948948
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
949949
if (SymbolFile *symbols = GetSymbolFile())
950-
return symbols->FindTypes(name, parent_decl_ctx, append, max_matches,
950+
return symbols->FindTypes(name, parent_decl_ctx, max_matches,
951951
searched_symbol_files, types);
952952
return 0;
953953
}
954954

955955
size_t Module::FindTypesInNamespace(ConstString type_name,
956956
const CompilerDeclContext *parent_decl_ctx,
957957
size_t max_matches, TypeList &type_list) {
958-
const bool append = true;
959958
TypeMap types_map;
960959
llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files;
961-
size_t num_types =
962-
FindTypes_Impl(type_name, parent_decl_ctx, append, max_matches,
963-
searched_symbol_files, types_map);
960+
size_t num_types = FindTypes_Impl(type_name, parent_decl_ctx, max_matches,
961+
searched_symbol_files, types_map);
964962
if (num_types > 0) {
965963
SymbolContext sc;
966964
sc.module_sp = shared_from_this();
@@ -988,7 +986,6 @@ size_t Module::FindTypes(
988986
const char *type_name_cstr = name.GetCString();
989987
llvm::StringRef type_scope;
990988
llvm::StringRef type_basename;
991-
const bool append = true;
992989
TypeClass type_class = eTypeClassAny;
993990
TypeMap typesmap;
994991

@@ -1001,7 +998,7 @@ size_t Module::FindTypes(
1001998
exact_match = type_scope.consume_front("::");
1002999

10031000
ConstString type_basename_const_str(type_basename);
1004-
if (FindTypes_Impl(type_basename_const_str, nullptr, append, max_matches,
1001+
if (FindTypes_Impl(type_basename_const_str, nullptr, max_matches,
10051002
searched_symbol_files, typesmap)) {
10061003
typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
10071004
exact_match);
@@ -1013,13 +1010,13 @@ size_t Module::FindTypes(
10131010
if (type_class != eTypeClassAny && !type_basename.empty()) {
10141011
// The "type_name_cstr" will have been modified if we have a valid type
10151012
// class prefix (like "struct", "class", "union", "typedef" etc).
1016-
FindTypes_Impl(ConstString(type_basename), nullptr, append, UINT_MAX,
1013+
FindTypes_Impl(ConstString(type_basename), nullptr, UINT_MAX,
10171014
searched_symbol_files, typesmap);
10181015
typesmap.RemoveMismatchedTypes(type_scope, type_basename, type_class,
10191016
exact_match);
10201017
num_matches = typesmap.GetSize();
10211018
} else {
1022-
num_matches = FindTypes_Impl(name, nullptr, append, UINT_MAX,
1019+
num_matches = FindTypes_Impl(name, nullptr, UINT_MAX,
10231020
searched_symbol_files, typesmap);
10241021
if (exact_match) {
10251022
std::string name_str(name.AsCString(""));
@@ -1038,11 +1035,11 @@ size_t Module::FindTypes(
10381035
}
10391036

10401037
size_t Module::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
1041-
LanguageSet languages, bool append, TypeMap &types) {
1038+
LanguageSet languages, TypeMap &types) {
10421039
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
10431040
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
10441041
if (SymbolFile *symbols = GetSymbolFile())
1045-
return symbols->FindTypes(pattern, languages, append, types);
1042+
return symbols->FindTypes(pattern, languages, types);
10461043
return 0;
10471044
}
10481045

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,14 @@ uint32_t SymbolFileBreakpad::FindFunctions(const RegularExpression &regex,
310310

311311
uint32_t SymbolFileBreakpad::FindTypes(
312312
ConstString name, const CompilerDeclContext *parent_decl_ctx,
313-
bool append, uint32_t max_matches,
314-
llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeMap &types) {
315-
if (!append)
316-
types.Clear();
317-
return types.GetSize();
313+
uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files,
314+
TypeMap &types) {
315+
return 0;
318316
}
319317

320318
size_t SymbolFileBreakpad::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
321-
LanguageSet languages, bool append,
322-
TypeMap &types) {
323-
if (!append)
324-
types.Clear();
325-
return types.GetSize();
319+
LanguageSet languages, TypeMap &types) {
320+
return 0;
326321
}
327322

328323
void SymbolFileBreakpad::AddSymbols(Symtab &symtab) {

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ class SymbolFileBreakpad : public SymbolFile {
112112
bool append, SymbolContextList &sc_list) override;
113113

114114
uint32_t FindTypes(ConstString name,
115-
const CompilerDeclContext *parent_decl_ctx, bool append,
115+
const CompilerDeclContext *parent_decl_ctx,
116116
uint32_t max_matches,
117117
llvm::DenseSet<SymbolFile *> &searched_symbol_files,
118118
TypeMap &types) override;
119119

120120
size_t FindTypes(llvm::ArrayRef<CompilerContext> pattern,
121-
LanguageSet languages, bool append, TypeMap &types) override;
121+
LanguageSet languages, TypeMap &types) override;
122122

123123
llvm::Expected<TypeSystem &>
124124
GetTypeSystemForLanguage(lldb::LanguageType language) override {

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) {
151151
// The type in the Clang module must have the same langage as the current CU.
152152
LanguageSet languages;
153153
languages.Insert(die.GetCU()->GetLanguageType());
154-
if (!dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, true,
154+
if (!dwo_module_sp->GetSymbolFile()->FindTypes(decl_context, languages,
155155
dwo_types)) {
156156
if (!IsClangModuleFwdDecl(die))
157157
return TypeSP();
@@ -162,8 +162,8 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) {
162162
for (const auto &name_module : sym_file.getExternalTypeModules()) {
163163
if (!name_module.second)
164164
continue;
165-
if (name_module.second->GetSymbolFile()->FindTypes(
166-
decl_context, languages, true, dwo_types))
165+
if (name_module.second->GetSymbolFile()->FindTypes(decl_context,
166+
languages, dwo_types))
167167
break;
168168
}
169169
}

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 46 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,15 +2384,11 @@ void SymbolFileDWARF::GetMangledNamesForFunction(
23842384
}
23852385

23862386
uint32_t SymbolFileDWARF::FindTypes(
2387-
ConstString name, const CompilerDeclContext *parent_decl_ctx, bool append,
2387+
ConstString name, const CompilerDeclContext *parent_decl_ctx,
23882388
uint32_t max_matches,
23892389
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
23902390
TypeMap &types) {
23912391
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2392-
// If we aren't appending the results to this list, then clear the list
2393-
if (!append)
2394-
types.Clear();
2395-
23962392
// Make sure we haven't already searched this SymbolFile before...
23972393
if (searched_symbol_files.count(this))
23982394
return 0;
@@ -2410,15 +2406,15 @@ uint32_t SymbolFileDWARF::FindTypes(
24102406
GetObjectFile()->GetModule()->LogMessage(
24112407
log,
24122408
"SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = "
2413-
"%p (\"%s\"), append=%u, max_matches=%u, type_list)",
2409+
"%p (\"%s\"), max_matches=%u, type_list)",
24142410
name.GetCString(), static_cast<const void *>(parent_decl_ctx),
2415-
parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches);
2411+
parent_decl_ctx->GetName().AsCString("<NULL>"), max_matches);
24162412
else
24172413
GetObjectFile()->GetModule()->LogMessage(
24182414
log,
24192415
"SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = "
2420-
"NULL, append=%u, max_matches=%u, type_list)",
2421-
name.GetCString(), append, max_matches);
2416+
"NULL, max_matches=%u, type_list)",
2417+
name.GetCString(), max_matches);
24222418
}
24232419

24242420
if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
@@ -2427,46 +2423,25 @@ uint32_t SymbolFileDWARF::FindTypes(
24272423
DIEArray die_offsets;
24282424
m_index->GetTypes(name, die_offsets);
24292425
const size_t num_die_matches = die_offsets.size();
2426+
const uint32_t initial_types_size = types.GetSize();
24302427

2431-
if (num_die_matches) {
2432-
const uint32_t initial_types_size = types.GetSize();
2433-
for (size_t i = 0; i < num_die_matches; ++i) {
2434-
const DIERef &die_ref = die_offsets[i];
2435-
DWARFDIE die = GetDIE(die_ref);
2428+
for (size_t i = 0; i < num_die_matches; ++i) {
2429+
const DIERef &die_ref = die_offsets[i];
2430+
DWARFDIE die = GetDIE(die_ref);
2431+
if (die) {
2432+
if (!DIEInDeclContext(parent_decl_ctx, die))
2433+
continue; // The containing decl contexts don't match
24362434

2437-
if (die) {
2438-
if (!DIEInDeclContext(parent_decl_ctx, die))
2439-
continue; // The containing decl contexts don't match
2440-
2441-
Type *matching_type = ResolveType(die, true, true);
2442-
if (matching_type) {
2443-
// We found a type pointer, now find the shared pointer form our type
2444-
// list
2445-
types.InsertUnique(matching_type->shared_from_this());
2446-
if (types.GetSize() >= max_matches)
2447-
break;
2448-
}
2449-
} else {
2450-
m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
2451-
}
2452-
}
2453-
const uint32_t num_matches = types.GetSize() - initial_types_size;
2454-
if (log && num_matches) {
2455-
if (parent_decl_ctx) {
2456-
GetObjectFile()->GetModule()->LogMessage(
2457-
log,
2458-
"SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2459-
"= %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u",
2460-
name.GetCString(), static_cast<const void *>(parent_decl_ctx),
2461-
parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches,
2462-
num_matches);
2463-
} else {
2464-
GetObjectFile()->GetModule()->LogMessage(
2465-
log,
2466-
"SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2467-
"= NULL, append=%u, max_matches=%u, type_list) => %u",
2468-
name.GetCString(), append, max_matches, num_matches);
2435+
Type *matching_type = ResolveType(die, true, true);
2436+
if (matching_type) {
2437+
// We found a type pointer, now find the shared pointer form our type
2438+
// list
2439+
types.InsertUnique(matching_type->shared_from_this());
2440+
if (types.GetSize() >= max_matches)
2441+
break;
24692442
}
2443+
} else {
2444+
m_index->ReportInvalidDIERef(die_ref, name.GetStringRef());
24702445
}
24712446
}
24722447

@@ -2476,31 +2451,38 @@ uint32_t SymbolFileDWARF::FindTypes(
24762451
if (num_die_matches < max_matches) {
24772452
UpdateExternalModuleListIfNeeded();
24782453

2479-
for (const auto &pair : m_external_type_modules) {
2480-
ModuleSP external_module_sp = pair.second;
2481-
if (external_module_sp) {
2482-
SymbolFile *sym_file = external_module_sp->GetSymbolFile();
2483-
if (sym_file) {
2484-
const uint32_t num_external_matches =
2485-
sym_file->FindTypes(name, parent_decl_ctx, append, max_matches,
2486-
searched_symbol_files, types);
2487-
if (num_external_matches)
2488-
return num_external_matches;
2489-
}
2490-
}
2454+
for (const auto &pair : m_external_type_modules)
2455+
if (ModuleSP external_module_sp = pair.second)
2456+
if (SymbolFile *sym_file = external_module_sp->GetSymbolFile())
2457+
sym_file->FindTypes(name, parent_decl_ctx, max_matches,
2458+
searched_symbol_files, types);
2459+
}
2460+
2461+
uint32_t num_matches = types.GetSize() - initial_types_size;
2462+
if (log && num_matches) {
2463+
if (parent_decl_ctx) {
2464+
GetObjectFile()->GetModule()->LogMessage(
2465+
log,
2466+
"SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2467+
"= %p (\"%s\"), max_matches=%u, type_list) => %u",
2468+
name.GetCString(), static_cast<const void *>(parent_decl_ctx),
2469+
parent_decl_ctx->GetName().AsCString("<NULL>"), max_matches,
2470+
num_matches);
2471+
} else {
2472+
GetObjectFile()->GetModule()->LogMessage(
2473+
log,
2474+
"SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2475+
"= NULL, max_matches=%u, type_list) => %u",
2476+
name.GetCString(), max_matches, num_matches);
24912477
}
24922478
}
24932479

2494-
return num_die_matches;
2480+
return num_matches;
24952481
}
24962482

24972483
size_t SymbolFileDWARF::FindTypes(llvm::ArrayRef<CompilerContext> pattern,
2498-
LanguageSet languages, bool append,
2499-
TypeMap &types) {
2484+
LanguageSet languages, TypeMap &types) {
25002485
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2501-
if (!append)
2502-
types.Clear();
2503-
25042486
if (pattern.empty())
25052487
return 0;
25062488

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
184184
uint32_t
185185
FindTypes(lldb_private::ConstString name,
186186
const lldb_private::CompilerDeclContext *parent_decl_ctx,
187-
bool append, uint32_t max_matches,
187+
uint32_t max_matches,
188188
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
189189
lldb_private::TypeMap &types) override;
190190

191191
size_t FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern,
192-
lldb_private::LanguageSet languages, bool append,
192+
lldb_private::LanguageSet languages,
193193
lldb_private::TypeMap &types) override;
194194

195195
size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,17 +1201,14 @@ TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
12011201

12021202
uint32_t SymbolFileDWARFDebugMap::FindTypes(
12031203
ConstString name, const CompilerDeclContext *parent_decl_ctx,
1204-
bool append, uint32_t max_matches,
1204+
uint32_t max_matches,
12051205
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
12061206
TypeMap &types) {
12071207
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1208-
if (!append)
1209-
types.Clear();
1210-
12111208
const uint32_t initial_types_size = types.GetSize();
12121209

12131210
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1214-
oso_dwarf->FindTypes(name, parent_decl_ctx, append, max_matches,
1211+
oso_dwarf->FindTypes(name, parent_decl_ctx, max_matches,
12151212
searched_symbol_files, types);
12161213
return types.GetSize() >= max_matches;
12171214
});

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
111111
uint32_t
112112
FindTypes(lldb_private::ConstString name,
113113
const lldb_private::CompilerDeclContext *parent_decl_ctx,
114-
bool append, uint32_t max_matches,
114+
uint32_t max_matches,
115115
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
116116
lldb_private::TypeMap &types) override;
117117
lldb_private::CompilerDeclContext FindNamespace(

0 commit comments

Comments
 (0)