| 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" |
| 11 #include "src/parsing/declaration-descriptor.h" |
| 11 #include "src/zone.h" | 12 #include "src/zone.h" |
| 12 | 13 |
| 13 namespace v8 { | 14 namespace v8 { |
| 14 namespace internal { | 15 namespace internal { |
| 15 | 16 |
| 16 class ParseInfo; | 17 class ParseInfo; |
| 18 class PendingCompilationErrorHandler; |
| 17 | 19 |
| 18 // A hash map to support fast variable declaration and lookup. | 20 // A hash map to support fast variable declaration and lookup. |
| 19 class VariableMap: public ZoneHashMap { | 21 class VariableMap: public ZoneHashMap { |
| 20 public: | 22 public: |
| 21 explicit VariableMap(Zone* zone); | 23 explicit VariableMap(Zone* zone); |
| 22 | 24 |
| 23 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 25 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
| 24 VariableMode mode, Variable::Kind kind, | 26 VariableMode mode, Variable::Kind kind, |
| 25 InitializationFlag initialization_flag, | 27 InitializationFlag initialization_flag, |
| 26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, | 28 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // Lookup a variable in this scope or outer scopes. | 136 // Lookup a variable in this scope or outer scopes. |
| 135 // Returns the variable or NULL if not found. | 137 // Returns the variable or NULL if not found. |
| 136 Variable* Lookup(const AstRawString* name); | 138 Variable* Lookup(const AstRawString* name); |
| 137 | 139 |
| 138 // Declare a local variable in this scope. If the variable has been | 140 // Declare a local variable in this scope. If the variable has been |
| 139 // declared before, the previously declared variable is returned. | 141 // declared before, the previously declared variable is returned. |
| 140 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 142 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
| 141 InitializationFlag init_flag, Variable::Kind kind, | 143 InitializationFlag init_flag, Variable::Kind kind, |
| 142 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 144 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 143 | 145 |
| 146 Variable* DeclareVariableOrParameter( |
| 147 Declaration* declaration, DeclarationDescriptor::Kind declaration_kind, |
| 148 VariableMode mode, InitializationFlag init, |
| 149 bool allow_harmony_restrictive_generators, |
| 150 PendingCompilationErrorHandler* error_handler, int* use_counts, bool* ok); |
| 151 |
| 144 // Declarations list. | 152 // Declarations list. |
| 145 ZoneList<Declaration*>* declarations() { return &decls_; } | 153 ZoneList<Declaration*>* declarations() { return &decls_; } |
| 146 | 154 |
| 147 // Create a new unresolved variable. | 155 // Create a new unresolved variable. |
| 148 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 156 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 149 const AstRawString* name, | 157 const AstRawString* name, |
| 150 int start_position = kNoSourcePosition, | 158 int start_position = kNoSourcePosition, |
| 151 int end_position = kNoSourcePosition, | 159 int end_position = kNoSourcePosition, |
| 152 Variable::Kind kind = Variable::NORMAL) { | 160 Variable::Kind kind = Variable::NORMAL) { |
| 153 // Note that we must not share the unresolved variables with | 161 // Note that we must not share the unresolved variables with |
| (...skipping 24 matching lines...) Expand all Loading... |
| 178 bool RemoveUnresolved(VariableProxy* var); | 186 bool RemoveUnresolved(VariableProxy* var); |
| 179 | 187 |
| 180 // Creates a new temporary variable in this scope's TemporaryScope. The | 188 // Creates a new temporary variable in this scope's TemporaryScope. The |
| 181 // name is only used for printing and cannot be used to find the variable. | 189 // name is only used for printing and cannot be used to find the variable. |
| 182 // In particular, the only way to get hold of the temporary is by keeping the | 190 // In particular, the only way to get hold of the temporary is by keeping the |
| 183 // Variable* around. The name should not clash with a legitimate variable | 191 // Variable* around. The name should not clash with a legitimate variable |
| 184 // names. | 192 // names. |
| 185 // TODO(verwaest): Move to DeclarationScope? | 193 // TODO(verwaest): Move to DeclarationScope? |
| 186 Variable* NewTemporary(const AstRawString* name); | 194 Variable* NewTemporary(const AstRawString* name); |
| 187 | 195 |
| 188 // Adds the specific declaration node to the list of declarations in | |
| 189 // this scope. The declarations are processed as part of entering | |
| 190 // the scope; see codegen.cc:ProcessDeclarations. | |
| 191 void AddDeclaration(Declaration* declaration); | |
| 192 | |
| 193 // --------------------------------------------------------------------------- | 196 // --------------------------------------------------------------------------- |
| 194 // Illegal redeclaration support. | 197 // Illegal redeclaration support. |
| 195 | 198 |
| 196 // Check if the scope has conflicting var | 199 // Check if the scope has conflicting var |
| 197 // declarations, i.e. a var declaration that has been hoisted from a nested | 200 // declarations, i.e. a var declaration that has been hoisted from a nested |
| 198 // scope over a let binding of the same name. | 201 // scope over a let binding of the same name. |
| 199 Declaration* CheckConflictingVarDeclarations(); | 202 Declaration* CheckConflictingVarDeclarations(); |
| 200 | 203 |
| 201 // Check if the scope has a conflicting lexical declaration that has a name in | 204 // Check if the scope has a conflicting lexical declaration that has a name in |
| 202 // the given list. This is used to catch patterns like | 205 // the given list. This is used to catch patterns like |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 void AllocateModuleVariables(); | 851 void AllocateModuleVariables(); |
| 849 | 852 |
| 850 private: | 853 private: |
| 851 ModuleDescriptor* module_descriptor_; | 854 ModuleDescriptor* module_descriptor_; |
| 852 }; | 855 }; |
| 853 | 856 |
| 854 } // namespace internal | 857 } // namespace internal |
| 855 } // namespace v8 | 858 } // namespace v8 |
| 856 | 859 |
| 857 #endif // V8_AST_SCOPES_H_ | 860 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |