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; |
| 152 library.SetName(H.DartSymbol(kernel_library->name())); |
150 | 153 |
151 // The bootstrapper will take care of creating the native wrapper classes, but | 154 // The bootstrapper will take care of creating the native wrapper classes, but |
152 // we will add the synthetic constructors to them here. | 155 // we will add the synthetic constructors to them here. |
153 if (library.name() == | 156 if (library.name() == |
154 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { | 157 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { |
155 ASSERT(library.LoadInProgress()); | 158 ASSERT(library.LoadInProgress()); |
156 } else { | 159 } else { |
157 library.SetLoadInProgress(); | 160 library.SetLoadInProgress(); |
158 } | 161 } |
159 // Setup toplevel class (which contains library fields/procedures). | 162 // Setup toplevel class (which contains library fields/procedures). |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 interfaces.SetAt(i, type); | 279 interfaces.SetAt(i, type); |
277 } | 280 } |
278 klass->set_interfaces(interfaces); | 281 klass->set_interfaces(interfaces); |
279 if (kernel_klass->is_abstract()) klass->set_is_abstract(); | 282 if (kernel_klass->is_abstract()) klass->set_is_abstract(); |
280 } | 283 } |
281 | 284 |
282 | 285 |
283 dart::Class& KernelReader::ReadClass(const dart::Library& library, | 286 dart::Class& KernelReader::ReadClass(const dart::Library& library, |
284 const dart::Class& toplevel_class, | 287 const dart::Class& toplevel_class, |
285 Class* kernel_klass) { | 288 Class* kernel_klass) { |
286 // This will trigger a call to [ReadPreliminaryClass] if not already done. | 289 dart::Class& klass = LookupClass(kernel_klass->canonical_name()); |
287 dart::Class& klass = LookupClass(kernel_klass); | 290 |
| 291 // The class needs to have a script because all the functions in the class |
| 292 // will inherit it. The predicate Function::IsOptimizable uses the absence of |
| 293 // a script to detect test functions that should not be optimized. |
| 294 if (klass.script() == Script::null()) { |
| 295 klass.set_script(ScriptAt(kernel_klass->source_uri_index())); |
| 296 } |
| 297 if (klass.token_pos() == TokenPosition::kNoSource) { |
| 298 klass.set_token_pos(kernel_klass->position()); |
| 299 } |
| 300 if (!klass.is_cycle_free()) { |
| 301 ReadPreliminaryClass(&klass, kernel_klass); |
| 302 } |
288 | 303 |
289 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); | 304 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); |
290 | 305 |
291 if (library.raw() == dart::Library::InternalLibrary() && | 306 if (library.raw() == dart::Library::InternalLibrary() && |
292 klass.Name() == Symbols::ClassID().raw()) { | 307 klass.Name() == Symbols::ClassID().raw()) { |
293 // If this is a dart:internal.ClassID class ignore field declarations | 308 // If this is a dart:internal.ClassID class ignore field declarations |
294 // contained in the Kernel file and instead inject our own const | 309 // contained in the Kernel file and instead inject our own const |
295 // fields. | 310 // fields. |
296 klass.InjectCIDFields(); | 311 klass.InjectCIDFields(); |
297 } else { | 312 } else { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 function.SetParameterNameAt(pos, Symbols::This()); | 751 function.SetParameterNameAt(pos, Symbols::This()); |
737 pos++; | 752 pos++; |
738 } | 753 } |
739 if (is_setter) { | 754 if (is_setter) { |
740 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); | 755 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); |
741 function.SetParameterNameAt(pos, Symbols::Value()); | 756 function.SetParameterNameAt(pos, Symbols::Value()); |
742 pos++; | 757 pos++; |
743 } | 758 } |
744 } | 759 } |
745 | 760 |
746 dart::Library& KernelReader::LookupLibrary(Library* library) { | 761 |
| 762 dart::Library& KernelReader::LookupLibrary(CanonicalName* library) { |
747 dart::Library* handle = NULL; | 763 dart::Library* handle = NULL; |
748 if (!libraries_.Lookup(library, &handle)) { | 764 if (!libraries_.Lookup(library, &handle)) { |
749 const dart::String& url = H.DartSymbol(library->import_uri()); | 765 const dart::String& url = H.DartSymbol(library->name()); |
750 handle = | 766 handle = |
751 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url)); | 767 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url)); |
752 if (handle->IsNull()) { | 768 if (handle->IsNull()) { |
753 *handle = dart::Library::New(url); | 769 *handle = dart::Library::New(url); |
754 handle->Register(thread_); | 770 handle->Register(thread_); |
755 handle->SetName(H.DartSymbol(library->name())); | |
756 } | 771 } |
757 ASSERT(!handle->IsNull()); | 772 ASSERT(!handle->IsNull()); |
758 libraries_.Insert(library, handle); | 773 libraries_.Insert(library, handle); |
759 } | 774 } |
760 return *handle; | 775 return *handle; |
761 } | 776 } |
762 | 777 |
763 dart::Class& KernelReader::LookupClass(Class* klass) { | 778 |
| 779 dart::Class& KernelReader::LookupClass(CanonicalName* klass) { |
764 dart::Class* handle = NULL; | 780 dart::Class* handle = NULL; |
765 if (!classes_.Lookup(klass, &handle)) { | 781 if (!classes_.Lookup(klass, &handle)) { |
766 dart::Library& library = LookupLibrary(klass->parent()); | 782 dart::Library& library = LookupLibrary(klass->parent()); |
767 const dart::String& name = H.DartClassName(klass); | 783 const dart::String& name = H.DartClassName(klass); |
768 handle = &dart::Class::Handle(Z, library.LookupClass(name)); | 784 handle = &dart::Class::Handle(Z, library.LookupClass(name)); |
769 if (handle->IsNull()) { | 785 if (handle->IsNull()) { |
770 // The class needs to have a script because all the functions in the class | 786 *handle = dart::Class::New(library, name, Script::Handle(Z), |
771 // will inherit it. The predicate Function::IsOptimizable uses the | 787 TokenPosition::kNoSource); |
772 // absence of a script to detect test functions that should not be | |
773 // optimized. | |
774 Script& script = ScriptAt(klass->source_uri_index()); | |
775 handle = &dart::Class::Handle( | |
776 Z, dart::Class::New(library, name, script, klass->position())); | |
777 library.AddClass(*handle); | 788 library.AddClass(*handle); |
778 } else if (handle->script() == Script::null()) { | |
779 // When bootstrapping we can encounter classes that do not yet have a | |
780 // dummy script. | |
781 Script& script = ScriptAt(klass->source_uri_index()); | |
782 handle->set_script(script); | |
783 } | 789 } |
784 // Insert the class in the cache before calling ReadPreliminaryClass so | 790 // Insert the class in the cache before calling ReadPreliminaryClass so |
785 // we do not risk allocating the class again by calling LookupClass | 791 // we do not risk allocating the class again by calling LookupClass |
786 // recursively from ReadPreliminaryClass for the same class. | 792 // recursively from ReadPreliminaryClass for the same class. |
787 classes_.Insert(klass, handle); | 793 classes_.Insert(klass, handle); |
788 if (!handle->is_cycle_free()) { | |
789 ReadPreliminaryClass(handle, klass); | |
790 } | |
791 } | 794 } |
792 return *handle; | 795 return *handle; |
793 } | 796 } |
794 | 797 |
795 | 798 |
796 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) { | 799 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) { |
797 intptr_t lookuptable[] = { | 800 intptr_t lookuptable[] = { |
798 RawFunction::kRegularFunction, // Procedure::kMethod | 801 RawFunction::kRegularFunction, // Procedure::kMethod |
799 RawFunction::kGetterFunction, // Procedure::kGetter | 802 RawFunction::kGetterFunction, // Procedure::kGetter |
800 RawFunction::kSetterFunction, // Procedure::kSetter | 803 RawFunction::kSetterFunction, // Procedure::kSetter |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 initializer_fun.set_is_debuggable(false); | 839 initializer_fun.set_is_debuggable(false); |
837 initializer_fun.set_is_reflectable(false); | 840 initializer_fun.set_is_reflectable(false); |
838 initializer_fun.set_is_inlinable(false); | 841 initializer_fun.set_is_inlinable(false); |
839 return new (zone) ParsedFunction(thread, initializer_fun); | 842 return new (zone) ParsedFunction(thread, initializer_fun); |
840 } | 843 } |
841 | 844 |
842 | 845 |
843 } // namespace kernel | 846 } // namespace kernel |
844 } // namespace dart | 847 } // namespace dart |
845 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 848 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |