| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return new SourceLabel(token_pos, | 175 return new SourceLabel(token_pos, |
| 176 Symbols::DefaultLabel(), | 176 Symbols::DefaultLabel(), |
| 177 kind); | 177 kind); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 TokenPosition token_pos() const { return token_pos_; } | 181 TokenPosition token_pos() const { return token_pos_; } |
| 182 const String& name() const { return name_; } | 182 const String& name() const { return name_; } |
| 183 LocalScope* owner() const { return owner_; } | 183 LocalScope* owner() const { return owner_; } |
| 184 void set_owner(LocalScope* owner) { | 184 void set_owner(LocalScope* owner) { |
| 185 ASSERT(owner_ == NULL); | |
| 186 owner_ = owner; | 185 owner_ = owner; |
| 187 } | 186 } |
| 188 | 187 |
| 189 Kind kind() const { return kind_; } | 188 Kind kind() const { return kind_; } |
| 190 | 189 |
| 191 // Returns the function level of the scope in which the label is defined. | 190 // Returns the function level of the scope in which the label is defined. |
| 192 int FunctionLevel() const; | 191 int FunctionLevel() const; |
| 193 | 192 |
| 193 bool IsUnresolved() { return kind_ == kForward; } |
| 194 void ResolveForwardReference() { kind_ = kCase; } | 194 void ResolveForwardReference() { kind_ = kCase; } |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 const TokenPosition token_pos_; | 197 const TokenPosition token_pos_; |
| 198 const String& name_; | 198 const String& name_; |
| 199 LocalScope* owner_; // Local scope declaring this label. | 199 LocalScope* owner_; // Local scope declaring this label. |
| 200 | 200 |
| 201 Kind kind_; | 201 Kind kind_; |
| 202 | 202 |
| 203 DISALLOW_COPY_AND_ASSIGN(SourceLabel); | 203 DISALLOW_COPY_AND_ASSIGN(SourceLabel); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 // Insert a formal parameter variable to the scope at the given position, | 249 // Insert a formal parameter variable to the scope at the given position, |
| 250 // possibly in front of aliases already added with AddVariable. | 250 // possibly in front of aliases already added with AddVariable. |
| 251 // Returns false if a variable with the same name is already present. | 251 // Returns false if a variable with the same name is already present. |
| 252 bool InsertParameterAt(intptr_t pos, LocalVariable* parameter); | 252 bool InsertParameterAt(intptr_t pos, LocalVariable* parameter); |
| 253 | 253 |
| 254 // Add a label to the scope. Returns false if a label with the same name | 254 // Add a label to the scope. Returns false if a label with the same name |
| 255 // is already present. | 255 // is already present. |
| 256 bool AddLabel(SourceLabel* label); | 256 bool AddLabel(SourceLabel* label); |
| 257 | 257 |
| 258 // Move an unresolved label of a switch case label to an outer switch. |
| 259 void MoveLabel(SourceLabel* label); |
| 260 |
| 258 // Lookup a variable in this scope only. | 261 // Lookup a variable in this scope only. |
| 259 LocalVariable* LocalLookupVariable(const String& name) const; | 262 LocalVariable* LocalLookupVariable(const String& name) const; |
| 260 | 263 |
| 261 // Lookup a label in this scope only. | 264 // Lookup a label in this scope only. |
| 262 SourceLabel* LocalLookupLabel(const String& name) const; | 265 SourceLabel* LocalLookupLabel(const String& name) const; |
| 263 | 266 |
| 264 // Lookup a variable in this scope and its parents. If the variable | 267 // Lookup a variable in this scope and its parents. If the variable |
| 265 // is found in a parent scope and 'test_only' is not true, we insert | 268 // is found in a parent scope and 'test_only' is not true, we insert |
| 266 // aliases of the variable in the current and intermediate scopes up to | 269 // aliases of the variable in the current and intermediate scopes up to |
| 267 // the declaration scope in order to detect "used before declared" errors. | 270 // the declaration scope in order to detect "used before declared" errors. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // List of names referenced in this scope and its children that | 378 // List of names referenced in this scope and its children that |
| 376 // are not resolved to local variables. | 379 // are not resolved to local variables. |
| 377 GrowableArray<NameReference*> referenced_; | 380 GrowableArray<NameReference*> referenced_; |
| 378 | 381 |
| 379 DISALLOW_COPY_AND_ASSIGN(LocalScope); | 382 DISALLOW_COPY_AND_ASSIGN(LocalScope); |
| 380 }; | 383 }; |
| 381 | 384 |
| 382 } // namespace dart | 385 } // namespace dart |
| 383 | 386 |
| 384 #endif // VM_SCOPES_H_ | 387 #endif // VM_SCOPES_H_ |
| OLD | NEW |