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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 // the given list. This is used to catch patterns like | 214 // the given list. This is used to catch patterns like |
215 // `try{}catch(e){let e;}`, | 215 // `try{}catch(e){let e;}`, |
216 // which is an error even though the two 'e's are declared in different | 216 // which is an error even though the two 'e's are declared in different |
217 // scopes. | 217 // scopes. |
218 Declaration* CheckLexDeclarationsConflictingWith( | 218 Declaration* CheckLexDeclarationsConflictingWith( |
219 const ZoneList<const AstRawString*>& names); | 219 const ZoneList<const AstRawString*>& names); |
220 | 220 |
221 // --------------------------------------------------------------------------- | 221 // --------------------------------------------------------------------------- |
222 // Scope-specific info. | 222 // Scope-specific info. |
223 | 223 |
224 // Inform the scope that the corresponding code contains an eval call. | 224 // Inform the scope and outer scopes that the corresponding code contains an |
225 void RecordEvalCall() { scope_calls_eval_ = true; } | 225 // eval call. |
226 void RecordEvalCall() { | |
227 scope_calls_eval_ = true; | |
228 for (Scope* scope = this; scope != nullptr; scope = scope->outer_scope()) { | |
229 scope->inner_scope_calls_eval_ = true; | |
230 } | |
231 } | |
226 | 232 |
neis
2016/08/22 13:21:47
Do I understand correctly that you are setting inn
Toon Verwaest
2016/08/22 14:13:28
Yes. All uses of inner_scope_calls_eval_ always di
| |
227 // Inform the scope that the corresponding code uses "super". | 233 // Inform the scope that the corresponding code uses "super". |
228 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } | 234 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } |
229 | 235 |
230 // Set the language mode flag (unless disabled by a global flag). | 236 // Set the language mode flag (unless disabled by a global flag). |
231 void SetLanguageMode(LanguageMode language_mode) { | 237 void SetLanguageMode(LanguageMode language_mode) { |
232 DCHECK(!is_module_scope() || is_strict(language_mode)); | 238 DCHECK(!is_module_scope() || is_strict(language_mode)); |
233 set_language_mode(language_mode); | 239 set_language_mode(language_mode); |
234 } | 240 } |
235 | 241 |
236 // Inform the scope that the scope may execute declarations nonlinearly. | 242 // Inform the scope that the scope may execute declarations nonlinearly. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 | 366 |
361 // Result of variable allocation. | 367 // Result of variable allocation. |
362 int num_stack_slots() const { return num_stack_slots_; } | 368 int num_stack_slots() const { return num_stack_slots_; } |
363 int num_heap_slots() const { return num_heap_slots_; } | 369 int num_heap_slots() const { return num_heap_slots_; } |
364 int num_global_slots() const { return num_global_slots_; } | 370 int num_global_slots() const { return num_global_slots_; } |
365 | 371 |
366 int StackLocalCount() const; | 372 int StackLocalCount() const; |
367 int ContextLocalCount() const; | 373 int ContextLocalCount() const; |
368 int ContextGlobalCount() const; | 374 int ContextGlobalCount() const; |
369 | 375 |
370 // Make sure this scope and all outer scopes are eagerly compiled. | |
371 void ForceEagerCompilation() { force_eager_compilation_ = true; } | |
372 | |
373 // Determine if we can parse a function literal in this scope lazily. | 376 // Determine if we can parse a function literal in this scope lazily. |
374 bool AllowsLazyParsing() const; | 377 bool AllowsLazyParsing() const; |
375 | 378 |
376 // Determine if we can use lazy compilation for this scope. | |
377 bool AllowsLazyCompilation() const; | |
378 | |
379 // Determine if we can use lazy compilation for this scope without a context. | |
380 bool AllowsLazyCompilationWithoutContext() const; | |
381 | |
382 // The number of contexts between this and scope; zero if this == scope. | 379 // The number of contexts between this and scope; zero if this == scope. |
383 int ContextChainLength(Scope* scope) const; | 380 int ContextChainLength(Scope* scope) const; |
384 | 381 |
385 // The number of contexts between this and the outermost context that has a | 382 // The number of contexts between this and the outermost context that has a |
386 // sloppy eval call. One if this->calls_sloppy_eval(). | 383 // sloppy eval call. One if this->calls_sloppy_eval(). |
387 int ContextChainLengthUntilOutermostSloppyEval() const; | 384 int ContextChainLengthUntilOutermostSloppyEval() const; |
388 | 385 |
389 // The maximum number of nested contexts required for this scope and any inner | 386 // The maximum number of nested contexts required for this scope and any inner |
390 // scopes. | 387 // scopes. |
391 int MaxNestedContextChainLength(); | 388 int MaxNestedContextChainLength(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 // This scope uses "super" property ('super.foo'). | 502 // This scope uses "super" property ('super.foo'). |
506 bool scope_uses_super_property_ : 1; | 503 bool scope_uses_super_property_ : 1; |
507 // This scope has a parameter called "arguments". | 504 // This scope has a parameter called "arguments". |
508 bool has_arguments_parameter_ : 1; | 505 bool has_arguments_parameter_ : 1; |
509 // This scope's declarations might not be executed in order (e.g., switch). | 506 // This scope's declarations might not be executed in order (e.g., switch). |
510 bool scope_nonlinear_ : 1; | 507 bool scope_nonlinear_ : 1; |
511 bool is_hidden_ : 1; | 508 bool is_hidden_ : 1; |
512 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 509 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
513 bool is_debug_evaluate_scope_ : 1; | 510 bool is_debug_evaluate_scope_ : 1; |
514 | 511 |
515 // Computed via PropagateScopeInfo. | |
516 bool inner_scope_calls_eval_ : 1; | 512 bool inner_scope_calls_eval_ : 1; |
517 bool force_eager_compilation_ : 1; | |
518 bool force_context_allocation_ : 1; | 513 bool force_context_allocation_ : 1; |
519 | 514 |
520 // True if it holds 'var' declarations. | 515 // True if it holds 'var' declarations. |
521 bool is_declaration_scope_ : 1; | 516 bool is_declaration_scope_ : 1; |
522 | 517 |
523 // Create a non-local variable with a given name. | 518 // Create a non-local variable with a given name. |
524 // These variables are looked up dynamically at runtime. | 519 // These variables are looked up dynamically at runtime. |
525 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 520 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
526 | 521 |
527 // Variable resolution. | 522 // Variable resolution. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 } | 652 } |
658 | 653 |
659 FunctionKind function_kind() const { return function_kind_; } | 654 FunctionKind function_kind() const { return function_kind_; } |
660 | 655 |
661 bool is_arrow_scope() const { | 656 bool is_arrow_scope() const { |
662 return is_function_scope() && IsArrowFunction(function_kind_); | 657 return is_function_scope() && IsArrowFunction(function_kind_); |
663 } | 658 } |
664 | 659 |
665 bool NeedsHomeObject() const { | 660 bool NeedsHomeObject() const { |
666 return scope_uses_super_property_ || | 661 return scope_uses_super_property_ || |
667 ((scope_calls_eval_ || inner_scope_calls_eval_) && | 662 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || |
668 (IsConciseMethod(function_kind()) || | 663 IsAccessorFunction(function_kind()) || |
669 IsAccessorFunction(function_kind()) || | 664 IsClassConstructor(function_kind()))); |
670 IsClassConstructor(function_kind()))); | |
671 } | 665 } |
672 | 666 |
673 bool asm_module() const { return asm_module_; } | 667 bool asm_module() const { return asm_module_; } |
674 void set_asm_module() { asm_module_ = true; } | 668 void set_asm_module() { asm_module_ = true; } |
675 bool asm_function() const { return asm_function_; } | 669 bool asm_function() const { return asm_function_; } |
676 void set_asm_function() { asm_module_ = true; } | 670 void set_asm_function() { asm_module_ = true; } |
677 | 671 |
678 void DeclareThis(AstValueFactory* ast_value_factory); | 672 void DeclareThis(AstValueFactory* ast_value_factory); |
679 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); | 673 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); |
680 | 674 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 // discard the Scope for lazily compiled functions. In particular, this | 821 // discard the Scope for lazily compiled functions. In particular, this |
828 // records variables which cannot be resolved inside the Scope (we don't yet | 822 // records variables which cannot be resolved inside the Scope (we don't yet |
829 // know what they will resolve to since the outer Scopes are incomplete) and | 823 // know what they will resolve to since the outer Scopes are incomplete) and |
830 // migrates them into migrate_to. | 824 // migrates them into migrate_to. |
831 void AnalyzePartially(DeclarationScope* migrate_to, | 825 void AnalyzePartially(DeclarationScope* migrate_to, |
832 AstNodeFactory* ast_node_factory); | 826 AstNodeFactory* ast_node_factory); |
833 | 827 |
834 Handle<StringSet> CollectNonLocals(ParseInfo* info, | 828 Handle<StringSet> CollectNonLocals(ParseInfo* info, |
835 Handle<StringSet> non_locals); | 829 Handle<StringSet> non_locals); |
836 | 830 |
831 // Determine if we can use lazy compilation for this scope. | |
832 bool AllowsLazyCompilation() const; | |
833 | |
834 // Determine if we can use lazy compilation for this scope without a context. | |
835 bool AllowsLazyCompilationWithoutContext() const; | |
836 | |
837 // Make this closure and all outer closures are eagerly compiled. | |
neis
2016/08/22 13:21:47
There's a word missing here.
Toon Verwaest
2016/08/22 14:13:28
Done.
| |
838 void ForceEagerCompilation() { | |
neis
2016/08/22 13:21:47
Can you add something like DCHECK(IsClosureScope)
Toon Verwaest
2016/08/22 14:13:29
Done.
| |
839 for (DeclarationScope* s = this; !s->is_script_scope(); | |
840 s = s->outer_scope()->GetClosureScope()) { | |
841 force_eager_compilation_ = true; | |
neis
2016/08/22 13:21:47
s->force_eager_compilation_
Should this have caus
| |
842 } | |
843 } | |
844 | |
837 #ifdef DEBUG | 845 #ifdef DEBUG |
838 void PrintParameters(); | 846 void PrintParameters(); |
839 #endif | 847 #endif |
840 | 848 |
841 void AllocateLocals(); | 849 void AllocateLocals(); |
842 void AllocateParameterLocals(); | 850 void AllocateParameterLocals(); |
843 void AllocateReceiver(); | 851 void AllocateReceiver(); |
844 | 852 |
845 private: | 853 private: |
846 void AllocateParameter(Variable* var, int index); | 854 void AllocateParameter(Variable* var, int index); |
847 | 855 |
848 void SetDefaults(); | 856 void SetDefaults(); |
849 | 857 |
850 // If the scope is a function scope, this is the function kind. | 858 // If the scope is a function scope, this is the function kind. |
851 const FunctionKind function_kind_; | 859 const FunctionKind function_kind_; |
852 | 860 |
853 bool has_simple_parameters_ : 1; | 861 bool has_simple_parameters_ : 1; |
854 // This scope contains an "use asm" annotation. | 862 // This scope contains an "use asm" annotation. |
855 bool asm_module_ : 1; | 863 bool asm_module_ : 1; |
856 // This scope's outer context is an asm module. | 864 // This scope's outer context is an asm module. |
857 bool asm_function_ : 1; | 865 bool asm_function_ : 1; |
866 bool force_eager_compilation_ : 1; | |
858 | 867 |
859 // Info about the parameter list of a function. | 868 // Info about the parameter list of a function. |
860 int arity_; | 869 int arity_; |
861 int rest_index_; | 870 int rest_index_; |
862 Variable* rest_parameter_; | 871 Variable* rest_parameter_; |
863 // Compiler-allocated (user-invisible) temporaries. | 872 // Compiler-allocated (user-invisible) temporaries. |
864 ZoneList<Variable*> temps_; | 873 ZoneList<Variable*> temps_; |
865 // Parameter list in source order. | 874 // Parameter list in source order. |
866 ZoneList<Variable*> params_; | 875 ZoneList<Variable*> params_; |
867 // Map of function names to lists of functions defined in sloppy blocks | 876 // Map of function names to lists of functions defined in sloppy blocks |
(...skipping 25 matching lines...) Expand all Loading... | |
893 void AllocateModuleVariables(); | 902 void AllocateModuleVariables(); |
894 | 903 |
895 private: | 904 private: |
896 ModuleDescriptor* module_descriptor_; | 905 ModuleDescriptor* module_descriptor_; |
897 }; | 906 }; |
898 | 907 |
899 } // namespace internal | 908 } // namespace internal |
900 } // namespace v8 | 909 } // namespace v8 |
901 | 910 |
902 #endif // V8_AST_SCOPES_H_ | 911 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |