Chromium Code Reviews| 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 "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/ast/scopeinfo.h" | 8 #include "src/ast/scopeinfo.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 } | 360 } |
| 361 outer_scope()->unresolved_ = unresolved_; | 361 outer_scope()->unresolved_ = unresolved_; |
| 362 unresolved_ = nullptr; | 362 unresolved_ = nullptr; |
| 363 } | 363 } |
| 364 | 364 |
| 365 PropagateUsageFlagsToScope(outer_scope_); | 365 PropagateUsageFlagsToScope(outer_scope_); |
| 366 | 366 |
| 367 return NULL; | 367 return NULL; |
| 368 } | 368 } |
| 369 | 369 |
| 370 void Scope::Snapshot::Reparent(Scope* new_parent) const { | |
| 371 DCHECK_EQ(new_parent, outer_scope_->inner_scope_); | |
| 372 DCHECK_EQ(new_parent->outer_scope_, outer_scope_); | |
| 373 DCHECK_EQ(new_parent, new_parent->ClosureScope()); | |
| 374 DCHECK_NULL(new_parent->inner_scope_); | |
| 375 DCHECK_NULL(new_parent->unresolved_); | |
| 376 DCHECK_EQ(0, new_parent->temps_.length()); | |
| 377 Scope* inner_scope = new_parent->sibling_; | |
| 378 if (inner_scope != top_inner_scope_) { | |
| 379 for (; inner_scope->sibling() != top_inner_scope_; | |
| 380 inner_scope = inner_scope->sibling()) { | |
| 381 inner_scope->outer_scope_ = new_parent; | |
| 382 DCHECK_NE(inner_scope, new_parent); | |
| 383 } | |
| 384 inner_scope->outer_scope_ = new_parent; | |
| 385 | |
| 386 new_parent->inner_scope_ = new_parent->sibling_; | |
| 387 inner_scope->sibling_ = nullptr; | |
| 388 // Reset the sibling rather than the inner_scope_ since we | |
| 389 // want to keep new_parent there. | |
| 390 DCHECK_EQ(new_parent, outer_scope_->inner_scope_); | |
|
nickie
2016/07/22 09:05:31
I'm not sure why we check this again. It's checke
adamk
2016/07/22 23:04:34
I agree that there's no need to check this again,
| |
| 391 new_parent->sibling_ = top_inner_scope_; | |
| 392 } | |
| 393 | |
| 394 if (outer_scope_->unresolved_ != top_unresolved_) { | |
| 395 VariableProxy* last = outer_scope_->unresolved_; | |
| 396 while (last->next_unresolved() != top_unresolved_) { | |
| 397 last = last->next_unresolved(); | |
| 398 } | |
| 399 last->set_next_unresolved(nullptr); | |
| 400 new_parent->unresolved_ = outer_scope_->unresolved_; | |
| 401 outer_scope_->unresolved_ = top_unresolved_; | |
| 402 } | |
| 403 | |
| 404 if (outer_scope_->ClosureScope()->temps_.length() != top_temp_) { | |
| 405 ZoneList<Variable*>* temps = &outer_scope_->ClosureScope()->temps_; | |
| 406 for (int i = top_temp_; i < temps->length(); i++) { | |
| 407 Variable* temp = temps->at(i); | |
| 408 DCHECK_EQ(temp->scope(), temp->scope()->ClosureScope()); | |
| 409 DCHECK_NE(temp->scope(), new_parent); | |
| 410 temp->set_scope(new_parent); | |
| 411 new_parent->AddTemporary(temp); | |
| 412 } | |
| 413 temps->Rewind(top_temp_); | |
| 414 } | |
| 415 } | |
| 370 | 416 |
| 371 void Scope::ReplaceOuterScope(Scope* outer) { | 417 void Scope::ReplaceOuterScope(Scope* outer) { |
| 372 DCHECK_NOT_NULL(outer); | 418 DCHECK_NOT_NULL(outer); |
| 373 DCHECK_NOT_NULL(outer_scope_); | 419 DCHECK_NOT_NULL(outer_scope_); |
| 374 DCHECK(!already_resolved()); | 420 DCHECK(!already_resolved()); |
| 375 DCHECK(!outer->already_resolved()); | 421 DCHECK(!outer->already_resolved()); |
| 376 DCHECK(!outer_scope_->already_resolved()); | 422 DCHECK(!outer_scope_->already_resolved()); |
| 377 outer_scope_->RemoveInnerScope(this); | 423 outer_scope_->RemoveInnerScope(this); |
| 378 outer->AddInnerScope(this); | 424 outer->AddInnerScope(this); |
| 379 outer_scope_ = outer; | 425 outer_scope_ = outer; |
| (...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1535 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1581 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
| 1536 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1582 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1537 (is_function_var_in_context ? 1 : 0); | 1583 (is_function_var_in_context ? 1 : 0); |
| 1538 } | 1584 } |
| 1539 | 1585 |
| 1540 | 1586 |
| 1541 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1587 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1542 | 1588 |
| 1543 } // namespace internal | 1589 } // namespace internal |
| 1544 } // namespace v8 | 1590 } // namespace v8 |
| OLD | NEW |