| 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 |
| 140 // scope) by a reference to an unresolved variable with no intervening | 140 // scope) by a reference to an unresolved variable with no intervening |
| 141 // with statements or eval calls. | 141 // with statements or eval calls. |
| 142 Variable* DeclareDynamicGlobal(const AstRawString* name); | 142 Variable* DeclareDynamicGlobal(const AstRawString* name); |
| 143 | 143 |
| 144 void ShadowParametersForExpressions(); |
| 145 |
| 144 // Create a new unresolved variable. | 146 // Create a new unresolved variable. |
| 145 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 147 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 146 const AstRawString* name, | 148 const AstRawString* name, |
| 147 Variable::Kind kind = Variable::NORMAL, | 149 Variable::Kind kind = Variable::NORMAL, |
| 148 int start_position = RelocInfo::kNoPosition, | 150 int start_position = RelocInfo::kNoPosition, |
| 149 int end_position = RelocInfo::kNoPosition) { | 151 int end_position = RelocInfo::kNoPosition) { |
| 150 // Note that we must not share the unresolved variables with | 152 // Note that we must not share the unresolved variables with |
| 151 // the same name because they may be removed selectively via | 153 // the same name because they may be removed selectively via |
| 152 // RemoveUnresolved(). | 154 // RemoveUnresolved(). |
| 153 DCHECK(!already_resolved()); | 155 DCHECK(!already_resolved()); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return function_; | 361 return function_; |
| 360 } | 362 } |
| 361 | 363 |
| 362 // Parameters. The left-most parameter has index 0. | 364 // Parameters. The left-most parameter has index 0. |
| 363 // Only valid for function scopes. | 365 // Only valid for function scopes. |
| 364 Variable* parameter(int index) const { | 366 Variable* parameter(int index) const { |
| 365 DCHECK(is_function_scope()); | 367 DCHECK(is_function_scope()); |
| 366 return params_[index]; | 368 return params_[index]; |
| 367 } | 369 } |
| 368 | 370 |
| 371 int parameter_position(int index) const { |
| 372 DCHECK(is_function_scope()); |
| 373 return param_positions_[index]; |
| 374 } |
| 375 |
| 369 // Returns the default function arity --- does not include rest parameters. | 376 // Returns the default function arity --- does not include rest parameters. |
| 370 int default_function_length() const { | 377 int default_function_length() const { |
| 371 int count = params_.length(); | 378 int count = params_.length(); |
| 372 if (rest_index_ >= 0) { | 379 if (rest_index_ >= 0) { |
| 373 DCHECK(count > 0); | 380 DCHECK(count > 0); |
| 374 DCHECK(is_function_scope()); | 381 DCHECK(is_function_scope()); |
| 375 --count; | 382 --count; |
| 376 } | 383 } |
| 377 return count; | 384 return count; |
| 378 } | 385 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 // All user-declared variables (incl. parameters). For script scopes | 545 // All user-declared variables (incl. parameters). For script scopes |
| 539 // variables may be implicitly 'declared' by being used (possibly in | 546 // variables may be implicitly 'declared' by being used (possibly in |
| 540 // an inner scope) with no intervening with statements or eval calls. | 547 // an inner scope) with no intervening with statements or eval calls. |
| 541 VariableMap variables_; | 548 VariableMap variables_; |
| 542 // Compiler-allocated (user-invisible) internals. | 549 // Compiler-allocated (user-invisible) internals. |
| 543 ZoneList<Variable*> internals_; | 550 ZoneList<Variable*> internals_; |
| 544 // Compiler-allocated (user-invisible) temporaries. | 551 // Compiler-allocated (user-invisible) temporaries. |
| 545 ZoneList<Variable*> temps_; | 552 ZoneList<Variable*> temps_; |
| 546 // Parameter list in source order. | 553 // Parameter list in source order. |
| 547 ZoneList<Variable*> params_; | 554 ZoneList<Variable*> params_; |
| 555 ZoneList<int> param_positions_; |
| 548 // Variables that must be looked up dynamically. | 556 // Variables that must be looked up dynamically. |
| 549 DynamicScopePart* dynamics_; | 557 DynamicScopePart* dynamics_; |
| 550 // Unresolved variables referred to from this scope. | 558 // Unresolved variables referred to from this scope. |
| 551 ZoneList<VariableProxy*> unresolved_; | 559 ZoneList<VariableProxy*> unresolved_; |
| 552 // Declarations. | 560 // Declarations. |
| 553 ZoneList<Declaration*> decls_; | 561 ZoneList<Declaration*> decls_; |
| 554 // Convenience variable. | 562 // Convenience variable. |
| 555 Variable* receiver_; | 563 Variable* receiver_; |
| 556 // Function variable, if any; function scopes only. | 564 // Function variable, if any; function scopes only. |
| 557 VariableDeclaration* function_; | 565 VariableDeclaration* function_; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 PendingCompilationErrorHandler pending_error_handler_; | 750 PendingCompilationErrorHandler pending_error_handler_; |
| 743 | 751 |
| 744 // For tracking which classes are declared consecutively. Needed for strong | 752 // For tracking which classes are declared consecutively. Needed for strong |
| 745 // mode. | 753 // mode. |
| 746 int class_declaration_group_start_; | 754 int class_declaration_group_start_; |
| 747 }; | 755 }; |
| 748 | 756 |
| 749 } } // namespace v8::internal | 757 } } // namespace v8::internal |
| 750 | 758 |
| 751 #endif // V8_SCOPES_H_ | 759 #endif // V8_SCOPES_H_ |
| OLD | NEW |