| 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/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
| 10 #include "src/zone.h" | 10 #include "src/zone.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 // 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 |
| 137 // script scope. The variable was introduced (possibly from an inner | 137 // script scope. The variable was introduced (possibly from an inner |
| 138 // scope) by a reference to an unresolved variable with no intervening | 138 // scope) by a reference to an unresolved variable with no intervening |
| 139 // with statements or eval calls. | 139 // with statements or eval calls. |
| 140 Variable* DeclareDynamicGlobal(const AstRawString* name); | 140 Variable* DeclareDynamicGlobal(const AstRawString* name); |
| 141 | 141 |
| 142 // Create a new unresolved variable. | 142 // Create a new unresolved variable. |
| 143 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 143 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 144 const AstRawString* name, | 144 const AstRawString* name, |
| 145 Variable::Kind kind = Variable::NORMAL, |
| 145 int start_position = RelocInfo::kNoPosition, | 146 int start_position = RelocInfo::kNoPosition, |
| 146 int end_position = RelocInfo::kNoPosition) { | 147 int end_position = RelocInfo::kNoPosition) { |
| 147 // Note that we must not share the unresolved variables with | 148 // Note that we must not share the unresolved variables with |
| 148 // the same name because they may be removed selectively via | 149 // the same name because they may be removed selectively via |
| 149 // RemoveUnresolved(). | 150 // RemoveUnresolved(). |
| 150 DCHECK(!already_resolved()); | 151 DCHECK(!already_resolved()); |
| 151 VariableProxy* proxy = factory->NewVariableProxy( | 152 VariableProxy* proxy = |
| 152 name, Variable::NORMAL, start_position, end_position); | 153 factory->NewVariableProxy(name, kind, start_position, end_position); |
| 153 unresolved_.Add(proxy, zone_); | 154 unresolved_.Add(proxy, zone_); |
| 154 return proxy; | 155 return proxy; |
| 155 } | 156 } |
| 156 | 157 |
| 157 // Remove a unresolved variable. During parsing, an unresolved variable | 158 // Remove a unresolved variable. During parsing, an unresolved variable |
| 158 // may have been added optimistically, but then only the variable name | 159 // may have been added optimistically, but then only the variable name |
| 159 // was used (typically for labels). If the variable was not declared, the | 160 // was used (typically for labels). If the variable was not declared, the |
| 160 // addition introduced a new unresolved variable which may end up being | 161 // addition introduced a new unresolved variable which may end up being |
| 161 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 162 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| 162 // such a variable again if it was added; otherwise this is a no-op. | 163 // such a variable again if it was added; otherwise this is a no-op. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 212 |
| 212 // Inform the scope that the corresponding code uses "arguments". | 213 // Inform the scope that the corresponding code uses "arguments". |
| 213 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } | 214 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } |
| 214 | 215 |
| 215 // Inform the scope that the corresponding code uses "super". | 216 // Inform the scope that the corresponding code uses "super". |
| 216 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } | 217 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } |
| 217 | 218 |
| 218 // Inform the scope that the corresponding code uses "this". | 219 // Inform the scope that the corresponding code uses "this". |
| 219 void RecordThisUsage() { scope_uses_this_ = true; } | 220 void RecordThisUsage() { scope_uses_this_ = true; } |
| 220 | 221 |
| 222 // Inform the scope that the corresponding code uses "new.target". |
| 223 void RecordNewTargetUsage() { scope_uses_new_target_ = true; } |
| 224 |
| 221 // Set the language mode flag (unless disabled by a global flag). | 225 // Set the language mode flag (unless disabled by a global flag). |
| 222 void SetLanguageMode(LanguageMode language_mode) { | 226 void SetLanguageMode(LanguageMode language_mode) { |
| 223 language_mode_ = language_mode; | 227 language_mode_ = language_mode; |
| 224 } | 228 } |
| 225 | 229 |
| 226 // Set the ASM module flag. | 230 // Set the ASM module flag. |
| 227 void SetAsmModule() { asm_module_ = true; } | 231 void SetAsmModule() { asm_module_ = true; } |
| 228 | 232 |
| 229 // Position in the source where this scope begins and ends. | 233 // Position in the source where this scope begins and ends. |
| 230 // | 234 // |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // Does this scope access "super" property (super.foo). | 322 // Does this scope access "super" property (super.foo). |
| 319 bool uses_super_property() const { return scope_uses_super_property_; } | 323 bool uses_super_property() const { return scope_uses_super_property_; } |
| 320 // Does any inner scope access "super" property. | 324 // Does any inner scope access "super" property. |
| 321 bool inner_uses_super_property() const { | 325 bool inner_uses_super_property() const { |
| 322 return inner_scope_uses_super_property_; | 326 return inner_scope_uses_super_property_; |
| 323 } | 327 } |
| 324 // Does this scope access "this". | 328 // Does this scope access "this". |
| 325 bool uses_this() const { return scope_uses_this_; } | 329 bool uses_this() const { return scope_uses_this_; } |
| 326 // Does any inner scope access "this". | 330 // Does any inner scope access "this". |
| 327 bool inner_uses_this() const { return inner_scope_uses_this_; } | 331 bool inner_uses_this() const { return inner_scope_uses_this_; } |
| 332 // Does this scope access "new.target". |
| 333 bool uses_new_target() const { |
| 334 return scope_uses_new_target_ || inner_scope_uses_new_target_; |
| 335 } |
| 336 // Does any inner scope access "new.target". |
| 337 bool inner_uses_new_target() const { return inner_scope_uses_new_target_; } |
| 338 |
| 328 | 339 |
| 329 const Scope* NearestOuterEvalScope() const { | 340 const Scope* NearestOuterEvalScope() const { |
| 330 if (is_eval_scope()) return this; | 341 if (is_eval_scope()) return this; |
| 331 if (outer_scope() == nullptr) return nullptr; | 342 if (outer_scope() == nullptr) return nullptr; |
| 332 return outer_scope()->NearestOuterEvalScope(); | 343 return outer_scope()->NearestOuterEvalScope(); |
| 333 } | 344 } |
| 334 | 345 |
| 335 // --------------------------------------------------------------------------- | 346 // --------------------------------------------------------------------------- |
| 336 // Accessors. | 347 // Accessors. |
| 337 | 348 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 bool scope_contains_with_; | 572 bool scope_contains_with_; |
| 562 // This scope or a nested catch scope or with scope contain an 'eval' call. At | 573 // This scope or a nested catch scope or with scope contain an 'eval' call. At |
| 563 // the 'eval' call site this scope is the declaration scope. | 574 // the 'eval' call site this scope is the declaration scope. |
| 564 bool scope_calls_eval_; | 575 bool scope_calls_eval_; |
| 565 // This scope uses "arguments". | 576 // This scope uses "arguments". |
| 566 bool scope_uses_arguments_; | 577 bool scope_uses_arguments_; |
| 567 // This scope uses "super" property ('super.foo'). | 578 // This scope uses "super" property ('super.foo'). |
| 568 bool scope_uses_super_property_; | 579 bool scope_uses_super_property_; |
| 569 // This scope uses "this". | 580 // This scope uses "this". |
| 570 bool scope_uses_this_; | 581 bool scope_uses_this_; |
| 582 // This scope uses "new.target". |
| 583 bool scope_uses_new_target_; |
| 571 // This scope contains an "use asm" annotation. | 584 // This scope contains an "use asm" annotation. |
| 572 bool asm_module_; | 585 bool asm_module_; |
| 573 // This scope's outer context is an asm module. | 586 // This scope's outer context is an asm module. |
| 574 bool asm_function_; | 587 bool asm_function_; |
| 575 // The language mode of this scope. | 588 // The language mode of this scope. |
| 576 LanguageMode language_mode_; | 589 LanguageMode language_mode_; |
| 577 // Source positions. | 590 // Source positions. |
| 578 int start_position_; | 591 int start_position_; |
| 579 int end_position_; | 592 int end_position_; |
| 580 | 593 |
| 581 // Computed via PropagateScopeInfo. | 594 // Computed via PropagateScopeInfo. |
| 582 bool outer_scope_calls_sloppy_eval_; | 595 bool outer_scope_calls_sloppy_eval_; |
| 583 bool inner_scope_calls_eval_; | 596 bool inner_scope_calls_eval_; |
| 584 bool inner_scope_uses_arguments_; | 597 bool inner_scope_uses_arguments_; |
| 585 bool inner_scope_uses_super_property_; | 598 bool inner_scope_uses_super_property_; |
| 586 bool inner_scope_uses_this_; | 599 bool inner_scope_uses_this_; |
| 600 bool inner_scope_uses_new_target_; |
| 587 bool force_eager_compilation_; | 601 bool force_eager_compilation_; |
| 588 bool force_context_allocation_; | 602 bool force_context_allocation_; |
| 589 | 603 |
| 590 // True if it doesn't need scope resolution (e.g., if the scope was | 604 // True if it doesn't need scope resolution (e.g., if the scope was |
| 591 // constructed based on a serialized scope info or a catch context). | 605 // constructed based on a serialized scope info or a catch context). |
| 592 bool already_resolved_; | 606 bool already_resolved_; |
| 593 | 607 |
| 594 // Computed as variables are declared. | 608 // Computed as variables are declared. |
| 595 int num_var_or_const_; | 609 int num_var_or_const_; |
| 596 | 610 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 | 744 |
| 731 AstValueFactory* ast_value_factory_; | 745 AstValueFactory* ast_value_factory_; |
| 732 Zone* zone_; | 746 Zone* zone_; |
| 733 | 747 |
| 734 PendingCompilationErrorHandler pending_error_handler_; | 748 PendingCompilationErrorHandler pending_error_handler_; |
| 735 }; | 749 }; |
| 736 | 750 |
| 737 } } // namespace v8::internal | 751 } } // namespace v8::internal |
| 738 | 752 |
| 739 #endif // V8_SCOPES_H_ | 753 #endif // V8_SCOPES_H_ |
| OLD | NEW |