From b2fa3b922ecb219429ec7b839d15a06aedbc955a Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 9 Nov 2020 15:25:59 -0800 Subject: [lldb] Make GetSelectedOrDummyTarget return the target by reference (NFC) Return references from GetDummyTarget and GetSelectedOrDummyTarget. This matches how the APIs are already used in practice. --- lldb/source/Commands/CommandObjectExpression.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'lldb/source/Commands/CommandObjectExpression.cpp') diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index b23adb0..58eaa3f 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -304,11 +304,8 @@ void CommandObjectExpression::HandleCompletion(CompletionRequest &request) { return; ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); - - Target *target = exe_ctx.GetTargetPtr(); - - if (!target) - target = &GetDummyTarget(); + Target *exe_target = exe_ctx.GetTargetPtr(); + Target &target = exe_target ? *exe_target : GetDummyTarget(); unsigned cursor_pos = request.GetRawCursorPos(); // Get the full user input including the suffix. The suffix is necessary @@ -342,7 +339,7 @@ void CommandObjectExpression::HandleCompletion(CompletionRequest &request) { auto language = exe_ctx.GetFrameRef().GetLanguage(); Status error; - lldb::UserExpressionSP expr(target->GetUserExpressionForLanguage( + lldb::UserExpressionSP expr(target.GetUserExpressionForLanguage( code, llvm::StringRef(), language, UserExpression::eResultTypeAny, options, nullptr, error)); if (error.Fail()) @@ -411,22 +408,19 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr, // command object DoExecute has finished when doing multi-line expression // that use an input reader... ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); - - Target *target = exe_ctx.GetTargetPtr(); - - if (!target) - target = &GetDummyTarget(); + Target *exe_target = exe_ctx.GetTargetPtr(); + Target &target = exe_target ? *exe_target : GetDummyTarget(); lldb::ValueObjectSP result_valobj_sp; StackFrame *frame = exe_ctx.GetFramePtr(); - const EvaluateExpressionOptions options = GetEvalOptions(*target); - ExpressionResults success = target->EvaluateExpression( + const EvaluateExpressionOptions options = GetEvalOptions(target); + ExpressionResults success = target.EvaluateExpression( expr, frame, result_valobj_sp, options, &m_fixed_expression); // We only tell you about the FixIt if we applied it. The compiler errors // will suggest the FixIt if it parsed. - if (!m_fixed_expression.empty() && target->GetEnableNotifyAboutFixIts()) { + if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) { if (success == eExpressionCompleted) error_stream.Printf(" Fix-it applied, fixed expression was: \n %s\n", m_fixed_expression.c_str()); -- cgit v1.1