| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 // Inform the scope and outer scopes that the corresponding code contains an | 225 // Inform the scope and outer scopes that the corresponding code contains an |
| 226 // eval call. | 226 // eval call. |
| 227 void RecordEvalCall() { | 227 void RecordEvalCall() { |
| 228 scope_calls_eval_ = true; | 228 scope_calls_eval_ = true; |
| 229 for (Scope* scope = this; scope != nullptr; scope = scope->outer_scope()) { | 229 for (Scope* scope = this; scope != nullptr; scope = scope->outer_scope()) { |
| 230 scope->inner_scope_calls_eval_ = true; | 230 scope->inner_scope_calls_eval_ = true; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 // Inform the scope that the corresponding code uses "super". | |
| 235 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } | |
| 236 | |
| 237 // Set the language mode flag (unless disabled by a global flag). | 234 // Set the language mode flag (unless disabled by a global flag). |
| 238 void SetLanguageMode(LanguageMode language_mode) { | 235 void SetLanguageMode(LanguageMode language_mode) { |
| 239 DCHECK(!is_module_scope() || is_strict(language_mode)); | 236 DCHECK(!is_module_scope() || is_strict(language_mode)); |
| 240 set_language_mode(language_mode); | 237 set_language_mode(language_mode); |
| 241 } | 238 } |
| 242 | 239 |
| 243 // Inform the scope that the scope may execute declarations nonlinearly. | 240 // Inform the scope that the scope may execute declarations nonlinearly. |
| 244 // Currently, the only nonlinear scope is a switch statement. The name is | 241 // Currently, the only nonlinear scope is a switch statement. The name is |
| 245 // more general in case something else comes up with similar control flow, | 242 // more general in case something else comes up with similar control flow, |
| 246 // for example the ability to break out of something which does not have | 243 // for example the ability to break out of something which does not have |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } | 309 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } |
| 313 bool is_declaration_scope() const { return is_declaration_scope_; } | 310 bool is_declaration_scope() const { return is_declaration_scope_; } |
| 314 | 311 |
| 315 // Information about which scopes calls eval. | 312 // Information about which scopes calls eval. |
| 316 bool calls_eval() const { return scope_calls_eval_; } | 313 bool calls_eval() const { return scope_calls_eval_; } |
| 317 bool calls_sloppy_eval() const { | 314 bool calls_sloppy_eval() const { |
| 318 return scope_calls_eval_ && is_sloppy(language_mode()); | 315 return scope_calls_eval_ && is_sloppy(language_mode()); |
| 319 } | 316 } |
| 320 bool IsAsmModule() const; | 317 bool IsAsmModule() const; |
| 321 bool IsAsmFunction() const; | 318 bool IsAsmFunction() const; |
| 322 // Does this scope access "super" property (super.foo). | |
| 323 bool uses_super_property() const { return scope_uses_super_property_; } | |
| 324 // Does this scope have the potential to execute declarations non-linearly? | 319 // Does this scope have the potential to execute declarations non-linearly? |
| 325 bool is_nonlinear() const { return scope_nonlinear_; } | 320 bool is_nonlinear() const { return scope_nonlinear_; } |
| 326 | 321 |
| 327 // Whether this needs to be represented by a runtime context. | 322 // Whether this needs to be represented by a runtime context. |
| 328 bool NeedsContext() const { | 323 bool NeedsContext() const { |
| 329 // Catch scopes always have heap slots. | 324 // Catch scopes always have heap slots. |
| 330 DCHECK(!is_catch_scope() || num_heap_slots() > 0); | 325 DCHECK(!is_catch_scope() || num_heap_slots() > 0); |
| 331 return num_heap_slots() > 0; | 326 return num_heap_slots() > 0; |
| 332 } | 327 } |
| 333 | 328 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 const ScopeType scope_type_; | 506 const ScopeType scope_type_; |
| 512 | 507 |
| 513 // Scope-specific information computed during parsing. | 508 // Scope-specific information computed during parsing. |
| 514 // | 509 // |
| 515 // The language mode of this scope. | 510 // The language mode of this scope. |
| 516 STATIC_ASSERT(LANGUAGE_END == 2); | 511 STATIC_ASSERT(LANGUAGE_END == 2); |
| 517 bool is_strict_ : 1; | 512 bool is_strict_ : 1; |
| 518 // This scope or a nested catch scope or with scope contain an 'eval' call. At | 513 // This scope or a nested catch scope or with scope contain an 'eval' call. At |
| 519 // the 'eval' call site this scope is the declaration scope. | 514 // the 'eval' call site this scope is the declaration scope. |
| 520 bool scope_calls_eval_ : 1; | 515 bool scope_calls_eval_ : 1; |
| 521 // This scope uses "super" property ('super.foo'). | |
| 522 bool scope_uses_super_property_ : 1; | |
| 523 // This scope's declarations might not be executed in order (e.g., switch). | 516 // This scope's declarations might not be executed in order (e.g., switch). |
| 524 bool scope_nonlinear_ : 1; | 517 bool scope_nonlinear_ : 1; |
| 525 bool is_hidden_ : 1; | 518 bool is_hidden_ : 1; |
| 526 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 519 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
| 527 bool is_debug_evaluate_scope_ : 1; | 520 bool is_debug_evaluate_scope_ : 1; |
| 528 | 521 |
| 529 bool inner_scope_calls_eval_ : 1; | 522 bool inner_scope_calls_eval_ : 1; |
| 530 bool force_context_allocation_ : 1; | 523 bool force_context_allocation_ : 1; |
| 531 | 524 |
| 532 // True if it holds 'var' declarations. | 525 // True if it holds 'var' declarations. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 // the assumptions explained above do not hold. | 662 // the assumptions explained above do not hold. |
| 670 return params_.Contains(variables_.Lookup(name)); | 663 return params_.Contains(variables_.Lookup(name)); |
| 671 } | 664 } |
| 672 | 665 |
| 673 FunctionKind function_kind() const { return function_kind_; } | 666 FunctionKind function_kind() const { return function_kind_; } |
| 674 | 667 |
| 675 bool is_arrow_scope() const { | 668 bool is_arrow_scope() const { |
| 676 return is_function_scope() && IsArrowFunction(function_kind_); | 669 return is_function_scope() && IsArrowFunction(function_kind_); |
| 677 } | 670 } |
| 678 | 671 |
| 672 // Inform the scope that the corresponding code uses "super". |
| 673 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } |
| 674 // Does this scope access "super" property (super.foo). |
| 675 bool uses_super_property() const { return scope_uses_super_property_; } |
| 676 |
| 679 bool NeedsHomeObject() const { | 677 bool NeedsHomeObject() const { |
| 680 return scope_uses_super_property_ || | 678 return scope_uses_super_property_ || |
| 681 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || | 679 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || |
| 682 IsAccessorFunction(function_kind()) || | 680 IsAccessorFunction(function_kind()) || |
| 683 IsClassConstructor(function_kind()))); | 681 IsClassConstructor(function_kind()))); |
| 684 } | 682 } |
| 685 | 683 |
| 686 bool asm_module() const { return asm_module_; } | 684 bool asm_module() const { return asm_module_; } |
| 687 void set_asm_module() { asm_module_ = true; } | 685 void set_asm_module() { asm_module_ = true; } |
| 688 bool asm_function() const { return asm_function_; } | 686 bool asm_function() const { return asm_function_; } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 const FunctionKind function_kind_; | 877 const FunctionKind function_kind_; |
| 880 | 878 |
| 881 bool has_simple_parameters_ : 1; | 879 bool has_simple_parameters_ : 1; |
| 882 // This scope contains an "use asm" annotation. | 880 // This scope contains an "use asm" annotation. |
| 883 bool asm_module_ : 1; | 881 bool asm_module_ : 1; |
| 884 // This scope's outer context is an asm module. | 882 // This scope's outer context is an asm module. |
| 885 bool asm_function_ : 1; | 883 bool asm_function_ : 1; |
| 886 bool force_eager_compilation_ : 1; | 884 bool force_eager_compilation_ : 1; |
| 887 // This scope has a parameter called "arguments". | 885 // This scope has a parameter called "arguments". |
| 888 bool has_arguments_parameter_ : 1; | 886 bool has_arguments_parameter_ : 1; |
| 887 // This scope uses "super" property ('super.foo'). |
| 888 bool scope_uses_super_property_ : 1; |
| 889 | 889 |
| 890 // Info about the parameter list of a function. | 890 // Info about the parameter list of a function. |
| 891 int arity_; | 891 int arity_; |
| 892 int rest_index_; | 892 int rest_index_; |
| 893 Variable* rest_parameter_; | 893 Variable* rest_parameter_; |
| 894 // Compiler-allocated (user-invisible) temporaries. | 894 // Compiler-allocated (user-invisible) temporaries. |
| 895 ZoneList<Variable*> temps_; | 895 ZoneList<Variable*> temps_; |
| 896 // Parameter list in source order. | 896 // Parameter list in source order. |
| 897 ZoneList<Variable*> params_; | 897 ZoneList<Variable*> params_; |
| 898 // Map of function names to lists of functions defined in sloppy blocks | 898 // Map of function names to lists of functions defined in sloppy blocks |
| (...skipping 25 matching lines...) Expand all Loading... |
| 924 void AllocateModuleVariables(); | 924 void AllocateModuleVariables(); |
| 925 | 925 |
| 926 private: | 926 private: |
| 927 ModuleDescriptor* module_descriptor_; | 927 ModuleDescriptor* module_descriptor_; |
| 928 }; | 928 }; |
| 929 | 929 |
| 930 } // namespace internal | 930 } // namespace internal |
| 931 } // namespace v8 | 931 } // namespace v8 |
| 932 | 932 |
| 933 #endif // V8_AST_SCOPES_H_ | 933 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |