Skip to content

Commit 46883f4

Browse files
author
Raphael Isemann
committed
[lldb][NFC] NFC refactoring for ClangExpressionDeclMap::LookupInModulesDeclVendor
Early exiting and deduplicating copy-pasted code.
1 parent 89bc4c6 commit 46883f4

File tree

1 file changed

+30
-55
lines changed

1 file changed

+30
-55
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,69 +1103,44 @@ void ClangExpressionDeclMap::LookupInModulesDeclVendor(
11031103
NameSearchContext &context, ConstString name, unsigned current_id) {
11041104
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
11051105

1106-
if (ClangModulesDeclVendor *modules_decl_vendor =
1107-
m_target->GetClangModulesDeclVendor()) {
1108-
bool append = false;
1109-
uint32_t max_matches = 1;
1110-
std::vector<clang::NamedDecl *> decls;
1111-
1112-
if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
1113-
return;
1114-
1115-
clang::NamedDecl *const decl_from_modules = decls[0];
1116-
1117-
if (llvm::isa<clang::FunctionDecl>(decl_from_modules)) {
1118-
if (log) {
1119-
LLDB_LOGF(log,
1120-
" CAS::FEVD[%u] Matching function found for "
1121-
"\"%s\" in the modules",
1122-
current_id, name.GetCString());
1123-
}
1124-
1125-
clang::Decl *copied_decl = CopyDecl(decl_from_modules);
1126-
clang::FunctionDecl *copied_function_decl =
1127-
copied_decl ? dyn_cast<clang::FunctionDecl>(copied_decl) : nullptr;
1128-
1129-
if (!copied_function_decl) {
1130-
LLDB_LOGF(log,
1131-
" CAS::FEVD[%u] - Couldn't export a function "
1132-
"declaration from the modules",
1133-
current_id);
1134-
1135-
return;
1136-
}
1106+
auto *modules_decl_vendor = m_target->GetClangModulesDeclVendor();
1107+
if (!modules_decl_vendor)
1108+
return;
11371109

1138-
MaybeRegisterFunctionBody(copied_function_decl);
1110+
bool append = false;
1111+
uint32_t max_matches = 1;
1112+
std::vector<clang::NamedDecl *> decls;
11391113

1140-
context.AddNamedDecl(copied_function_decl);
1114+
if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
1115+
return;
11411116

1142-
context.m_found.function_with_type_info = true;
1143-
context.m_found.function = true;
1144-
} else if (llvm::isa<clang::VarDecl>(decl_from_modules)) {
1145-
if (log) {
1146-
LLDB_LOGF(log,
1147-
" CAS::FEVD[%u] Matching variable found for "
1148-
"\"%s\" in the modules",
1149-
current_id, name.GetCString());
1150-
}
1117+
assert(!decls.empty() && "FindDecls returned true but no decls?");
1118+
clang::NamedDecl *const decl_from_modules = decls[0];
11511119

1152-
clang::Decl *copied_decl = CopyDecl(decl_from_modules);
1153-
clang::VarDecl *copied_var_decl =
1154-
copied_decl ? dyn_cast_or_null<clang::VarDecl>(copied_decl) : nullptr;
1120+
LLDB_LOG(log,
1121+
" CAS::FEVD[{0}] Matching decl found for "
1122+
"\"{1}\" in the modules",
1123+
current_id, name);
11551124

1156-
if (!copied_var_decl) {
1157-
LLDB_LOGF(log,
1158-
" CAS::FEVD[%u] - Couldn't export a variable "
1159-
"declaration from the modules",
1160-
current_id);
1125+
clang::Decl *copied_decl = CopyDecl(decl_from_modules);
1126+
if (!copied_decl) {
1127+
LLDB_LOG(log,
1128+
" CAS::FEVD[{0}] - Couldn't export a "
1129+
"declaration from the modules",
1130+
current_id);
1131+
return;
1132+
}
11611133

1162-
return;
1163-
}
1134+
if (auto copied_function = dyn_cast<clang::FunctionDecl>(copied_decl)) {
1135+
MaybeRegisterFunctionBody(copied_function);
11641136

1165-
context.AddNamedDecl(copied_var_decl);
1137+
context.AddNamedDecl(copied_function);
11661138

1167-
context.m_found.variable = true;
1168-
}
1139+
context.m_found.function_with_type_info = true;
1140+
context.m_found.function = true;
1141+
} else if (auto copied_var = dyn_cast<clang::VarDecl>(copied_decl)) {
1142+
context.AddNamedDecl(copied_var);
1143+
context.m_found.variable = true;
11691144
}
11701145
}
11711146

0 commit comments

Comments
 (0)