| 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/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } else { | 52 } else { |
| 53 receiver_info = NONE; | 53 receiver_info = NONE; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool has_new_target = | 56 bool has_new_target = |
| 57 scope->is_declaration_scope() && | 57 scope->is_declaration_scope() && |
| 58 scope->AsDeclarationScope()->new_target_var() != nullptr; | 58 scope->AsDeclarationScope()->new_target_var() != nullptr; |
| 59 | 59 |
| 60 // Determine use and location of the function variable if it is present. | 60 // Determine use and location of the function variable if it is present. |
| 61 VariableAllocationInfo function_name_info; | 61 VariableAllocationInfo function_name_info; |
| 62 VariableMode function_variable_mode; | |
| 63 if (scope->is_function_scope() && | 62 if (scope->is_function_scope() && |
| 64 scope->AsDeclarationScope()->function_var() != nullptr) { | 63 scope->AsDeclarationScope()->function_var() != nullptr) { |
| 65 Variable* var = scope->AsDeclarationScope()->function_var(); | 64 Variable* var = scope->AsDeclarationScope()->function_var(); |
| 66 if (!var->is_used()) { | 65 if (!var->is_used()) { |
| 67 function_name_info = UNUSED; | 66 function_name_info = UNUSED; |
| 68 } else if (var->IsContextSlot()) { | 67 } else if (var->IsContextSlot()) { |
| 69 function_name_info = CONTEXT; | 68 function_name_info = CONTEXT; |
| 70 } else { | 69 } else { |
| 71 DCHECK(var->IsStackLocal()); | 70 DCHECK(var->IsStackLocal()); |
| 72 function_name_info = STACK; | 71 function_name_info = STACK; |
| 73 } | 72 } |
| 74 function_variable_mode = var->mode(); | |
| 75 } else { | 73 } else { |
| 76 function_name_info = NONE; | 74 function_name_info = NONE; |
| 77 function_variable_mode = VAR; | |
| 78 } | 75 } |
| 79 | 76 |
| 80 const bool has_function_name = function_name_info != NONE; | 77 const bool has_function_name = function_name_info != NONE; |
| 81 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; | 78 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; |
| 82 const int parameter_count = scope->num_parameters(); | 79 const int parameter_count = scope->num_parameters(); |
| 83 const int length = kVariablePartIndex + parameter_count + | 80 const int length = kVariablePartIndex + parameter_count + |
| 84 (1 + stack_local_count) + 2 * context_local_count + | 81 (1 + stack_local_count) + 2 * context_local_count + |
| 85 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 82 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); |
| 86 | 83 |
| 87 Factory* factory = isolate->factory(); | 84 Factory* factory = isolate->factory(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 } | 97 } |
| 101 | 98 |
| 102 // Encode the flags. | 99 // Encode the flags. |
| 103 int flags = ScopeTypeField::encode(scope->scope_type()) | | 100 int flags = ScopeTypeField::encode(scope->scope_type()) | |
| 104 CallsEvalField::encode(scope->calls_eval()) | | 101 CallsEvalField::encode(scope->calls_eval()) | |
| 105 LanguageModeField::encode(scope->language_mode()) | | 102 LanguageModeField::encode(scope->language_mode()) | |
| 106 DeclarationScopeField::encode(scope->is_declaration_scope()) | | 103 DeclarationScopeField::encode(scope->is_declaration_scope()) | |
| 107 ReceiverVariableField::encode(receiver_info) | | 104 ReceiverVariableField::encode(receiver_info) | |
| 108 HasNewTargetField::encode(has_new_target) | | 105 HasNewTargetField::encode(has_new_target) | |
| 109 FunctionVariableField::encode(function_name_info) | | 106 FunctionVariableField::encode(function_name_info) | |
| 110 FunctionVariableMode::encode(function_variable_mode) | | |
| 111 AsmModuleField::encode(asm_module) | | 107 AsmModuleField::encode(asm_module) | |
| 112 AsmFunctionField::encode(asm_function) | | 108 AsmFunctionField::encode(asm_function) | |
| 113 HasSimpleParametersField::encode(has_simple_parameters) | | 109 HasSimpleParametersField::encode(has_simple_parameters) | |
| 114 FunctionKindField::encode(function_kind); | 110 FunctionKindField::encode(function_kind); |
| 115 scope_info->SetFlags(flags); | 111 scope_info->SetFlags(flags); |
| 116 scope_info->SetParameterCount(parameter_count); | 112 scope_info->SetParameterCount(parameter_count); |
| 117 scope_info->SetStackLocalCount(stack_local_count); | 113 scope_info->SetStackLocalCount(stack_local_count); |
| 118 scope_info->SetContextLocalCount(context_local_count); | 114 scope_info->SetContextLocalCount(context_local_count); |
| 119 | 115 |
| 120 int index = kVariablePartIndex; | 116 int index = kVariablePartIndex; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 187 |
| 192 | 188 |
| 193 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | 189 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
| 194 DCHECK(isolate->bootstrapper()->IsActive()); | 190 DCHECK(isolate->bootstrapper()->IsActive()); |
| 195 | 191 |
| 196 const int stack_local_count = 0; | 192 const int stack_local_count = 0; |
| 197 const int context_local_count = 1; | 193 const int context_local_count = 1; |
| 198 const bool has_simple_parameters = true; | 194 const bool has_simple_parameters = true; |
| 199 const VariableAllocationInfo receiver_info = CONTEXT; | 195 const VariableAllocationInfo receiver_info = CONTEXT; |
| 200 const VariableAllocationInfo function_name_info = NONE; | 196 const VariableAllocationInfo function_name_info = NONE; |
| 201 const VariableMode function_variable_mode = VAR; | |
| 202 const bool has_function_name = false; | 197 const bool has_function_name = false; |
| 203 const bool has_receiver = true; | 198 const bool has_receiver = true; |
| 204 const int parameter_count = 0; | 199 const int parameter_count = 0; |
| 205 const int length = kVariablePartIndex + parameter_count + | 200 const int length = kVariablePartIndex + parameter_count + |
| 206 (1 + stack_local_count) + 2 * context_local_count + | 201 (1 + stack_local_count) + 2 * context_local_count + |
| 207 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 202 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); |
| 208 | 203 |
| 209 Factory* factory = isolate->factory(); | 204 Factory* factory = isolate->factory(); |
| 210 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 205 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
| 211 | 206 |
| 212 // Encode the flags. | 207 // Encode the flags. |
| 213 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | | 208 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | |
| 214 CallsEvalField::encode(false) | | 209 CallsEvalField::encode(false) | |
| 215 LanguageModeField::encode(SLOPPY) | | 210 LanguageModeField::encode(SLOPPY) | |
| 216 DeclarationScopeField::encode(true) | | 211 DeclarationScopeField::encode(true) | |
| 217 ReceiverVariableField::encode(receiver_info) | | 212 ReceiverVariableField::encode(receiver_info) | |
| 218 FunctionVariableField::encode(function_name_info) | | 213 FunctionVariableField::encode(function_name_info) | |
| 219 FunctionVariableMode::encode(function_variable_mode) | | |
| 220 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | | 214 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | |
| 221 HasSimpleParametersField::encode(has_simple_parameters) | | 215 HasSimpleParametersField::encode(has_simple_parameters) | |
| 222 FunctionKindField::encode(FunctionKind::kNormalFunction); | 216 FunctionKindField::encode(FunctionKind::kNormalFunction); |
| 223 scope_info->SetFlags(flags); | 217 scope_info->SetFlags(flags); |
| 224 scope_info->SetParameterCount(parameter_count); | 218 scope_info->SetParameterCount(parameter_count); |
| 225 scope_info->SetStackLocalCount(stack_local_count); | 219 scope_info->SetStackLocalCount(stack_local_count); |
| 226 scope_info->SetContextLocalCount(context_local_count); | 220 scope_info->SetContextLocalCount(context_local_count); |
| 227 | 221 |
| 228 int index = kVariablePartIndex; | 222 int index = kVariablePartIndex; |
| 229 const int first_slot_index = 0; | 223 const int first_slot_index = 0; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 return -1; | 526 return -1; |
| 533 } | 527 } |
| 534 | 528 |
| 535 | 529 |
| 536 int ScopeInfo::ReceiverContextSlotIndex() { | 530 int ScopeInfo::ReceiverContextSlotIndex() { |
| 537 if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) | 531 if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) |
| 538 return Smi::cast(get(ReceiverEntryIndex()))->value(); | 532 return Smi::cast(get(ReceiverEntryIndex()))->value(); |
| 539 return -1; | 533 return -1; |
| 540 } | 534 } |
| 541 | 535 |
| 542 | 536 int ScopeInfo::FunctionContextSlotIndex(String* name) { |
| 543 int ScopeInfo::FunctionContextSlotIndex(String* name, VariableMode* mode) { | |
| 544 DCHECK(name->IsInternalizedString()); | 537 DCHECK(name->IsInternalizedString()); |
| 545 DCHECK_NOT_NULL(mode); | |
| 546 if (length() > 0) { | 538 if (length() > 0) { |
| 547 if (FunctionVariableField::decode(Flags()) == CONTEXT && | 539 if (FunctionVariableField::decode(Flags()) == CONTEXT && |
| 548 FunctionName() == name) { | 540 FunctionName() == name) { |
| 549 *mode = FunctionVariableMode::decode(Flags()); | |
| 550 return Smi::cast(get(FunctionNameEntryIndex() + 1))->value(); | 541 return Smi::cast(get(FunctionNameEntryIndex() + 1))->value(); |
| 551 } | 542 } |
| 552 } | 543 } |
| 553 return -1; | 544 return -1; |
| 554 } | 545 } |
| 555 | 546 |
| 556 | 547 |
| 557 FunctionKind ScopeInfo::function_kind() { | 548 FunctionKind ScopeInfo::function_kind() { |
| 558 return FunctionKindField::decode(Flags()); | 549 return FunctionKindField::decode(Flags()); |
| 559 } | 550 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); | 625 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); |
| 635 } | 626 } |
| 636 | 627 |
| 637 PrintF("}\n"); | 628 PrintF("}\n"); |
| 638 } | 629 } |
| 639 #endif // DEBUG | 630 #endif // DEBUG |
| 640 | 631 |
| 641 | 632 |
| 642 } // namespace internal | 633 } // namespace internal |
| 643 } // namespace v8 | 634 } // namespace v8 |
| OLD | NEW |