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/ast.h" |
9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const AstRawString* name, | 176 const AstRawString* name, |
177 Variable::Kind kind = Variable::NORMAL, | 177 Variable::Kind kind = Variable::NORMAL, |
178 int start_position = kNoSourcePosition, | 178 int start_position = kNoSourcePosition, |
179 int end_position = kNoSourcePosition) { | 179 int end_position = kNoSourcePosition) { |
180 // Note that we must not share the unresolved variables with | 180 // Note that we must not share the unresolved variables with |
181 // the same name because they may be removed selectively via | 181 // the same name because they may be removed selectively via |
182 // RemoveUnresolved(). | 182 // RemoveUnresolved(). |
183 DCHECK(!already_resolved()); | 183 DCHECK(!already_resolved()); |
184 VariableProxy* proxy = | 184 VariableProxy* proxy = |
185 factory->NewVariableProxy(name, kind, start_position, end_position); | 185 factory->NewVariableProxy(name, kind, start_position, end_position); |
186 unresolved_.Add(proxy, zone_); | 186 proxy->set_next_unresolved(unresolved_); |
| 187 unresolved_ = proxy; |
187 return proxy; | 188 return proxy; |
188 } | 189 } |
189 | 190 |
190 void AddUnresolved(VariableProxy* proxy) { | 191 void AddUnresolved(VariableProxy* proxy) { |
191 DCHECK(!already_resolved()); | 192 DCHECK(!already_resolved()); |
192 DCHECK(!proxy->is_resolved()); | 193 DCHECK(!proxy->is_resolved()); |
193 unresolved_.Add(proxy, zone_); | 194 proxy->set_next_unresolved(unresolved_); |
| 195 unresolved_ = proxy; |
194 } | 196 } |
195 | 197 |
196 // Remove a unresolved variable. During parsing, an unresolved variable | 198 // Remove a unresolved variable. During parsing, an unresolved variable |
197 // may have been added optimistically, but then only the variable name | 199 // may have been added optimistically, but then only the variable name |
198 // was used (typically for labels). If the variable was not declared, the | 200 // was used (typically for labels). If the variable was not declared, the |
199 // addition introduced a new unresolved variable which may end up being | 201 // addition introduced a new unresolved variable which may end up being |
200 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 202 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
201 // such a variable again if it was added; otherwise this is a no-op. | 203 // such a variable again if it was added; otherwise this is a no-op. |
202 bool RemoveUnresolved(VariableProxy* var); | 204 bool RemoveUnresolved(VariableProxy* var); |
203 | 205 |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 // an inner scope) with no intervening with statements or eval calls. | 624 // an inner scope) with no intervening with statements or eval calls. |
623 VariableMap variables_; | 625 VariableMap variables_; |
624 // Compiler-allocated (user-invisible) temporaries. Due to the implementation | 626 // Compiler-allocated (user-invisible) temporaries. Due to the implementation |
625 // of RemoveTemporary(), may contain nulls, which must be skipped-over during | 627 // of RemoveTemporary(), may contain nulls, which must be skipped-over during |
626 // allocation and printing. | 628 // allocation and printing. |
627 ZoneList<Variable*> temps_; | 629 ZoneList<Variable*> temps_; |
628 // Parameter list in source order. | 630 // Parameter list in source order. |
629 ZoneList<Variable*> params_; | 631 ZoneList<Variable*> params_; |
630 // Variables that must be looked up dynamically. | 632 // Variables that must be looked up dynamically. |
631 DynamicScopePart* dynamics_; | 633 DynamicScopePart* dynamics_; |
632 // Unresolved variables referred to from this scope. | 634 // Unresolved variables referred to from this scope. The proxies themselves |
633 ZoneList<VariableProxy*> unresolved_; | 635 // form a linked list of all unresolved proxies. |
| 636 VariableProxy* unresolved_; |
634 // Declarations. | 637 // Declarations. |
635 ZoneList<Declaration*> decls_; | 638 ZoneList<Declaration*> decls_; |
636 // Convenience variable. | 639 // Convenience variable. |
637 Variable* receiver_; | 640 Variable* receiver_; |
638 // Function variable, if any; function scopes only. | 641 // Function variable, if any; function scopes only. |
639 VariableDeclaration* function_; | 642 VariableDeclaration* function_; |
640 // new.target variable, function scopes only. | 643 // new.target variable, function scopes only. |
641 Variable* new_target_; | 644 Variable* new_target_; |
642 // Convenience variable; function scopes only. | 645 // Convenience variable; function scopes only. |
643 Variable* arguments_; | 646 Variable* arguments_; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 AstValueFactory* ast_value_factory_; | 831 AstValueFactory* ast_value_factory_; |
829 Zone* zone_; | 832 Zone* zone_; |
830 | 833 |
831 PendingCompilationErrorHandler pending_error_handler_; | 834 PendingCompilationErrorHandler pending_error_handler_; |
832 }; | 835 }; |
833 | 836 |
834 } // namespace internal | 837 } // namespace internal |
835 } // namespace v8 | 838 } // namespace v8 |
836 | 839 |
837 #endif // V8_AST_SCOPES_H_ | 840 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |