[Lldb-commits] [lldb] 0e5ed1b - [lldb][NFC] Split up ClangASTSource::FindExternalVisibleDecls
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 21 00:48:14 PST 2020
Author: Raphael Isemann
Date: 2020-02-21T09:47:52+01:00
New Revision: 0e5ed1b26264f7eee32b23c533371c18ce1cdec0
URL: https://github.com/llvm/llvm-project/commit/0e5ed1b26264f7eee32b23c533371c18ce1cdec0
DIFF: https://github.com/llvm/llvm-project/commit/0e5ed1b26264f7eee32b23c533371c18ce1cdec0.diff
LOG: [lldb][NFC] Split up ClangASTSource::FindExternalVisibleDecls
This function has two functions hidden inside it. Let's make
them proper functions.
Added:
Modified:
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 02b1f9bcd4a0..2395e3444d9d 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<clang::NamedDecl *> 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<clang::TypeDecl>(decl_from_modules) ||
- llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) ||
- llvm::isa<clang::EnumConstantDecl>(decl_from_modules)) {
- clang::Decl *copied_decl = CopyDecl(decl_from_modules);
- clang::NamedDecl *copied_named_decl =
- copied_decl ? dyn_cast<clang::NamedDecl>(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<clang::NamedDecl *> decls;
-
- auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(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<clang::NamedDecl>(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<clang::NamedDecl *> 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<clang::TypeDecl>(decl_from_modules) ||
+ llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) ||
+ llvm::isa<clang::EnumConstantDecl>(decl_from_modules)) {
+ clang::Decl *copied_decl = CopyDecl(decl_from_modules);
+ clang::NamedDecl *copied_named_decl =
+ copied_decl ? dyn_cast<clang::NamedDecl>(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<clang::NamedDecl *> decls;
+
+ auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(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<clang::NamedDecl>(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 cafd6d5ad833..c923cce4fb7b 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;
More information about the lldb-commits
mailing list