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 #include "src/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 if (var != NULL) return var; | 673 if (var != NULL) return var; |
674 } | 674 } |
675 return NULL; | 675 return NULL; |
676 } | 676 } |
677 | 677 |
678 Variable* DeclarationScope::DeclareParameter( | 678 Variable* DeclarationScope::DeclareParameter( |
679 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, | 679 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, |
680 bool* is_duplicate, AstValueFactory* ast_value_factory) { | 680 bool* is_duplicate, AstValueFactory* ast_value_factory) { |
681 DCHECK(!already_resolved_); | 681 DCHECK(!already_resolved_); |
682 DCHECK(is_function_scope()); | 682 DCHECK(is_function_scope()); |
683 DCHECK(!has_rest_parameter()); | 683 DCHECK(!has_rest_); |
684 DCHECK(!is_optional || !is_rest); | 684 DCHECK(!is_optional || !is_rest); |
685 Variable* var; | 685 Variable* var; |
686 if (mode == TEMPORARY) { | 686 if (mode == TEMPORARY) { |
687 var = NewTemporary(name); | 687 var = NewTemporary(name); |
688 } else { | 688 } else { |
689 var = Declare(zone(), this, name, mode, Variable::NORMAL, | 689 var = Declare(zone(), this, name, mode, Variable::NORMAL, |
690 kCreatedInitialized); | 690 kCreatedInitialized); |
691 // TODO(wingo): Avoid O(n^2) check. | 691 // TODO(wingo): Avoid O(n^2) check. |
692 *is_duplicate = IsDeclaredParameter(name); | 692 *is_duplicate = IsDeclaredParameter(name); |
693 } | 693 } |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 } else { | 1486 } else { |
1487 DCHECK(is_arrow_scope()); | 1487 DCHECK(is_arrow_scope()); |
1488 } | 1488 } |
1489 | 1489 |
1490 // The same parameter may occur multiple times in the parameters_ list. | 1490 // The same parameter may occur multiple times in the parameters_ list. |
1491 // If it does, and if it is not copied into the context object, it must | 1491 // If it does, and if it is not copied into the context object, it must |
1492 // receive the highest parameter index for that parameter; thus iteration | 1492 // receive the highest parameter index for that parameter; thus iteration |
1493 // order is relevant! | 1493 // order is relevant! |
1494 for (int i = num_parameters() - 1; i >= 0; --i) { | 1494 for (int i = num_parameters() - 1; i >= 0; --i) { |
1495 Variable* var = params_[i]; | 1495 Variable* var = params_[i]; |
1496 DCHECK(!has_rest_parameter() || var != rest_parameter()); | 1496 DCHECK(!has_rest_ || var != rest_parameter()); |
1497 DCHECK_EQ(this, var->scope()); | 1497 DCHECK_EQ(this, var->scope()); |
1498 if (uses_sloppy_arguments) { | 1498 if (uses_sloppy_arguments) { |
1499 var->ForceContextAllocation(); | 1499 var->ForceContextAllocation(); |
1500 } | 1500 } |
1501 AllocateParameter(var, i); | 1501 AllocateParameter(var, i); |
1502 } | 1502 } |
1503 } | 1503 } |
1504 | 1504 |
1505 void DeclarationScope::AllocateParameter(Variable* var, int index) { | 1505 void DeclarationScope::AllocateParameter(Variable* var, int index) { |
1506 if (MustAllocate(var)) { | 1506 if (MustAllocate(var)) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 | 1579 |
1580 void DeclarationScope::AllocateLocals() { | 1580 void DeclarationScope::AllocateLocals() { |
1581 // For now, function_ must be allocated at the very end. If it gets | 1581 // For now, function_ must be allocated at the very end. If it gets |
1582 // allocated in the context, it must be the last slot in the context, | 1582 // allocated in the context, it must be the last slot in the context, |
1583 // because of the current ScopeInfo implementation (see | 1583 // because of the current ScopeInfo implementation (see |
1584 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). | 1584 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). |
1585 if (function_ != nullptr) { | 1585 if (function_ != nullptr) { |
1586 AllocateNonParameterLocal(function_); | 1586 AllocateNonParameterLocal(function_); |
1587 } | 1587 } |
1588 | 1588 |
1589 DCHECK(!has_rest_parameter() || !MustAllocate(rest_parameter()) || | 1589 DCHECK(!has_rest_ || !MustAllocate(rest_parameter()) || |
1590 !rest_parameter()->IsUnallocated()); | 1590 !rest_parameter()->IsUnallocated()); |
1591 | 1591 |
1592 if (new_target_ != nullptr && !MustAllocate(new_target_)) { | 1592 if (new_target_ != nullptr && !MustAllocate(new_target_)) { |
1593 new_target_ = nullptr; | 1593 new_target_ = nullptr; |
1594 } | 1594 } |
1595 | 1595 |
1596 if (this_function_ != nullptr && !MustAllocate(this_function_)) { | 1596 if (this_function_ != nullptr && !MustAllocate(this_function_)) { |
1597 this_function_ = nullptr; | 1597 this_function_ = nullptr; |
1598 } | 1598 } |
1599 } | 1599 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 function != nullptr && function->IsContextSlot(); | 1673 function != nullptr && function->IsContextSlot(); |
1674 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1674 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1675 (is_function_var_in_context ? 1 : 0); | 1675 (is_function_var_in_context ? 1 : 0); |
1676 } | 1676 } |
1677 | 1677 |
1678 | 1678 |
1679 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1679 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1680 | 1680 |
1681 } // namespace internal | 1681 } // namespace internal |
1682 } // namespace v8 | 1682 } // namespace v8 |
OLD | NEW |