Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, 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" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class LocalScope; | 14 class LocalScope; |
| 15 class LocalVariable; | 15 class LocalVariable; |
| 16 class SourceLabel; | 16 class SourceLabel; |
| 17 | 17 |
| 18 | 18 |
| 19 class LocalVariable : public ZoneAllocated { | 19 class LocalVariable : public ZoneAllocated { |
| 20 public: | 20 public: |
| 21 LocalVariable(intptr_t token_index, | 21 LocalVariable(intptr_t token_index, |
| 22 const String& name, | 22 const String& name, |
| 23 const AbstractType& type) | 23 const AbstractType& type) |
| 24 : token_index_(token_index), | 24 : token_index_(token_index), |
| 25 name_(name), | 25 name_(name), |
| 26 owner_(NULL), | 26 owner_(NULL), |
| 27 type_(type), | 27 type_(type), |
| 28 is_final_(false), | 28 is_final_(false), |
| 29 is_captured_(false), | 29 is_captured_(false), |
| 30 is_invisible_(false), | 30 is_invisible_(false), |
| 31 index_(LocalVariable::kUnitializedIndex_) { | 31 index_(LocalVariable::kUnitializedIndex) { |
| 32 ASSERT(type.IsZoneHandle()); | 32 ASSERT(type.IsZoneHandle()); |
| 33 ASSERT(type.IsFinalized()); | 33 ASSERT(type.IsFinalized()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 intptr_t token_index() const { return token_index_; } | 36 intptr_t token_index() const { return token_index_; } |
| 37 const String& name() const { return name_; } | 37 const String& name() const { return name_; } |
| 38 LocalScope* owner() const { return owner_; } | 38 LocalScope* owner() const { return owner_; } |
| 39 void set_owner(LocalScope* owner) { | 39 void set_owner(LocalScope* owner) { |
| 40 ASSERT(owner_ == NULL); | 40 ASSERT(owner_ == NULL); |
| 41 owner_ = owner; | 41 owner_ = owner; |
| 42 } | 42 } |
| 43 | 43 |
| 44 const AbstractType& type() const { return type_; } | 44 const AbstractType& type() const { return type_; } |
| 45 | 45 |
| 46 bool is_final() const { return is_final_; } | 46 bool is_final() const { return is_final_; } |
| 47 void set_is_final() { is_final_ = true; } | 47 void set_is_final() { is_final_ = true; } |
| 48 | 48 |
| 49 bool is_captured() const { return is_captured_; } | 49 bool is_captured() const { return is_captured_; } |
| 50 void set_is_captured() { is_captured_ = true; } | 50 void set_is_captured() { is_captured_ = true; } |
| 51 | 51 |
| 52 bool HasIndex() const { | 52 bool HasIndex() const { |
| 53 return index_ != kUnitializedIndex_; | 53 return index_ != kUnitializedIndex; |
| 54 } | 54 } |
| 55 int index() const { | 55 int index() const { |
| 56 ASSERT(HasIndex()); | 56 ASSERT(HasIndex()); |
| 57 return index_; | 57 return index_; |
| 58 } | 58 } |
| 59 void set_index(int index) { | 59 void set_index(int index) { |
| 60 ASSERT(!HasIndex()); | 60 ASSERT(!HasIndex() || (index_ == index)); |
|
Kevin Millikin (Google)
2012/02/27 13:40:42
There's no simple way to clear variables that have
| |
| 61 ASSERT(index != kUnitializedIndex_); | 61 ASSERT(index != kUnitializedIndex); |
| 62 index_ = index; | 62 index_ = index; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void set_invisible(bool value) { | 65 void set_invisible(bool value) { |
| 66 is_invisible_ = value; | 66 is_invisible_ = value; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool Equals(const LocalVariable& other) const; | 69 bool Equals(const LocalVariable& other) const; |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 static const int kUnitializedIndex_ = INT_MIN; | 72 static const int kUnitializedIndex = INT_MIN; |
| 73 | 73 |
| 74 const intptr_t token_index_; | 74 const intptr_t token_index_; |
| 75 const String& name_; | 75 const String& name_; |
| 76 LocalScope* owner_; // Local scope declaring this variable. | 76 LocalScope* owner_; // Local scope declaring this variable. |
| 77 | 77 |
| 78 const AbstractType& type_; // Declaration type of local variable. | 78 const AbstractType& type_; // Declaration type of local variable. |
| 79 | 79 |
| 80 bool is_final_; // If true, this variable is readonly. | 80 bool is_final_; // If true, this variable is readonly. |
| 81 bool is_captured_; // If true, this variable lives in the context, otherwise | 81 bool is_captured_; // If true, this variable lives in the context, otherwise |
| 82 // in the stack frame. | 82 // in the stack frame. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 LocalScope* sibling() const { return sibling_; } | 162 LocalScope* sibling() const { return sibling_; } |
| 163 int function_level() const { return function_level_; } | 163 int function_level() const { return function_level_; } |
| 164 int loop_level() const { return loop_level_; } | 164 int loop_level() const { return loop_level_; } |
| 165 | 165 |
| 166 // Check if this scope is nested within the passed in scope. | 166 // Check if this scope is nested within the passed in scope. |
| 167 bool IsNestedWithin(LocalScope* scope) const; | 167 bool IsNestedWithin(LocalScope* scope) const; |
| 168 | 168 |
| 169 // The context level is only set in a scope that is either the owner scope of | 169 // The context level is only set in a scope that is either the owner scope of |
| 170 // a captured variable or that is the owner scope of a context. | 170 // a captured variable or that is the owner scope of a context. |
| 171 bool HasContextLevel() const { | 171 bool HasContextLevel() const { |
| 172 return context_level_ != kUnitializedContextLevel_; | 172 return context_level_ != kUnitializedContextLevel; |
| 173 } | 173 } |
| 174 int context_level() const { | 174 int context_level() const { |
| 175 ASSERT(HasContextLevel()); | 175 ASSERT(HasContextLevel()); |
| 176 return context_level_; | 176 return context_level_; |
| 177 } | 177 } |
| 178 void set_context_level(int context_level) { | 178 void set_context_level(int context_level) { |
| 179 ASSERT(!HasContextLevel()); | 179 ASSERT(!HasContextLevel()); |
| 180 ASSERT(context_level != kUnitializedContextLevel_); | 180 ASSERT(context_level != kUnitializedContextLevel); |
| 181 context_level_ = context_level; | 181 context_level_ = context_level; |
| 182 } | 182 } |
| 183 | 183 |
| 184 intptr_t end_token_index() const { return end_token_index_; } | 184 intptr_t end_token_index() const { return end_token_index_; } |
| 185 void set_end_token_index(intptr_t value) { end_token_index_ = value; } | 185 void set_end_token_index(intptr_t value) { end_token_index_ = value; } |
| 186 | 186 |
| 187 // The number of variables allocated in the context and belonging to this | 187 // The number of variables allocated in the context and belonging to this |
| 188 // scope and to its children at the same loop level. | 188 // scope and to its children at the same loop level. |
| 189 int num_context_variables() const { return num_context_variables_; } | 189 int num_context_variables() const { return num_context_variables_; } |
| 190 | 190 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 // Allocate the variable in the current context, possibly updating the current | 276 // Allocate the variable in the current context, possibly updating the current |
| 277 // context owner scope, if the variable is the first one to be allocated at | 277 // context owner scope, if the variable is the first one to be allocated at |
| 278 // this loop level. | 278 // this loop level. |
| 279 // The variable may belong to this scope or to any of its children, but at the | 279 // The variable may belong to this scope or to any of its children, but at the |
| 280 // same loop level. | 280 // same loop level. |
| 281 void AllocateContextVariable(LocalVariable* variable, | 281 void AllocateContextVariable(LocalVariable* variable, |
| 282 LocalScope** context_owner); | 282 LocalScope** context_owner); |
| 283 | 283 |
| 284 void CollectLocalVariables(GrowableArray<LocalVariable*>* vars); | 284 void CollectLocalVariables(GrowableArray<LocalVariable*>* vars); |
| 285 | 285 |
| 286 static const int kUnitializedContextLevel_ = INT_MIN; | 286 static const int kUnitializedContextLevel = INT_MIN; |
| 287 LocalScope* parent_; | 287 LocalScope* parent_; |
| 288 LocalScope* child_; | 288 LocalScope* child_; |
| 289 LocalScope* sibling_; | 289 LocalScope* sibling_; |
| 290 int function_level_; // Reflects the nesting level of local functions. | 290 int function_level_; // Reflects the nesting level of local functions. |
| 291 int loop_level_; // Reflects the loop nesting level. | 291 int loop_level_; // Reflects the loop nesting level. |
| 292 int context_level_; // Reflects the level of the runtime context. | 292 int context_level_; // Reflects the level of the runtime context. |
| 293 int num_context_variables_; // Only set if this scope is a context owner. | 293 int num_context_variables_; // Only set if this scope is a context owner. |
| 294 intptr_t end_token_index_; // Token index of end of scope. | 294 intptr_t end_token_index_; // Token index of end of scope. |
| 295 GrowableArray<LocalVariable*> variables_; | 295 GrowableArray<LocalVariable*> variables_; |
| 296 GrowableArray<SourceLabel*> labels_; | 296 GrowableArray<SourceLabel*> labels_; |
| 297 | 297 |
| 298 DISALLOW_COPY_AND_ASSIGN(LocalScope); | 298 DISALLOW_COPY_AND_ASSIGN(LocalScope); |
| 299 }; | 299 }; |
| 300 | 300 |
| 301 } // namespace dart | 301 } // namespace dart |
| 302 | 302 |
| 303 #endif // VM_SCOPES_H_ | 303 #endif // VM_SCOPES_H_ |
| OLD | NEW |