Skip to content

Commit a0408ab

Browse files
committed
[lldb][NFC] Move searching the ClangModulesDeclVendor into own function
1 parent aa981c1 commit a0408ab

File tree

2 files changed

+86
-72
lines changed

2 files changed

+86
-72
lines changed

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

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,76 @@ void ClangExpressionDeclMap::LookupLocalVarNamespace(
10991099
}
11001100
}
11011101

1102+
void ClangExpressionDeclMap::LookupInModulesDeclVendor(
1103+
NameSearchContext &context, ConstString name, unsigned current_id) {
1104+
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1105+
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+
}
1137+
1138+
MaybeRegisterFunctionBody(copied_function_decl);
1139+
1140+
context.AddNamedDecl(copied_function_decl);
1141+
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+
}
1151+
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;
1155+
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);
1161+
1162+
return;
1163+
}
1164+
1165+
context.AddNamedDecl(copied_var_decl);
1166+
1167+
context.m_found.variable = true;
1168+
}
1169+
}
1170+
}
1171+
11021172
void ClangExpressionDeclMap::FindExternalVisibleDecls(
11031173
NameSearchContext &context, lldb::ModuleSP module_sp,
11041174
CompilerDeclContext &namespace_decl, unsigned int current_id) {
@@ -1433,78 +1503,9 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
14331503
}
14341504
}
14351505

1436-
if (!context.m_found.function_with_type_info) {
1437-
// Try the modules next.
1438-
1439-
do {
1440-
if (ClangModulesDeclVendor *modules_decl_vendor =
1441-
m_target->GetClangModulesDeclVendor()) {
1442-
bool append = false;
1443-
uint32_t max_matches = 1;
1444-
std::vector<clang::NamedDecl *> decls;
1445-
1446-
if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls))
1447-
break;
1448-
1449-
clang::NamedDecl *const decl_from_modules = decls[0];
1450-
1451-
if (llvm::isa<clang::FunctionDecl>(decl_from_modules)) {
1452-
if (log) {
1453-
LLDB_LOGF(log,
1454-
" CAS::FEVD[%u] Matching function found for "
1455-
"\"%s\" in the modules",
1456-
current_id, name.GetCString());
1457-
}
1458-
1459-
clang::Decl *copied_decl = CopyDecl(decl_from_modules);
1460-
clang::FunctionDecl *copied_function_decl =
1461-
copied_decl ? dyn_cast<clang::FunctionDecl>(copied_decl)
1462-
: nullptr;
1463-
1464-
if (!copied_function_decl) {
1465-
LLDB_LOGF(log,
1466-
" CAS::FEVD[%u] - Couldn't export a function "
1467-
"declaration from the modules",
1468-
current_id);
1469-
1470-
break;
1471-
}
1472-
1473-
MaybeRegisterFunctionBody(copied_function_decl);
1474-
1475-
context.AddNamedDecl(copied_function_decl);
1476-
1477-
context.m_found.function_with_type_info = true;
1478-
context.m_found.function = true;
1479-
} else if (llvm::isa<clang::VarDecl>(decl_from_modules)) {
1480-
if (log) {
1481-
LLDB_LOGF(log,
1482-
" CAS::FEVD[%u] Matching variable found for "
1483-
"\"%s\" in the modules",
1484-
current_id, name.GetCString());
1485-
}
1486-
1487-
clang::Decl *copied_decl = CopyDecl(decl_from_modules);
1488-
clang::VarDecl *copied_var_decl =
1489-
copied_decl ? dyn_cast_or_null<clang::VarDecl>(copied_decl)
1490-
: nullptr;
1491-
1492-
if (!copied_var_decl) {
1493-
LLDB_LOGF(log,
1494-
" CAS::FEVD[%u] - Couldn't export a variable "
1495-
"declaration from the modules",
1496-
current_id);
1497-
1498-
break;
1499-
}
1500-
1501-
context.AddNamedDecl(copied_var_decl);
1502-
1503-
context.m_found.variable = true;
1504-
}
1505-
}
1506-
} while (false);
1507-
}
1506+
// Try the modules next.
1507+
if (!context.m_found.function_with_type_info)
1508+
LookupInModulesDeclVendor(context, name, current_id);
15081509

15091510
if (target && !context.m_found.variable && !namespace_decl) {
15101511
// We couldn't find a non-symbol variable for this. Now we'll hunt for a

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,19 @@ class ClangExpressionDeclMap : public ClangASTSource {
421421
void LookupLocalVarNamespace(SymbolContext &sym_ctx,
422422
NameSearchContext &context);
423423

424+
/// Lookup entities in the ClangModulesDeclVendor.
425+
/// \param[in] context
426+
/// The NameSearchContext that can construct Decls for this name.
427+
///
428+
/// \param[in] name
429+
/// The name of the entities that need to be found.
430+
///
431+
/// \param[in] current_id
432+
/// The ID for the current FindExternalVisibleDecls invocation,
433+
/// for logging purposes.
434+
void LookupInModulesDeclVendor(NameSearchContext &context, ConstString name,
435+
unsigned current_id);
436+
424437
/// Given a target, find a variable that matches the given name and type.
425438
///
426439
/// \param[in] target

0 commit comments

Comments
 (0)