435 {
441
442
444
445
447
448
449 const ContextScope& context_scope =
451
452 LocalVariable* awaiter_link = nullptr;
453
454
455
456 int captured_idx = 0;
459
460 if (variable->owner()->function_level() != 1) {
461 context_scope.SetTokenIndexAt(captured_idx, variable->token_pos());
462 context_scope.SetDeclarationTokenIndexAt(
463 captured_idx, variable->declaration_token_pos());
464 context_scope.SetNameAt(captured_idx, variable->name());
465 context_scope.ClearFlagsAt(captured_idx);
466 context_scope.SetIsFinalAt(captured_idx, variable->is_final());
467 context_scope.SetIsLateAt(captured_idx, variable->is_late());
468 if (variable->is_late()) {
469 context_scope.SetLateInitOffsetAt(captured_idx,
470 variable->late_init_offset());
471 }
472 CompileType*
type = variable->inferred_type();
473 context_scope.SetTypeAt(captured_idx, *
type->ToAbstractType());
474 context_scope.SetCidAt(captured_idx,
type->ToNullableCid());
475 context_scope.SetIsNullableAt(captured_idx,
type->is_nullable());
476 context_scope.SetIsInvisibleAt(captured_idx, variable->is_invisible());
477 context_scope.SetContextIndexAt(captured_idx, variable->index().value());
478
479
480
481 intptr_t adjusted_context_level =
482 variable->owner()->context_level() - current_context_level;
483 context_scope.SetContextLevelAt(captured_idx, adjusted_context_level);
484 context_scope.SetKernelOffsetAt(captured_idx, variable->kernel_offset());
485
486
487 const bool is_awaiter_link = variable->ComputeIfIsAwaiterLink(library);
488 context_scope.SetIsAwaiterLinkAt(captured_idx, is_awaiter_link);
489 if (is_awaiter_link) {
490 awaiter_link = variable;
491 }
492 captured_idx++;
493 }
494 }
495 ASSERT(context_scope.num_variables() == captured_idx);
496
497 if (awaiter_link != nullptr) {
498 const intptr_t depth =
499 current_context_level - awaiter_link->owner()->context_level();
500 const intptr_t index = awaiter_link->index().value();
503 {static_cast<uint8_t>(depth), static_cast<uint8_t>(index)});
504 } else if (FLAG_precompiled_mode) {
506 "Warning: @pragma('vm:awaiter-link') marked variable %s is visible "
507 "from the function %s but the link {%" Pd ", %" Pd
508 "} can't be encoded\n",
509 awaiter_link->name().ToCString(),
511 index);
512 }
513 }
514
515 return context_scope.ptr();
516}
int NumCapturedVariables() const
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static bool IsUint(intptr_t N, T value)