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/base/hashmap.h" | 8 #include "src/base/hashmap.h" |
9 #include "src/globals.h" | 9 #include "src/globals.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 return function_; | 699 return function_; |
700 } | 700 } |
701 | 701 |
702 // Parameters. The left-most parameter has index 0. | 702 // Parameters. The left-most parameter has index 0. |
703 // Only valid for function and module scopes. | 703 // Only valid for function and module scopes. |
704 Variable* parameter(int index) const { | 704 Variable* parameter(int index) const { |
705 DCHECK(is_function_scope() || is_module_scope()); | 705 DCHECK(is_function_scope() || is_module_scope()); |
706 return params_[index]; | 706 return params_[index]; |
707 } | 707 } |
708 | 708 |
709 // Returns the default function arity excluding default or rest parameters. | |
710 // This will be used to set the length of the function, by default. | |
711 // Class field initializers use this property to indicate the number of | |
712 // fields being initialized. | |
713 int arity() const { return arity_; } | |
714 | |
715 // Normal code should not need to call this. Class field initializers use this | |
716 // property to indicate the number of fields being initialized. | |
717 void set_arity(int arity) { arity_ = arity; } | |
718 | |
719 // Returns the number of formal parameters, excluding a possible rest | 709 // Returns the number of formal parameters, excluding a possible rest |
720 // parameter. Examples: | 710 // parameter. Examples: |
721 // function foo(a, b) {} ==> 2 | 711 // function foo(a, b) {} ==> 2 |
722 // function foo(a, b, ...c) {} ==> 2 | 712 // function foo(a, b, ...c) {} ==> 2 |
723 // function foo(a, b, c = 1) {} ==> 3 | 713 // function foo(a, b, c = 1) {} ==> 3 |
724 int num_parameters() const { | 714 int num_parameters() const { |
725 return has_rest_ ? params_.length() - 1 : params_.length(); | 715 return has_rest_ ? params_.length() - 1 : params_.length(); |
726 } | 716 } |
727 | 717 |
728 // The function's rest parameter (nullptr if there is none). | 718 // The function's rest parameter (nullptr if there is none). |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 // This scope's outer context is an asm module. | 831 // This scope's outer context is an asm module. |
842 bool asm_function_ : 1; | 832 bool asm_function_ : 1; |
843 bool force_eager_compilation_ : 1; | 833 bool force_eager_compilation_ : 1; |
844 // This function scope has a rest parameter. | 834 // This function scope has a rest parameter. |
845 bool has_rest_ : 1; | 835 bool has_rest_ : 1; |
846 // This scope has a parameter called "arguments". | 836 // This scope has a parameter called "arguments". |
847 bool has_arguments_parameter_ : 1; | 837 bool has_arguments_parameter_ : 1; |
848 // This scope uses "super" property ('super.foo'). | 838 // This scope uses "super" property ('super.foo'). |
849 bool scope_uses_super_property_ : 1; | 839 bool scope_uses_super_property_ : 1; |
850 | 840 |
851 // Info about the parameter list of a function. | |
852 int arity_; | |
853 // Parameter list in source order. | 841 // Parameter list in source order. |
854 ZoneList<Variable*> params_; | 842 ZoneList<Variable*> params_; |
855 // Map of function names to lists of functions defined in sloppy blocks | 843 // Map of function names to lists of functions defined in sloppy blocks |
856 SloppyBlockFunctionMap sloppy_block_function_map_; | 844 SloppyBlockFunctionMap sloppy_block_function_map_; |
857 // Convenience variable. | 845 // Convenience variable. |
858 Variable* receiver_; | 846 Variable* receiver_; |
859 // Function variable, if any; function scopes only. | 847 // Function variable, if any; function scopes only. |
860 Variable* function_; | 848 Variable* function_; |
861 // new.target variable, function scopes only. | 849 // new.target variable, function scopes only. |
862 Variable* new_target_; | 850 Variable* new_target_; |
(...skipping 25 matching lines...) Expand all Loading... |
888 void AllocateModuleVariables(); | 876 void AllocateModuleVariables(); |
889 | 877 |
890 private: | 878 private: |
891 ModuleDescriptor* module_descriptor_; | 879 ModuleDescriptor* module_descriptor_; |
892 }; | 880 }; |
893 | 881 |
894 } // namespace internal | 882 } // namespace internal |
895 } // namespace v8 | 883 } // namespace v8 |
896 | 884 |
897 #endif // V8_AST_SCOPES_H_ | 885 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |