| 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 "vm/kernel_reader.h" | 5 #include "vm/kernel_reader.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 TranslationHelper translation_helper_; | 79 TranslationHelper translation_helper_; |
| 80 dart::Zone* zone_; | 80 dart::Zone* zone_; |
| 81 bool is_simple_; | 81 bool is_simple_; |
| 82 dart::Instance* simple_value_; | 82 dart::Instance* simple_value_; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 | 85 |
| 86 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( | 86 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( |
| 87 Library* library) { | 87 CanonicalName* library) { |
| 88 return reader_->LookupLibrary(library).raw(); | 88 return reader_->LookupLibrary(library).raw(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) { | 92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass( |
| 93 CanonicalName* klass) { |
| 93 return reader_->LookupClass(klass).raw(); | 94 return reader_->LookupClass(klass).raw(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 KernelReader::KernelReader(Program* program) | 97 KernelReader::KernelReader(Program* program) |
| 97 : program_(program), | 98 : program_(program), |
| 98 thread_(dart::Thread::Current()), | 99 thread_(dart::Thread::Current()), |
| 99 zone_(thread_->zone()), | 100 zone_(thread_->zone()), |
| 100 isolate_(thread_->isolate()), | 101 isolate_(thread_->isolate()), |
| 101 scripts_(Array::ZoneHandle(zone_)), | 102 scripts_(Array::ZoneHandle(zone_)), |
| 102 translation_helper_(this, thread_), | 103 translation_helper_(this, thread_), |
| 103 type_translator_(&translation_helper_, | 104 type_translator_(&translation_helper_, |
| 104 &active_class_, | 105 &active_class_, |
| 105 /*finalize=*/false) { | 106 /*finalize=*/false) { |
| 106 intptr_t source_file_count = program_->source_table().size(); | 107 intptr_t source_file_count = program_->source_table().size(); |
| 107 scripts_ = Array::New(source_file_count, Heap::kOld); | 108 scripts_ = Array::New(source_file_count, Heap::kOld); |
| 108 } | 109 } |
| 109 | 110 |
| 110 Object& KernelReader::ReadProgram() { | 111 Object& KernelReader::ReadProgram() { |
| 111 LongJumpScope jump; | 112 LongJumpScope jump; |
| 112 if (setjmp(*jump.Set()) == 0) { | 113 if (setjmp(*jump.Set()) == 0) { |
| 113 Procedure* main = program_->main_method(); | |
| 114 Library* kernel_main_library = Library::Cast(main->parent()); | |
| 115 | |
| 116 intptr_t length = program_->libraries().length(); | 114 intptr_t length = program_->libraries().length(); |
| 117 for (intptr_t i = 0; i < length; i++) { | 115 for (intptr_t i = 0; i < length; i++) { |
| 118 Library* kernel_library = program_->libraries()[i]; | 116 Library* kernel_library = program_->libraries()[i]; |
| 119 ReadLibrary(kernel_library); | 117 ReadLibrary(kernel_library); |
| 120 } | 118 } |
| 121 | 119 |
| 122 for (intptr_t i = 0; i < length; i++) { | 120 for (intptr_t i = 0; i < length; i++) { |
| 123 dart::Library& library = LookupLibrary(program_->libraries()[i]); | 121 dart::Library& library = |
| 122 LookupLibrary(program_->libraries()[i]->canonical_name()); |
| 124 if (!library.Loaded()) library.SetLoaded(); | 123 if (!library.Loaded()) library.SetLoaded(); |
| 125 } | 124 } |
| 126 | 125 |
| 127 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { | 126 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { |
| 128 dart::Library& library = LookupLibrary(kernel_main_library); | 127 Procedure* main = program_->main_method(); |
| 128 Library* kernel_main_library = Library::Cast(main->parent()); |
| 129 dart::Library& library = |
| 130 LookupLibrary(kernel_main_library->canonical_name()); |
| 129 | 131 |
| 130 // Sanity check that we can find the main entrypoint. | 132 // Sanity check that we can find the main entrypoint. |
| 131 Object& main_obj = Object::Handle( | 133 Object& main_obj = Object::Handle( |
| 132 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); | 134 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); |
| 133 ASSERT(!main_obj.IsNull()); | 135 ASSERT(!main_obj.IsNull()); |
| 134 return library; | 136 return library; |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 // Either class finalization failed or we caught a compile error. | 140 // Either class finalization failed or we caught a compile error. |
| 139 // In both cases sticky error would be set. | 141 // In both cases sticky error would be set. |
| 140 Error& error = Error::Handle(Z); | 142 Error& error = Error::Handle(Z); |
| 141 error = thread_->sticky_error(); | 143 error = thread_->sticky_error(); |
| 142 thread_->clear_sticky_error(); | 144 thread_->clear_sticky_error(); |
| 143 return error; | 145 return error; |
| 144 } | 146 } |
| 145 | 147 |
| 146 | 148 |
| 147 void KernelReader::ReadLibrary(Library* kernel_library) { | 149 void KernelReader::ReadLibrary(Library* kernel_library) { |
| 148 dart::Library& library = LookupLibrary(kernel_library); | 150 dart::Library& library = LookupLibrary(kernel_library->canonical_name()); |
| 149 if (library.Loaded()) return; | 151 if (library.Loaded()) return; |
| 150 | 152 |
| 151 // The bootstrapper will take care of creating the native wrapper classes, but | 153 // The bootstrapper will take care of creating the native wrapper classes, but |
| 152 // we will add the synthetic constructors to them here. | 154 // we will add the synthetic constructors to them here. |
| 153 if (library.name() == | 155 if (library.name() == |
| 154 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { | 156 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { |
| 155 ASSERT(library.LoadInProgress()); | 157 ASSERT(library.LoadInProgress()); |
| 156 } else { | 158 } else { |
| 157 library.SetLoadInProgress(); | 159 library.SetLoadInProgress(); |
| 158 } | 160 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 interfaces.SetAt(i, type); | 278 interfaces.SetAt(i, type); |
| 277 } | 279 } |
| 278 klass->set_interfaces(interfaces); | 280 klass->set_interfaces(interfaces); |
| 279 if (kernel_klass->is_abstract()) klass->set_is_abstract(); | 281 if (kernel_klass->is_abstract()) klass->set_is_abstract(); |
| 280 } | 282 } |
| 281 | 283 |
| 282 | 284 |
| 283 dart::Class& KernelReader::ReadClass(const dart::Library& library, | 285 dart::Class& KernelReader::ReadClass(const dart::Library& library, |
| 284 const dart::Class& toplevel_class, | 286 const dart::Class& toplevel_class, |
| 285 Class* kernel_klass) { | 287 Class* kernel_klass) { |
| 286 // This will trigger a call to [ReadPreliminaryClass] if not already done. | 288 dart::Class& klass = LookupClass(kernel_klass->canonical_name()); |
| 287 dart::Class& klass = LookupClass(kernel_klass); | 289 |
| 290 // The class needs to have a script because all the functions in the class |
| 291 // will inherit it. The predicate Function::IsOptimizable uses the absence of |
| 292 // a script to detect test functions that should not be optimized. |
| 293 if (klass.script() == Script::null()) { |
| 294 klass.set_script(ScriptAt(kernel_klass->source_uri_index())); |
| 295 } |
| 296 if (klass.token_pos() == TokenPosition::kNoSource) { |
| 297 klass.set_token_pos(kernel_klass->position()); |
| 298 } |
| 299 if (!klass.is_cycle_free()) { |
| 300 ReadPreliminaryClass(&klass, kernel_klass); |
| 301 } |
| 288 | 302 |
| 289 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); | 303 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); |
| 290 | 304 |
| 291 if (library.raw() == dart::Library::InternalLibrary() && | 305 if (library.raw() == dart::Library::InternalLibrary() && |
| 292 klass.Name() == Symbols::ClassID().raw()) { | 306 klass.Name() == Symbols::ClassID().raw()) { |
| 293 // If this is a dart:internal.ClassID class ignore field declarations | 307 // If this is a dart:internal.ClassID class ignore field declarations |
| 294 // contained in the Kernel file and instead inject our own const | 308 // contained in the Kernel file and instead inject our own const |
| 295 // fields. | 309 // fields. |
| 296 klass.InjectCIDFields(); | 310 klass.InjectCIDFields(); |
| 297 } else { | 311 } else { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 function.SetParameterNameAt(pos, Symbols::This()); | 744 function.SetParameterNameAt(pos, Symbols::This()); |
| 731 pos++; | 745 pos++; |
| 732 } | 746 } |
| 733 if (is_setter) { | 747 if (is_setter) { |
| 734 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); | 748 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); |
| 735 function.SetParameterNameAt(pos, Symbols::Value()); | 749 function.SetParameterNameAt(pos, Symbols::Value()); |
| 736 pos++; | 750 pos++; |
| 737 } | 751 } |
| 738 } | 752 } |
| 739 | 753 |
| 740 dart::Library& KernelReader::LookupLibrary(Library* library) { | 754 dart::Library& KernelReader::LookupLibrary(CanonicalName* library) { |
| 741 dart::Library* handle = NULL; | 755 dart::Library* handle = NULL; |
| 742 if (!libraries_.Lookup(library, &handle)) { | 756 if (!libraries_.Lookup(library, &handle)) { |
| 743 const dart::String& url = H.DartSymbol(library->import_uri()); | 757 const dart::String& url = H.DartSymbol(library->name()); |
| 744 handle = | 758 handle = |
| 745 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url)); | 759 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url)); |
| 746 if (handle->IsNull()) { | 760 if (handle->IsNull()) { |
| 747 *handle = dart::Library::New(url); | 761 *handle = dart::Library::New(url); |
| 748 handle->Register(thread_); | 762 handle->Register(thread_); |
| 749 handle->SetName(H.DartSymbol(library->name())); | 763 handle->SetName(H.DartSymbol(library->name())); |
| 750 } | 764 } |
| 751 ASSERT(!handle->IsNull()); | 765 ASSERT(!handle->IsNull()); |
| 752 libraries_.Insert(library, handle); | 766 libraries_.Insert(library, handle); |
| 753 } | 767 } |
| 754 return *handle; | 768 return *handle; |
| 755 } | 769 } |
| 756 | 770 |
| 757 dart::Class& KernelReader::LookupClass(Class* klass) { | 771 dart::Class& KernelReader::LookupClass(CanonicalName* klass) { |
| 758 dart::Class* handle = NULL; | 772 dart::Class* handle = NULL; |
| 759 if (!classes_.Lookup(klass, &handle)) { | 773 if (!classes_.Lookup(klass, &handle)) { |
| 760 dart::Library& library = LookupLibrary(klass->parent()); | 774 dart::Library& library = LookupLibrary(klass->parent()); |
| 761 const dart::String& name = H.DartClassName(klass); | 775 const dart::String& name = H.DartClassName(klass); |
| 762 handle = &dart::Class::Handle(Z, library.LookupClass(name)); | 776 handle = &dart::Class::Handle(Z, library.LookupClass(name)); |
| 763 if (handle->IsNull()) { | 777 if (handle->IsNull()) { |
| 764 // The class needs to have a script because all the functions in the class | 778 *handle = dart::Class::New(library, name, Script::Handle(Z), |
| 765 // will inherit it. The predicate Function::IsOptimizable uses the | 779 TokenPosition::kNoSource); |
| 766 // absence of a script to detect test functions that should not be | |
| 767 // optimized. | |
| 768 Script& script = ScriptAt(klass->source_uri_index()); | |
| 769 handle = &dart::Class::Handle( | |
| 770 Z, dart::Class::New(library, name, script, klass->position())); | |
| 771 library.AddClass(*handle); | 780 library.AddClass(*handle); |
| 772 } else if (handle->script() == Script::null()) { | |
| 773 // When bootstrapping we can encounter classes that do not yet have a | |
| 774 // dummy script. | |
| 775 Script& script = ScriptAt(klass->source_uri_index()); | |
| 776 handle->set_script(script); | |
| 777 } | 781 } |
| 778 // Insert the class in the cache before calling ReadPreliminaryClass so | 782 // Insert the class in the cache before calling ReadPreliminaryClass so |
| 779 // we do not risk allocating the class again by calling LookupClass | 783 // we do not risk allocating the class again by calling LookupClass |
| 780 // recursively from ReadPreliminaryClass for the same class. | 784 // recursively from ReadPreliminaryClass for the same class. |
| 781 classes_.Insert(klass, handle); | 785 classes_.Insert(klass, handle); |
| 782 if (!handle->is_cycle_free()) { | |
| 783 ReadPreliminaryClass(handle, klass); | |
| 784 } | |
| 785 } | 786 } |
| 786 return *handle; | 787 return *handle; |
| 787 } | 788 } |
| 788 | 789 |
| 789 | 790 |
| 790 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) { | 791 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) { |
| 791 intptr_t lookuptable[] = { | 792 intptr_t lookuptable[] = { |
| 792 RawFunction::kRegularFunction, // Procedure::kMethod | 793 RawFunction::kRegularFunction, // Procedure::kMethod |
| 793 RawFunction::kGetterFunction, // Procedure::kGetter | 794 RawFunction::kGetterFunction, // Procedure::kGetter |
| 794 RawFunction::kSetterFunction, // Procedure::kSetter | 795 RawFunction::kSetterFunction, // Procedure::kSetter |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 initializer_fun.set_is_debuggable(false); | 831 initializer_fun.set_is_debuggable(false); |
| 831 initializer_fun.set_is_reflectable(false); | 832 initializer_fun.set_is_reflectable(false); |
| 832 initializer_fun.set_is_inlinable(false); | 833 initializer_fun.set_is_inlinable(false); |
| 833 return new (zone) ParsedFunction(thread, initializer_fun); | 834 return new (zone) ParsedFunction(thread, initializer_fun); |
| 834 } | 835 } |
| 835 | 836 |
| 836 | 837 |
| 837 } // namespace kernel | 838 } // namespace kernel |
| 838 } // namespace dart | 839 } // namespace dart |
| 839 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 840 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |