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() { | |
adamk
2016/08/22 19:12:07
Note that in sloppy mode we make two calls to Reco
| |
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 |
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 |
(...skipping 124 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 // the 'eval' call site this scope is the declaration scope. | 500 // the 'eval' call site this scope is the declaration scope. |
504 bool scope_calls_eval_ : 1; | 501 bool scope_calls_eval_ : 1; |
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's declarations might not be executed in order (e.g., switch). | 504 // This scope's declarations might not be executed in order (e.g., switch). |
508 bool scope_nonlinear_ : 1; | 505 bool scope_nonlinear_ : 1; |
509 bool is_hidden_ : 1; | 506 bool is_hidden_ : 1; |
510 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 507 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
511 bool is_debug_evaluate_scope_ : 1; | 508 bool is_debug_evaluate_scope_ : 1; |
512 | 509 |
513 // Computed via PropagateScopeInfo. | |
514 bool inner_scope_calls_eval_ : 1; | 510 bool inner_scope_calls_eval_ : 1; |
515 bool force_eager_compilation_ : 1; | |
516 bool force_context_allocation_ : 1; | 511 bool force_context_allocation_ : 1; |
517 | 512 |
518 // True if it holds 'var' declarations. | 513 // True if it holds 'var' declarations. |
519 bool is_declaration_scope_ : 1; | 514 bool is_declaration_scope_ : 1; |
520 | 515 |
521 // Create a non-local variable with a given name. | 516 // Create a non-local variable with a given name. |
522 // These variables are looked up dynamically at runtime. | 517 // These variables are looked up dynamically at runtime. |
523 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 518 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
524 | 519 |
525 // Variable resolution. | 520 // Variable resolution. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 } | 650 } |
656 | 651 |
657 FunctionKind function_kind() const { return function_kind_; } | 652 FunctionKind function_kind() const { return function_kind_; } |
658 | 653 |
659 bool is_arrow_scope() const { | 654 bool is_arrow_scope() const { |
660 return is_function_scope() && IsArrowFunction(function_kind_); | 655 return is_function_scope() && IsArrowFunction(function_kind_); |
661 } | 656 } |
662 | 657 |
663 bool NeedsHomeObject() const { | 658 bool NeedsHomeObject() const { |
664 return scope_uses_super_property_ || | 659 return scope_uses_super_property_ || |
665 ((scope_calls_eval_ || inner_scope_calls_eval_) && | 660 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || |
666 (IsConciseMethod(function_kind()) || | 661 IsAccessorFunction(function_kind()) || |
667 IsAccessorFunction(function_kind()) || | 662 IsClassConstructor(function_kind()))); |
668 IsClassConstructor(function_kind()))); | |
669 } | 663 } |
670 | 664 |
671 bool asm_module() const { return asm_module_; } | 665 bool asm_module() const { return asm_module_; } |
672 void set_asm_module() { asm_module_ = true; } | 666 void set_asm_module() { asm_module_ = true; } |
673 bool asm_function() const { return asm_function_; } | 667 bool asm_function() const { return asm_function_; } |
674 void set_asm_function() { asm_module_ = true; } | 668 void set_asm_function() { asm_module_ = true; } |
675 | 669 |
676 void DeclareThis(AstValueFactory* ast_value_factory); | 670 void DeclareThis(AstValueFactory* ast_value_factory); |
677 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); | 671 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); |
678 | 672 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 // discard the Scope for lazily compiled functions. In particular, this | 819 // discard the Scope for lazily compiled functions. In particular, this |
826 // records variables which cannot be resolved inside the Scope (we don't yet | 820 // records variables which cannot be resolved inside the Scope (we don't yet |
827 // know what they will resolve to since the outer Scopes are incomplete) and | 821 // know what they will resolve to since the outer Scopes are incomplete) and |
828 // migrates them into migrate_to. | 822 // migrates them into migrate_to. |
829 void AnalyzePartially(DeclarationScope* migrate_to, | 823 void AnalyzePartially(DeclarationScope* migrate_to, |
830 AstNodeFactory* ast_node_factory); | 824 AstNodeFactory* ast_node_factory); |
831 | 825 |
832 Handle<StringSet> CollectNonLocals(ParseInfo* info, | 826 Handle<StringSet> CollectNonLocals(ParseInfo* info, |
833 Handle<StringSet> non_locals); | 827 Handle<StringSet> non_locals); |
834 | 828 |
829 // Determine if we can use lazy compilation for this scope. | |
830 bool AllowsLazyCompilation() const; | |
831 | |
832 // Determine if we can use lazy compilation for this scope without a context. | |
833 bool AllowsLazyCompilationWithoutContext() const; | |
834 | |
835 // Make sure this closure and all outer closures are eagerly compiled. | |
836 void ForceEagerCompilation() { | |
837 DCHECK_EQ(this, GetClosureScope()); | |
838 for (DeclarationScope* s = this; !s->is_script_scope(); | |
839 s = s->outer_scope()->GetClosureScope()) { | |
840 s->force_eager_compilation_ = true; | |
841 } | |
842 } | |
843 | |
835 #ifdef DEBUG | 844 #ifdef DEBUG |
836 void PrintParameters(); | 845 void PrintParameters(); |
837 #endif | 846 #endif |
838 | 847 |
839 void AllocateLocals(); | 848 void AllocateLocals(); |
840 void AllocateParameterLocals(); | 849 void AllocateParameterLocals(); |
841 void AllocateReceiver(); | 850 void AllocateReceiver(); |
842 | 851 |
843 private: | 852 private: |
844 void AllocateParameter(Variable* var, int index); | 853 void AllocateParameter(Variable* var, int index); |
845 | 854 |
846 void SetDefaults(); | 855 void SetDefaults(); |
847 | 856 |
848 // If the scope is a function scope, this is the function kind. | 857 // If the scope is a function scope, this is the function kind. |
849 const FunctionKind function_kind_; | 858 const FunctionKind function_kind_; |
850 | 859 |
851 bool has_simple_parameters_ : 1; | 860 bool has_simple_parameters_ : 1; |
852 // This scope contains an "use asm" annotation. | 861 // This scope contains an "use asm" annotation. |
853 bool asm_module_ : 1; | 862 bool asm_module_ : 1; |
854 // This scope's outer context is an asm module. | 863 // This scope's outer context is an asm module. |
855 bool asm_function_ : 1; | 864 bool asm_function_ : 1; |
865 bool force_eager_compilation_ : 1; | |
856 // This scope has a parameter called "arguments". | 866 // This scope has a parameter called "arguments". |
857 bool has_arguments_parameter_ : 1; | 867 bool has_arguments_parameter_ : 1; |
858 | 868 |
859 // Info about the parameter list of a function. | 869 // Info about the parameter list of a function. |
860 int arity_; | 870 int arity_; |
861 int rest_index_; | 871 int rest_index_; |
862 Variable* rest_parameter_; | 872 Variable* rest_parameter_; |
863 // Compiler-allocated (user-invisible) temporaries. | 873 // Compiler-allocated (user-invisible) temporaries. |
864 ZoneList<Variable*> temps_; | 874 ZoneList<Variable*> temps_; |
865 // Parameter list in source order. | 875 // Parameter list in source order. |
(...skipping 27 matching lines...) Expand all Loading... | |
893 void AllocateModuleVariables(); | 903 void AllocateModuleVariables(); |
894 | 904 |
895 private: | 905 private: |
896 ModuleDescriptor* module_descriptor_; | 906 ModuleDescriptor* module_descriptor_; |
897 }; | 907 }; |
898 | 908 |
899 } // namespace internal | 909 } // namespace internal |
900 } // namespace v8 | 910 } // namespace v8 |
901 | 911 |
902 #endif // V8_AST_SCOPES_H_ | 912 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |