| 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" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class JoinEntryInstr; |
| 14 class LocalScope; | 15 class LocalScope; |
| 15 class LocalVariable; | 16 class LocalVariable; |
| 16 class SourceLabel; | 17 class SourceLabel; |
| 17 | 18 |
| 18 | 19 |
| 19 class LocalVariable : public ZoneAllocated { | 20 class LocalVariable : public ZoneAllocated { |
| 20 public: | 21 public: |
| 21 LocalVariable(intptr_t token_index, | 22 LocalVariable(intptr_t token_index, |
| 22 const String& name, | 23 const String& name, |
| 23 const AbstractType& type) | 24 const AbstractType& type) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 kForward, | 108 kForward, |
| 108 kStatement // Any statement other than the above | 109 kStatement // Any statement other than the above |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 SourceLabel(intptr_t token_index, const String& name, Kind kind) | 112 SourceLabel(intptr_t token_index, const String& name, Kind kind) |
| 112 : token_index_(token_index), | 113 : token_index_(token_index), |
| 113 name_(name), | 114 name_(name), |
| 114 owner_(NULL), | 115 owner_(NULL), |
| 115 kind_(kind), | 116 kind_(kind), |
| 116 continue_label_(), | 117 continue_label_(), |
| 117 break_label_() { | 118 break_label_(), |
| 119 join_for_break_(NULL), |
| 120 join_for_continue_(NULL) { |
| 118 } | 121 } |
| 119 | 122 |
| 120 static SourceLabel* New(intptr_t token_index, String* name, Kind kind) { | 123 static SourceLabel* New(intptr_t token_index, String* name, Kind kind) { |
| 121 if (name != NULL) { | 124 if (name != NULL) { |
| 122 return new SourceLabel(token_index, *name, kind); | 125 return new SourceLabel(token_index, *name, kind); |
| 123 } else { | 126 } else { |
| 124 return new SourceLabel(token_index, | 127 return new SourceLabel(token_index, |
| 125 String::ZoneHandle(String::New(kDefaultLabelName)), | 128 String::ZoneHandle(String::New(kDefaultLabelName)), |
| 126 kind); | 129 kind); |
| 127 } | 130 } |
| 128 } | 131 } |
| 129 | 132 |
| 130 intptr_t token_index() const { return token_index_; } | 133 intptr_t token_index() const { return token_index_; } |
| 131 const String& name() const { return name_; } | 134 const String& name() const { return name_; } |
| 132 LocalScope* owner() const { return owner_; } | 135 LocalScope* owner() const { return owner_; } |
| 133 void set_owner(LocalScope* owner) { | 136 void set_owner(LocalScope* owner) { |
| 134 ASSERT(owner_ == NULL); | 137 ASSERT(owner_ == NULL); |
| 135 owner_ = owner; | 138 owner_ = owner; |
| 136 } | 139 } |
| 137 | 140 |
| 138 Kind kind() const { return kind_; } | 141 Kind kind() const { return kind_; } |
| 139 Label* break_label() { return &break_label_; } | 142 Label* break_label() { return &break_label_; } |
| 140 Label* continue_label() { return &continue_label_; } | 143 Label* continue_label() { return &continue_label_; } |
| 141 | 144 |
| 145 void set_join_for_continue(JoinEntryInstr* join) { |
| 146 ASSERT(join_for_continue_ == NULL); |
| 147 join_for_continue_ = join; |
| 148 } |
| 149 |
| 150 JoinEntryInstr* join_for_continue() const { |
| 151 return join_for_continue_; |
| 152 } |
| 153 |
| 154 void set_join_for_break(JoinEntryInstr* join) { |
| 155 ASSERT(join_for_break_ == NULL); |
| 156 join_for_break_ = join; |
| 157 } |
| 158 |
| 159 JoinEntryInstr* join_for_break() const { |
| 160 return join_for_break_; |
| 161 } |
| 162 |
| 142 // Returns the function level of the scope in which the label is defined. | 163 // Returns the function level of the scope in which the label is defined. |
| 143 int FunctionLevel() const; | 164 int FunctionLevel() const; |
| 144 | 165 |
| 145 void ResolveForwardReference() { kind_ = kCase; } | 166 void ResolveForwardReference() { kind_ = kCase; } |
| 146 | 167 |
| 147 private: | 168 private: |
| 148 const intptr_t token_index_; | 169 const intptr_t token_index_; |
| 149 const String& name_; | 170 const String& name_; |
| 150 LocalScope* owner_; // Local scope declaring this label. | 171 LocalScope* owner_; // Local scope declaring this label. |
| 151 | 172 |
| 152 Kind kind_; | 173 Kind kind_; |
| 153 Label continue_label_; | 174 Label continue_label_; |
| 154 Label break_label_; | 175 Label break_label_; |
| 176 JoinEntryInstr* join_for_break_; |
| 177 JoinEntryInstr* join_for_continue_; |
| 155 static const char* kDefaultLabelName; | 178 static const char* kDefaultLabelName; |
| 156 | 179 |
| 157 DISALLOW_COPY_AND_ASSIGN(SourceLabel); | 180 DISALLOW_COPY_AND_ASSIGN(SourceLabel); |
| 158 }; | 181 }; |
| 159 | 182 |
| 160 | 183 |
| 161 class LocalScope : public ZoneAllocated { | 184 class LocalScope : public ZoneAllocated { |
| 162 public: | 185 public: |
| 163 LocalScope(LocalScope* parent, int function_level, int loop_level); | 186 LocalScope(LocalScope* parent, int function_level, int loop_level); |
| 164 | 187 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 intptr_t end_token_index_; // Token index of end of scope. | 322 intptr_t end_token_index_; // Token index of end of scope. |
| 300 GrowableArray<LocalVariable*> variables_; | 323 GrowableArray<LocalVariable*> variables_; |
| 301 GrowableArray<SourceLabel*> labels_; | 324 GrowableArray<SourceLabel*> labels_; |
| 302 | 325 |
| 303 DISALLOW_COPY_AND_ASSIGN(LocalScope); | 326 DISALLOW_COPY_AND_ASSIGN(LocalScope); |
| 304 }; | 327 }; |
| 305 | 328 |
| 306 } // namespace dart | 329 } // namespace dart |
| 307 | 330 |
| 308 #endif // VM_SCOPES_H_ | 331 #endif // VM_SCOPES_H_ |
| OLD | NEW |