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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 } | 359 } |
360 outer_scope()->unresolved_ = unresolved_; | 360 outer_scope()->unresolved_ = unresolved_; |
361 unresolved_ = nullptr; | 361 unresolved_ = nullptr; |
362 } | 362 } |
363 | 363 |
364 PropagateUsageFlagsToScope(outer_scope_); | 364 PropagateUsageFlagsToScope(outer_scope_); |
365 | 365 |
366 return NULL; | 366 return NULL; |
367 } | 367 } |
368 | 368 |
369 void Scope::Snapshot::Reparent(Scope* new_parent) const { | |
370 DCHECK_EQ(new_parent, outer_scope_->inner_scope_); | |
371 DCHECK_EQ(new_parent->outer_scope_, outer_scope_); | |
372 DCHECK_EQ(new_parent, new_parent->ClosureScope()); | |
373 Scope* inner_scope = new_parent->sibling_; | |
374 if (inner_scope != top_inner_scope_) { | |
375 for (; inner_scope->sibling() != top_inner_scope_; | |
376 inner_scope = inner_scope->sibling()) { | |
377 inner_scope->outer_scope_ = new_parent; | |
378 DCHECK_NE(inner_scope, new_parent); | |
379 } | |
380 inner_scope->outer_scope_ = new_parent; | |
381 | |
382 new_parent->inner_scope_ = new_parent->sibling_; | |
nickie
2016/07/21 15:08:52
As you're blindly assigning here, I'd recommend to
| |
383 inner_scope->sibling_ = nullptr; | |
384 // Reset the sibling rather than the inner_scope_ since we | |
385 // want to keep new_parent there. | |
386 DCHECK_EQ(new_parent, outer_scope_->inner_scope_); | |
387 new_parent->sibling_ = top_inner_scope_; | |
388 } | |
389 | |
390 if (outer_scope_->unresolved_ != top_unresolved_) { | |
391 VariableProxy* last; | |
392 for (last = outer_scope_->unresolved_; | |
393 last->next_unresolved() != top_unresolved_; | |
394 last = last->next_unresolved()) { | |
395 } | |
396 last->set_next_unresolved(nullptr); | |
397 new_parent->unresolved_ = outer_scope_->unresolved_; | |
398 outer_scope_->unresolved_ = top_unresolved_; | |
399 } | |
400 | |
401 if (outer_scope_->ClosureScope()->temps_.length() != top_temp_) { | |
402 ZoneList<Variable*>* temps = &outer_scope_->ClosureScope()->temps_; | |
403 for (int i = top_temp_; i < temps->length(); i++) { | |
404 Variable* temp = (*temps)[i]; | |
405 DCHECK_EQ(temp->scope(), temp->scope()->ClosureScope()); | |
406 DCHECK_NE(temp->scope(), new_parent); | |
407 temp->set_scope(new_parent); | |
408 new_parent->AddTemporary(temp); | |
409 } | |
410 temps->Rewind(top_temp_); | |
411 } | |
412 } | |
369 | 413 |
370 void Scope::ReplaceOuterScope(Scope* outer) { | 414 void Scope::ReplaceOuterScope(Scope* outer) { |
371 DCHECK_NOT_NULL(outer); | 415 DCHECK_NOT_NULL(outer); |
372 DCHECK_NOT_NULL(outer_scope_); | 416 DCHECK_NOT_NULL(outer_scope_); |
373 DCHECK(!already_resolved()); | 417 DCHECK(!already_resolved()); |
374 DCHECK(!outer->already_resolved()); | 418 DCHECK(!outer->already_resolved()); |
375 DCHECK(!outer_scope_->already_resolved()); | 419 DCHECK(!outer_scope_->already_resolved()); |
376 outer_scope_->RemoveInnerScope(this); | 420 outer_scope_->RemoveInnerScope(this); |
377 outer->AddInnerScope(this); | 421 outer->AddInnerScope(this); |
378 outer_scope_ = outer; | 422 outer_scope_ = outer; |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1545 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1589 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1546 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1590 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1547 (is_function_var_in_context ? 1 : 0); | 1591 (is_function_var_in_context ? 1 : 0); |
1548 } | 1592 } |
1549 | 1593 |
1550 | 1594 |
1551 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1595 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1552 | 1596 |
1553 } // namespace internal | 1597 } // namespace internal |
1554 } // namespace v8 | 1598 } // namespace v8 |
OLD | NEW |