OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "vm/kernel_to_il.h" | 9 #include "vm/kernel_to_il.h" |
10 | 10 |
11 #include "vm/compiler.h" | 11 #include "vm/compiler.h" |
12 #include "vm/intermediate_language.h" | 12 #include "vm/intermediate_language.h" |
13 #include "vm/kernel_reader.h" | 13 #include "vm/kernel_reader.h" |
14 #include "vm/longjump.h" | 14 #include "vm/longjump.h" |
15 #include "vm/method_recognizer.h" | 15 #include "vm/method_recognizer.h" |
16 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
17 #include "vm/report.h" | 17 #include "vm/report.h" |
18 #include "vm/resolver.h" | 18 #include "vm/resolver.h" |
19 #include "vm/stack_frame.h" | 19 #include "vm/stack_frame.h" |
20 | 20 |
| 21 #if !defined(DART_PRECOMPILED_RUNTIME) |
21 namespace dart { | 22 namespace dart { |
22 | 23 |
23 DECLARE_FLAG(bool, support_externalizable_strings); | 24 DECLARE_FLAG(bool, support_externalizable_strings); |
24 | 25 |
25 namespace kernel { | 26 namespace kernel { |
26 | 27 |
27 #define Z (zone_) | 28 #define Z (zone_) |
28 #define H (translation_helper_) | 29 #define H (translation_helper_) |
29 #define T (type_translator_) | 30 #define T (type_translator_) |
30 #define I Isolate::Current() | 31 #define I Isolate::Current() |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 node->finalizer()->AcceptStatementVisitor(this); | 639 node->finalizer()->AcceptStatementVisitor(this); |
639 --depth_.catch_; | 640 --depth_.catch_; |
640 } | 641 } |
641 | 642 |
642 | 643 |
643 void ScopeBuilder::VisitFunctionNode(FunctionNode* node) { | 644 void ScopeBuilder::VisitFunctionNode(FunctionNode* node) { |
644 List<TypeParameter>& type_parameters = node->type_parameters(); | 645 List<TypeParameter>& type_parameters = node->type_parameters(); |
645 for (intptr_t i = 0; i < type_parameters.length(); ++i) { | 646 for (intptr_t i = 0; i < type_parameters.length(); ++i) { |
646 VisitTypeParameter(type_parameters[i]); | 647 VisitTypeParameter(type_parameters[i]); |
647 } | 648 } |
| 649 |
| 650 if (node->async_marker() == FunctionNode::kSyncYielding) { |
| 651 LocalScope* scope = parsed_function_->node_sequence()->scope(); |
| 652 for (intptr_t i = 0; |
| 653 i < parsed_function_->function().NumOptionalPositionalParameters(); |
| 654 i++) { |
| 655 scope->VariableAt(i)->set_is_forced_stack(); |
| 656 } |
| 657 } |
| 658 |
648 // Do not visit the positional and named parameters, because they've | 659 // Do not visit the positional and named parameters, because they've |
649 // already been added to the scope. | 660 // already been added to the scope. |
650 if (node->body() != NULL) { | 661 if (node->body() != NULL) { |
651 node->body()->AcceptStatementVisitor(this); | 662 node->body()->AcceptStatementVisitor(this); |
652 } | 663 } |
653 | 664 |
654 // Ensure that :await_jump_var and :await_ctx_var are captured. | 665 // Ensure that :await_jump_var and :await_ctx_var are captured. |
655 if (node->async_marker() == FunctionNode::kSyncYielding) { | 666 if (node->async_marker() == FunctionNode::kSyncYielding) { |
656 { | 667 { |
657 LocalVariable* temp = NULL; | 668 LocalVariable* temp = NULL; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 Library* kernel_library = Library::Cast(kernel_klass->parent()); | 1109 Library* kernel_library = Library::Cast(kernel_klass->parent()); |
1099 dart::Library& library = | 1110 dart::Library& library = |
1100 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); | 1111 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); |
1101 klass = library.LookupClassAllowPrivate(class_name); | 1112 klass = library.LookupClassAllowPrivate(class_name); |
1102 | 1113 |
1103 ASSERT(klass != Object::null()); | 1114 ASSERT(klass != Object::null()); |
1104 return klass; | 1115 return klass; |
1105 } | 1116 } |
1106 | 1117 |
1107 | 1118 |
| 1119 dart::RawUnresolvedClass* TranslationHelper::ToUnresolvedClass( |
| 1120 Class* kernel_klass) { |
| 1121 dart::RawClass* klass = NULL; |
| 1122 |
| 1123 const dart::String& class_name = DartClassName(kernel_klass); |
| 1124 Library* kernel_library = Library::Cast(kernel_klass->parent()); |
| 1125 dart::Library& library = |
| 1126 dart::Library::Handle(Z, LookupLibraryByKernelLibrary(kernel_library)); |
| 1127 |
| 1128 ASSERT(klass != Object::null()); |
| 1129 return dart::UnresolvedClass::New(library, class_name, |
| 1130 TokenPosition::kNoSource); |
| 1131 } |
| 1132 |
| 1133 |
1108 dart::RawField* TranslationHelper::LookupFieldByKernelField( | 1134 dart::RawField* TranslationHelper::LookupFieldByKernelField( |
1109 Field* kernel_field) { | 1135 Field* kernel_field) { |
1110 TreeNode* node = kernel_field->parent(); | 1136 TreeNode* node = kernel_field->parent(); |
1111 | 1137 |
1112 dart::Class& klass = dart::Class::Handle(Z); | 1138 dart::Class& klass = dart::Class::Handle(Z); |
1113 if (node->IsClass()) { | 1139 if (node->IsClass()) { |
1114 klass = LookupClassByKernelClass(Class::Cast(node)); | 1140 klass = LookupClassByKernelClass(Class::Cast(node)); |
1115 } else { | 1141 } else { |
1116 ASSERT(node->IsLibrary()); | 1142 ASSERT(node->IsLibrary()); |
1117 dart::Library& library = dart::Library::Handle( | 1143 dart::Library& library = dart::Library::Handle( |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 stack_(NULL), | 1858 stack_(NULL), |
1833 pending_argument_count_(0), | 1859 pending_argument_count_(0), |
1834 graph_entry_(NULL), | 1860 graph_entry_(NULL), |
1835 scopes_(NULL), | 1861 scopes_(NULL), |
1836 breakable_block_(NULL), | 1862 breakable_block_(NULL), |
1837 switch_block_(NULL), | 1863 switch_block_(NULL), |
1838 try_finally_block_(NULL), | 1864 try_finally_block_(NULL), |
1839 try_catch_block_(NULL), | 1865 try_catch_block_(NULL), |
1840 next_used_try_index_(0), | 1866 next_used_try_index_(0), |
1841 catch_block_(NULL), | 1867 catch_block_(NULL), |
1842 type_translator_(&translation_helper_, &active_class_), | 1868 type_translator_(&translation_helper_, |
| 1869 &active_class_, |
| 1870 /* finalize= */ true), |
1843 constant_evaluator_(this, | 1871 constant_evaluator_(this, |
1844 zone_, | 1872 zone_, |
1845 &translation_helper_, | 1873 &translation_helper_, |
1846 &type_translator_) {} | 1874 &type_translator_) {} |
1847 | 1875 |
1848 | 1876 |
1849 FlowGraphBuilder::~FlowGraphBuilder() {} | 1877 FlowGraphBuilder::~FlowGraphBuilder() {} |
1850 | 1878 |
1851 | 1879 |
1852 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( | 1880 Fragment FlowGraphBuilder::TranslateFinallyFinalizers( |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3834 // We return a new `ZoneHandle` here on purpose: The intermediate language | 3862 // We return a new `ZoneHandle` here on purpose: The intermediate language |
3835 // instructions do not make a copy of the handle, so we do it. | 3863 // instructions do not make a copy of the handle, so we do it. |
3836 return dart::AbstractType::ZoneHandle(Z, result_.raw()); | 3864 return dart::AbstractType::ZoneHandle(Z, result_.raw()); |
3837 } | 3865 } |
3838 | 3866 |
3839 | 3867 |
3840 AbstractType& DartTypeTranslator::TranslateTypeWithoutFinalization( | 3868 AbstractType& DartTypeTranslator::TranslateTypeWithoutFinalization( |
3841 DartType* node) { | 3869 DartType* node) { |
3842 bool saved_finalize = finalize_; | 3870 bool saved_finalize = finalize_; |
3843 finalize_ = false; | 3871 finalize_ = false; |
3844 H.SetFinalize(false); | |
3845 AbstractType& result = TranslateType(node); | 3872 AbstractType& result = TranslateType(node); |
3846 finalize_ = saved_finalize; | 3873 finalize_ = saved_finalize; |
3847 H.SetFinalize(saved_finalize); | |
3848 return result; | 3874 return result; |
3849 } | 3875 } |
3850 | 3876 |
3851 | 3877 |
3852 const AbstractType& DartTypeTranslator::TranslateVariableType( | 3878 const AbstractType& DartTypeTranslator::TranslateVariableType( |
3853 VariableDeclaration* variable) { | 3879 VariableDeclaration* variable) { |
3854 AbstractType& abstract_type = TranslateType(variable->type()); | 3880 AbstractType& abstract_type = TranslateType(variable->type()); |
3855 | 3881 |
3856 // We return a new `ZoneHandle` here on purpose: The intermediate language | 3882 // We return a new `ZoneHandle` here on purpose: The intermediate language |
3857 // instructions do not make a copy of the handle, so we do it. | 3883 // instructions do not make a copy of the handle, so we do it. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3993 } | 4019 } |
3994 | 4020 |
3995 | 4021 |
3996 void DartTypeTranslator::VisitInterfaceType(InterfaceType* node) { | 4022 void DartTypeTranslator::VisitInterfaceType(InterfaceType* node) { |
3997 // NOTE: That an interface type like `T<A, B>` is considered to be | 4023 // NOTE: That an interface type like `T<A, B>` is considered to be |
3998 // malformed iff `T` is malformed. | 4024 // malformed iff `T` is malformed. |
3999 // => We therefore ignore errors in `A` or `B`. | 4025 // => We therefore ignore errors in `A` or `B`. |
4000 const TypeArguments& type_arguments = TranslateTypeArguments( | 4026 const TypeArguments& type_arguments = TranslateTypeArguments( |
4001 node->type_arguments().raw_array(), node->type_arguments().length()); | 4027 node->type_arguments().raw_array(), node->type_arguments().length()); |
4002 | 4028 |
4003 const dart::Class& klass = | |
4004 dart::Class::Handle(Z, H.LookupClassByKernelClass(node->klass())); | |
4005 | 4029 |
| 4030 dart::Object& klass = |
| 4031 dart::Object::Handle(Z, H.ToUnresolvedClass(node->klass())); |
4006 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); | 4032 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); |
4007 result_.SetIsResolved(); | |
4008 if (finalize_) { | 4033 if (finalize_) { |
4009 result_ = ClassFinalizer::FinalizeType(klass, result_, | 4034 ASSERT(active_class_->klass != NULL); |
| 4035 result_ = ClassFinalizer::FinalizeType(*active_class_->klass, result_, |
4010 ClassFinalizer::kCanonicalize); | 4036 ClassFinalizer::kCanonicalize); |
4011 } | 4037 } |
4012 } | 4038 } |
4013 | 4039 |
4014 | 4040 |
4015 void DartTypeTranslator::VisitDynamicType(DynamicType* node) { | 4041 void DartTypeTranslator::VisitDynamicType(DynamicType* node) { |
4016 result_ = Object::dynamic_type().raw(); | 4042 result_ = Object::dynamic_type().raw(); |
4017 } | 4043 } |
4018 | 4044 |
4019 | 4045 |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5626 // ... | 5652 // ... |
5627 // } | 5653 // } |
5628 // | 5654 // |
5629 LocalScope* scope = parsed_function_->node_sequence()->scope(); | 5655 LocalScope* scope = parsed_function_->node_sequence()->scope(); |
5630 LocalVariable* exception_var = scope->VariableAt(2); | 5656 LocalVariable* exception_var = scope->VariableAt(2); |
5631 LocalVariable* stack_trace_var = scope->VariableAt(3); | 5657 LocalVariable* stack_trace_var = scope->VariableAt(3); |
5632 ASSERT(exception_var->name().raw() == Symbols::ExceptionParameter().raw()); | 5658 ASSERT(exception_var->name().raw() == Symbols::ExceptionParameter().raw()); |
5633 ASSERT(stack_trace_var->name().raw() == | 5659 ASSERT(stack_trace_var->name().raw() == |
5634 Symbols::StackTraceParameter().raw()); | 5660 Symbols::StackTraceParameter().raw()); |
5635 | 5661 |
5636 exception_var->set_is_forced_stack(); | |
5637 stack_trace_var->set_is_forced_stack(); | |
5638 | |
5639 TargetEntryInstr* no_error; | 5662 TargetEntryInstr* no_error; |
5640 TargetEntryInstr* error; | 5663 TargetEntryInstr* error; |
5641 | 5664 |
5642 continuation += LoadLocal(exception_var); | 5665 continuation += LoadLocal(exception_var); |
5643 continuation += BranchIfNull(&no_error, &error); | 5666 continuation += BranchIfNull(&no_error, &error); |
5644 | 5667 |
5645 Fragment rethrow(error); | 5668 Fragment rethrow(error); |
5646 rethrow += LoadLocal(exception_var); | 5669 rethrow += LoadLocal(exception_var); |
5647 rethrow += PushArgument(); | 5670 rethrow += PushArgument(); |
5648 rethrow += LoadLocal(stack_trace_var); | 5671 rethrow += LoadLocal(stack_trace_var); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5718 instructions += LoadLocal(closure); | 5741 instructions += LoadLocal(closure); |
5719 instructions += LoadLocal(parsed_function_->current_context_var()); | 5742 instructions += LoadLocal(parsed_function_->current_context_var()); |
5720 instructions += StoreInstanceField(Closure::context_offset()); | 5743 instructions += StoreInstanceField(Closure::context_offset()); |
5721 | 5744 |
5722 return instructions; | 5745 return instructions; |
5723 } | 5746 } |
5724 | 5747 |
5725 | 5748 |
5726 } // namespace kernel | 5749 } // namespace kernel |
5727 } // namespace dart | 5750 } // namespace dart |
| 5751 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |