Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
dart::LocalScope Class Reference

#include <scopes.h>

Inheritance diagram for dart::LocalScope:
dart::ZoneAllocated

Public Member Functions

 LocalScope (LocalScope *parent, int function_level, int loop_level)
 
LocalScopeparent () const
 
LocalScopechild () const
 
LocalScopesibling () const
 
int function_level () const
 
int loop_level () const
 
bool IsNestedWithin (LocalScope *scope) const
 
bool HasContextLevel () const
 
int context_level () const
 
void set_context_level (int context_level)
 
TokenPosition begin_token_pos () const
 
void set_begin_token_pos (TokenPosition value)
 
TokenPosition end_token_pos () const
 
void set_end_token_pos (TokenPosition value)
 
const GrowableArray< LocalVariable * > & context_variables () const
 
const ZoneGrowableArray< const Slot * > & context_slots () const
 
int num_context_variables () const
 
bool AddVariable (LocalVariable *variable)
 
void AddContextVariable (LocalVariable *var)
 
bool InsertParameterAt (intptr_t pos, LocalVariable *parameter)
 
LocalVariableLocalLookupVariable (const String &name, intptr_t kernel_offset) const
 
LocalVariableLookupVariable (const String &name, intptr_t kernel_offset, bool test_only)
 
LocalVariableLookupVariableByName (const String &name)
 
void CaptureVariable (LocalVariable *variable)
 
intptr_t num_variables () const
 
LocalVariableVariableAt (intptr_t index) const
 
int NumCapturedVariables () const
 
VariableIndex AllocateVariables (const Function &function, VariableIndex first_parameter_index, int num_parameters, VariableIndex first_local_index, LocalScope *context_owner, bool *found_captured_variables)
 
LocalVarDescriptorsPtr GetVarDescriptors (const Function &func, ZoneGrowableArray< intptr_t > *context_level_array)
 
ContextScopePtr PreserveOuterScope (const Function &function, intptr_t current_context_level) const
 
void CaptureLocalVariables (LocalScope *top_scope)
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Static Public Member Functions

static LocalScopeRestoreOuterScope (const ContextScope &context_scope)
 
static ContextScopePtr CreateImplicitClosureScope (const Function &func)
 

Detailed Description

Definition at line 315 of file scopes.h.

Constructor & Destructor Documentation

◆ LocalScope()

dart::LocalScope::LocalScope ( LocalScope parent,
int  function_level,
int  loop_level 
)

Definition at line 24 of file scopes.cc.

25 : parent_(parent),
26 child_(nullptr),
27 sibling_(nullptr),
28 function_level_(function_level),
29 loop_level_(loop_level),
30 context_level_(LocalScope::kUninitializedContextLevel),
31 begin_token_pos_(TokenPosition::kNoSource),
32 end_token_pos_(TokenPosition::kNoSource),
33 variables_(),
34 context_variables_(),
35 context_slots_(new(Thread::Current()->zone())
36 ZoneGrowableArray<const Slot*>()) {
37 // Hook this node into the children of the parent, unless the parent has a
38 // different function_level, since the local scope of a nested function can
39 // be discarded after it has been parsed.
40 if ((parent != nullptr) && (parent->function_level() == function_level)) {
41 sibling_ = parent->child_;
42 parent->child_ = this;
43 }
44}
LocalScope * parent() const
Definition scopes.h:319
int loop_level() const
Definition scopes.h:323
int function_level() const
Definition scopes.h:322
static Thread * Current()
Definition thread.h:361

Member Function Documentation

◆ AddContextVariable()

void dart::LocalScope::AddContextVariable ( LocalVariable var)

Definition at line 126 of file scopes.cc.

