Skip to content

Commit 18b5f85

Browse files
committed
Unify Swift AST section parsing and logging
1 parent 5e20d8b commit 18b5f85

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,21 +4142,36 @@ void SwiftASTContext::RegisterSectionModules(
41424142
if (!section_list)
41434143
return;
41444144

4145-
SectionSP section_sp(
4146-
section_list->FindSectionByType(eSectionTypeSwiftModules, true));
4147-
if (section_sp) {
4145+
auto parse_ast_section = [&](llvm::StringRef section_data_ref, size_t n,
4146+
size_t total) {
4147+
llvm::SmallVector<std::string, 4> swift_modules;
4148+
if (!swift::parseASTSection(*loader, section_data_ref, swift_modules)) {
4149+
LOG_PRINTF(LIBLLDB_LOG_TYPES,
4150+
"failed to parse AST section %zu/%zu in image \"%s\".", n,
4151+
total, module.GetFileSpec().GetFilename().GetCString());
4152+
return;
4153+
}
4154+
4155+
// Collect the Swift module names referenced by the AST.
4156+
for (auto module_name : swift_modules) {
4157+
module_names.push_back(module_name);
4158+
LOG_PRINTF(LIBLLDB_LOG_TYPES,
4159+
"parsed module \"%s\" from Swift AST section %zu/%zu in "
4160+
"image \"%s\".",
4161+
module_name.c_str(), n, total,
4162+
module.GetFileSpec().GetFilename().GetCString());
4163+
}
4164+
};
4165+
4166+
if (auto section_sp =
4167+
section_list->FindSectionByType(eSectionTypeSwiftModules, true)) {
41484168
DataExtractor section_data;
41494169

41504170
if (section_sp->GetSectionData(section_data)) {
41514171
llvm::StringRef section_data_ref(
41524172
(const char *)section_data.GetDataStart(),
41534173
section_data.GetByteSize());
4154-
llvm::SmallVector<std::string, 4> llvm_modules;
4155-
if (swift::parseASTSection(*loader, section_data_ref, llvm_modules)) {
4156-
for (auto module_name : llvm_modules)
4157-
module_names.push_back(module_name);
4158-
return;
4159-
}
4174+
parse_ast_section(section_data_ref, 1, 1);
41604175
}
41614176
} else {
41624177
if (m_ast_file_data_map.find(&module) != m_ast_file_data_map.end())
@@ -4176,37 +4191,15 @@ void SwiftASTContext::RegisterSectionModules(
41764191

41774192
// Retrieve the module names from the AST blobs retrieved
41784193
// from the symbol vendor.
4179-
size_t parse_fail_count = 0;
4180-
size_t ast_number = 0;
4194+
size_t i = 0;
41814195
for (auto ast_file_data_sp : ast_file_datas) {
41824196
// Parse the AST section info from the AST blob.
4183-
++ast_number;
41844197
llvm::StringRef section_data_ref(
41854198
(const char *)ast_file_data_sp->GetBytes(),
41864199
ast_file_data_sp->GetByteSize());
4187-
llvm::SmallVector<std::string, 4> swift_modules;
4188-
if (swift::parseASTSection(*loader, section_data_ref, swift_modules)) {
4189-
// Collect the Swift module names referenced by the AST.
4190-
for (auto module_name : swift_modules) {
4191-
module_names.push_back(module_name);
4192-
LOG_PRINTF(LIBLLDB_LOG_TYPES,
4193-
"parsed module \"%s\" from Swift AST section %zu of %zu.",
4194-
module_name.c_str(), ast_number, ast_file_datas.size());
4195-
}
4196-
} else {
4197-
// Keep track of the fact that we failed to parse the AST section
4198-
// info.
4199-
LOG_PRINTF(LIBLLDB_LOG_TYPES, "failed to parse AST section %zu of %zu.",
4200-
ast_number, ast_file_datas.size());
4201-
++parse_fail_count;
4202-
}
4203-
}
4204-
if (!ast_file_datas.empty() && (parse_fail_count == 0)) {
4205-
// We found AST data entries and we successfully parsed all of them.
4206-
return;
4200+
parse_ast_section(section_data_ref, ++i, ast_file_datas.size());
42074201
}
42084202
}
4209-
return;
42104203
}
42114204

42124205
void SwiftASTContext::ValidateSectionModules(

0 commit comments

Comments
 (0)