| 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/zone.h" | 9 #include "src/zone.h" |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // is in an intermediate scope between this function scope and the the | 119 // is in an intermediate scope between this function scope and the the |
| 120 // outer scope. Only possible for function scopes; at most one variable. | 120 // outer scope. Only possible for function scopes; at most one variable. |
| 121 void DeclareFunctionVar(VariableDeclaration* declaration) { | 121 void DeclareFunctionVar(VariableDeclaration* declaration) { |
| 122 DCHECK(is_function_scope()); | 122 DCHECK(is_function_scope()); |
| 123 function_ = declaration; | 123 function_ = declaration; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Declare a parameter in this scope. When there are duplicated | 126 // Declare a parameter in this scope. When there are duplicated |
| 127 // parameters the rightmost one 'wins'. However, the implementation | 127 // parameters the rightmost one 'wins'. However, the implementation |
| 128 // expects all parameters to be declared and from left to right. | 128 // expects all parameters to be declared and from left to right. |
| 129 Variable* DeclareParameter(const AstRawString* name, VariableMode mode); | 129 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, |
| 130 bool is_rest = false); |
| 130 | 131 |
| 131 // Declare a local variable in this scope. If the variable has been | 132 // Declare a local variable in this scope. If the variable has been |
| 132 // declared before, the previously declared variable is returned. | 133 // declared before, the previously declared variable is returned. |
| 133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 134 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
| 134 InitializationFlag init_flag, | 135 InitializationFlag init_flag, |
| 135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, | 136 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
| 136 Interface* interface = Interface::NewValue()); | 137 Interface* interface = Interface::NewValue()); |
| 137 | 138 |
| 138 // Declare an implicit global variable in this scope which must be a | 139 // Declare an implicit global variable in this scope which must be a |
| 139 // script scope. The variable was introduced (possibly from an inner | 140 // script scope. The variable was introduced (possibly from an inner |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return function_; | 352 return function_; |
| 352 } | 353 } |
| 353 | 354 |
| 354 // Parameters. The left-most parameter has index 0. | 355 // Parameters. The left-most parameter has index 0. |
| 355 // Only valid for function scopes. | 356 // Only valid for function scopes. |
| 356 Variable* parameter(int index) const { | 357 Variable* parameter(int index) const { |
| 357 DCHECK(is_function_scope()); | 358 DCHECK(is_function_scope()); |
| 358 return params_[index]; | 359 return params_[index]; |
| 359 } | 360 } |
| 360 | 361 |
| 362 // Returns the default function arity --- does not include rest parameters. |
| 363 int default_function_length() const { |
| 364 int count = params_.length(); |
| 365 if (rest_index_ >= 0) { |
| 366 DCHECK(count > 0); |
| 367 DCHECK(is_function_scope()); |
| 368 --count; |
| 369 } |
| 370 return count; |
| 371 } |
| 372 |
| 361 int num_parameters() const { return params_.length(); } | 373 int num_parameters() const { return params_.length(); } |
| 362 | 374 |
| 375 // A function can have at most one rest parameter. Returns Variable* or NULL. |
| 376 Variable* rest_parameter(int* index) const { |
| 377 *index = rest_index_; |
| 378 if (rest_index_ < 0) return NULL; |
| 379 return rest_parameter_; |
| 380 } |
| 381 |
| 382 bool is_simple_parameter_list() const { |
| 383 DCHECK(is_function_scope()); |
| 384 if (rest_index_ >= 0) return false; |
| 385 return true; |
| 386 } |
| 387 |
| 363 // The local variable 'arguments' if we need to allocate it; NULL otherwise. | 388 // The local variable 'arguments' if we need to allocate it; NULL otherwise. |
| 364 Variable* arguments() const { return arguments_; } | 389 Variable* arguments() const { return arguments_; } |
| 365 | 390 |
| 366 // Declarations list. | 391 // Declarations list. |
| 367 ZoneList<Declaration*>* declarations() { return &decls_; } | 392 ZoneList<Declaration*>* declarations() { return &decls_; } |
| 368 | 393 |
| 369 // Inner scope list. | 394 // Inner scope list. |
| 370 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } | 395 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } |
| 371 | 396 |
| 372 // The scope immediately surrounding this scope, or NULL. | 397 // The scope immediately surrounding this scope, or NULL. |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 // Computed via AllocateVariables; function, block and catch scopes only. | 573 // Computed via AllocateVariables; function, block and catch scopes only. |
| 549 int num_stack_slots_; | 574 int num_stack_slots_; |
| 550 int num_heap_slots_; | 575 int num_heap_slots_; |
| 551 | 576 |
| 552 // The number of modules (including nested ones). | 577 // The number of modules (including nested ones). |
| 553 int num_modules_; | 578 int num_modules_; |
| 554 | 579 |
| 555 // For module scopes, the host scope's internal variable binding this module. | 580 // For module scopes, the host scope's internal variable binding this module. |
| 556 Variable* module_var_; | 581 Variable* module_var_; |
| 557 | 582 |
| 583 // Rest parameter |
| 584 Variable* rest_parameter_; |
| 585 int rest_index_; |
| 586 |
| 558 // Serialized scope info support. | 587 // Serialized scope info support. |
| 559 Handle<ScopeInfo> scope_info_; | 588 Handle<ScopeInfo> scope_info_; |
| 560 bool already_resolved() { return already_resolved_; } | 589 bool already_resolved() { return already_resolved_; } |
| 561 | 590 |
| 562 // Create a non-local variable with a given name. | 591 // Create a non-local variable with a given name. |
| 563 // These variables are looked up dynamically at runtime. | 592 // These variables are looked up dynamically at runtime. |
| 564 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 593 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
| 565 | 594 |
| 566 // Variable resolution. | 595 // Variable resolution. |
| 567 // Possible results of a recursive variable lookup telling if and how a | 596 // Possible results of a recursive variable lookup telling if and how a |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 Scope* outer_scope, | 700 Scope* outer_scope, |
| 672 Handle<ScopeInfo> scope_info); | 701 Handle<ScopeInfo> scope_info); |
| 673 | 702 |
| 674 AstValueFactory* ast_value_factory_; | 703 AstValueFactory* ast_value_factory_; |
| 675 Zone* zone_; | 704 Zone* zone_; |
| 676 }; | 705 }; |
| 677 | 706 |
| 678 } } // namespace v8::internal | 707 } } // namespace v8::internal |
| 679 | 708 |
| 680 #endif // V8_SCOPES_H_ | 709 #endif // V8_SCOPES_H_ |
| OLD | NEW |