126 {
127 variable->set_index(VariableIndex(context_variables_.length()));
128 context_variables_.Add(variable);
129 context_slots_->Add(
131}
static const Slot & GetContextVariableSlotFor(Thread *thread, const LocalVariable &var)
Definition slot.cc:292

◆ AddVariable()

bool dart::LocalScope::AddVariable ( LocalVariable variable)

Definition at line 57 of file scopes.cc.

57 {
58 ASSERT(variable != nullptr);
59 if (LocalLookupVariable(variable->name(), variable->kernel_offset()) !=
60 nullptr) {
61 return false;
62 }
63 variables_.Add(variable);
64 if (variable->owner() == nullptr) {
65 // Variables must be added to their owner scope first. Subsequent calls
66 // to 'add' treat the variable as an alias.
67 variable->set_owner(this);
68 }
69 return true;
70}
LocalVariable * LocalLookupVariable(const String &name, intptr_t kernel_offset) const
Definition scopes.cc:336
#define ASSERT(E)

◆ AllocateVariables()

VariableIndex dart::LocalScope::AllocateVariables ( const Function function,
VariableIndex  first_parameter_index,
int  num_parameters,
VariableIndex  first_local_index,
LocalScope context_owner,
bool *  found_captured_variables 
)

Definition at line 133 of file scopes.cc.

138 {
139 // We should not allocate variables of nested functions while compiling an
140 // enclosing function.
141 ASSERT(function_level() == 0);
142 ASSERT(num_parameters >= 0);
143 // Parameters must be listed first and must all appear in the top scope.
144 ASSERT(num_parameters <= num_variables());
145 int pos = 0; // Current variable position.
146 VariableIndex next_index =
147 first_parameter_index; // Current free frame index.
148
149 LocalVariable* suspend_state_var = nullptr;
150 for (intptr_t i = 0; i < num_variables(); i++) {
151 LocalVariable* variable = VariableAt(i);
152 if (variable->owner() == this &&
153 variable->name().Equals(Symbols::SuspendStateVar())) {
154 ASSERT(!variable->is_captured());
155 suspend_state_var = variable;
156 }
157 }
158
159 if (suspend_state_var != nullptr) {
160 suspend_state_var->set_index(
162 ASSERT(next_index.value() == SuspendState::kSuspendStateVarIndex - 1);
163 }
164
165 while (pos < num_parameters) {
166 LocalVariable* parameter = VariableAt(pos);
167 pos++;
168 // Parsing formal parameter default values may add local variable aliases
169 // to the local scope before the formal parameters are added. However,
170 // the parameters get inserted in front of the aliases, therefore, no
171 // aliases can be encountered among the first num_parameters variables.
172 ASSERT(parameter->owner() == this);
173 if (parameter->is_captured()) {
174 // A captured parameter has a slot allocated in the frame and one in the
175 // context, where it gets copied to. The parameter index reflects the
176 // context allocation index.
177 next_index = VariableIndex(next_index.value() - 1);
178 AllocateContextVariable(parameter, &context_owner);
179 *found_captured_variables = true;
180 } else {
181 parameter->set_index(next_index);
182 next_index = VariableIndex(next_index.value() - 1);
183 }
184 }
185 // No overlapping of parameters and locals.
186 ASSERT(next_index.value() >= first_local_index.value());
187 next_index = first_local_index;
188 for (; pos < num_variables(); pos++) {
189 LocalVariable* variable = VariableAt(pos);
190 if (variable == suspend_state_var) {
191 continue;
192 }
193
194 if (variable->owner() == this) {
195 if (variable->is_captured()) {
196 AllocateContextVariable(variable, &context_owner);
197 *found_captured_variables = true;
198 } else {
199 variable->set_index(next_index);
200 next_index = VariableIndex(next_index.value() - 1);
201 }
202 }
203 }
204 // Allocate variables of all children.
205 VariableIndex min_index = next_index;
206 LocalScope* child = this->child();
207 while (child != nullptr) {
208 // Ignored, since no parameters.
209 const VariableIndex dummy_parameter_index(0);
210
211 // No parameters in children scopes.
212 const int num_parameters_in_child = 0;
213 VariableIndex child_next_index = child->AllocateVariables(
214 function, dummy_parameter_index, num_parameters_in_child, next_index,
215 context_owner, found_captured_variables);
216 if (child_next_index.value() < min_index.value()) {
217 min_index = child_next_index;
218 }
219 child = child->sibling();
220 }
221 return min_index;
222}
SkPoint pos
LocalScope(LocalScope *parent, int function_level, int loop_level)
Definition scopes.cc:24
LocalScope * sibling() const
Definition scopes.h:321
VariableIndex AllocateVariables(const Function &function, VariableIndex first_parameter_index, int num_parameters, VariableIndex first_local_index, LocalScope *context_owner, bool *found_captured_variables)
Definition scopes.cc:133
LocalVariable * VariableAt(intptr_t index) const
Definition scopes.h:398
intptr_t num_variables() const
Definition scopes.h:397
LocalScope * child() const
Definition scopes.h:320
static constexpr intptr_t kSuspendStateVarIndex
Definition object.h:12591
Dart_NativeFunction function
Definition fuchsia.cc:51

◆ begin_token_pos()

TokenPosition dart::LocalScope::begin_token_pos ( ) const
inline

Definition at line 343 of file scopes.h.

343{ return begin_token_pos_; }

◆ CaptureLocalVariables()

void dart::LocalScope::CaptureLocalVariables ( LocalScope top_scope)

Definition at line 558 of file scopes.cc.

558 {
559 ASSERT(top_scope->function_level() == function_level());
560 LocalScope* scope = this;
561 while (scope != top_scope->parent()) {
562 for (intptr_t i = 0; i < scope->num_variables(); i++) {
563 LocalVariable* variable = scope->VariableAt(i);
564 if (variable->is_forced_stack() ||
565 (variable->name().ptr() == Symbols::ExceptionVar().ptr()) ||
566 (variable->name().ptr() == Symbols::SavedTryContextVar().ptr()) ||
567 (variable->name().ptr() == Symbols::ArgDescVar().ptr()) ||
568 (variable->name().ptr() ==
569 Symbols::FunctionTypeArgumentsVar().ptr())) {
570 // Don't capture those variables because the VM expects them to be on
571 // the stack.
572 continue;
573 }
574 scope->CaptureVariable(variable);
575 }
576 scope = scope->parent();
577 }
578}

◆ CaptureVariable()

void dart::LocalScope::CaptureVariable ( LocalVariable variable)

Definition at line 383 of file scopes.cc.

383 {
384 ASSERT(variable != nullptr);
385
386 // The variable must exist in an enclosing scope, not necessarily in this one.
387 variable->set_is_captured();
388 const int variable_function_level = variable->owner()->function_level();
389 LocalScope* scope = this;
390 while (scope->function_level() != variable_function_level) {
391 // Insert an alias of the variable in the top scope of each function
392 // level so that the variable is found in the context.
393 LocalScope* parent_scope = scope->parent();
394 while ((parent_scope != nullptr) &&
395 (parent_scope->function_level() == scope->function_level())) {
396 scope = parent_scope;
397 parent_scope = scope->parent();
398 }
399 // An alias may already have been added in this scope, and in that case,
400 // in parent scopes as needed. If so, we are done.
401 if (!scope->AddVariable(variable)) {
402 return;
403 }
404 ASSERT(variable->owner() != scope); // Item is an alias.
405 scope = parent_scope;
406 }
407}

◆ child()

LocalScope * dart::LocalScope::child ( ) const
inline

Definition at line 320 of file scopes.h.

320{ return child_; }

◆ context_level()

int dart::LocalScope::context_level ( ) const
inline

Definition at line 333 of file scopes.h.

333 {
335 return context_level_;
336 }
bool HasContextLevel() const
Definition scopes.h:330

◆ context_slots()

const ZoneGrowableArray< const Slot * > & dart::LocalScope::context_slots ( ) const
inline

Definition at line 355 of file scopes.h.

355 {
356 return *context_slots_;
357 }

◆ context_variables()

const GrowableArray< LocalVariable * > & dart::LocalScope::context_variables ( ) const
inline

Definition at line 351 of file scopes.h.

351 {
352 return context_variables_;
353 }

◆ CreateImplicitClosureScope()

ContextScopePtr dart::LocalScope::CreateImplicitClosureScope ( const Function func)
static

Definition at line 580 of file scopes.cc.

580 {
581 const intptr_t kNumCapturedVars = 1;
582
583 // Create a ContextScope with space for kNumCapturedVars descriptors.
584 const ContextScope& context_scope =
585 ContextScope::Handle(ContextScope::New(kNumCapturedVars, true));
586
587 // Create a descriptor for 'this' variable.
588 context_scope.SetTokenIndexAt(0, func.token_pos());
589 context_scope.SetDeclarationTokenIndexAt(0, func.token_pos());
590 context_scope.SetNameAt(0, Symbols::This());
591 context_scope.ClearFlagsAt(0);
592 context_scope.SetIsFinalAt(0, true);
593 const AbstractType& type = AbstractType::Handle(func.ParameterTypeAt(0));
594 context_scope.SetTypeAt(0, type);
595 context_scope.SetCidAt(0, kIllegalCid);
596 context_scope.SetContextIndexAt(0, 0);
597 context_scope.SetContextLevelAt(0, 0);
598 context_scope.SetKernelOffsetAt(0, LocalVariable::kNoKernelOffset);
599 ASSERT(context_scope.num_variables() == kNumCapturedVars); // Verify count.
600 return context_scope.ptr();
601}
static ContextScopePtr New(intptr_t num_variables, bool is_implicit)
Definition object.cc:18627
static constexpr intptr_t kNoKernelOffset
Definition scopes.h:77
static Object & Handle()
Definition object.h:407
static const String & This()
Definition symbols.h:691
@ kIllegalCid
Definition class_id.h:214

◆ end_token_pos()

TokenPosition dart::LocalScope::end_token_pos ( ) const
inline

Definition at line 346 of file scopes.h.

346{ return end_token_pos_; }

◆ function_level()

int dart::LocalScope::function_level ( ) const
inline

Definition at line 322 of file scopes.h.

322{ return function_level_; }

◆ GetVarDescriptors()

LocalVarDescriptorsPtr dart::LocalScope::GetVarDescriptors ( const Function func,
ZoneGrowableArray< intptr_t > *  context_level_array 
)

Definition at line 249 of file scopes.cc.

251 {
252 LocalVarDescriptorsBuilder vars;
253 vars.AddDeoptIdToContextLevelMappings(context_level_array);
254
255 // First enter all variables from scopes of outer functions.
256 const ContextScope& context_scope =
257 ContextScope::Handle(func.context_scope());
258 if (!context_scope.IsNull()) {
259 ASSERT(func.HasParent());
260 for (int i = 0; i < context_scope.num_variables(); i++) {
261 if (context_scope.IsInvisibleAt(i)) {
262 continue;
263 }
264 String& name = String::Handle(context_scope.NameAt(i));
265 ASSERT(!LocalVariable::IsFilteredIdentifier(name));
266
267 LocalVarDescriptorsBuilder::VarDesc desc;
268 desc.name = &name;
270 desc.info.scope_id = context_scope.ContextLevelAt(i);
271 desc.info.declaration_pos = context_scope.DeclarationTokenIndexAt(i);
272 desc.info.begin_pos = begin_token_pos();
273 desc.info.end_pos = end_token_pos();
274 ASSERT((desc.info.begin_pos.IsReal() != desc.info.end_pos.IsReal()) ||
275 (desc.info.begin_pos <= desc.info.end_pos));
276 desc.info.set_index(context_scope.ContextIndexAt(i));
277 vars.Add(desc);
278 }
279 }
280 // Now collect all variables from local scopes.
281 int16_t scope_id = 0;
282 CollectLocalVariables(&vars, &scope_id);
283
284 return vars.Done();
285}
TokenPosition end_token_pos() const
Definition scopes.h:346
TokenPosition begin_token_pos() const
Definition scopes.h:343
const char *const name

◆ HasContextLevel()

bool dart::LocalScope::HasContextLevel ( ) const
inline

Definition at line 330 of file scopes.h.

330 {
331 return context_level_ != kUninitializedContextLevel;
332 }

◆ InsertParameterAt()

bool dart::LocalScope::InsertParameterAt ( intptr_t  pos,
LocalVariable parameter 
)

Definition at line 72 of file scopes.cc.

72 {
73 ASSERT(parameter != nullptr);
74 if (LocalLookupVariable(parameter->name(), parameter->kernel_offset()) !=
75 nullptr) {
76 return false;
77 }
78 variables_.InsertAt(pos, parameter);
79 // InsertParameterAt is not used to add aliases of parameters.
80 ASSERT(parameter->owner() == nullptr);
81 parameter->set_owner(this);
82 return true;
83}

◆ IsNestedWithin()

bool dart::LocalScope::IsNestedWithin ( LocalScope scope) const

Definition at line 46 of file scopes.cc.

46 {
47 const LocalScope* current_scope = this;
48 while (current_scope != nullptr) {
49 if (current_scope == scope) {
50 return true;
51 }
52 current_scope = current_scope->parent();
53 }
54 return false;
55}

◆ LocalLookupVariable()

LocalVariable * dart::LocalScope::LocalLookupVariable ( const String name,
intptr_t  kernel_offset 
) const

Definition at line 336 of file scopes.cc.

337 {
338 ASSERT(name.IsSymbol());
339 for (intptr_t i = 0; i < variables_.length(); i++) {
340 LocalVariable* var = variables_[i];
341 ASSERT(var->name().IsSymbol());
342 if ((var->name().ptr() == name.ptr()) &&
343 (var->kernel_offset() == kernel_offset)) {
344 return var;
345 }
346 }
347 return nullptr;
348}

◆ LookupVariable()

LocalVariable * dart::LocalScope::LookupVariable ( const String name,
intptr_t  kernel_offset,
bool  test_only 
)

Definition at line 350 of file scopes.cc.

352 {
353 LocalScope* current_scope = this;
354 while (current_scope != nullptr) {
355 LocalVariable* var =
356 current_scope->LocalLookupVariable(name, kernel_offset);
357 // If testing only, return the variable even if invisible.
358 if ((var != nullptr) && (!var->is_invisible() || test_only)) {
359 if (!test_only && (var->owner()->function_level() != function_level())) {
360 CaptureVariable(var);
361 }
362 return var;
363 }
364 current_scope = current_scope->parent();
365 }
366 return nullptr;
367}
void CaptureVariable(LocalVariable *variable)
Definition scopes.cc:383

◆ LookupVariableByName()

LocalVariable * dart::LocalScope::LookupVariableByName ( const String name)

Definition at line 369 of file scopes.cc.

369 {
370 ASSERT(name.IsSymbol());
371 for (LocalScope* scope = this; scope != nullptr; scope = scope->parent()) {
372 for (intptr_t i = 0, n = scope->variables_.length(); i < n; ++i) {
373 LocalVariable* var = scope->variables_[i];
374 ASSERT(var->name().IsSymbol());
375 if (var->name().ptr() == name.ptr()) {
376 return var;
377 }
378 }
379 }
380 return nullptr;
381}

◆ loop_level()

int dart::LocalScope::loop_level ( ) const
inline

Definition at line 323 of file scopes.h.

323{ return loop_level_; }

◆ num_context_variables()

int dart::LocalScope::num_context_variables ( ) const
inline

Definition at line 361 of file scopes.h.

361{ return context_variables().length(); }
const GrowableArray< LocalVariable * > & context_variables() const
Definition scopes.h:351

◆ num_variables()

intptr_t dart::LocalScope::num_variables ( ) const
inline

Definition at line 397 of file scopes.h.

397{ return variables_.length(); }

◆ NumCapturedVariables()

int dart::LocalScope::NumCapturedVariables ( ) const

Definition at line 409 of file scopes.cc.

409 {
410 // It is not necessary to traverse parent scopes, since we are only interested
411 // in the captured variables referenced in this scope. If this scope is the
412 // top scope at function level 1 and it (or its children scopes) references a
413 // captured variable declared in a parent scope at function level 0, it will
414 // contain an alias for that variable.
415
416 // Since code generation for nested functions is postponed until first
417 // invocation, the function level of the closure scope can only be 1.
418 ASSERT(function_level() == 1);
419
420 int num_captured = 0;
421 for (int i = 0; i < num_variables(); i++) {
422 LocalVariable* variable = VariableAt(i);
423 // Count the aliases of captured variables belonging to outer scopes.
424 if (variable->owner()->function_level() != 1) {
425 ASSERT(variable->is_captured());
426 ASSERT(variable->owner()->function_level() == 0);
427 num_captured++;
428 }
429 }
430 return num_captured;
431}

◆ parent()

LocalScope * dart::LocalScope::parent ( ) const
inline

Definition at line 319 of file scopes.h.

319{ return parent_; }

◆ PreserveOuterScope()

ContextScopePtr dart::LocalScope::PreserveOuterScope ( const Function function,
intptr_t  current_context_level 
) const

Definition at line 433 of file scopes.cc.

435 {
436 Zone* zone = Thread::Current()->zone();
437 auto& library = Library::Handle(
438 zone, function.IsNull()
439 ? Library::null()
440 : Class::Handle(zone, function.Owner()).library());
441 // Since code generation for nested functions is postponed until first
442 // invocation, the function level of the closure scope can only be 1.
443 ASSERT(function_level() == 1);
444
445 // Count the number of referenced captured variables.
446 intptr_t num_captured_vars = NumCapturedVariables();
447
448 // Create a ContextScope with space for num_captured_vars descriptors.
449 const ContextScope& context_scope =
450 ContextScope::Handle(ContextScope::New(num_captured_vars, false));
451
452 LocalVariable* awaiter_link = nullptr;
453
454 // Create a descriptor for each referenced captured variable of enclosing
455 // functions to preserve its name and its context allocation information.
456 int captured_idx = 0;
457 for (int i = 0; i < num_variables(); i++) {
458 LocalVariable* variable = VariableAt(i);
459 // Preserve the aliases of captured variables belonging to outer scopes.
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 // Adjust the context level relative to the current context level,
479 // since the context of the current scope will be at level 0 when
480 // compiling the nested function.
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 // Handle async frame link.
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); // Verify count.
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();
501 if (Utils::IsUint(8, depth) && Utils::IsUint(8, index)) {
502 function.set_awaiter_link(
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(),
510 function.IsNull() ? "<?>" : function.ToFullyQualifiedCString(), depth,
511 index);
512 }
513 }
514
515 return context_scope.ptr();
516}
int NumCapturedVariables() const
Definition scopes.cc:409
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static ObjectPtr null()
Definition object.h:433
Zone * zone() const
static bool IsUint(intptr_t N, T value)
Definition utils.h:313
#define Pd
Definition globals.h:408

◆ RestoreOuterScope()

LocalScope * dart::LocalScope::RestoreOuterScope ( const ContextScope context_scope)
static

Definition at line 518 of file scopes.cc.

518 {
519 // The function level of the outer scope is one less than the function level
520 // of the current function, which is 0.
521 LocalScope* outer_scope = new LocalScope(nullptr, -1, 0);
522 // Add all variables as aliases to the outer scope.
523 for (int i = 0; i < context_scope.num_variables(); i++) {
524 const bool is_late = context_scope.IsLateAt(i);
525 const auto& static_type = AbstractType::ZoneHandle(context_scope.TypeAt(i));
526 CompileType* inferred_type =
527 new CompileType(context_scope.IsNullableAt(i), is_late,
528 context_scope.CidAt(i), &static_type);
529 LocalVariable* variable = new LocalVariable(
530 context_scope.DeclarationTokenIndexAt(i), context_scope.TokenIndexAt(i),
531 String::ZoneHandle(context_scope.NameAt(i)), static_type,
532 context_scope.KernelOffsetAt(i), inferred_type);
533 variable->set_is_awaiter_link(context_scope.IsAwaiterLinkAt(i));
534 variable->set_is_captured();
535 variable->set_index(VariableIndex(context_scope.ContextIndexAt(i)));
536 if (context_scope.IsFinalAt(i)) {
537 variable->set_is_final();
538 }
539 if (is_late) {
540 variable->set_is_late();
541 variable->set_late_init_offset(context_scope.LateInitOffsetAt(i));
542 }
543 if (context_scope.IsInvisibleAt(i)) {
544 variable->set_invisible(true);
545 }
546 // Create a fake owner scope describing the index and context level of the
547 // variable. Function level and loop level are unused (set to 0), since
548 // context level has already been assigned.
549 LocalScope* owner_scope = new LocalScope(nullptr, 0, 0);
550 owner_scope->set_context_level(context_scope.ContextLevelAt(i));
551 owner_scope->AddVariable(variable);
552 outer_scope->AddVariable(variable); // As alias.
553 ASSERT(variable->owner() == owner_scope);
554 }
555 return outer_scope;
556}
static Object & ZoneHandle()
Definition object.h:419

◆ set_begin_token_pos()

void dart::LocalScope::set_begin_token_pos ( TokenPosition  value)
inline

Definition at line 344 of file scopes.h.

344{ begin_token_pos_ = value; }
uint8_t value

◆ set_context_level()

void dart::LocalScope::set_context_level ( int  context_level)
inline

Definition at line 337 of file scopes.h.

337 {
339 ASSERT(context_level != kUninitializedContextLevel);
340 context_level_ = context_level;
341 }
int context_level() const
Definition scopes.h:333

◆ set_end_token_pos()

void dart::LocalScope::set_end_token_pos ( TokenPosition  value)
inline

Definition at line 347 of file scopes.h.

347{ end_token_pos_ = value; }

◆ sibling()

LocalScope * dart::LocalScope::sibling ( ) const
inline

Definition at line 321 of file scopes.h.

321{ return sibling_; }

◆ VariableAt()

LocalVariable * dart::LocalScope::VariableAt ( intptr_t  index) const
inline

Definition at line 398 of file scopes.h.

398 {
399 ASSERT((index >= 0) && (index < variables_.length()));
400 return variables_[index];
401 }

The documentation for this class was generated from the following files: