[lldb][NFC] Rename TypeSystemClang::GetScratch to ScratchTypeSystemClang::GetForTarget

Also add some documentation while I'm at it.
This commit is contained in:
Raphael Isemann 2020-12-04 10:26:03 +01:00
parent c25b039e21
commit 594308c7ad
25 changed files with 79 additions and 56 deletions

View File

@ -1113,7 +1113,7 @@ DynamicLoaderDarwin::GetThreadLocalData(const lldb::ModuleSP module_sp,
StackFrameSP frame_sp = thread_sp->GetStackFrameAtIndex(0);
if (frame_sp) {
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(target);
ScratchTypeSystemClang::GetForTarget(target);
if (!clang_ast_context)
return LLDB_INVALID_ADDRESS;

View File

@ -224,7 +224,7 @@ bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton,
// get the values from the ABI:
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(process->GetTarget());
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
if (!clang_ast_context)
return false;

View File

@ -343,7 +343,7 @@ bool DynamicLoaderMacOSXDYLD::NotifyBreakpointHit(
// get the values from the ABI:
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(process->GetTarget());
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
if (!clang_ast_context)
return false;

View File

@ -443,7 +443,7 @@ void ASTResultSynthesizer::CommitPersistentDecls() {
return;
auto *persistent_vars = llvm::cast<ClangPersistentVariables>(state);
TypeSystemClang *scratch_ctx = TypeSystemClang::GetScratch(m_target);
TypeSystemClang *scratch_ctx = ScratchTypeSystemClang::GetForTarget(m_target);
for (clang::NamedDecl *decl : m_decls) {
StringRef name = decl->getName();

View File

@ -75,7 +75,7 @@ ClangASTSource::~ClangASTSource() {
// demand by passing false to
// Target::GetScratchTypeSystemClang(create_on_demand).
TypeSystemClang *scratch_clang_ast_context =
TypeSystemClang::GetScratch(*m_target, false);
ScratchTypeSystemClang::GetForTarget(*m_target, false);
if (!scratch_clang_ast_context)
return;

View File

@ -110,7 +110,7 @@ bool ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx,
m_parser_vars->m_persistent_vars = llvm::cast<ClangPersistentVariables>(
target->GetPersistentExpressionStateForLanguage(eLanguageTypeC));
if (!TypeSystemClang::GetScratch(*target))
if (!ScratchTypeSystemClang::GetForTarget(*target))
return false;
}
@ -184,7 +184,7 @@ ClangExpressionDeclMap::TargetInfo ClangExpressionDeclMap::GetTargetInfo() {
TypeFromUser ClangExpressionDeclMap::DeportType(TypeSystemClang &target,
TypeSystemClang &source,
TypeFromParser parser_type) {
assert(&target == TypeSystemClang::GetScratch(*m_target));
assert(&target == ScratchTypeSystemClang::GetForTarget(*m_target));
assert((TypeSystem *)&source == parser_type.GetTypeSystem());
assert(&source.getASTContext() == m_ast_context);
@ -222,7 +222,7 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl,
if (target == nullptr)
return false;
auto *clang_ast_context = TypeSystemClang::GetScratch(*target);
auto *clang_ast_context = ScratchTypeSystemClang::GetForTarget(*target);
if (!clang_ast_context)
return false;
@ -260,7 +260,7 @@ bool ClangExpressionDeclMap::AddPersistentVariable(const NamedDecl *decl,
if (target == nullptr)
return false;
TypeSystemClang *context = TypeSystemClang::GetScratch(*target);
TypeSystemClang *context = ScratchTypeSystemClang::GetForTarget(*target);
if (!context)
return false;
@ -721,7 +721,7 @@ clang::NamedDecl *ClangExpressionDeclMap::GetPersistentDecl(ConstString name) {
if (!target)
return nullptr;
TypeSystemClang::GetScratch(*target);
ScratchTypeSystemClang::GetForTarget(*target);
if (!m_parser_vars->m_persistent_vars)
return nullptr;
@ -1638,7 +1638,8 @@ void ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
if (target == nullptr)
return;
TypeSystemClang *scratch_ast_context = TypeSystemClang::GetScratch(*target);
TypeSystemClang *scratch_ast_context =
ScratchTypeSystemClang::GetForTarget(*target);
if (!scratch_ast_context)
return;

View File

@ -692,7 +692,7 @@ bool lldb_private::formatters::LibcxxWStringSummaryProvider(
// std::wstring::size() is measured in 'characters', not bytes
TypeSystemClang *ast_context =
TypeSystemClang::GetScratch(*valobj.GetTargetSP());
ScratchTypeSystemClang::GetForTarget(*valobj.GetTargetSP());
if (!ast_context)
return false;

View File

@ -441,7 +441,7 @@ lldb_private::formatters::NSArrayMSyntheticFrontEndBase::NSArrayMSyntheticFrontE
: SyntheticChildrenFrontEnd(*valobj_sp), m_exe_ctx_ref(), m_ptr_size(8),
m_id_type() {
if (valobj_sp) {
auto *clang_ast_context = TypeSystemClang::GetScratch(
auto *clang_ast_context = ScratchTypeSystemClang::GetForTarget(
*valobj_sp->GetExecutionContextRef().GetTargetSP());
if (clang_ast_context)
m_id_type = CompilerType(
@ -589,7 +589,7 @@ lldb_private::formatters::GenericNSArrayISyntheticFrontEnd<D32, D64, Inline>::
if (valobj_sp) {
CompilerType type = valobj_sp->GetCompilerType();
if (type) {
auto *clang_ast_context = TypeSystemClang::GetScratch(
auto *clang_ast_context = ScratchTypeSystemClang::GetForTarget(
*valobj_sp->GetExecutionContextRef().GetTargetSP());
if (clang_ast_context)
m_id_type = clang_ast_context->GetType(
@ -758,7 +758,7 @@ lldb_private::formatters::NSArray1SyntheticFrontEnd::GetChildAtIndex(
if (idx == 0) {
auto *clang_ast_context =
TypeSystemClang::GetScratch(*m_backend.GetTargetSP());
ScratchTypeSystemClang::GetForTarget(*m_backend.GetTargetSP());
if (clang_ast_context) {
CompilerType id_type(
clang_ast_context->GetBasicType(lldb::eBasicTypeObjCID));

View File

@ -66,7 +66,8 @@ NSDictionary_Additionals::GetAdditionalSynthetics() {
static CompilerType GetLLDBNSPairType(TargetSP target_sp) {
CompilerType compiler_type;
TypeSystemClang *target_ast_context = TypeSystemClang::GetScratch(*target_sp);
TypeSystemClang *target_ast_context =
ScratchTypeSystemClang::GetForTarget(*target_sp);
if (target_ast_context) {
ConstString g___lldb_autogen_nspair("__lldb_autogen_nspair");

View File

@ -87,7 +87,7 @@ bool lldb_private::formatters::NSError_SummaryProvider(
ValueObjectSP domain_str_sp = ValueObject::CreateValueObjectFromData(
"domain_str", isw.GetAsData(process_sp->GetByteOrder()),
valobj.GetExecutionContextRef(),
TypeSystemClang::GetScratch(process_sp->GetTarget())
ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget())
->GetBasicType(lldb::eBasicTypeVoid)
.GetPointerType());
@ -156,7 +156,7 @@ public:
m_child_sp = CreateValueObjectFromData(
"_userInfo", isw.GetAsData(process_sp->GetByteOrder()),
m_backend.GetExecutionContextRef(),
TypeSystemClang::GetScratch(process_sp->GetTarget())
ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget())
->GetBasicType(lldb::eBasicTypeObjCID));
return false;
}

View File

@ -69,7 +69,8 @@ static bool ExtractFields(ValueObject &valobj, ValueObjectSP *name_sp,
InferiorSizedWord userinfo_isw(userinfo, *process_sp);
InferiorSizedWord reserved_isw(reserved, *process_sp);
auto *clang_ast_context = TypeSystemClang::GetScratch(process_sp->GetTarget());
auto *clang_ast_context =
ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget());
if (!clang_ast_context)
return false;

View File

@ -53,7 +53,7 @@ public:
if (!type_system)
return false;
TypeSystemClang *ast = TypeSystemClang::GetScratch(
TypeSystemClang *ast = ScratchTypeSystemClang::GetForTarget(
*m_backend.GetExecutionContextRef().GetTargetSP());
if (!ast)
return false;

View File

@ -34,7 +34,7 @@ NSString_Additionals::GetAdditionalSummaries() {
static CompilerType GetNSPathStore2Type(Target &target) {
static ConstString g_type_name("__lldb_autogen_nspathstore2");
TypeSystemClang *ast_ctx = TypeSystemClang::GetScratch(target);
TypeSystemClang *ast_ctx = ScratchTypeSystemClang::GetForTarget(target);
if (!ast_ctx)
return CompilerType();

View File

@ -536,7 +536,7 @@ ValueObjectSP ItaniumABILanguageRuntime::GetExceptionObjectForThread(
return {};
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(m_process->GetTarget());
ScratchTypeSystemClang::GetForTarget(m_process->GetTarget());
if (!clang_ast_context)
return {};

View File

@ -122,7 +122,8 @@ bool AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value,
}
} else {
// If it is not a pointer, see if we can make it into a pointer.
TypeSystemClang *ast_context = TypeSystemClang::GetScratch(*target);
TypeSystemClang *ast_context =
ScratchTypeSystemClang::GetForTarget(*target);
if (!ast_context)
return false;
@ -137,7 +138,7 @@ bool AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value,
arg_value_list.PushValue(value);
// This is the return value:
TypeSystemClang *ast_context = TypeSystemClang::GetScratch(*target);
TypeSystemClang *ast_context = ScratchTypeSystemClang::GetForTarget(*target);
if (!ast_context)
return false;
@ -525,7 +526,7 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
return FailExceptionParsing("Failed to get synthetic value.");
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(*exception_sp->GetTargetSP());
ScratchTypeSystemClang::GetForTarget(*exception_sp->GetTargetSP());
if (!clang_ast_context)
return FailExceptionParsing("Failed to get scratch AST.");
CompilerType objc_id =

View File

@ -1304,7 +1304,8 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapDynamic(
return DescriptorMapUpdateResult::Fail();
thread_sp->CalculateExecutionContext(exe_ctx);
TypeSystemClang *ast = TypeSystemClang::GetScratch(process->GetTarget());
TypeSystemClang *ast =
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
if (!ast)
return DescriptorMapUpdateResult::Fail();
@ -1547,7 +1548,8 @@ AppleObjCRuntimeV2::UpdateISAToDescriptorMapSharedCache() {
return DescriptorMapUpdateResult::Fail();
thread_sp->CalculateExecutionContext(exe_ctx);
TypeSystemClang *ast = TypeSystemClang::GetScratch(process->GetTarget());
TypeSystemClang *ast =
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
if (!ast)
return DescriptorMapUpdateResult::Fail();
@ -2609,7 +2611,7 @@ class ObjCExceptionRecognizedStackFrame : public RecognizedStackFrame {
if (!abi) return;
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(process_sp->GetTarget());
ScratchTypeSystemClang::GetForTarget(process_sp->GetTarget());
if (!clang_ast_context)
return;
CompilerType voidstar =

View File

@ -521,7 +521,7 @@ bool AppleObjCTrampolineHandler::AppleObjCVTables::RefreshTrampolines(
const ABI *abi = process->GetABI().get();
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(process->GetTarget());
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
if (!clang_ast_context)
return false;
@ -827,8 +827,8 @@ AppleObjCTrampolineHandler::SetupDispatchFunction(Thread &thread,
}
// Next make the runner function for our implementation utility function.
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(thread.GetProcess()->GetTarget());
TypeSystemClang *clang_ast_context = ScratchTypeSystemClang::GetForTarget(
thread.GetProcess()->GetTarget());
if (!clang_ast_context)
return LLDB_INVALID_ADDRESS;
@ -931,7 +931,8 @@ AppleObjCTrampolineHandler::GetStepThroughDispatchPlan(Thread &thread,
TargetSP target_sp(thread.CalculateTarget());
TypeSystemClang *clang_ast_context = TypeSystemClang::GetScratch(*target_sp);
TypeSystemClang *clang_ast_context =
ScratchTypeSystemClang::GetForTarget(*target_sp);
if (!clang_ast_context)
return ret_plan_sp;

View File

@ -651,7 +651,8 @@ PlatformPOSIX::MakeLoadImageUtilityFunction(ExecutionContext &exe_ctx,
FunctionCaller *do_dlopen_function = nullptr;
// Fetch the clang types we will need:
TypeSystemClang *ast = TypeSystemClang::GetScratch(process->GetTarget());
TypeSystemClang *ast =
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
if (!ast)
return nullptr;
@ -895,7 +896,8 @@ uint32_t PlatformPOSIX::DoLoadImage(lldb_private::Process *process,
Value return_value;
// Fetch the clang types we will need:
TypeSystemClang *ast = TypeSystemClang::GetScratch(process->GetTarget());
TypeSystemClang *ast =
ScratchTypeSystemClang::GetForTarget(process->GetTarget());
if (!ast) {
error.SetErrorString("dlopen error: Unable to get TypeSystemClang");
return LLDB_INVALID_IMAGE_TOKEN;

View File

@ -216,7 +216,8 @@ AppleGetItemInfoHandler::GetItemInfo(Thread &thread, uint64_t item,
lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0);
ProcessSP process_sp(thread.CalculateProcess());
TargetSP target_sp(thread.CalculateTarget());
TypeSystemClang *clang_ast_context = TypeSystemClang::GetScratch(*target_sp);
TypeSystemClang *clang_ast_context =
ScratchTypeSystemClang::GetForTarget(*target_sp);
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME));
GetItemInfoReturnInfo return_value;

View File

@ -163,8 +163,8 @@ lldb::addr_t AppleGetPendingItemsHandler::SetupGetPendingItemsFunction(
// Next make the runner function for our implementation utility function.
Status error;
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(thread.GetProcess()->GetTarget());
TypeSystemClang *clang_ast_context = ScratchTypeSystemClang::GetForTarget(
thread.GetProcess()->GetTarget());
CompilerType get_pending_items_return_type =
clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
get_pending_items_caller =
@ -215,7 +215,8 @@ AppleGetPendingItemsHandler::GetPendingItems(Thread &thread, addr_t queue,
lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0);
ProcessSP process_sp(thread.CalculateProcess());
TargetSP target_sp(thread.CalculateTarget());
TypeSystemClang *clang_ast_context = TypeSystemClang::GetScratch(*target_sp);
TypeSystemClang *clang_ast_context =
ScratchTypeSystemClang::GetForTarget(*target_sp);
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME));
GetPendingItemsReturnInfo return_value;

View File

@ -180,7 +180,7 @@ AppleGetQueuesHandler::SetupGetQueuesFunction(Thread &thread,
// Next make the runner function for our implementation utility function.
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(thread.GetProcess()->GetTarget());
ScratchTypeSystemClang::GetForTarget(thread.GetProcess()->GetTarget());
CompilerType get_queues_return_type =
clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
Status error;
@ -220,7 +220,8 @@ AppleGetQueuesHandler::GetCurrentQueues(Thread &thread, addr_t page_to_free,
lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0);
ProcessSP process_sp(thread.CalculateProcess());
TargetSP target_sp(thread.CalculateTarget());
TypeSystemClang *clang_ast_context = TypeSystemClang::GetScratch(*target_sp);
TypeSystemClang *clang_ast_context =
ScratchTypeSystemClang::GetForTarget(*target_sp);
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME));
GetQueuesReturnInfo return_value;

View File

@ -170,8 +170,8 @@ lldb::addr_t AppleGetThreadItemInfoHandler::SetupGetThreadItemInfoFunction(
// Also make the FunctionCaller for this UtilityFunction:
TypeSystemClang *clang_ast_context =
TypeSystemClang::GetScratch(thread.GetProcess()->GetTarget());
TypeSystemClang *clang_ast_context = ScratchTypeSystemClang::GetForTarget(
thread.GetProcess()->GetTarget());
CompilerType get_thread_item_info_return_type =
clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
@ -222,7 +222,8 @@ AppleGetThreadItemInfoHandler::GetThreadItemInfo(Thread &thread,
lldb::StackFrameSP thread_cur_frame = thread.GetStackFrameAtIndex(0);
ProcessSP process_sp(thread.CalculateProcess());
TargetSP target_sp(thread.CalculateTarget());
TypeSystemClang *clang_ast_context = TypeSystemClang::GetScratch(*target_sp);
TypeSystemClang *clang_ast_context =
ScratchTypeSystemClang::GetForTarget(*target_sp);
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYSTEM_RUNTIME));
GetThreadItemInfoReturnInfo return_value;

View File

@ -414,7 +414,7 @@ void SystemRuntimeMacOSX::ReadLibdispatchTSDIndexes() {
#endif
TypeSystemClang *ast_ctx =
TypeSystemClang::GetScratch(m_process->GetTarget());
ScratchTypeSystemClang::GetForTarget(m_process->GetTarget());
if (m_dispatch_tsd_indexes_addr != LLDB_INVALID_ADDRESS) {
CompilerType uint16 =
ast_ctx->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 16);

View File

@ -9585,6 +9585,18 @@ void ScratchTypeSystemClang::Finalize() {
m_scratch_ast_source_up.reset();
}
TypeSystemClang *ScratchTypeSystemClang::GetForTarget(Target &target,
bool create_on_demand) {
auto type_system_or_err = target.GetScratchTypeSystemForLanguage(
lldb::eLanguageTypeC, create_on_demand);
if (auto err = type_system_or_err.takeError()) {
LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
std::move(err), "Couldn't get scratch TypeSystemClang");
return nullptr;
}
return llvm::dyn_cast<TypeSystemClang>(&type_system_or_err.get());
}
UserExpression *ScratchTypeSystemClang::GetUserExpression(
llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,
Expression::ResultType desired_type,

View File

@ -156,18 +156,6 @@ public:
static TypeSystemClang *GetASTContext(clang::ASTContext *ast_ctx);
static TypeSystemClang *GetScratch(Target &target,
bool create_on_demand = true) {
auto type_system_or_err = target.GetScratchTypeSystemForLanguage(
lldb::eLanguageTypeC, create_on_demand);
if (auto err = type_system_or_err.takeError()) {
LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
std::move(err), "Couldn't get scratch TypeSystemClang");
return nullptr;
}
return llvm::dyn_cast<TypeSystemClang>(&type_system_or_err.get());
}
/// Returns the display name of this TypeSystemClang that indicates what
/// purpose it serves in LLDB. Used for example in logs.
llvm::StringRef getDisplayName() const { return m_display_name; }
@ -1130,6 +1118,16 @@ public:
void Finalize() override;
/// Returns the scratch TypeSystemClang for the given target.
/// \param target The Target which scratch TypeSystemClang should be returned.
/// \param create_on_demand If the scratch TypeSystemClang instance can be
/// created by this call if it doesn't exist yet. If it doesn't exist yet and
/// this parameter is false, this function returns a nullptr.
/// \return The scratch type system of the target or a nullptr in case an
/// error occurred.
static TypeSystemClang *GetForTarget(Target &target,
bool create_on_demand = true);
UserExpression *
GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
lldb::LanguageType language,