| 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_SCOPES_H_ | 5 #ifndef V8_SCOPES_H_ |
| 6 #define V8_SCOPES_H_ | 6 #define V8_SCOPES_H_ |
| 7 | 7 |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/zone.h" | 9 #include "src/zone.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 class CompilationInfo; | 14 class CompilationInfo; |
| 15 | 15 |
| 16 | 16 |
| 17 // A hash map to support fast variable declaration and lookup. | 17 // A hash map to support fast variable declaration and lookup. |
| 18 class VariableMap: public ZoneHashMap { | 18 class VariableMap: public ZoneHashMap { |
| 19 public: | 19 public: |
| 20 explicit VariableMap(Zone* zone); | 20 explicit VariableMap(Zone* zone); |
| 21 | 21 |
| 22 virtual ~VariableMap(); | 22 virtual ~VariableMap(); |
| 23 | 23 |
| 24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, | 24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, |
| 25 bool is_valid_lhs, Variable::Kind kind, | 25 bool is_valid_lhs, Variable::Kind kind, |
| 26 InitializationFlag initialization_flag, | 26 InitializationFlag initialization_flag, |
| 27 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, | 27 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 28 Interface* interface = Interface::NewValue()); | |
| 29 | 28 |
| 30 Variable* Lookup(const AstRawString* name); | 29 Variable* Lookup(const AstRawString* name); |
| 31 | 30 |
| 32 Zone* zone() const { return zone_; } | 31 Zone* zone() const { return zone_; } |
| 33 | 32 |
| 34 private: | 33 private: |
| 35 Zone* zone_; | 34 Zone* zone_; |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 | 37 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Declare a parameter in this scope. When there are duplicated | 124 // Declare a parameter in this scope. When there are duplicated |
| 126 // parameters the rightmost one 'wins'. However, the implementation | 125 // parameters the rightmost one 'wins'. However, the implementation |
| 127 // expects all parameters to be declared and from left to right. | 126 // expects all parameters to be declared and from left to right. |
| 128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, | 127 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, |
| 129 bool is_rest = false); | 128 bool is_rest = false); |
| 130 | 129 |
| 131 // Declare a local variable in this scope. If the variable has been | 130 // Declare a local variable in this scope. If the variable has been |
| 132 // declared before, the previously declared variable is returned. | 131 // declared before, the previously declared variable is returned. |
| 133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 132 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
| 134 InitializationFlag init_flag, | 133 InitializationFlag init_flag, |
| 135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, | 134 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 136 Interface* interface = Interface::NewValue()); | |
| 137 | 135 |
| 138 // Declare an implicit global variable in this scope which must be a | 136 // Declare an implicit global variable in this scope which must be a |
| 139 // script scope. The variable was introduced (possibly from an inner | 137 // script scope. The variable was introduced (possibly from an inner |
| 140 // scope) by a reference to an unresolved variable with no intervening | 138 // scope) by a reference to an unresolved variable with no intervening |
| 141 // with statements or eval calls. | 139 // with statements or eval calls. |
| 142 Variable* DeclareDynamicGlobal(const AstRawString* name); | 140 Variable* DeclareDynamicGlobal(const AstRawString* name); |
| 143 | 141 |
| 144 // Create a new unresolved variable. | 142 // Create a new unresolved variable. |
| 145 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 143 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 146 const AstRawString* name, | 144 const AstRawString* name, |
| 147 Interface* interface = Interface::NewValue(), | |
| 148 int position = RelocInfo::kNoPosition) { | 145 int position = RelocInfo::kNoPosition) { |
| 149 // Note that we must not share the unresolved variables with | 146 // Note that we must not share the unresolved variables with |
| 150 // the same name because they may be removed selectively via | 147 // the same name because they may be removed selectively via |
| 151 // RemoveUnresolved(). | 148 // RemoveUnresolved(). |
| 152 DCHECK(!already_resolved()); | 149 DCHECK(!already_resolved()); |
| 153 VariableProxy* proxy = | 150 VariableProxy* proxy = factory->NewVariableProxy(name, false, position); |
| 154 factory->NewVariableProxy(name, false, interface, position); | |
| 155 unresolved_.Add(proxy, zone_); | 151 unresolved_.Add(proxy, zone_); |
| 156 return proxy; | 152 return proxy; |
| 157 } | 153 } |
| 158 | 154 |
| 159 // Remove a unresolved variable. During parsing, an unresolved variable | 155 // Remove a unresolved variable. During parsing, an unresolved variable |
| 160 // may have been added optimistically, but then only the variable name | 156 // may have been added optimistically, but then only the variable name |
| 161 // was used (typically for labels). If the variable was not declared, the | 157 // was used (typically for labels). If the variable was not declared, the |
| 162 // addition introduced a new unresolved variable which may end up being | 158 // addition introduced a new unresolved variable which may end up being |
| 163 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 159 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| 164 // such a variable again if it was added; otherwise this is a no-op. | 160 // such a variable again if it was added; otherwise this is a no-op. |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 Scope* outer_scope, | 699 Scope* outer_scope, |
| 704 Handle<ScopeInfo> scope_info); | 700 Handle<ScopeInfo> scope_info); |
| 705 | 701 |
| 706 AstValueFactory* ast_value_factory_; | 702 AstValueFactory* ast_value_factory_; |
| 707 Zone* zone_; | 703 Zone* zone_; |
| 708 }; | 704 }; |
| 709 | 705 |
| 710 } } // namespace v8::internal | 706 } } // namespace v8::internal |
| 711 | 707 |
| 712 #endif // V8_SCOPES_H_ | 708 #endif // V8_SCOPES_H_ |
| OLD | NEW |