OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_SCOPES_H_ | 5 #ifndef VM_SCOPES_H_ |
6 #define VM_SCOPES_H_ | 6 #define VM_SCOPES_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // in the stack frame. | 110 // in the stack frame. |
111 bool is_invisible_; | 111 bool is_invisible_; |
112 int index_; // Allocation index in words relative to frame pointer (if not | 112 int index_; // Allocation index in words relative to frame pointer (if not |
113 // captured), or relative to the context pointer (if captured). | 113 // captured), or relative to the context pointer (if captured). |
114 | 114 |
115 friend class LocalScope; | 115 friend class LocalScope; |
116 DISALLOW_COPY_AND_ASSIGN(LocalVariable); | 116 DISALLOW_COPY_AND_ASSIGN(LocalVariable); |
117 }; | 117 }; |
118 | 118 |
119 | 119 |
| 120 class NameReference : public ZoneAllocated { |
| 121 public: |
| 122 NameReference(intptr_t token_pos, const String& name) |
| 123 : token_pos_(token_pos), |
| 124 name_(name) { |
| 125 } |
| 126 const String& name() const { return name_; } |
| 127 intptr_t token_pos() const { return token_pos_; } |
| 128 void set_token_pos(intptr_t value) { token_pos_ = value; } |
| 129 private: |
| 130 intptr_t token_pos_; |
| 131 const String& name_; |
| 132 }; |
| 133 |
| 134 |
120 class SourceLabel : public ZoneAllocated { | 135 class SourceLabel : public ZoneAllocated { |
121 public: | 136 public: |
122 enum Kind { | 137 enum Kind { |
123 kFor, | 138 kFor, |
124 kWhile, | 139 kWhile, |
125 kDoWhile, | 140 kDoWhile, |
126 kSwitch, | 141 kSwitch, |
127 kCase, | 142 kCase, |
128 kTry, | 143 kTry, |
129 kCatch, | 144 kCatch, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 intptr_t num_variables() const { return variables_.length(); } | 314 intptr_t num_variables() const { return variables_.length(); } |
300 LocalVariable* VariableAt(intptr_t index) const { | 315 LocalVariable* VariableAt(intptr_t index) const { |
301 ASSERT((index >= 0) && (index < variables_.length())); | 316 ASSERT((index >= 0) && (index < variables_.length())); |
302 return variables_[index]; | 317 return variables_[index]; |
303 } | 318 } |
304 | 319 |
305 // Count the captured variables belonging to outer scopes and referenced in | 320 // Count the captured variables belonging to outer scopes and referenced in |
306 // this local scope. | 321 // this local scope. |
307 int NumCapturedVariables() const; | 322 int NumCapturedVariables() const; |
308 | 323 |
| 324 // Add a reference to the given name into this scope and the enclosing |
| 325 // scopes that do not have a local variable declaration for this name |
| 326 // already. |
| 327 void AddReferencedName(intptr_t token_pos, const String& name); |
| 328 intptr_t PreviousReferencePos(const String& name) const; |
| 329 |
309 // Allocate both captured and non-captured variables declared in this scope | 330 // Allocate both captured and non-captured variables declared in this scope |
310 // and in its children scopes of the same function level. Allocating means | 331 // and in its children scopes of the same function level. Allocating means |
311 // assigning a frame slot index or a context slot index. | 332 // assigning a frame slot index or a context slot index. |
312 // Parameters to be allocated in the frame must all appear in the top scope | 333 // Parameters to be allocated in the frame must all appear in the top scope |
313 // and not in its children (we do not yet handle register parameters). | 334 // and not in its children (we do not yet handle register parameters). |
314 // Locals must be listed after parameters in top scope and in its children. | 335 // Locals must be listed after parameters in top scope and in its children. |
315 // Two locals in different sibling scopes may share the same frame slot. | 336 // Two locals in different sibling scopes may share the same frame slot. |
316 // Return the index of the next available frame slot. | 337 // Return the index of the next available frame slot. |
317 int AllocateVariables(int first_parameter_index, | 338 int AllocateVariables(int first_parameter_index, |
318 int num_parameters, | 339 int num_parameters, |
(...skipping 28 matching lines...) Expand all Loading... |
347 // Allocate the variable in the current context, possibly updating the current | 368 // Allocate the variable in the current context, possibly updating the current |
348 // context owner scope, if the variable is the first one to be allocated at | 369 // context owner scope, if the variable is the first one to be allocated at |
349 // this loop level. | 370 // this loop level. |
350 // The variable may belong to this scope or to any of its children, but at the | 371 // The variable may belong to this scope or to any of its children, but at the |
351 // same loop level. | 372 // same loop level. |
352 void AllocateContextVariable(LocalVariable* variable, | 373 void AllocateContextVariable(LocalVariable* variable, |
353 LocalScope** context_owner); | 374 LocalScope** context_owner); |
354 | 375 |
355 void CollectLocalVariables(GrowableArray<VarDesc>* vars, int16_t* scope_id); | 376 void CollectLocalVariables(GrowableArray<VarDesc>* vars, int16_t* scope_id); |
356 | 377 |
| 378 NameReference* FindReference(const String& name) const; |
| 379 |
357 static const int kUnitializedContextLevel = INT_MIN; | 380 static const int kUnitializedContextLevel = INT_MIN; |
358 LocalScope* parent_; | 381 LocalScope* parent_; |
359 LocalScope* child_; | 382 LocalScope* child_; |
360 LocalScope* sibling_; | 383 LocalScope* sibling_; |
361 int function_level_; // Reflects the nesting level of local functions. | 384 int function_level_; // Reflects the nesting level of local functions. |
362 int loop_level_; // Reflects the loop nesting level. | 385 int loop_level_; // Reflects the loop nesting level. |
363 int context_level_; // Reflects the level of the runtime context. | 386 int context_level_; // Reflects the level of the runtime context. |
364 int num_context_variables_; // Only set if this scope is a context owner. | 387 int num_context_variables_; // Only set if this scope is a context owner. |
365 intptr_t begin_token_pos_; // Token index of beginning of scope. | 388 intptr_t begin_token_pos_; // Token index of beginning of scope. |
366 intptr_t end_token_pos_; // Token index of end of scope. | 389 intptr_t end_token_pos_; // Token index of end of scope. |
367 GrowableArray<LocalVariable*> variables_; | 390 GrowableArray<LocalVariable*> variables_; |
368 GrowableArray<SourceLabel*> labels_; | 391 GrowableArray<SourceLabel*> labels_; |
369 | 392 |
| 393 // List of names referenced in this scope and its children that |
| 394 // are not resolved to local variables. |
| 395 GrowableArray<NameReference*> referenced_; |
| 396 |
370 DISALLOW_COPY_AND_ASSIGN(LocalScope); | 397 DISALLOW_COPY_AND_ASSIGN(LocalScope); |
371 }; | 398 }; |
372 | 399 |
373 } // namespace dart | 400 } // namespace dart |
374 | 401 |
375 #endif // VM_SCOPES_H_ | 402 #endif // VM_SCOPES_H_ |
OLD | NEW |