Skip to content

Commit 44f63b8

Browse files
committed
SwiftUserExpression: Sink initialization of scratch context into Parse()
so it can (in a follow-up commit) be initialized with the current frame as ExecutionContextScope. NFC
1 parent 5a4aa73 commit 44f63b8

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,9 @@ SwiftUserExpression::SwiftUserExpression(
5757
m_type_system_helper(*m_target_wp.lock().get()),
5858
m_result_delegate(exe_scope.CalculateTarget(), *this, false),
5959
m_error_delegate(exe_scope.CalculateTarget(), *this, true),
60-
m_persistent_variable_delegate(*this),
61-
m_swift_scratch_ctx(
62-
exe_scope.CalculateTarget()
63-
? exe_scope.CalculateTarget()->GetSwiftScratchContext(m_err,
64-
exe_scope)
65-
: llvm::None) {
60+
m_persistent_variable_delegate(*this) {
6661
m_runs_in_playground_or_repl =
6762
options.GetREPLEnabled() || options.GetPlaygroundTransformEnabled();
68-
if (m_swift_scratch_ctx)
69-
if (m_swift_scratch_ctx->get())
70-
m_swift_ast_ctx = llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(
71-
m_swift_scratch_ctx->get()->GetSwiftASTContext());
7263
}
7364

7465
SwiftUserExpression::~SwiftUserExpression() {}
@@ -305,6 +296,23 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
305296
return false;
306297
}
307298

299+
auto exe_scope = exe_ctx.GetBestExecutionContextScope();
300+
if (!exe_scope) {
301+
LLDB_LOG(log, "no execution context scope");
302+
return false;
303+
}
304+
305+
ExecutionContext target_scope(*target);
306+
m_swift_scratch_ctx = target->GetSwiftScratchContext(
307+
m_err, /* FIXME: should be exe_scope */ *target_scope
308+
.GetBestExecutionContextScope());
309+
if (!m_swift_scratch_ctx) {
310+
LLDB_LOG(log, "no scratch context", m_err.AsCString());
311+
return false;
312+
}
313+
m_swift_ast_ctx = llvm::dyn_cast_or_null<SwiftASTContextForExpressions>(
314+
m_swift_scratch_ctx->get()->GetSwiftASTContext());
315+
308316
if (!m_swift_ast_ctx) {
309317
LLDB_LOG(log, "no Swift AST Context");
310318
return false;
@@ -397,22 +405,6 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
397405
Callback m_callback;
398406
};
399407

400-
ExecutionContextScope *exe_scope = NULL;
401-
402-
Process *process = exe_ctx.GetProcessPtr();
403-
404-
do {
405-
exe_scope = exe_ctx.GetFramePtr();
406-
if (exe_scope)
407-
break;
408-
409-
exe_scope = process;
410-
if (exe_scope)
411-
break;
412-
413-
exe_scope = exe_ctx.GetTargetPtr();
414-
} while (0);
415-
416408
auto *swift_parser =
417409
new SwiftExpressionParser(exe_scope, *m_swift_ast_ctx, *this, m_options);
418410
unsigned error_code = swift_parser->Parse(
@@ -482,6 +474,7 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
482474
auto module =
483475
m_execution_unit_sp->CreateJITModule(jit_module_name.GetString().data());
484476

477+
Process *process = exe_ctx.GetProcessPtr();
485478
auto *swift_runtime = SwiftLanguageRuntime::Get(process);
486479
if (module && swift_runtime) {
487480
ModuleList modules;

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ class SwiftUserExpression : public LLVMUserExpression {
179179
void DidDematerialize(lldb::ExpressionVariableSP &variable) override;
180180
};
181181

182+
llvm::Optional<SwiftScratchContextReader> m_swift_scratch_ctx;
182183
SwiftASTContextForExpressions *m_swift_ast_ctx;
183184
PersistentVariableDelegate m_persistent_variable_delegate;
184185
std::unique_ptr<SwiftExpressionParser> m_parser;
185186
Status m_err;
186-
llvm::Optional<SwiftScratchContextReader> m_swift_scratch_ctx;
187187
bool m_runs_in_playground_or_repl;
188188
bool m_needs_object_ptr = false;
189189
bool m_in_static_method = false;

0 commit comments

Comments
 (0)