| 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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 return module_descriptor_; | 682 return module_descriptor_; |
| 683 } | 683 } |
| 684 | 684 |
| 685 void DeclareThis(AstValueFactory* ast_value_factory); | 685 void DeclareThis(AstValueFactory* ast_value_factory); |
| 686 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); | 686 void DeclareDefaultFunctionVariables(AstValueFactory* ast_value_factory); |
| 687 | 687 |
| 688 // This lookup corresponds to a lookup in the "intermediate" scope sitting | 688 // This lookup corresponds to a lookup in the "intermediate" scope sitting |
| 689 // between this scope and the outer scope. (ECMA-262, 3rd., requires that | 689 // between this scope and the outer scope. (ECMA-262, 3rd., requires that |
| 690 // the name of named function literal is kept in an intermediate scope | 690 // the name of named function literal is kept in an intermediate scope |
| 691 // in between this scope and the next outer scope.) | 691 // in between this scope and the next outer scope.) |
| 692 Variable* LookupFunctionVar(const AstRawString* name, | 692 Variable* LookupFunctionVar(const AstRawString* name); |
| 693 AstNodeFactory* factory); | |
| 694 | 693 |
| 695 // Declare the function variable for a function literal. This variable | 694 // Declare the function variable for a function literal. This variable |
| 696 // is in an intermediate scope between this function scope and the the | 695 // is in an intermediate scope between this function scope and the the |
| 697 // outer scope. Only possible for function scopes; at most one variable. | 696 // outer scope. Only possible for function scopes; at most one variable. |
| 698 void DeclareFunctionVar(VariableDeclaration* declaration) { | 697 Variable* DeclareFunctionVar(const AstRawString* name); |
| 699 DCHECK(is_function_scope()); | |
| 700 // Handle implicit declaration of the function name in named function | |
| 701 // expressions before other declarations. | |
| 702 declarations()->InsertAt(0, declaration, zone()); | |
| 703 function_ = declaration; | |
| 704 } | |
| 705 | 698 |
| 706 // Declare a parameter in this scope. When there are duplicated | 699 // Declare a parameter in this scope. When there are duplicated |
| 707 // parameters the rightmost one 'wins'. However, the implementation | 700 // parameters the rightmost one 'wins'. However, the implementation |
| 708 // expects all parameters to be declared and from left to right. | 701 // expects all parameters to be declared and from left to right. |
| 709 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, | 702 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, |
| 710 bool is_optional, bool is_rest, bool* is_duplicate, | 703 bool is_optional, bool is_rest, bool* is_duplicate, |
| 711 AstValueFactory* ast_value_factory); | 704 AstValueFactory* ast_value_factory); |
| 712 | 705 |
| 713 // Declare an implicit global variable in this scope which must be a | 706 // Declare an implicit global variable in this scope which must be a |
| 714 // script scope. The variable was introduced (possibly from an inner | 707 // script scope. The variable was introduced (possibly from an inner |
| (...skipping 13 matching lines...) Expand all Loading... |
| 728 // will not have a "this" declaration. | 721 // will not have a "this" declaration. |
| 729 bool has_this_declaration() const { | 722 bool has_this_declaration() const { |
| 730 return (is_function_scope() && !is_arrow_scope()) || is_module_scope(); | 723 return (is_function_scope() && !is_arrow_scope()) || is_module_scope(); |
| 731 } | 724 } |
| 732 | 725 |
| 733 // The variable corresponding to the 'new.target' value. | 726 // The variable corresponding to the 'new.target' value. |
| 734 Variable* new_target_var() { return new_target_; } | 727 Variable* new_target_var() { return new_target_; } |
| 735 | 728 |
| 736 // The variable holding the function literal for named function | 729 // The variable holding the function literal for named function |
| 737 // literals, or NULL. Only valid for function scopes. | 730 // literals, or NULL. Only valid for function scopes. |
| 738 VariableDeclaration* function() const { | 731 Variable* function_var() const { |
| 739 DCHECK(is_function_scope()); | 732 DCHECK(is_function_scope()); |
| 740 return function_; | 733 return function_; |
| 741 } | 734 } |
| 742 | 735 |
| 743 // Parameters. The left-most parameter has index 0. | 736 // Parameters. The left-most parameter has index 0. |
| 744 // Only valid for function scopes. | 737 // Only valid for function scopes. |
| 745 Variable* parameter(int index) const { | 738 Variable* parameter(int index) const { |
| 746 DCHECK(is_function_scope()); | 739 DCHECK(is_function_scope()); |
| 747 return params_[index]; | 740 return params_[index]; |
| 748 } | 741 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 // of RemoveTemporary(), may contain nulls, which must be skipped-over during | 875 // of RemoveTemporary(), may contain nulls, which must be skipped-over during |
| 883 // allocation and printing. | 876 // allocation and printing. |
| 884 ZoneList<Variable*> temps_; | 877 ZoneList<Variable*> temps_; |
| 885 // Parameter list in source order. | 878 // Parameter list in source order. |
| 886 ZoneList<Variable*> params_; | 879 ZoneList<Variable*> params_; |
| 887 // Map of function names to lists of functions defined in sloppy blocks | 880 // Map of function names to lists of functions defined in sloppy blocks |
| 888 SloppyBlockFunctionMap sloppy_block_function_map_; | 881 SloppyBlockFunctionMap sloppy_block_function_map_; |
| 889 // Convenience variable. | 882 // Convenience variable. |
| 890 Variable* receiver_; | 883 Variable* receiver_; |
| 891 // Function variable, if any; function scopes only. | 884 // Function variable, if any; function scopes only. |
| 892 VariableDeclaration* function_; | 885 Variable* function_; |
| 893 // new.target variable, function scopes only. | 886 // new.target variable, function scopes only. |
| 894 Variable* new_target_; | 887 Variable* new_target_; |
| 895 // Convenience variable; function scopes only. | 888 // Convenience variable; function scopes only. |
| 896 Variable* arguments_; | 889 Variable* arguments_; |
| 897 // Convenience variable; Subclass constructor only | 890 // Convenience variable; Subclass constructor only |
| 898 Variable* this_function_; | 891 Variable* this_function_; |
| 899 // Module descriptor; module scopes only. | 892 // Module descriptor; module scopes only. |
| 900 ModuleDescriptor* module_descriptor_; | 893 ModuleDescriptor* module_descriptor_; |
| 901 }; | 894 }; |
| 902 | 895 |
| 903 } // namespace internal | 896 } // namespace internal |
| 904 } // namespace v8 | 897 } // namespace v8 |
| 905 | 898 |
| 906 #endif // V8_AST_SCOPES_H_ | 899 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |