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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 return function_; | 366 return function_; |
367 } | 367 } |
368 | 368 |
369 // Parameters. The left-most parameter has index 0. | 369 // Parameters. The left-most parameter has index 0. |
370 // Only valid for function scopes. | 370 // Only valid for function scopes. |
371 Variable* parameter(int index) const { | 371 Variable* parameter(int index) const { |
372 DCHECK(is_function_scope()); | 372 DCHECK(is_function_scope()); |
373 return params_[index]; | 373 return params_[index]; |
374 } | 374 } |
375 | 375 |
| 376 // TODO(caitp): This probably won't work when BindingPatterns are supported |
| 377 // in function parameters. Need a better way. |
| 378 int parameter_position(int index) const { |
| 379 DCHECK(is_function_scope()); |
| 380 return param_positions_[index]; |
| 381 } |
| 382 |
376 // Returns the default function arity --- does not include rest parameters. | 383 // Returns the default function arity --- does not include rest parameters. |
377 int default_function_length() const { | 384 int default_function_length() const { |
378 int count = params_.length(); | 385 int count = params_.length(); |
379 if (rest_index_ >= 0) { | 386 if (rest_index_ >= 0) { |
380 DCHECK(count > 0); | 387 DCHECK(count > 0); |
381 DCHECK(is_function_scope()); | 388 DCHECK(is_function_scope()); |
382 --count; | 389 --count; |
383 } | 390 } |
384 return count; | 391 return count; |
385 } | 392 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 // All user-declared variables (incl. parameters). For script scopes | 553 // All user-declared variables (incl. parameters). For script scopes |
547 // variables may be implicitly 'declared' by being used (possibly in | 554 // variables may be implicitly 'declared' by being used (possibly in |
548 // an inner scope) with no intervening with statements or eval calls. | 555 // an inner scope) with no intervening with statements or eval calls. |
549 VariableMap variables_; | 556 VariableMap variables_; |
550 // Compiler-allocated (user-invisible) internals. | 557 // Compiler-allocated (user-invisible) internals. |
551 ZoneList<Variable*> internals_; | 558 ZoneList<Variable*> internals_; |
552 // Compiler-allocated (user-invisible) temporaries. | 559 // Compiler-allocated (user-invisible) temporaries. |
553 ZoneList<Variable*> temps_; | 560 ZoneList<Variable*> temps_; |
554 // Parameter list in source order. | 561 // Parameter list in source order. |
555 ZoneList<Variable*> params_; | 562 ZoneList<Variable*> params_; |
| 563 ZoneList<int> param_positions_; |
556 // Variables that must be looked up dynamically. | 564 // Variables that must be looked up dynamically. |
557 DynamicScopePart* dynamics_; | 565 DynamicScopePart* dynamics_; |
558 // Unresolved variables referred to from this scope. | 566 // Unresolved variables referred to from this scope. |
559 ZoneList<VariableProxy*> unresolved_; | 567 ZoneList<VariableProxy*> unresolved_; |
560 // Declarations. | 568 // Declarations. |
561 ZoneList<Declaration*> decls_; | 569 ZoneList<Declaration*> decls_; |
562 // Convenience variable. | 570 // Convenience variable. |
563 Variable* receiver_; | 571 Variable* receiver_; |
564 // Function variable, if any; function scopes only. | 572 // Function variable, if any; function scopes only. |
565 VariableDeclaration* function_; | 573 VariableDeclaration* function_; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 PendingCompilationErrorHandler pending_error_handler_; | 761 PendingCompilationErrorHandler pending_error_handler_; |
754 | 762 |
755 // For tracking which classes are declared consecutively. Needed for strong | 763 // For tracking which classes are declared consecutively. Needed for strong |
756 // mode. | 764 // mode. |
757 int class_declaration_group_start_; | 765 int class_declaration_group_start_; |
758 }; | 766 }; |
759 | 767 |
760 } } // namespace v8::internal | 768 } } // namespace v8::internal |
761 | 769 |
762 #endif // V8_SCOPES_H_ | 770 #endif // V8_SCOPES_H_ |
OLD | NEW |