diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index 02b1f9bcd4a06f..2395e3444d9d50 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -750,100 +750,11 @@ void ClangASTSource::FindExternalVisibleDecls( if (!context.m_found.type) { // Try the modules next. - - do { - if (ClangModulesDeclVendor *modules_decl_vendor = - m_target->GetClangModulesDeclVendor()) { - bool append = false; - uint32_t max_matches = 1; - std::vector decls; - - if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls)) - break; - - if (log) { - LLDB_LOG(log, - " CAS::FEVD[{0}] Matching entity found for \"{1}\" in " - "the modules", - current_id, name); - } - - clang::NamedDecl *const decl_from_modules = decls[0]; - - if (llvm::isa(decl_from_modules) || - llvm::isa(decl_from_modules) || - llvm::isa(decl_from_modules)) { - clang::Decl *copied_decl = CopyDecl(decl_from_modules); - clang::NamedDecl *copied_named_decl = - copied_decl ? dyn_cast(copied_decl) : nullptr; - - if (!copied_named_decl) { - LLDB_LOG( - log, - " CAS::FEVD[{0}] - Couldn't export a type from the modules", - current_id); - - break; - } - - context.AddNamedDecl(copied_named_decl); - - context.m_found.type = true; - } - } - } while (false); + FindDeclInModules(context, name, current_id); } if (!context.m_found.type) { - do { - // Couldn't find any types elsewhere. Try the Objective-C runtime if - // one exists. - - lldb::ProcessSP process(m_target->GetProcessSP()); - - if (!process) - break; - - ObjCLanguageRuntime *language_runtime( - ObjCLanguageRuntime::Get(*process)); - - if (!language_runtime) - break; - - DeclVendor *decl_vendor = language_runtime->GetDeclVendor(); - - if (!decl_vendor) - break; - - bool append = false; - uint32_t max_matches = 1; - std::vector decls; - - auto *clang_decl_vendor = llvm::cast(decl_vendor); - if (!clang_decl_vendor->FindDecls(name, append, max_matches, decls)) - break; - - if (log) { - LLDB_LOG( - log, - " CAS::FEVD[{0}] Matching type found for \"{0}\" in the runtime", - current_id, name); - } - - clang::Decl *copied_decl = CopyDecl(decls[0]); - clang::NamedDecl *copied_named_decl = - copied_decl ? dyn_cast(copied_decl) : nullptr; - - if (!copied_named_decl) { - LLDB_LOG(log, - " CAS::FEVD[{0}] - Couldn't export a type from the runtime", - current_id); - - break; - } - - context.AddNamedDecl(copied_named_decl); - } while (false); + FindDeclInObjCRuntime(context, name, current_id); } } @@ -979,6 +890,100 @@ bool ClangASTSource::FindObjCMethodDeclsWithOrigin( return true; } +void ClangASTSource::FindDeclInModules(NameSearchContext &context, + ConstString name, unsigned current_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + + ClangModulesDeclVendor *modules_decl_vendor = + m_target->GetClangModulesDeclVendor(); + if (!modules_decl_vendor) + return; + + bool append = false; + uint32_t max_matches = 1; + std::vector decls; + + if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls)) + return; + + if (log) { + LLDB_LOG(log, + " CAS::FEVD[{0}] Matching entity found for \"{1}\" in " + "the modules", + current_id, name); + } + + clang::NamedDecl *const decl_from_modules = decls[0]; + + if (llvm::isa(decl_from_modules) || + llvm::isa(decl_from_modules) || + llvm::isa(decl_from_modules)) { + clang::Decl *copied_decl = CopyDecl(decl_from_modules); + clang::NamedDecl *copied_named_decl = + copied_decl ? dyn_cast(copied_decl) : nullptr; + + if (!copied_named_decl) { + LLDB_LOG(log, + " CAS::FEVD[{0}] - Couldn't export a type from the modules", + current_id); + + return; + } + + context.AddNamedDecl(copied_named_decl); + + context.m_found.type = true; + } +} + +void ClangASTSource::FindDeclInObjCRuntime(NameSearchContext &context, + ConstString name, + unsigned current_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + + lldb::ProcessSP process(m_target->GetProcessSP()); + + if (!process) + return; + + ObjCLanguageRuntime *language_runtime(ObjCLanguageRuntime::Get(*process)); + + if (!language_runtime) + return; + + DeclVendor *decl_vendor = language_runtime->GetDeclVendor(); + + if (!decl_vendor) + return; + + bool append = false; + uint32_t max_matches = 1; + std::vector decls; + + auto *clang_decl_vendor = llvm::cast(decl_vendor); + if (!clang_decl_vendor->FindDecls(name, append, max_matches, decls)) + return; + + if (log) { + LLDB_LOG(log, + " CAS::FEVD[{0}] Matching type found for \"{0}\" in the runtime", + current_id, name); + } + + clang::Decl *copied_decl = CopyDecl(decls[0]); + clang::NamedDecl *copied_named_decl = + copied_decl ? dyn_cast(copied_decl) : nullptr; + + if (!copied_named_decl) { + LLDB_LOG(log, " CAS::FEVD[{0}] - Couldn't export a type from the runtime", + current_id); + + return; + } + + context.AddNamedDecl(copied_named_decl); +} + void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h index cafd6d5ad833b8..c923cce4fb7bd5 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h @@ -359,6 +359,11 @@ class ClangASTSource : public clang::ExternalASTSource, unsigned int current_id, NameSearchContext &context, clang::ObjCInterfaceDecl *original_interface_decl, const char *log_info); + void FindDeclInModules(NameSearchContext &context, ConstString name, + unsigned current_id); + void FindDeclInObjCRuntime(NameSearchContext &context, ConstString name, + unsigned current_id); + friend struct NameSearchContext; bool m_import_in_progress;