OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_AST_SCOPES_H_ | 5 #ifndef V8_AST_SCOPES_H_ |
6 #define V8_AST_SCOPES_H_ | 6 #define V8_AST_SCOPES_H_ |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/variables.h" |
9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
11 #include "src/zone.h" | 11 #include "src/zone.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
| 16 class AstNodeFactory; |
| 17 class AstValueFactory; |
| 18 class AstRawString; |
| 19 class Declaration; |
16 class ParseInfo; | 20 class ParseInfo; |
| 21 class SloppyBlockFunctionStatement; |
| 22 class VariableProxy; |
17 | 23 |
18 // A hash map to support fast variable declaration and lookup. | 24 // A hash map to support fast variable declaration and lookup. |
19 class VariableMap: public ZoneHashMap { | 25 class VariableMap: public ZoneHashMap { |
20 public: | 26 public: |
21 explicit VariableMap(Zone* zone); | 27 explicit VariableMap(Zone* zone); |
22 | 28 |
23 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 29 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
24 VariableMode mode, Variable::Kind kind, | 30 VariableMode mode, Variable::Kind kind, |
25 InitializationFlag initialization_flag, | 31 InitializationFlag initialization_flag, |
26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, | 32 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Declarations list. | 152 // Declarations list. |
147 ZoneList<Declaration*>* declarations() { return &decls_; } | 153 ZoneList<Declaration*>* declarations() { return &decls_; } |
148 | 154 |
149 ZoneList<Variable*>* locals() { return &locals_; } | 155 ZoneList<Variable*>* locals() { return &locals_; } |
150 | 156 |
151 // Create a new unresolved variable. | 157 // Create a new unresolved variable. |
152 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 158 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
153 const AstRawString* name, | 159 const AstRawString* name, |
154 int start_position = kNoSourcePosition, | 160 int start_position = kNoSourcePosition, |
155 int end_position = kNoSourcePosition, | 161 int end_position = kNoSourcePosition, |
156 Variable::Kind kind = Variable::NORMAL) { | 162 Variable::Kind kind = Variable::NORMAL); |
157 // Note that we must not share the unresolved variables with | |
158 // the same name because they may be removed selectively via | |
159 // RemoveUnresolved(). | |
160 DCHECK(!already_resolved_); | |
161 DCHECK_EQ(factory->zone(), zone()); | |
162 VariableProxy* proxy = | |
163 factory->NewVariableProxy(name, kind, start_position, end_position); | |
164 proxy->set_next_unresolved(unresolved_); | |
165 unresolved_ = proxy; | |
166 return proxy; | |
167 } | |
168 | 163 |
169 void AddUnresolved(VariableProxy* proxy) { | 164 void AddUnresolved(VariableProxy* proxy); |
170 DCHECK(!already_resolved_); | |
171 DCHECK(!proxy->is_resolved()); | |
172 proxy->set_next_unresolved(unresolved_); | |
173 unresolved_ = proxy; | |
174 } | |
175 | 165 |
176 // Remove a unresolved variable. During parsing, an unresolved variable | 166 // Remove a unresolved variable. During parsing, an unresolved variable |
177 // may have been added optimistically, but then only the variable name | 167 // may have been added optimistically, but then only the variable name |
178 // was used (typically for labels). If the variable was not declared, the | 168 // was used (typically for labels). If the variable was not declared, the |
179 // addition introduced a new unresolved variable which may end up being | 169 // addition introduced a new unresolved variable which may end up being |
180 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 170 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
181 // such a variable again if it was added; otherwise this is a no-op. | 171 // such a variable again if it was added; otherwise this is a no-op. |
182 bool RemoveUnresolved(VariableProxy* var); | 172 bool RemoveUnresolved(VariableProxy* var); |
183 | 173 |
184 // Creates a new temporary variable in this scope's TemporaryScope. The | 174 // Creates a new temporary variable in this scope's TemporaryScope. The |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 void AllocateModuleVariables(); | 842 void AllocateModuleVariables(); |
853 | 843 |
854 private: | 844 private: |
855 ModuleDescriptor* module_descriptor_; | 845 ModuleDescriptor* module_descriptor_; |
856 }; | 846 }; |
857 | 847 |
858 } // namespace internal | 848 } // namespace internal |
859 } // namespace v8 | 849 } // namespace v8 |
860 | 850 |
861 #endif // V8_AST_SCOPES_H_ | 851 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |