[API] Remove use of ClangASTContext from SBTarget

Summary:
The methods to find types in a Target aren't clang specific and are
pretty generalizable to type systems. Additionally, to support some of
the use cases in SBTarget, I've added a "GetScratchTypeSystems" method
to Target to support getting all type systems for a target we are
debugging.

Differential Revision: https://reviews.llvm.org/D64964

llvm-svn: 367480
This commit is contained in:
Alex Langford 2019-07-31 20:47:38 +00:00
parent 33703fb9f9
commit 70402bfc46
3 changed files with 42 additions and 13 deletions

View File

@ -1026,6 +1026,8 @@ public:
GetScratchTypeSystemForLanguage(lldb::LanguageType language,
bool create_on_demand = true);
std::vector<TypeSystem *> GetScratchTypeSystems(bool create_on_demand = true);
PersistentExpressionState *
GetPersistentExpressionStateForLanguage(lldb::LanguageType language);

View File

@ -44,11 +44,11 @@
#include "lldb/Core/ValueObjectList.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/DeclVendor.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/Language.h"
@ -1858,11 +1858,11 @@ lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
}
// No matches, search for basic typename matches
ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
if (clang_ast)
return LLDB_RECORD_RESULT(SBType(ClangASTContext::GetBasicType(
clang_ast->getASTContext(), const_typename)));
for (auto *type_system : target_sp->GetScratchTypeSystems())
if (auto type = type_system->GetBuiltinTypeByName(const_typename))
return LLDB_RECORD_RESULT(SBType(type));
}
return LLDB_RECORD_RESULT(SBType());
}
@ -1872,10 +1872,9 @@ SBType SBTarget::GetBasicType(lldb::BasicType type) {
TargetSP target_sp(GetSP());
if (target_sp) {
ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
if (clang_ast)
return LLDB_RECORD_RESULT(SBType(
ClangASTContext::GetBasicType(clang_ast->getASTContext(), type)));
for (auto *type_system : target_sp->GetScratchTypeSystems())
if (auto compiler_type = type_system->GetBasicTypeFromAST(type))
return LLDB_RECORD_RESULT(SBType(compiler_type));
}
return LLDB_RECORD_RESULT(SBType());
}
@ -1918,10 +1917,10 @@ lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
if (sb_type_list.GetSize() == 0) {
// No matches, search for basic typename matches
ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
if (clang_ast)
sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
clang_ast->getASTContext(), const_typename)));
for (auto *type_system : target_sp->GetScratchTypeSystems())
if (auto compiler_type =
type_system->GetBuiltinTypeByName(const_typename))
sb_type_list.Append(SBType(compiler_type));
}
}
return LLDB_RECORD_RESULT(sb_type_list);

View File

@ -2153,6 +2153,34 @@ Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
create_on_demand);
}
std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) {
if (!m_valid)
return {};
std::vector<TypeSystem *> scratch_type_systems;
std::set<lldb::LanguageType> languages_for_types;
std::set<lldb::LanguageType> languages_for_expressions;
Language::GetLanguagesSupportingTypeSystems(languages_for_types,
languages_for_expressions);
for (auto lang : languages_for_expressions) {
auto type_system_or_err =
GetScratchTypeSystemForLanguage(lang, create_on_demand);
if (!type_system_or_err)
LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
type_system_or_err.takeError(),
"Language '{}' has expression support but no scratch type "
"system available",
Language::GetNameForLanguageType(lang));
else
scratch_type_systems.emplace_back(&type_system_or_err.get());
}
return scratch_type_systems;
}
PersistentExpressionState *
Target::GetPersistentExpressionStateForLanguage(lldb::LanguageType language) {
auto type_system_or_err = GetScratchTypeSystemForLanguage(language, true);