| 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" | 7 #include "src/ast/context-slot-cache.h" | 
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" | 
| 9 #include "src/ast/variables.h" | 9 #include "src/ast/variables.h" | 
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 51       } | 51       } | 
| 52     } | 52     } | 
| 53   } | 53   } | 
| 54   return true; | 54   return true; | 
| 55 } | 55 } | 
| 56 #endif | 56 #endif | 
| 57 | 57 | 
| 58 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope, | 58 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope, | 
| 59                                     MaybeHandle<ScopeInfo> outer_scope) { | 59                                     MaybeHandle<ScopeInfo> outer_scope) { | 
| 60   // Collect variables. | 60   // Collect variables. | 
| 61   ZoneList<Variable*>* locals = scope->locals(); |  | 
| 62   int stack_local_count = 0; | 61   int stack_local_count = 0; | 
| 63   int context_local_count = 0; | 62   int context_local_count = 0; | 
| 64   int module_vars_count = 0; | 63   int module_vars_count = 0; | 
| 65   // Stack allocated block scope variables are allocated in the parent | 64   // Stack allocated block scope variables are allocated in the parent | 
| 66   // declaration scope, but are recorded in the block scope's scope info. First | 65   // declaration scope, but are recorded in the block scope's scope info. First | 
| 67   // slot index indicates at which offset a particular scope starts in the | 66   // slot index indicates at which offset a particular scope starts in the | 
| 68   // parent declaration scope. | 67   // parent declaration scope. | 
| 69   int first_slot_index = 0; | 68   int first_slot_index = 0; | 
| 70   for (int i = 0; i < locals->length(); i++) { | 69   for (Variable* var : *scope->locals()) { | 
| 71     Variable* var = locals->at(i); |  | 
| 72     switch (var->location()) { | 70     switch (var->location()) { | 
| 73       case VariableLocation::LOCAL: | 71       case VariableLocation::LOCAL: | 
| 74         if (stack_local_count == 0) first_slot_index = var->index(); | 72         if (stack_local_count == 0) first_slot_index = var->index(); | 
| 75         stack_local_count++; | 73         stack_local_count++; | 
| 76         break; | 74         break; | 
| 77       case VariableLocation::CONTEXT: | 75       case VariableLocation::CONTEXT: | 
| 78         context_local_count++; | 76         context_local_count++; | 
| 79         break; | 77         break; | 
| 80       case VariableLocation::MODULE: | 78       case VariableLocation::MODULE: | 
| 81         module_vars_count++; | 79         module_vars_count++; | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 191   // Context locals are added using their index. | 189   // Context locals are added using their index. | 
| 192   DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 190   DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 
| 193   scope_info->set(index++, Smi::FromInt(first_slot_index)); | 191   scope_info->set(index++, Smi::FromInt(first_slot_index)); | 
| 194   DCHECK_EQ(index, scope_info->StackLocalNamesIndex()); | 192   DCHECK_EQ(index, scope_info->StackLocalNamesIndex()); | 
| 195 | 193 | 
| 196   int stack_local_base = index; | 194   int stack_local_base = index; | 
| 197   int context_local_base = stack_local_base + stack_local_count; | 195   int context_local_base = stack_local_base + stack_local_count; | 
| 198   int context_local_info_base = context_local_base + context_local_count; | 196   int context_local_info_base = context_local_base + context_local_count; | 
| 199   int module_var_entry = scope_info->ModuleVariablesIndex(); | 197   int module_var_entry = scope_info->ModuleVariablesIndex(); | 
| 200 | 198 | 
| 201   for (int i = 0; i < locals->length(); ++i) { | 199   for (Variable* var : *scope->locals()) { | 
| 202     Variable* var = locals->at(i); |  | 
| 203     switch (var->location()) { | 200     switch (var->location()) { | 
| 204       case VariableLocation::LOCAL: { | 201       case VariableLocation::LOCAL: { | 
| 205         int local_index = var->index() - first_slot_index; | 202         int local_index = var->index() - first_slot_index; | 
| 206         DCHECK_LE(0, local_index); | 203         DCHECK_LE(0, local_index); | 
| 207         DCHECK_LT(local_index, stack_local_count); | 204         DCHECK_LT(local_index, stack_local_count); | 
| 208         scope_info->set(stack_local_base + local_index, *var->name()); | 205         scope_info->set(stack_local_base + local_index, *var->name()); | 
| 209         break; | 206         break; | 
| 210       } | 207       } | 
| 211       case VariableLocation::CONTEXT: { | 208       case VariableLocation::CONTEXT: { | 
| 212         // Due to duplicate parameters, context locals aren't guaranteed to come | 209         // Due to duplicate parameters, context locals aren't guaranteed to come | 
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 945     if (String::cast(entry->local_name())->Equals(*local_name)) { | 942     if (String::cast(entry->local_name())->Equals(*local_name)) { | 
| 946       return entry; | 943       return entry; | 
| 947     } | 944     } | 
| 948   } | 945   } | 
| 949   UNREACHABLE(); | 946   UNREACHABLE(); | 
| 950   return Handle<ModuleInfoEntry>(); | 947   return Handle<ModuleInfoEntry>(); | 
| 951 } | 948 } | 
| 952 | 949 | 
| 953 }  // namespace internal | 950 }  // namespace internal | 
| 954 }  // namespace v8 | 951 }  // namespace v8 | 
| OLD | NEW | 
|---|