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_SCOPES_H_ | 5 #ifndef V8_SCOPES_H_ |
6 #define V8_SCOPES_H_ | 6 #define V8_SCOPES_H_ |
7 | 7 |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
10 #include "src/zone.h" | 10 #include "src/zone.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // outer scope. Only possible for function scopes; at most one variable. | 119 // outer scope. Only possible for function scopes; at most one variable. |
120 void DeclareFunctionVar(VariableDeclaration* declaration) { | 120 void DeclareFunctionVar(VariableDeclaration* declaration) { |
121 DCHECK(is_function_scope()); | 121 DCHECK(is_function_scope()); |
122 function_ = declaration; | 122 function_ = declaration; |
123 } | 123 } |
124 | 124 |
125 // Declare a parameter in this scope. When there are duplicated | 125 // Declare a parameter in this scope. When there are duplicated |
126 // parameters the rightmost one 'wins'. However, the implementation | 126 // parameters the rightmost one 'wins'. However, the implementation |
127 // expects all parameters to be declared and from left to right. | 127 // expects all parameters to be declared and from left to right. |
128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, | 128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, |
129 bool is_rest, bool* is_duplicate); | 129 bool is_rest, bool* is_duplicate, int pos); |
130 | 130 |
131 // Declare a local variable in this scope. If the variable has been | 131 // Declare a local variable in this scope. If the variable has been |
132 // declared before, the previously declared variable is returned. | 132 // declared before, the previously declared variable is returned. |
133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
134 InitializationFlag init_flag, Variable::Kind kind, | 134 InitializationFlag init_flag, Variable::Kind kind, |
135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, | 135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
136 int declaration_group_start = -1); | 136 int declaration_group_start = -1); |
137 | 137 |
138 // Declare an implicit global variable in this scope which must be a | 138 // Declare an implicit global variable in this scope which must be a |
139 // script scope. The variable was introduced (possibly from an inner | 139 // script scope. The variable was introduced (possibly from an inner |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // for printing and cannot be used to find the variable. In particular, | 175 // for printing and cannot be used to find the variable. In particular, |
176 // the only way to get hold of the temporary is by keeping the Variable* | 176 // the only way to get hold of the temporary is by keeping the Variable* |
177 // around. The name should not clash with a legitimate variable names. | 177 // around. The name should not clash with a legitimate variable names. |
178 Variable* NewTemporary(const AstRawString* name); | 178 Variable* NewTemporary(const AstRawString* name); |
179 | 179 |
180 // Adds the specific declaration node to the list of declarations in | 180 // Adds the specific declaration node to the list of declarations in |
181 // this scope. The declarations are processed as part of entering | 181 // this scope. The declarations are processed as part of entering |
182 // the scope; see codegen.cc:ProcessDeclarations. | 182 // the scope; see codegen.cc:ProcessDeclarations. |
183 void AddDeclaration(Declaration* declaration); | 183 void AddDeclaration(Declaration* declaration); |
184 | 184 |
| 185 // Formal parameters may be re-declared as lexical declarations in order to |
| 186 // support TDZ semantics specified in ECMAScript 6. |
| 187 void UndeclareParametersForExpressions(); |
| 188 |
185 // --------------------------------------------------------------------------- | 189 // --------------------------------------------------------------------------- |
186 // Illegal redeclaration support. | 190 // Illegal redeclaration support. |
187 | 191 |
188 // Set an expression node that will be executed when the scope is | 192 // Set an expression node that will be executed when the scope is |
189 // entered. We only keep track of one illegal redeclaration node per | 193 // entered. We only keep track of one illegal redeclaration node per |
190 // scope - the first one - so if you try to set it multiple times | 194 // scope - the first one - so if you try to set it multiple times |
191 // the additional requests will be silently ignored. | 195 // the additional requests will be silently ignored. |
192 void SetIllegalRedeclaration(Expression* expression); | 196 void SetIllegalRedeclaration(Expression* expression); |
193 | 197 |
194 // Visit the illegal redeclaration expression. Do not call if the | 198 // Visit the illegal redeclaration expression. Do not call if the |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 return function_; | 370 return function_; |
367 } | 371 } |
368 | 372 |
369 // Parameters. The left-most parameter has index 0. | 373 // Parameters. The left-most parameter has index 0. |
370 // Only valid for function scopes. | 374 // Only valid for function scopes. |
371 Variable* parameter(int index) const { | 375 Variable* parameter(int index) const { |
372 DCHECK(is_function_scope()); | 376 DCHECK(is_function_scope()); |
373 return params_[index]; | 377 return params_[index]; |
374 } | 378 } |
375 | 379 |
| 380 // TODO(caitp): This probably won't work when BindingPatterns are supported |
| 381 // in function parameters. Need a better way. |
| 382 int parameter_position(int index) const { |
| 383 DCHECK(is_function_scope()); |
| 384 return param_positions_[index]; |
| 385 } |
| 386 |
376 // Returns the default function arity --- does not include rest parameters. | 387 // Returns the default function arity --- does not include rest parameters. |
377 int default_function_length() const { | 388 int default_function_length() const { |
378 int count = params_.length(); | 389 int count = params_.length(); |
379 if (rest_index_ >= 0) { | 390 if (rest_index_ >= 0) { |
380 DCHECK(count > 0); | 391 DCHECK(count > 0); |
381 DCHECK(is_function_scope()); | 392 DCHECK(is_function_scope()); |
382 --count; | 393 --count; |
383 } | 394 } |
384 return count; | 395 return count; |
385 } | 396 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 // All user-declared variables (incl. parameters). For script scopes | 567 // All user-declared variables (incl. parameters). For script scopes |
557 // variables may be implicitly 'declared' by being used (possibly in | 568 // variables may be implicitly 'declared' by being used (possibly in |
558 // an inner scope) with no intervening with statements or eval calls. | 569 // an inner scope) with no intervening with statements or eval calls. |
559 VariableMap variables_; | 570 VariableMap variables_; |
560 // Compiler-allocated (user-invisible) internals. | 571 // Compiler-allocated (user-invisible) internals. |
561 ZoneList<Variable*> internals_; | 572 ZoneList<Variable*> internals_; |
562 // Compiler-allocated (user-invisible) temporaries. | 573 // Compiler-allocated (user-invisible) temporaries. |
563 ZoneList<Variable*> temps_; | 574 ZoneList<Variable*> temps_; |
564 // Parameter list in source order. | 575 // Parameter list in source order. |
565 ZoneList<Variable*> params_; | 576 ZoneList<Variable*> params_; |
| 577 ZoneList<int> param_positions_; |
566 // Variables that must be looked up dynamically. | 578 // Variables that must be looked up dynamically. |
567 DynamicScopePart* dynamics_; | 579 DynamicScopePart* dynamics_; |
568 // Unresolved variables referred to from this scope. | 580 // Unresolved variables referred to from this scope. |
569 ZoneList<VariableProxy*> unresolved_; | 581 ZoneList<VariableProxy*> unresolved_; |
570 // Declarations. | 582 // Declarations. |
571 ZoneList<Declaration*> decls_; | 583 ZoneList<Declaration*> decls_; |
572 // Convenience variable. | 584 // Convenience variable. |
573 Variable* receiver_; | 585 Variable* receiver_; |
574 // Function variable, if any; function scopes only. | 586 // Function variable, if any; function scopes only. |
575 VariableDeclaration* function_; | 587 VariableDeclaration* function_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // The number of modules (including nested ones). | 642 // The number of modules (including nested ones). |
631 int num_modules_; | 643 int num_modules_; |
632 | 644 |
633 // For module scopes, the host scope's internal variable binding this module. | 645 // For module scopes, the host scope's internal variable binding this module. |
634 Variable* module_var_; | 646 Variable* module_var_; |
635 | 647 |
636 // Rest parameter | 648 // Rest parameter |
637 Variable* rest_parameter_; | 649 Variable* rest_parameter_; |
638 int rest_index_; | 650 int rest_index_; |
639 | 651 |
| 652 bool has_parameter_expressions_; |
| 653 |
640 // Serialized scope info support. | 654 // Serialized scope info support. |
641 Handle<ScopeInfo> scope_info_; | 655 Handle<ScopeInfo> scope_info_; |
642 bool already_resolved() { return already_resolved_; } | 656 bool already_resolved() { return already_resolved_; } |
643 | 657 |
644 // Create a non-local variable with a given name. | 658 // Create a non-local variable with a given name. |
645 // These variables are looked up dynamically at runtime. | 659 // These variables are looked up dynamically at runtime. |
646 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 660 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
647 | 661 |
648 // Variable resolution. | 662 // Variable resolution. |
649 // Possible results of a recursive variable lookup telling if and how a | 663 // Possible results of a recursive variable lookup telling if and how a |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 PendingCompilationErrorHandler pending_error_handler_; | 779 PendingCompilationErrorHandler pending_error_handler_; |
766 | 780 |
767 // For tracking which classes are declared consecutively. Needed for strong | 781 // For tracking which classes are declared consecutively. Needed for strong |
768 // mode. | 782 // mode. |
769 int class_declaration_group_start_; | 783 int class_declaration_group_start_; |
770 }; | 784 }; |
771 | 785 |
772 } } // namespace v8::internal | 786 } } // namespace v8::internal |
773 | 787 |
774 #endif // V8_SCOPES_H_ | 788 #endif // V8_SCOPES_H_ |
OLD | NEW |