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/hashmap.h" | 9 #include "src/hashmap.h" |
10 #include "src/pending-compilation-error-handler.h" | 10 #include "src/pending-compilation-error-handler.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 Variable* parameter(int index) const { | 414 Variable* parameter(int index) const { |
415 DCHECK(is_function_scope()); | 415 DCHECK(is_function_scope()); |
416 return params_[index]; | 416 return params_[index]; |
417 } | 417 } |
418 | 418 |
419 // Returns the default function arity excluding default or rest parameters. | 419 // Returns the default function arity excluding default or rest parameters. |
420 int default_function_length() const { return arity_; } | 420 int default_function_length() const { return arity_; } |
421 | 421 |
422 int num_parameters() const { return params_.length(); } | 422 int num_parameters() const { return params_.length(); } |
423 | 423 |
| 424 // A function can have at most one rest parameter. Returns Variable* or NULL. |
| 425 Variable* rest_parameter(int* index) const { |
| 426 *index = rest_index_; |
| 427 if (rest_index_ < 0) return NULL; |
| 428 return rest_parameter_; |
| 429 } |
| 430 |
| 431 bool has_rest_parameter() const { return rest_index_ >= 0; } |
| 432 |
424 bool has_simple_parameters() const { | 433 bool has_simple_parameters() const { |
425 return has_simple_parameters_; | 434 return has_simple_parameters_; |
426 } | 435 } |
427 | 436 |
428 // TODO(caitp): manage this state in a better way. PreParser must be able to | 437 // TODO(caitp): manage this state in a better way. PreParser must be able to |
429 // communicate that the scope is non-simple, without allocating any parameters | 438 // communicate that the scope is non-simple, without allocating any parameters |
430 // as the Parser does. This is necessary to ensure that TC39's proposed early | 439 // as the Parser does. This is necessary to ensure that TC39's proposed early |
431 // error can be reported consistently regardless of whether lazily parsed or | 440 // error can be reported consistently regardless of whether lazily parsed or |
432 // not. | 441 // not. |
433 void SetHasNonSimpleParameters() { | 442 void SetHasNonSimpleParameters() { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 684 |
676 // Computed via AllocateVariables; function, block and catch scopes only. | 685 // Computed via AllocateVariables; function, block and catch scopes only. |
677 int num_stack_slots_; | 686 int num_stack_slots_; |
678 int num_heap_slots_; | 687 int num_heap_slots_; |
679 int num_global_slots_; | 688 int num_global_slots_; |
680 | 689 |
681 // Info about the parameter list of a function. | 690 // Info about the parameter list of a function. |
682 int arity_; | 691 int arity_; |
683 bool has_simple_parameters_; | 692 bool has_simple_parameters_; |
684 Variable* rest_parameter_; | 693 Variable* rest_parameter_; |
| 694 int rest_index_; |
685 | 695 |
686 // Serialized scope info support. | 696 // Serialized scope info support. |
687 Handle<ScopeInfo> scope_info_; | 697 Handle<ScopeInfo> scope_info_; |
688 bool already_resolved() { return already_resolved_; } | 698 bool already_resolved() { return already_resolved_; } |
689 | 699 |
690 // Create a non-local variable with a given name. | 700 // Create a non-local variable with a given name. |
691 // These variables are looked up dynamically at runtime. | 701 // These variables are looked up dynamically at runtime. |
692 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 702 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
693 | 703 |
694 // Variable resolution. | 704 // Variable resolution. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 | 831 |
822 // For tracking which classes are declared consecutively. Needed for strong | 832 // For tracking which classes are declared consecutively. Needed for strong |
823 // mode. | 833 // mode. |
824 int class_declaration_group_start_; | 834 int class_declaration_group_start_; |
825 }; | 835 }; |
826 | 836 |
827 } // namespace internal | 837 } // namespace internal |
828 } // namespace v8 | 838 } // namespace v8 |
829 | 839 |
830 #endif // V8_AST_SCOPES_H_ | 840 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |