@@ -57,18 +57,9 @@ SwiftUserExpression::SwiftUserExpression(
57
57
m_type_system_helper(*m_target_wp.lock().get()),
58
58
m_result_delegate(exe_scope.CalculateTarget(), *this, false),
59
59
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 ) {
66
61
m_runs_in_playground_or_repl =
67
62
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 ());
72
63
}
73
64
74
65
SwiftUserExpression::~SwiftUserExpression () {}
@@ -305,6 +296,23 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
305
296
return false ;
306
297
}
307
298
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
+
308
316
if (!m_swift_ast_ctx) {
309
317
LLDB_LOG (log, " no Swift AST Context" );
310
318
return false ;
@@ -397,22 +405,6 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
397
405
Callback m_callback;
398
406
};
399
407
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
-
416
408
auto *swift_parser =
417
409
new SwiftExpressionParser (exe_scope, *m_swift_ast_ctx, *this , m_options);
418
410
unsigned error_code = swift_parser->Parse (
@@ -482,6 +474,7 @@ bool SwiftUserExpression::Parse(DiagnosticManager &diagnostic_manager,
482
474
auto module =
483
475
m_execution_unit_sp->CreateJITModule (jit_module_name.GetString ().data ());
484
476
477
+ Process *process = exe_ctx.GetProcessPtr ();
485
478
auto *swift_runtime = SwiftLanguageRuntime::Get (process);
486
479
if (module && swift_runtime) {
487
480
ModuleList modules;
0 commit comments