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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 // Inform the scope that the corresponding code uses "super". | 228 // Inform the scope that the corresponding code uses "super". |
229 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } | 229 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } |
230 | 230 |
231 // Set the language mode flag (unless disabled by a global flag). | 231 // Set the language mode flag (unless disabled by a global flag). |
232 void SetLanguageMode(LanguageMode language_mode) { | 232 void SetLanguageMode(LanguageMode language_mode) { |
233 DCHECK(!is_module_scope() || is_strict(language_mode)); | 233 DCHECK(!is_module_scope() || is_strict(language_mode)); |
234 language_mode_ = language_mode; | 234 language_mode_ = language_mode; |
235 } | 235 } |
236 | 236 |
237 // Set the ASM module flag. | |
238 void SetAsmModule() { asm_module_ = true; } | |
239 | |
240 // Inform the scope that the scope may execute declarations nonlinearly. | 237 // Inform the scope that the scope may execute declarations nonlinearly. |
241 // Currently, the only nonlinear scope is a switch statement. The name is | 238 // Currently, the only nonlinear scope is a switch statement. The name is |
242 // more general in case something else comes up with similar control flow, | 239 // more general in case something else comes up with similar control flow, |
243 // for example the ability to break out of something which does not have | 240 // for example the ability to break out of something which does not have |
244 // its own lexical scope. | 241 // its own lexical scope. |
245 // The bit does not need to be stored on the ScopeInfo because none of | 242 // The bit does not need to be stored on the ScopeInfo because none of |
246 // the three compilers will perform hole check elimination on a variable | 243 // the three compilers will perform hole check elimination on a variable |
247 // located in VariableLocation::CONTEXT. So, direct eval and closures | 244 // located in VariableLocation::CONTEXT. So, direct eval and closures |
248 // will not expose holes. | 245 // will not expose holes. |
249 void SetNonlinear() { scope_nonlinear_ = true; } | 246 void SetNonlinear() { scope_nonlinear_ = true; } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 bool is_declaration_scope() const { return is_declaration_scope_; } | 307 bool is_declaration_scope() const { return is_declaration_scope_; } |
311 | 308 |
312 // Information about which scopes calls eval. | 309 // Information about which scopes calls eval. |
313 bool calls_eval() const { return scope_calls_eval_; } | 310 bool calls_eval() const { return scope_calls_eval_; } |
314 bool calls_sloppy_eval() const { | 311 bool calls_sloppy_eval() const { |
315 return scope_calls_eval_ && is_sloppy(language_mode_); | 312 return scope_calls_eval_ && is_sloppy(language_mode_); |
316 } | 313 } |
317 bool outer_scope_calls_sloppy_eval() const { | 314 bool outer_scope_calls_sloppy_eval() const { |
318 return outer_scope_calls_sloppy_eval_; | 315 return outer_scope_calls_sloppy_eval_; |
319 } | 316 } |
320 bool asm_module() const { return asm_module_; } | 317 bool IsAsmModule() const; |
321 bool asm_function() const { return asm_function_; } | 318 bool IsAsmFunction() const; |
322 | |
323 // Does this scope access "super" property (super.foo). | 319 // Does this scope access "super" property (super.foo). |
324 bool uses_super_property() const { return scope_uses_super_property_; } | 320 bool uses_super_property() const { return scope_uses_super_property_; } |
325 // Does this scope have the potential to execute declarations non-linearly? | 321 // Does this scope have the potential to execute declarations non-linearly? |
326 bool is_nonlinear() const { return scope_nonlinear_; } | 322 bool is_nonlinear() const { return scope_nonlinear_; } |
327 | 323 |
328 // Whether this needs to be represented by a runtime context. | 324 // Whether this needs to be represented by a runtime context. |
329 bool NeedsContext() const { | 325 bool NeedsContext() const { |
330 // Catch scopes always have heap slots. | 326 // Catch scopes always have heap slots. |
331 DCHECK(!is_catch_scope() || num_heap_slots() > 0); | 327 DCHECK(!is_catch_scope() || num_heap_slots() > 0); |
332 return num_heap_slots() > 0; | 328 return num_heap_slots() > 0; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 LanguageMode language_mode_ : 2; | 492 LanguageMode language_mode_ : 2; |
497 // This scope is inside a 'with' of some outer scope. | 493 // This scope is inside a 'with' of some outer scope. |
498 bool scope_inside_with_ : 1; | 494 bool scope_inside_with_ : 1; |
499 // This scope or a nested catch scope or with scope contain an 'eval' call. At | 495 // This scope or a nested catch scope or with scope contain an 'eval' call. At |
500 // the 'eval' call site this scope is the declaration scope. | 496 // the 'eval' call site this scope is the declaration scope. |
501 bool scope_calls_eval_ : 1; | 497 bool scope_calls_eval_ : 1; |
502 // This scope uses "super" property ('super.foo'). | 498 // This scope uses "super" property ('super.foo'). |
503 bool scope_uses_super_property_ : 1; | 499 bool scope_uses_super_property_ : 1; |
504 // This scope has a parameter called "arguments". | 500 // This scope has a parameter called "arguments". |
505 bool has_arguments_parameter_ : 1; | 501 bool has_arguments_parameter_ : 1; |
506 // This scope contains an "use asm" annotation. | |
507 bool asm_module_ : 1; | |
508 // This scope's outer context is an asm module. | |
509 bool asm_function_ : 1; | |
510 // This scope's declarations might not be executed in order (e.g., switch). | 502 // This scope's declarations might not be executed in order (e.g., switch). |
511 bool scope_nonlinear_ : 1; | 503 bool scope_nonlinear_ : 1; |
512 bool is_hidden_ : 1; | 504 bool is_hidden_ : 1; |
513 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 505 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
514 bool is_debug_evaluate_scope_ : 1; | 506 bool is_debug_evaluate_scope_ : 1; |
515 | 507 |
516 // Computed via PropagateScopeInfo. | 508 // Computed via PropagateScopeInfo. |
517 bool outer_scope_calls_sloppy_eval_ : 1; | 509 bool outer_scope_calls_sloppy_eval_ : 1; |
518 bool inner_scope_calls_eval_ : 1; | 510 bool inner_scope_calls_eval_ : 1; |
519 bool force_eager_compilation_ : 1; | 511 bool force_eager_compilation_ : 1; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 } | 666 } |
675 | 667 |
676 // The ModuleDescriptor for this scope; only for module scopes. | 668 // The ModuleDescriptor for this scope; only for module scopes. |
677 // TODO(verwaest): Move to ModuleScope? | 669 // TODO(verwaest): Move to ModuleScope? |
678 ModuleDescriptor* module() const { | 670 ModuleDescriptor* module() const { |
679 DCHECK(is_module_scope()); | 671 DCHECK(is_module_scope()); |
680 DCHECK_NOT_NULL(module_descriptor_); | 672 DCHECK_NOT_NULL(module_descriptor_); |
681 return module_descriptor_; | 673 return module_descriptor_; |
682 } | 674 } |
683 | 675 |
| 676 bool asm_module() const { return asm_module_; } |
| 677 void set_asm_module() { asm_module_ = true; } |
| 678 bool asm_function() const { return asm_function_; } |
| 679 void set_asm_function() { asm_module_ = true; } |
| 680 |
684 void DeclareThis(AstValueFactory* ast_value_factory); | 681 void DeclareThis(AstValueFactory* ast_value_factory); |
685 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); | 682 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); |
686 | 683 |
687 // This lookup corresponds to a lookup in the "intermediate" scope sitting | 684 // This lookup corresponds to a lookup in the "intermediate" scope sitting |
688 // between this scope and the outer scope. (ECMA-262, 3rd., requires that | 685 // between this scope and the outer scope. (ECMA-262, 3rd., requires that |
689 // the name of named function literal is kept in an intermediate scope | 686 // the name of named function literal is kept in an intermediate scope |
690 // in between this scope and the next outer scope.) | 687 // in between this scope and the next outer scope.) |
691 Variable* LookupFunctionVar(const AstRawString* name); | 688 Variable* LookupFunctionVar(const AstRawString* name); |
692 | 689 |
693 // Declare the function variable for a function literal. This variable | 690 // Declare the function variable for a function literal. This variable |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 | 850 |
854 private: | 851 private: |
855 void AllocateParameter(Variable* var, int index); | 852 void AllocateParameter(Variable* var, int index); |
856 | 853 |
857 void SetDefaults(); | 854 void SetDefaults(); |
858 | 855 |
859 // If the scope is a function scope, this is the function kind. | 856 // If the scope is a function scope, this is the function kind. |
860 const FunctionKind function_kind_; | 857 const FunctionKind function_kind_; |
861 | 858 |
862 bool has_simple_parameters_ : 1; | 859 bool has_simple_parameters_ : 1; |
| 860 // This scope contains an "use asm" annotation. |
| 861 bool asm_module_ : 1; |
| 862 // This scope's outer context is an asm module. |
| 863 bool asm_function_ : 1; |
863 | 864 |
864 // Info about the parameter list of a function. | 865 // Info about the parameter list of a function. |
865 int arity_; | 866 int arity_; |
866 int rest_index_; | 867 int rest_index_; |
867 Variable* rest_parameter_; | 868 Variable* rest_parameter_; |
868 // Compiler-allocated (user-invisible) temporaries. | 869 // Compiler-allocated (user-invisible) temporaries. |
869 ZoneList<Variable*> temps_; | 870 ZoneList<Variable*> temps_; |
870 // Parameter list in source order. | 871 // Parameter list in source order. |
871 ZoneList<Variable*> params_; | 872 ZoneList<Variable*> params_; |
872 // Map of function names to lists of functions defined in sloppy blocks | 873 // Map of function names to lists of functions defined in sloppy blocks |
873 SloppyBlockFunctionMap sloppy_block_function_map_; | 874 SloppyBlockFunctionMap sloppy_block_function_map_; |
874 // Convenience variable. | 875 // Convenience variable. |
875 Variable* receiver_; | 876 Variable* receiver_; |
876 // Function variable, if any; function scopes only. | 877 // Function variable, if any; function scopes only. |
877 Variable* function_; | 878 Variable* function_; |
878 // new.target variable, function scopes only. | 879 // new.target variable, function scopes only. |
879 Variable* new_target_; | 880 Variable* new_target_; |
880 // Convenience variable; function scopes only. | 881 // Convenience variable; function scopes only. |
881 Variable* arguments_; | 882 Variable* arguments_; |
882 // Convenience variable; Subclass constructor only | 883 // Convenience variable; Subclass constructor only |
883 Variable* this_function_; | 884 Variable* this_function_; |
884 // Module descriptor; module scopes only. | 885 // Module descriptor; module scopes only. |
885 ModuleDescriptor* module_descriptor_; | 886 ModuleDescriptor* module_descriptor_; |
886 }; | 887 }; |
887 | 888 |
888 } // namespace internal | 889 } // namespace internal |
889 } // namespace v8 | 890 } // namespace v8 |
890 | 891 |
891 #endif // V8_AST_SCOPES_H_ | 892 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |