| 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 "src/ast/scopeinfo.h" | 5 #include "src/ast/scopeinfo.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "src/ast/context-slot-cache.h" | 9 #include "src/ast/context-slot-cache.h" |
| 10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } else { | 46 } else { |
| 47 receiver_info = NONE; | 47 receiver_info = NONE; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool has_new_target = | 50 bool has_new_target = |
| 51 scope->is_declaration_scope() && | 51 scope->is_declaration_scope() && |
| 52 scope->AsDeclarationScope()->new_target_var() != nullptr; | 52 scope->AsDeclarationScope()->new_target_var() != nullptr; |
| 53 | 53 |
| 54 // Determine use and location of the function variable if it is present. | 54 // Determine use and location of the function variable if it is present. |
| 55 VariableAllocationInfo function_name_info; | 55 VariableAllocationInfo function_name_info; |
| 56 VariableMode function_variable_mode; | |
| 57 if (scope->is_function_scope() && | 56 if (scope->is_function_scope() && |
| 58 scope->AsDeclarationScope()->function_var() != nullptr) { | 57 scope->AsDeclarationScope()->function_var() != nullptr) { |
| 59 Variable* var = scope->AsDeclarationScope()->function_var(); | 58 Variable* var = scope->AsDeclarationScope()->function_var(); |
| 60 if (!var->is_used()) { | 59 if (!var->is_used()) { |
| 61 function_name_info = UNUSED; | 60 function_name_info = UNUSED; |
| 62 } else if (var->IsContextSlot()) { | 61 } else if (var->IsContextSlot()) { |
| 63 function_name_info = CONTEXT; | 62 function_name_info = CONTEXT; |
| 64 } else { | 63 } else { |
| 65 DCHECK(var->IsStackLocal()); | 64 DCHECK(var->IsStackLocal()); |
| 66 function_name_info = STACK; | 65 function_name_info = STACK; |
| 67 } | 66 } |
| 68 function_variable_mode = var->mode(); | |
| 69 } else { | 67 } else { |
| 70 function_name_info = NONE; | 68 function_name_info = NONE; |
| 71 function_variable_mode = VAR; | |
| 72 } | 69 } |
| 73 DCHECK(context_global_count == 0 || scope->scope_type() == SCRIPT_SCOPE); | 70 DCHECK(context_global_count == 0 || scope->scope_type() == SCRIPT_SCOPE); |
| 74 | 71 |
| 75 const bool has_function_name = function_name_info != NONE; | 72 const bool has_function_name = function_name_info != NONE; |
| 76 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; | 73 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; |
| 77 const int parameter_count = scope->num_parameters(); | 74 const int parameter_count = scope->num_parameters(); |
| 78 const int length = kVariablePartIndex + parameter_count + | 75 const int length = kVariablePartIndex + parameter_count + |
| 79 (1 + stack_local_count) + 2 * context_local_count + | 76 (1 + stack_local_count) + 2 * context_local_count + |
| 80 2 * context_global_count + | 77 2 * context_global_count + |
| 81 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 78 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 : kNormalFunction; | 89 : kNormalFunction; |
| 93 | 90 |
| 94 // Encode the flags. | 91 // Encode the flags. |
| 95 int flags = ScopeTypeField::encode(scope->scope_type()) | | 92 int flags = ScopeTypeField::encode(scope->scope_type()) | |
| 96 CallsEvalField::encode(scope->calls_eval()) | | 93 CallsEvalField::encode(scope->calls_eval()) | |
| 97 LanguageModeField::encode(scope->language_mode()) | | 94 LanguageModeField::encode(scope->language_mode()) | |
| 98 DeclarationScopeField::encode(scope->is_declaration_scope()) | | 95 DeclarationScopeField::encode(scope->is_declaration_scope()) | |
| 99 ReceiverVariableField::encode(receiver_info) | | 96 ReceiverVariableField::encode(receiver_info) | |
| 100 HasNewTargetField::encode(has_new_target) | | 97 HasNewTargetField::encode(has_new_target) | |
| 101 FunctionVariableField::encode(function_name_info) | | 98 FunctionVariableField::encode(function_name_info) | |
| 102 FunctionVariableMode::encode(function_variable_mode) | | |
| 103 AsmModuleField::encode(scope->asm_module()) | | 99 AsmModuleField::encode(scope->asm_module()) | |
| 104 AsmFunctionField::encode(scope->asm_function()) | | 100 AsmFunctionField::encode(scope->asm_function()) | |
| 105 HasSimpleParametersField::encode(has_simple_parameters) | | 101 HasSimpleParametersField::encode(has_simple_parameters) | |
| 106 FunctionKindField::encode(function_kind); | 102 FunctionKindField::encode(function_kind); |
| 107 scope_info->SetFlags(flags); | 103 scope_info->SetFlags(flags); |
| 108 scope_info->SetParameterCount(parameter_count); | 104 scope_info->SetParameterCount(parameter_count); |
| 109 scope_info->SetStackLocalCount(stack_local_count); | 105 scope_info->SetStackLocalCount(stack_local_count); |
| 110 scope_info->SetContextLocalCount(context_local_count); | 106 scope_info->SetContextLocalCount(context_local_count); |
| 111 scope_info->SetContextGlobalCount(context_global_count); | 107 scope_info->SetContextGlobalCount(context_global_count); |
| 112 | 108 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 207 |
| 212 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | 208 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
| 213 DCHECK(isolate->bootstrapper()->IsActive()); | 209 DCHECK(isolate->bootstrapper()->IsActive()); |
| 214 | 210 |
| 215 const int stack_local_count = 0; | 211 const int stack_local_count = 0; |
| 216 const int context_local_count = 1; | 212 const int context_local_count = 1; |
| 217 const int context_global_count = 0; | 213 const int context_global_count = 0; |
| 218 const bool has_simple_parameters = true; | 214 const bool has_simple_parameters = true; |
| 219 const VariableAllocationInfo receiver_info = CONTEXT; | 215 const VariableAllocationInfo receiver_info = CONTEXT; |
| 220 const VariableAllocationInfo function_name_info = NONE; | 216 const VariableAllocationInfo function_name_info = NONE; |
| 221 const VariableMode function_variable_mode = VAR; | |
| 222 const bool has_function_name = false; | 217 const bool has_function_name = false; |
| 223 const bool has_receiver = true; | 218 const bool has_receiver = true; |
| 224 const int parameter_count = 0; | 219 const int parameter_count = 0; |
| 225 const int length = kVariablePartIndex + parameter_count + | 220 const int length = kVariablePartIndex + parameter_count + |
| 226 (1 + stack_local_count) + 2 * context_local_count + | 221 (1 + stack_local_count) + 2 * context_local_count + |
| 227 2 * context_global_count + | 222 2 * context_global_count + |
| 228 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 223 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); |
| 229 | 224 |
| 230 Factory* factory = isolate->factory(); | 225 Factory* factory = isolate->factory(); |
| 231 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 226 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
| 232 | 227 |
| 233 // Encode the flags. | 228 // Encode the flags. |
| 234 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | | 229 int flags = ScopeTypeField::encode(SCRIPT_SCOPE) | |
| 235 CallsEvalField::encode(false) | | 230 CallsEvalField::encode(false) | |
| 236 LanguageModeField::encode(SLOPPY) | | 231 LanguageModeField::encode(SLOPPY) | |
| 237 DeclarationScopeField::encode(true) | | 232 DeclarationScopeField::encode(true) | |
| 238 ReceiverVariableField::encode(receiver_info) | | 233 ReceiverVariableField::encode(receiver_info) | |
| 239 FunctionVariableField::encode(function_name_info) | | 234 FunctionVariableField::encode(function_name_info) | |
| 240 FunctionVariableMode::encode(function_variable_mode) | | |
| 241 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | | 235 AsmModuleField::encode(false) | AsmFunctionField::encode(false) | |
| 242 HasSimpleParametersField::encode(has_simple_parameters) | | 236 HasSimpleParametersField::encode(has_simple_parameters) | |
| 243 FunctionKindField::encode(FunctionKind::kNormalFunction); | 237 FunctionKindField::encode(FunctionKind::kNormalFunction); |
| 244 scope_info->SetFlags(flags); | 238 scope_info->SetFlags(flags); |
| 245 scope_info->SetParameterCount(parameter_count); | 239 scope_info->SetParameterCount(parameter_count); |
| 246 scope_info->SetStackLocalCount(stack_local_count); | 240 scope_info->SetStackLocalCount(stack_local_count); |
| 247 scope_info->SetContextLocalCount(context_local_count); | 241 scope_info->SetContextLocalCount(context_local_count); |
| 248 scope_info->SetContextGlobalCount(context_global_count); | 242 scope_info->SetContextGlobalCount(context_global_count); |
| 249 | 243 |
| 250 int index = kVariablePartIndex; | 244 int index = kVariablePartIndex; |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 return -1; | 573 return -1; |
| 580 } | 574 } |
| 581 | 575 |
| 582 | 576 |
| 583 int ScopeInfo::ReceiverContextSlotIndex() { | 577 int ScopeInfo::ReceiverContextSlotIndex() { |
| 584 if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) | 578 if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) |
| 585 return Smi::cast(get(ReceiverEntryIndex()))->value(); | 579 return Smi::cast(get(ReceiverEntryIndex()))->value(); |
| 586 return -1; | 580 return -1; |
| 587 } | 581 } |
| 588 | 582 |
| 589 | 583 int ScopeInfo::FunctionContextSlotIndex(String* name) { |
| 590 int ScopeInfo::FunctionContextSlotIndex(String* name, VariableMode* mode) { | |
| 591 DCHECK(name->IsInternalizedString()); | 584 DCHECK(name->IsInternalizedString()); |
| 592 DCHECK(mode != NULL); | |
| 593 if (length() > 0) { | 585 if (length() > 0) { |
| 594 if (FunctionVariableField::decode(Flags()) == CONTEXT && | 586 if (FunctionVariableField::decode(Flags()) == CONTEXT && |
| 595 FunctionName() == name) { | 587 FunctionName() == name) { |
| 596 *mode = FunctionVariableMode::decode(Flags()); | |
| 597 return Smi::cast(get(FunctionNameEntryIndex() + 1))->value(); | 588 return Smi::cast(get(FunctionNameEntryIndex() + 1))->value(); |
| 598 } | 589 } |
| 599 } | 590 } |
| 600 return -1; | 591 return -1; |
| 601 } | 592 } |
| 602 | 593 |
| 603 | 594 |
| 604 FunctionKind ScopeInfo::function_kind() { | 595 FunctionKind ScopeInfo::function_kind() { |
| 605 return FunctionKindField::decode(Flags()); | 596 return FunctionKindField::decode(Flags()); |
| 606 } | 597 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); | 682 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); |
| 692 } | 683 } |
| 693 | 684 |
| 694 PrintF("}\n"); | 685 PrintF("}\n"); |
| 695 } | 686 } |
| 696 #endif // DEBUG | 687 #endif // DEBUG |
| 697 | 688 |
| 698 | 689 |
| 699 } // namespace internal | 690 } // namespace internal |
| 700 } // namespace v8 | 691 } // namespace v8 |
| OLD | NEW |