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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 // | 723 // |
724 // function foo(a, b, c = 1) { ... } | 724 // function foo(a, b, c = 1) { ... } |
725 // | 725 // |
726 // we return 3 here. | 726 // we return 3 here. |
727 int num_parameters() const { | 727 int num_parameters() const { |
728 return has_rest_parameter() ? params_.length() - 1 : params_.length(); | 728 return has_rest_parameter() ? params_.length() - 1 : params_.length(); |
729 } | 729 } |
730 | 730 |
731 // A function can have at most one rest parameter. Returns Variable* or NULL. | 731 // A function can have at most one rest parameter. Returns Variable* or NULL. |
732 Variable* rest_parameter(int* index) const { | 732 Variable* rest_parameter(int* index) const { |
733 *index = rest_index_; | 733 if (!has_rest_parameter()) return nullptr; |
734 if (rest_index_ < 0) return nullptr; | 734 *index = params_.length() - 1; |
735 return params_[rest_index_]; | 735 return rest_parameter(); |
| 736 } |
| 737 Variable* rest_parameter() const { |
| 738 DCHECK(has_rest_parameter()); |
| 739 return params_[params_.length() - 1]; |
736 } | 740 } |
737 | 741 |
738 bool has_rest_parameter() const { return rest_index_ >= 0; } | 742 bool has_rest_parameter() const { return has_rest_; } |
739 | 743 |
740 bool has_simple_parameters() const { return has_simple_parameters_; } | 744 bool has_simple_parameters() const { return has_simple_parameters_; } |
741 | 745 |
742 // TODO(caitp): manage this state in a better way. PreParser must be able to | 746 // TODO(caitp): manage this state in a better way. PreParser must be able to |
743 // communicate that the scope is non-simple, without allocating any parameters | 747 // communicate that the scope is non-simple, without allocating any parameters |
744 // as the Parser does. This is necessary to ensure that TC39's proposed early | 748 // as the Parser does. This is necessary to ensure that TC39's proposed early |
745 // error can be reported consistently regardless of whether lazily parsed or | 749 // error can be reported consistently regardless of whether lazily parsed or |
746 // not. | 750 // not. |
747 void SetHasNonSimpleParameters() { | 751 void SetHasNonSimpleParameters() { |
748 DCHECK(is_function_scope()); | 752 DCHECK(is_function_scope()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 | 840 |
837 // If the scope is a function scope, this is the function kind. | 841 // If the scope is a function scope, this is the function kind. |
838 const FunctionKind function_kind_; | 842 const FunctionKind function_kind_; |
839 | 843 |
840 bool has_simple_parameters_ : 1; | 844 bool has_simple_parameters_ : 1; |
841 // This scope contains an "use asm" annotation. | 845 // This scope contains an "use asm" annotation. |
842 bool asm_module_ : 1; | 846 bool asm_module_ : 1; |
843 // This scope's outer context is an asm module. | 847 // This scope's outer context is an asm module. |
844 bool asm_function_ : 1; | 848 bool asm_function_ : 1; |
845 bool force_eager_compilation_ : 1; | 849 bool force_eager_compilation_ : 1; |
| 850 // This function scope has a rest parameter. |
| 851 bool has_rest_ : 1; |
846 // This scope has a parameter called "arguments". | 852 // This scope has a parameter called "arguments". |
847 bool has_arguments_parameter_ : 1; | 853 bool has_arguments_parameter_ : 1; |
848 // This scope uses "super" property ('super.foo'). | 854 // This scope uses "super" property ('super.foo'). |
849 bool scope_uses_super_property_ : 1; | 855 bool scope_uses_super_property_ : 1; |
850 | 856 |
851 // Info about the parameter list of a function. | 857 // Info about the parameter list of a function. |
852 int arity_; | 858 int arity_; |
853 int rest_index_; | |
854 // Compiler-allocated (user-invisible) temporaries. | 859 // Compiler-allocated (user-invisible) temporaries. |
855 ZoneList<Variable*> temps_; | 860 ZoneList<Variable*> temps_; |
856 // Parameter list in source order. | 861 // Parameter list in source order. |
857 ZoneList<Variable*> params_; | 862 ZoneList<Variable*> params_; |
858 // Map of function names to lists of functions defined in sloppy blocks | 863 // Map of function names to lists of functions defined in sloppy blocks |
859 SloppyBlockFunctionMap sloppy_block_function_map_; | 864 SloppyBlockFunctionMap sloppy_block_function_map_; |
860 // Convenience variable. | 865 // Convenience variable. |
861 Variable* receiver_; | 866 Variable* receiver_; |
862 // Function variable, if any; function scopes only. | 867 // Function variable, if any; function scopes only. |
863 Variable* function_; | 868 Variable* function_; |
(...skipping 20 matching lines...) Expand all Loading... |
884 void AllocateModuleVariables(); | 889 void AllocateModuleVariables(); |
885 | 890 |
886 private: | 891 private: |
887 ModuleDescriptor* module_descriptor_; | 892 ModuleDescriptor* module_descriptor_; |
888 }; | 893 }; |
889 | 894 |
890 } // namespace internal | 895 } // namespace internal |
891 } // namespace v8 | 896 } // namespace v8 |
892 | 897 |
893 #endif // V8_AST_SCOPES_H_ | 898 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |