| 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 "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 const AbstractType& type) | 26 const AbstractType& type) |
| 27 : token_pos_(token_pos), | 27 : token_pos_(token_pos), |
| 28 name_(name), | 28 name_(name), |
| 29 owner_(NULL), | 29 owner_(NULL), |
| 30 type_(type), | 30 type_(type), |
| 31 const_value_(NULL), | 31 const_value_(NULL), |
| 32 is_final_(false), | 32 is_final_(false), |
| 33 is_captured_(false), | 33 is_captured_(false), |
| 34 is_invisible_(false), | 34 is_invisible_(false), |
| 35 is_captured_parameter_(false), | 35 is_captured_parameter_(false), |
| 36 is_forced_stack_(false), |
| 36 index_(LocalVariable::kUninitializedIndex) { | 37 index_(LocalVariable::kUninitializedIndex) { |
| 37 ASSERT(type.IsZoneHandle() || type.IsReadOnlyHandle()); | 38 ASSERT(type.IsZoneHandle() || type.IsReadOnlyHandle()); |
| 38 ASSERT(type.IsFinalized()); | 39 ASSERT(type.IsFinalized()); |
| 39 ASSERT(name.IsSymbol()); | 40 ASSERT(name.IsSymbol()); |
| 40 } | 41 } |
| 41 | 42 |
| 42 TokenPosition token_pos() const { return token_pos_; } | 43 TokenPosition token_pos() const { return token_pos_; } |
| 43 const String& name() const { return name_; } | 44 const String& name() const { return name_; } |
| 44 LocalScope* owner() const { return owner_; } | 45 LocalScope* owner() const { return owner_; } |
| 45 void set_owner(LocalScope* owner) { | 46 void set_owner(LocalScope* owner) { |
| 46 ASSERT(owner_ == NULL); | 47 ASSERT(owner_ == NULL); |
| 47 owner_ = owner; | 48 owner_ = owner; |
| 48 } | 49 } |
| 49 | 50 |
| 50 const AbstractType& type() const { return type_; } | 51 const AbstractType& type() const { return type_; } |
| 51 | 52 |
| 52 bool is_final() const { return is_final_; } | 53 bool is_final() const { return is_final_; } |
| 53 void set_is_final() { is_final_ = true; } | 54 void set_is_final() { is_final_ = true; } |
| 54 | 55 |
| 55 bool is_captured() const { return is_captured_; } | 56 bool is_captured() const { return is_captured_; } |
| 56 void set_is_captured() { is_captured_ = true; } | 57 void set_is_captured() { is_captured_ = true; } |
| 57 | 58 |
| 59 // Variables marked as forced to stack are skipped and not captured by |
| 60 // CaptureLocalVariables - which iterates scope chain between two scopes |
| 61 // and indiscriminately marks all variables as captured. |
| 62 // TODO(27590) remove the hardcoded blacklist from CaptureLocalVariables |
| 63 bool is_forced_stack() const { return is_forced_stack_; } |
| 64 void set_is_forced_stack() { is_forced_stack_ = true; } |
| 65 |
| 58 bool HasIndex() const { | 66 bool HasIndex() const { |
| 59 return index_ != kUninitializedIndex; | 67 return index_ != kUninitializedIndex; |
| 60 } | 68 } |
| 61 int index() const { | 69 int index() const { |
| 62 ASSERT(HasIndex()); | 70 ASSERT(HasIndex()); |
| 63 return index_; | 71 return index_; |
| 64 } | 72 } |
| 65 | 73 |
| 66 // Assign an index to a local. | 74 // Assign an index to a local. |
| 67 void set_index(int index) { | 75 void set_index(int index) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 123 |
| 116 const AbstractType& type_; // Declaration type of local variable. | 124 const AbstractType& type_; // Declaration type of local variable. |
| 117 | 125 |
| 118 const Instance* const_value_; // NULL or compile-time const value. | 126 const Instance* const_value_; // NULL or compile-time const value. |
| 119 | 127 |
| 120 bool is_final_; // If true, this variable is readonly. | 128 bool is_final_; // If true, this variable is readonly. |
| 121 bool is_captured_; // If true, this variable lives in the context, otherwise | 129 bool is_captured_; // If true, this variable lives in the context, otherwise |
| 122 // in the stack frame. | 130 // in the stack frame. |
| 123 bool is_invisible_; | 131 bool is_invisible_; |
| 124 bool is_captured_parameter_; | 132 bool is_captured_parameter_; |
| 133 bool is_forced_stack_; |
| 125 int index_; // Allocation index in words relative to frame pointer (if not | 134 int index_; // Allocation index in words relative to frame pointer (if not |
| 126 // captured), or relative to the context pointer (if captured). | 135 // captured), or relative to the context pointer (if captured). |
| 127 | 136 |
| 128 friend class LocalScope; | 137 friend class LocalScope; |
| 129 DISALLOW_COPY_AND_ASSIGN(LocalVariable); | 138 DISALLOW_COPY_AND_ASSIGN(LocalVariable); |
| 130 }; | 139 }; |
| 131 | 140 |
| 132 | 141 |
| 133 class NameReference : public ZoneAllocated { | 142 class NameReference : public ZoneAllocated { |
| 134 public: | 143 public: |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 333 |
| 325 // Creates variable info for the scope and all its nested scopes. | 334 // Creates variable info for the scope and all its nested scopes. |
| 326 // Must be called after AllocateVariables() has been called. | 335 // Must be called after AllocateVariables() has been called. |
| 327 RawLocalVarDescriptors* GetVarDescriptors(const Function& func); | 336 RawLocalVarDescriptors* GetVarDescriptors(const Function& func); |
| 328 | 337 |
| 329 // Create a ContextScope object describing all captured variables referenced | 338 // Create a ContextScope object describing all captured variables referenced |
| 330 // from this scope and belonging to outer scopes. | 339 // from this scope and belonging to outer scopes. |
| 331 RawContextScope* PreserveOuterScope(int current_context_level) const; | 340 RawContextScope* PreserveOuterScope(int current_context_level) const; |
| 332 | 341 |
| 333 // Mark all local variables that are accessible from this scope up to | 342 // Mark all local variables that are accessible from this scope up to |
| 334 // top_scope (included) as captured. | 343 // top_scope (included) as captured unless they are marked as forced to stack. |
| 335 void CaptureLocalVariables(LocalScope* top_scope); | 344 void CaptureLocalVariables(LocalScope* top_scope); |
| 336 | 345 |
| 337 // Creates a LocalScope representing the outer scope of a local function to be | 346 // Creates a LocalScope representing the outer scope of a local function to be |
| 338 // compiled. This outer scope contains the variables captured by the function | 347 // compiled. This outer scope contains the variables captured by the function |
| 339 // as specified by the given ContextScope, which was created during the | 348 // as specified by the given ContextScope, which was created during the |
| 340 // compilation of the enclosing function. | 349 // compilation of the enclosing function. |
| 341 static LocalScope* RestoreOuterScope(const ContextScope& context_scope); | 350 static LocalScope* RestoreOuterScope(const ContextScope& context_scope); |
| 342 | 351 |
| 343 // Create a ContextScope object which will capture "this" for an implicit | 352 // Create a ContextScope object which will capture "this" for an implicit |
| 344 // closure object. | 353 // closure object. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // List of names referenced in this scope and its children that | 387 // List of names referenced in this scope and its children that |
| 379 // are not resolved to local variables. | 388 // are not resolved to local variables. |
| 380 GrowableArray<NameReference*> referenced_; | 389 GrowableArray<NameReference*> referenced_; |
| 381 | 390 |
| 382 DISALLOW_COPY_AND_ASSIGN(LocalScope); | 391 DISALLOW_COPY_AND_ASSIGN(LocalScope); |
| 383 }; | 392 }; |
| 384 | 393 |
| 385 } // namespace dart | 394 } // namespace dart |
| 386 | 395 |
| 387 #endif // VM_SCOPES_H_ | 396 #endif // VM_SCOPES_H_ |
| OLD | NEW |