OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/ast/context-slot-cache.h" | |
8 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
9 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
10 | 9 |
11 namespace v8 { | 10 namespace v8 { |
12 namespace internal { | 11 namespace internal { |
13 | 12 |
14 | 13 |
15 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, | 14 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, |
16 Scope* scope) { | 15 Scope* scope) { |
17 // Collect variables. | 16 // Collect variables. |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, | 471 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, |
473 Handle<String> name, VariableMode* mode, | 472 Handle<String> name, VariableMode* mode, |
474 InitializationFlag* init_flag, | 473 InitializationFlag* init_flag, |
475 MaybeAssignedFlag* maybe_assigned_flag) { | 474 MaybeAssignedFlag* maybe_assigned_flag) { |
476 DCHECK(name->IsInternalizedString()); | 475 DCHECK(name->IsInternalizedString()); |
477 DCHECK_NOT_NULL(mode); | 476 DCHECK_NOT_NULL(mode); |
478 DCHECK_NOT_NULL(init_flag); | 477 DCHECK_NOT_NULL(init_flag); |
479 DCHECK_NOT_NULL(maybe_assigned_flag); | 478 DCHECK_NOT_NULL(maybe_assigned_flag); |
480 | 479 |
481 if (scope_info->length() > 0) { | 480 if (scope_info->length() > 0) { |
482 ContextSlotCache* context_slot_cache = | |
483 scope_info->GetIsolate()->context_slot_cache(); | |
484 int result = context_slot_cache->Lookup(*scope_info, *name, mode, init_flag, | |
485 maybe_assigned_flag); | |
486 if (result != ContextSlotCache::kNotFound) { | |
487 DCHECK(result < scope_info->ContextLength()); | |
488 return result; | |
489 } | |
490 | |
491 int start = scope_info->ContextLocalNameEntriesIndex(); | 481 int start = scope_info->ContextLocalNameEntriesIndex(); |
492 int end = start + scope_info->ContextLocalCount(); | 482 int end = start + scope_info->ContextLocalCount(); |
493 for (int i = start; i < end; ++i) { | 483 for (int i = start; i < end; ++i) { |
494 if (*name == scope_info->get(i)) { | 484 if (*name == scope_info->get(i)) { |
495 int var = i - start; | 485 int var = i - start; |
496 *mode = scope_info->ContextLocalMode(var); | 486 *mode = scope_info->ContextLocalMode(var); |
497 *init_flag = scope_info->ContextLocalInitFlag(var); | 487 *init_flag = scope_info->ContextLocalInitFlag(var); |
498 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); | 488 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); |
499 result = Context::MIN_CONTEXT_SLOTS + var; | 489 int result = Context::MIN_CONTEXT_SLOTS + var; |
500 | |
501 context_slot_cache->Update(scope_info, name, *mode, *init_flag, | |
502 *maybe_assigned_flag, result); | |
503 DCHECK(result < scope_info->ContextLength()); | 490 DCHECK(result < scope_info->ContextLength()); |
504 return result; | 491 return result; |
505 } | 492 } |
506 } | 493 } |
507 // Cache as not found. Mode, init flag and maybe assigned flag don't matter. | |
508 context_slot_cache->Update(scope_info, name, TEMPORARY, | |
509 kNeedsInitialization, kNotAssigned, -1); | |
510 } | 494 } |
511 | 495 |
512 return -1; | 496 return -1; |
513 } | 497 } |
514 | 498 |
515 int ScopeInfo::ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info, | 499 int ScopeInfo::ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info, |
516 Handle<String> name, VariableMode* mode, | 500 Handle<String> name, VariableMode* mode, |
517 InitializationFlag* init_flag, | 501 InitializationFlag* init_flag, |
518 MaybeAssignedFlag* maybe_assigned_flag) { | 502 MaybeAssignedFlag* maybe_assigned_flag) { |
519 DCHECK(name->IsInternalizedString()); | 503 DCHECK(name->IsInternalizedString()); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); | 667 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); |
684 } | 668 } |
685 | 669 |
686 PrintF("}\n"); | 670 PrintF("}\n"); |
687 } | 671 } |
688 #endif // DEBUG | 672 #endif // DEBUG |
689 | 673 |
690 | 674 |
691 } // namespace internal | 675 } // namespace internal |
692 } // namespace v8 | 676 } // namespace v8 |
OLD | NEW |