| 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 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 // function foo(a, b, c = 1) { ... } | 765 // function foo(a, b, c = 1) { ... } |
| 766 // | 766 // |
| 767 // we return 3 here. | 767 // we return 3 here. |
| 768 int num_parameters() const { | 768 int num_parameters() const { |
| 769 return has_rest_parameter() ? params_.length() - 1 : params_.length(); | 769 return has_rest_parameter() ? params_.length() - 1 : params_.length(); |
| 770 } | 770 } |
| 771 | 771 |
| 772 // A function can have at most one rest parameter. Returns Variable* or NULL. | 772 // A function can have at most one rest parameter. Returns Variable* or NULL. |
| 773 Variable* rest_parameter(int* index) const { | 773 Variable* rest_parameter(int* index) const { |
| 774 *index = rest_index_; | 774 *index = rest_index_; |
| 775 if (rest_index_ < 0) return NULL; | 775 if (rest_index_ < 0) return nullptr; |
| 776 return rest_parameter_; | 776 return params_[rest_index_]; |
| 777 } | 777 } |
| 778 | 778 |
| 779 bool has_rest_parameter() const { return rest_index_ >= 0; } | 779 bool has_rest_parameter() const { return rest_index_ >= 0; } |
| 780 | 780 |
| 781 bool has_simple_parameters() const { return has_simple_parameters_; } | 781 bool has_simple_parameters() const { return has_simple_parameters_; } |
| 782 | 782 |
| 783 // TODO(caitp): manage this state in a better way. PreParser must be able to | 783 // TODO(caitp): manage this state in a better way. PreParser must be able to |
| 784 // communicate that the scope is non-simple, without allocating any parameters | 784 // communicate that the scope is non-simple, without allocating any parameters |
| 785 // as the Parser does. This is necessary to ensure that TC39's proposed early | 785 // as the Parser does. This is necessary to ensure that TC39's proposed early |
| 786 // error can be reported consistently regardless of whether lazily parsed or | 786 // error can be reported consistently regardless of whether lazily parsed or |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 bool asm_module_ : 1; | 883 bool asm_module_ : 1; |
| 884 // This scope's outer context is an asm module. | 884 // This scope's outer context is an asm module. |
| 885 bool asm_function_ : 1; | 885 bool asm_function_ : 1; |
| 886 bool force_eager_compilation_ : 1; | 886 bool force_eager_compilation_ : 1; |
| 887 // This scope has a parameter called "arguments". | 887 // This scope has a parameter called "arguments". |
| 888 bool has_arguments_parameter_ : 1; | 888 bool has_arguments_parameter_ : 1; |
| 889 | 889 |
| 890 // Info about the parameter list of a function. | 890 // Info about the parameter list of a function. |
| 891 int arity_; | 891 int arity_; |
| 892 int rest_index_; | 892 int rest_index_; |
| 893 Variable* rest_parameter_; | |
| 894 // Compiler-allocated (user-invisible) temporaries. | 893 // Compiler-allocated (user-invisible) temporaries. |
| 895 ZoneList<Variable*> temps_; | 894 ZoneList<Variable*> temps_; |
| 896 // Parameter list in source order. | 895 // Parameter list in source order. |
| 897 ZoneList<Variable*> params_; | 896 ZoneList<Variable*> params_; |
| 898 // Map of function names to lists of functions defined in sloppy blocks | 897 // Map of function names to lists of functions defined in sloppy blocks |
| 899 SloppyBlockFunctionMap sloppy_block_function_map_; | 898 SloppyBlockFunctionMap sloppy_block_function_map_; |
| 900 // Convenience variable. | 899 // Convenience variable. |
| 901 Variable* receiver_; | 900 Variable* receiver_; |
| 902 // Function variable, if any; function scopes only. | 901 // Function variable, if any; function scopes only. |
| 903 Variable* function_; | 902 Variable* function_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 924 void AllocateModuleVariables(); | 923 void AllocateModuleVariables(); |
| 925 | 924 |
| 926 private: | 925 private: |
| 927 ModuleDescriptor* module_descriptor_; | 926 ModuleDescriptor* module_descriptor_; |
| 928 }; | 927 }; |
| 929 | 928 |
| 930 } // namespace internal | 929 } // namespace internal |
| 931 } // namespace v8 | 930 } // namespace v8 |
| 932 | 931 |
| 933 #endif // V8_AST_SCOPES_H_ | 932 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |