Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: src/scopes.cc

Issue 1163853002: Revert of [es6] implement default parameters via desugaring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/scopes.h ('k') | src/variables.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/parser.h" 10 #include "src/parser.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // ---------------------------------------------------------------------------- 70 // ----------------------------------------------------------------------------
71 // Implementation of Scope 71 // Implementation of Scope
72 72
73 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, 73 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
74 AstValueFactory* ast_value_factory, FunctionKind function_kind) 74 AstValueFactory* ast_value_factory, FunctionKind function_kind)
75 : inner_scopes_(4, zone), 75 : inner_scopes_(4, zone),
76 variables_(zone), 76 variables_(zone),
77 internals_(4, zone), 77 internals_(4, zone),
78 temps_(4, zone), 78 temps_(4, zone),
79 params_(4, zone), 79 params_(4, zone),
80 param_positions_(4, zone),
81 unresolved_(16, zone), 80 unresolved_(16, zone),
82 decls_(4, zone), 81 decls_(4, zone),
83 module_descriptor_( 82 module_descriptor_(
84 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), 83 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL),
85 already_resolved_(false), 84 already_resolved_(false),
86 ast_value_factory_(ast_value_factory), 85 ast_value_factory_(ast_value_factory),
87 zone_(zone), 86 zone_(zone),
88 class_declaration_group_start_(-1) { 87 class_declaration_group_start_(-1) {
89 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), 88 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(),
90 function_kind); 89 function_kind);
91 // The outermost scope must be a script scope. 90 // The outermost scope must be a script scope.
92 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); 91 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL);
93 DCHECK(!HasIllegalRedeclaration()); 92 DCHECK(!HasIllegalRedeclaration());
94 } 93 }
95 94
96 95
97 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, 96 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
98 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) 97 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory)
99 : inner_scopes_(4, zone), 98 : inner_scopes_(4, zone),
100 variables_(zone), 99 variables_(zone),
101 internals_(4, zone), 100 internals_(4, zone),
102 temps_(4, zone), 101 temps_(4, zone),
103 params_(4, zone), 102 params_(4, zone),
104 param_positions_(4, zone),
105 unresolved_(16, zone), 103 unresolved_(16, zone),
106 decls_(4, zone), 104 decls_(4, zone),
107 module_descriptor_(NULL), 105 module_descriptor_(NULL),
108 already_resolved_(true), 106 already_resolved_(true),
109 ast_value_factory_(value_factory), 107 ast_value_factory_(value_factory),
110 zone_(zone), 108 zone_(zone),
111 class_declaration_group_start_(-1) { 109 class_declaration_group_start_(-1) {
112 SetDefaults(scope_type, NULL, scope_info); 110 SetDefaults(scope_type, NULL, scope_info);
113 if (!scope_info.is_null()) { 111 if (!scope_info.is_null()) {
114 num_heap_slots_ = scope_info_->ContextLength(); 112 num_heap_slots_ = scope_info_->ContextLength();
115 } 113 }
116 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. 114 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
117 num_heap_slots_ = Max(num_heap_slots_, 115 num_heap_slots_ = Max(num_heap_slots_,
118 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); 116 static_cast<int>(Context::MIN_CONTEXT_SLOTS));
119 AddInnerScope(inner_scope); 117 AddInnerScope(inner_scope);
120 } 118 }
121 119
122 120
123 Scope::Scope(Zone* zone, Scope* inner_scope, 121 Scope::Scope(Zone* zone, Scope* inner_scope,
124 const AstRawString* catch_variable_name, 122 const AstRawString* catch_variable_name,
125 AstValueFactory* value_factory) 123 AstValueFactory* value_factory)
126 : inner_scopes_(1, zone), 124 : inner_scopes_(1, zone),
127 variables_(zone), 125 variables_(zone),
128 internals_(0, zone), 126 internals_(0, zone),
129 temps_(0, zone), 127 temps_(0, zone),
130 params_(0, zone), 128 params_(0, zone),
131 param_positions_(0, zone),
132 unresolved_(0, zone), 129 unresolved_(0, zone),
133 decls_(0, zone), 130 decls_(0, zone),
134 module_descriptor_(NULL), 131 module_descriptor_(NULL),
135 already_resolved_(true), 132 already_resolved_(true),
136 ast_value_factory_(value_factory), 133 ast_value_factory_(value_factory),
137 zone_(zone), 134 zone_(zone),
138 class_declaration_group_start_(-1) { 135 class_declaration_group_start_(-1) {
139 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); 136 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null());
140 AddInnerScope(inner_scope); 137 AddInnerScope(inner_scope);
141 ++num_var_or_const_; 138 ++num_var_or_const_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 force_eager_compilation_ = false; 176 force_eager_compilation_ = false;
180 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) 177 force_context_allocation_ = (outer_scope != NULL && !is_function_scope())
181 ? outer_scope->has_forced_context_allocation() : false; 178 ? outer_scope->has_forced_context_allocation() : false;
182 num_var_or_const_ = 0; 179 num_var_or_const_ = 0;
183 num_stack_slots_ = 0; 180 num_stack_slots_ = 0;
184 num_heap_slots_ = 0; 181 num_heap_slots_ = 0;
185 num_modules_ = 0; 182 num_modules_ = 0;
186 module_var_ = NULL, 183 module_var_ = NULL,
187 rest_parameter_ = NULL; 184 rest_parameter_ = NULL;
188 rest_index_ = -1; 185 rest_index_ = -1;
189 has_parameter_expressions_ = false;
190 scope_info_ = scope_info; 186 scope_info_ = scope_info;
191 start_position_ = RelocInfo::kNoPosition; 187 start_position_ = RelocInfo::kNoPosition;
192 end_position_ = RelocInfo::kNoPosition; 188 end_position_ = RelocInfo::kNoPosition;
193 if (!scope_info.is_null()) { 189 if (!scope_info.is_null()) {
194 scope_calls_eval_ = scope_info->CallsEval(); 190 scope_calls_eval_ = scope_info->CallsEval();
195 language_mode_ = scope_info->language_mode(); 191 language_mode_ = scope_info->language_mode();
196 block_scope_is_class_scope_ = scope_info->block_scope_is_class_scope(); 192 block_scope_is_class_scope_ = scope_info->block_scope_is_class_scope();
197 function_kind_ = scope_info->function_kind(); 193 function_kind_ = scope_info->function_kind();
198 } 194 }
199 } 195 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 scope != NULL; 463 scope != NULL;
468 scope = scope->outer_scope()) { 464 scope = scope->outer_scope()) {
469 Variable* var = scope->LookupLocal(name); 465 Variable* var = scope->LookupLocal(name);
470 if (var != NULL) return var; 466 if (var != NULL) return var;
471 } 467 }
472 return NULL; 468 return NULL;
473 } 469 }
474 470
475 471
476 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, 472 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode,
477 bool is_rest, bool* is_duplicate, int pos) { 473 bool is_rest, bool* is_duplicate) {
478 DCHECK(!already_resolved()); 474 DCHECK(!already_resolved());
479 DCHECK(is_function_scope()); 475 DCHECK(is_function_scope());
480 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL, 476 Variable* var = variables_.Declare(this, name, mode, Variable::NORMAL,
481 kCreatedInitialized); 477 kCreatedInitialized);
482 if (is_rest) { 478 if (is_rest) {
483 DCHECK_NULL(rest_parameter_); 479 DCHECK_NULL(rest_parameter_);
484 rest_parameter_ = var; 480 rest_parameter_ = var;
485 rest_index_ = num_parameters(); 481 rest_index_ = num_parameters();
486 } 482 }
487 // TODO(wingo): Avoid O(n^2) check. 483 // TODO(wingo): Avoid O(n^2) check.
488 *is_duplicate = IsDeclaredParameter(name); 484 *is_duplicate = IsDeclaredParameter(name);
489 params_.Add(var, zone()); 485 params_.Add(var, zone());
490 param_positions_.Add(pos, zone());
491 return var; 486 return var;
492 } 487 }
493 488
494 489
495 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, 490 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode,
496 InitializationFlag init_flag, Variable::Kind kind, 491 InitializationFlag init_flag, Variable::Kind kind,
497 MaybeAssignedFlag maybe_assigned_flag, 492 MaybeAssignedFlag maybe_assigned_flag,
498 int declaration_group_start) { 493 int declaration_group_start) {
499 DCHECK(!already_resolved()); 494 DCHECK(!already_resolved());
500 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are 495 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 temps_.Add(var, zone()); 546 temps_.Add(var, zone());
552 return var; 547 return var;
553 } 548 }
554 549
555 550
556 void Scope::AddDeclaration(Declaration* declaration) { 551 void Scope::AddDeclaration(Declaration* declaration) {
557 decls_.Add(declaration, zone()); 552 decls_.Add(declaration, zone());
558 } 553 }
559 554
560 555
561 void Scope::UndeclareParametersForExpressions() {
562 DCHECK(is_function_scope());
563 DCHECK(!has_parameter_expressions_);
564 has_parameter_expressions_ = true;
565 for (int i = 0; i < num_parameters(); ++i) {
566 Variable* p = parameter(i);
567 const AstRawString* name = p->raw_name();
568 variables_.Remove(const_cast<AstRawString*>(name), name->hash());
569 }
570 }
571
572
573 void Scope::SetIllegalRedeclaration(Expression* expression) { 556 void Scope::SetIllegalRedeclaration(Expression* expression) {
574 // Record only the first illegal redeclaration. 557 // Record only the first illegal redeclaration.
575 if (!HasIllegalRedeclaration()) { 558 if (!HasIllegalRedeclaration()) {
576 illegal_redecl_ = expression; 559 illegal_redecl_ = expression;
577 } 560 }
578 DCHECK(HasIllegalRedeclaration()); 561 DCHECK(HasIllegalRedeclaration());
579 } 562 }
580 563
581 564
582 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) { 565 void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) {
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 // home_object_var. 1412 // home_object_var.
1430 // Consider splitting the AST node into 2 different nodes since the 1413 // Consider splitting the AST node into 2 different nodes since the
1431 // semantics is just so different. 1414 // semantics is just so different.
1432 home_object_ = home_object_var; 1415 home_object_ = home_object_var;
1433 } 1416 }
1434 1417
1435 // The same parameter may occur multiple times in the parameters_ list. 1418 // The same parameter may occur multiple times in the parameters_ list.
1436 // If it does, and if it is not copied into the context object, it must 1419 // If it does, and if it is not copied into the context object, it must
1437 // receive the highest parameter index for that parameter; thus iteration 1420 // receive the highest parameter index for that parameter; thus iteration
1438 // order is relevant! 1421 // order is relevant!
1439 // 1422 for (int i = params_.length() - 1; i >= 0; --i) {
1440 // If hasParameterExpressions is true, parameters are redeclared during 1423 Variable* var = params_[i];
1441 // desugaring, and must not be allocated here. 1424 if (var == rest_parameter_) continue;
1442 if (!has_parameter_expressions_) {
1443 for (int i = params_.length() - 1; i >= 0; --i) {
1444 Variable* var = params_[i];
1445 if (var == rest_parameter_) continue;
1446 1425
1447 DCHECK(var->scope() == this); 1426 DCHECK(var->scope() == this);
1448 if (uses_sloppy_arguments || has_forced_context_allocation()) { 1427 if (uses_sloppy_arguments || has_forced_context_allocation()) {
1449 // Force context allocation of the parameter. 1428 // Force context allocation of the parameter.
1450 var->ForceContextAllocation(); 1429 var->ForceContextAllocation();
1451 }
1452 AllocateParameter(var, i);
1453 } 1430 }
1431 AllocateParameter(var, i);
1454 } 1432 }
1455 } 1433 }
1456 1434
1457 1435
1458 void Scope::AllocateParameter(Variable* var, int index) { 1436 void Scope::AllocateParameter(Variable* var, int index) {
1459 if (MustAllocate(var)) { 1437 if (MustAllocate(var)) {
1460 if (MustAllocateInContext(var)) { 1438 if (MustAllocateInContext(var)) {
1461 DCHECK(var->IsUnallocated() || var->IsContextSlot()); 1439 DCHECK(var->IsUnallocated() || var->IsContextSlot());
1462 if (var->IsUnallocated()) { 1440 if (var->IsUnallocated()) {
1463 AllocateHeapSlot(var); 1441 AllocateHeapSlot(var);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); 1573 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1596 } 1574 }
1597 1575
1598 1576
1599 int Scope::ContextLocalCount() const { 1577 int Scope::ContextLocalCount() const {
1600 if (num_heap_slots() == 0) return 0; 1578 if (num_heap_slots() == 0) return 0;
1601 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1579 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1602 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1580 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1603 } 1581 }
1604 } } // namespace v8::internal 1582 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698