summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Langford <apl@fb.com>2019-07-02 19:53:07 +0000
committerAlex Langford <apl@fb.com>2019-07-02 19:53:07 +0000
commit8055cbc4490932e617e5dd0278a38e498adee98c (patch)
tree291371f3046f1de046491e091254af0ed3d8e312
parent99316043bbce99081d977a276e8a4c879cfa9de2 (diff)
downloadbcm5719-llvm-8055cbc4490932e617e5dd0278a38e498adee98c.tar.gz
bcm5719-llvm-8055cbc4490932e617e5dd0278a38e498adee98c.zip
[Symbol] Add DeclVendor::FindTypes
Summary: Following up on the plan I outlined in D63622, we can remove the dependence on clang in all the places where we only want to find the types from the DeclVendor. This means that currently DeclVendor depends on clang, but centralizing the dependency makes it easier to refactor cleanly. Differential Revision: https://reviews.llvm.org/D63853 llvm-svn: 364962
-rw-r--r--lldb/include/lldb/Symbol/DeclVendor.h13
-rw-r--r--lldb/source/API/SBTarget.cpp26
-rw-r--r--lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp44
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp10
-rw-r--r--lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp14
-rw-r--r--lldb/source/Symbol/CMakeLists.txt1
-rw-r--r--lldb/source/Symbol/DeclVendor.cpp29
7 files changed, 73 insertions, 64 deletions
diff --git a/lldb/include/lldb/Symbol/DeclVendor.h b/lldb/include/lldb/Symbol/DeclVendor.h
index 19458773b10..9c10fe1177f 100644
--- a/lldb/include/lldb/Symbol/DeclVendor.h
+++ b/lldb/include/lldb/Symbol/DeclVendor.h
@@ -47,6 +47,19 @@ public:
uint32_t max_matches,
std::vector<clang::NamedDecl *> &decls) = 0;
+ /// Look up the types that the DeclVendor currently knows about matching a
+ /// given name.
+ ///
+ /// \param[in] name
+ /// The name to look for.
+ ///
+ /// \param[in] max_matches
+ // The maximum number of matches. UINT32_MAX means "as many as possible".
+ ///
+ /// \return
+ /// The vector of CompilerTypes that was found.
+ std::vector<CompilerType> FindTypes(ConstString name, uint32_t max_matches);
+
/// Interface for ExternalASTMerger. Returns an ImporterSource
/// allowing type completion.
///
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index b1ad0d8f58b..5e87eb6273b 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1847,18 +1847,12 @@ lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
}
// Didn't find the type in the symbols; Try the loaded language runtimes
- // FIXME: This depends on clang, but should be able to support any
- // TypeSystem/compiler.
if (auto process_sp = target_sp->GetProcessSP()) {
for (auto *runtime : process_sp->GetLanguageRuntimes()) {
if (auto vendor = runtime->GetDeclVendor()) {
- std::vector<clang::NamedDecl *> decls;
- if (vendor->FindDecls(const_typename, /*append*/ true,
- /*max_matches*/ 1, decls) > 0) {
- if (CompilerType type =
- ClangASTContext::GetTypeForDecl(decls.front()))
- return LLDB_RECORD_RESULT(SBType(type));
- }
+ auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
+ if (!types.empty())
+ return LLDB_RECORD_RESULT(SBType(types.front()));
}
}
}
@@ -1911,19 +1905,13 @@ lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
}
// Try the loaded language runtimes
- // FIXME: This depends on clang, but should be able to support any
- // TypeSystem/compiler.
if (auto process_sp = target_sp->GetProcessSP()) {
for (auto *runtime : process_sp->GetLanguageRuntimes()) {
if (auto *vendor = runtime->GetDeclVendor()) {
- std::vector<clang::NamedDecl *> decls;
- if (vendor->FindDecls(const_typename, /*append*/ true,
- /*max_matches*/ 1, decls) > 0) {
- for (auto *decl : decls) {
- if (CompilerType type = ClangASTContext::GetTypeForDecl(decl))
- sb_type_list.Append(SBType(type));
- }
- }
+ auto types =
+ vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
+ for (auto type : types)
+ sb_type_list.Append(SBType(type));
}
}
}
diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
index bce7e93ad3a..fc0c933e13f 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -932,25 +932,16 @@ std::unique_ptr<Language::TypeScavenger> ObjCLanguage::GetTypeScavenger() {
ResultSet &results) override {
bool result = false;
- Process *process = exe_scope->CalculateProcess().get();
- if (process) {
- auto objc_runtime = ObjCLanguageRuntime::Get(*process);
- if (objc_runtime) {
- auto decl_vendor = objc_runtime->GetDeclVendor();
- if (decl_vendor) {
- std::vector<clang::NamedDecl *> decls;
+ if (auto *process = exe_scope->CalculateProcess().get()) {
+ if (auto *objc_runtime = ObjCLanguageRuntime::Get(*process)) {
+ if (auto *decl_vendor = objc_runtime->GetDeclVendor()) {
ConstString name(key);
- decl_vendor->FindDecls(name, true, UINT32_MAX, decls);
- for (auto decl : decls) {
- if (decl) {
- if (CompilerType candidate =
- ClangASTContext::GetTypeForDecl(decl)) {
- result = true;
- std::unique_ptr<Language::TypeScavenger::Result> result(
- new ObjCScavengerResult(candidate));
- results.insert(std::move(result));
- }
- }
+ for (const CompilerType &type :
+ decl_vendor->FindTypes(name, /*max_matches*/ UINT32_MAX)) {
+ result = true;
+ std::unique_ptr<Language::TypeScavenger::Result> result(
+ new ObjCScavengerResult(type));
+ results.insert(std::move(result));
}
}
}
@@ -968,21 +959,16 @@ std::unique_ptr<Language::TypeScavenger> ObjCLanguage::GetTypeScavenger() {
ResultSet &results) override {
bool result = false;
- Target *target = exe_scope->CalculateTarget().get();
- if (target) {
- if (auto clang_modules_decl_vendor =
+ if (auto *target = exe_scope->CalculateTarget().get()) {
+ if (auto *clang_modules_decl_vendor =
target->GetClangModulesDeclVendor()) {
- std::vector<clang::NamedDecl *> decls;
ConstString key_cs(key);
-
- if (clang_modules_decl_vendor->FindDecls(key_cs, false, UINT32_MAX,
- decls) > 0 &&
- !decls.empty()) {
- CompilerType module_type =
- ClangASTContext::GetTypeForDecl(decls.front());
+ auto types = clang_modules_decl_vendor->FindTypes(
+ key_cs, /*max_matches*/ UINT32_MAX);
+ if (!types.empty()) {
result = true;
std::unique_ptr<Language::TypeScavenger::Result> result(
- new ObjCScavengerResult(module_type));
+ new ObjCScavengerResult(types.front()));
results.insert(std::move(result));
}
}
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index c849a5441f0..38a4f9e4094 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -474,12 +474,10 @@ bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
class_type_or_name.SetTypeSP(type_sp);
} else {
// try to go for a CompilerType at least
- DeclVendor *vendor = GetDeclVendor();
- if (vendor) {
- std::vector<clang::NamedDecl *> decls;
- if (vendor->FindDecls(class_name, false, 1, decls) && decls.size())
- class_type_or_name.SetCompilerType(
- ClangASTContext::GetTypeForDecl(decls[0]));
+ if (auto *vendor = GetDeclVendor()) {
+ auto types = vendor->FindTypes(class_name, /*max_matches*/ 1);
+ if (!types.empty())
+ class_type_or_name.SetCompilerType(types.front());
}
}
}
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
index e1068e8d403..26654e9212b 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
@@ -245,25 +245,19 @@ clang::QualType AppleObjCTypeEncodingParser::BuildObjCObjectPointerType(
if (!decl_vendor)
return clang::QualType();
- const bool append = false;
- const uint32_t max_matches = 1;
- std::vector<clang::NamedDecl *> decls;
-
- uint32_t num_types =
- decl_vendor->FindDecls(ConstString(name), append, max_matches, decls);
+ auto types = decl_vendor->FindTypes(ConstString(name), /*max_matches*/ 1);
// The user can forward-declare something that has no definition. The runtime
// doesn't prohibit this at all. This is a rare and very weird case. We keep
// this assert in debug builds so we catch other weird cases.
#ifdef LLDB_CONFIGURATION_DEBUG
- assert(num_types);
+ assert(!types.empty());
#else
- if (!num_types)
+ if (types.empty())
return ast_ctx.getObjCIdType();
#endif
- return ClangUtil::GetQualType(
- ClangASTContext::GetTypeForDecl(decls[0]).GetPointerType());
+ return ClangUtil::GetQualType(types.front().GetPointerType());
} else {
// We're going to resolve this dynamically anyway, so just smile and wave.
return ast_ctx.getObjCIdType();
diff --git a/lldb/source/Symbol/CMakeLists.txt b/lldb/source/Symbol/CMakeLists.txt
index 18e3725b783..96ccc25220a 100644
--- a/lldb/source/Symbol/CMakeLists.txt
+++ b/lldb/source/Symbol/CMakeLists.txt
@@ -21,6 +21,7 @@ add_lldb_library(lldbSymbol
DWARFCallFrameInfo.cpp
DebugMacros.cpp
Declaration.cpp
+ DeclVendor.cpp
FuncUnwinders.cpp
Function.cpp
LineEntry.cpp
diff --git a/lldb/source/Symbol/DeclVendor.cpp b/lldb/source/Symbol/DeclVendor.cpp
new file mode 100644
index 00000000000..0a912a2fd21
--- /dev/null
+++ b/lldb/source/Symbol/DeclVendor.cpp
@@ -0,0 +1,29 @@
+//===-- DeclVendor.cpp ------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/DeclVendor.h"
+
+#include "lldb/Symbol/ClangASTContext.h"
+
+#include <vector>
+
+using namespace lldb;
+using namespace lldb_private;
+
+std::vector<CompilerType> DeclVendor::FindTypes(ConstString name,
+ uint32_t max_matches) {
+ // FIXME: This depends on clang, but should be able to support any
+ // TypeSystem.
+ std::vector<CompilerType> ret;
+ std::vector<clang::NamedDecl *> decls;
+ if (FindDecls(name, /*append*/ true, max_matches, decls))
+ for (auto *decl : decls)
+ if (auto type = ClangASTContext::GetTypeForDecl(decl))
+ ret.push_back(type);
+ return ret;
+}
OpenPOWER on IntegriCloud