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_loader.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/kernel_binary.h" | 10 #include "vm/kernel_binary.h" |
11 #include "vm/kernel_binary_flowgraph.h" | |
12 #include "vm/kernel_to_il.h" | 11 #include "vm/kernel_to_il.h" |
13 #include "vm/longjump.h" | 12 #include "vm/longjump.h" |
14 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
15 #include "vm/parser.h" | 14 #include "vm/parser.h" |
16 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
17 | 16 |
18 #if !defined(DART_PRECOMPILED_RUNTIME) | 17 #if !defined(DART_PRECOMPILED_RUNTIME) |
19 namespace dart { | 18 namespace dart { |
20 namespace kernel { | 19 namespace kernel { |
21 | 20 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 const Instance& SimpleValue() { return *simple_value_; } | 96 const Instance& SimpleValue() { return *simple_value_; } |
98 Zone* zone() const { return zone_; } | 97 Zone* zone() const { return zone_; } |
99 | 98 |
100 private: | 99 private: |
101 TranslationHelper& translation_helper_; | 100 TranslationHelper& translation_helper_; |
102 Zone* zone_; | 101 Zone* zone_; |
103 Instance* simple_value_; | 102 Instance* simple_value_; |
104 StreamingFlowGraphBuilder* builder_; | 103 StreamingFlowGraphBuilder* builder_; |
105 }; | 104 }; |
106 | 105 |
107 RawArray* KernelReader::MakeFunctionsArray() { | 106 RawArray* KernelLoader::MakeFunctionsArray() { |
108 const intptr_t len = functions_.length(); | 107 const intptr_t len = functions_.length(); |
109 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld)); | 108 const Array& res = Array::Handle(zone_, Array::New(len, Heap::kOld)); |
110 for (intptr_t i = 0; i < len; i++) { | 109 for (intptr_t i = 0; i < len; i++) { |
111 res.SetAt(i, *functions_[i]); | 110 res.SetAt(i, *functions_[i]); |
112 } | 111 } |
113 return res.raw(); | 112 return res.raw(); |
114 } | 113 } |
115 | 114 |
116 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( | 115 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( |
117 NameIndex library) { | 116 NameIndex library) { |
118 return reader_->LookupLibrary(library).raw(); | 117 return loader_->LookupLibrary(library).raw(); |
119 } | 118 } |
120 | 119 |
121 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(NameIndex klass) { | 120 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(NameIndex klass) { |
122 return reader_->LookupClass(klass).raw(); | 121 return loader_->LookupClass(klass).raw(); |
123 } | 122 } |
124 | 123 |
125 KernelReader::KernelReader(Program* program) | 124 KernelLoader::KernelLoader(Program* program) |
126 : program_(program), | 125 : program_(program), |
127 thread_(Thread::Current()), | 126 thread_(Thread::Current()), |
128 zone_(thread_->zone()), | 127 zone_(thread_->zone()), |
129 isolate_(thread_->isolate()), | 128 isolate_(thread_->isolate()), |
130 scripts_(Array::ZoneHandle(zone_)), | 129 scripts_(Array::ZoneHandle(zone_)), |
131 patch_classes_(Array::ZoneHandle(zone_)), | 130 patch_classes_(Array::ZoneHandle(zone_)), |
132 translation_helper_(this, thread_), | 131 translation_helper_(this, thread_), |
133 builder_(&translation_helper_, | 132 builder_(&translation_helper_, |
134 zone_, | 133 zone_, |
135 program_->kernel_data(), | 134 program_->kernel_data(), |
(...skipping 30 matching lines...) Expand all Loading... |
166 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld)); | 165 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld)); |
167 for (intptr_t i = 0; i < count; ++i) { | 166 for (intptr_t i = 0; i < count; ++i) { |
168 names.SetUint32(i << 2, reader.ReadUInt()); | 167 names.SetUint32(i << 2, reader.ReadUInt()); |
169 } | 168 } |
170 | 169 |
171 H.SetStringOffsets(offsets); | 170 H.SetStringOffsets(offsets); |
172 H.SetStringData(data); | 171 H.SetStringData(data); |
173 H.SetCanonicalNames(names); | 172 H.SetCanonicalNames(names); |
174 } | 173 } |
175 | 174 |
176 Object& KernelReader::ReadProgram() { | 175 Object& KernelLoader::LoadProgram() { |
177 LongJumpScope jump; | 176 LongJumpScope jump; |
178 if (setjmp(*jump.Set()) == 0) { | 177 if (setjmp(*jump.Set()) == 0) { |
179 intptr_t length = program_->library_count(); | 178 intptr_t length = program_->library_count(); |
180 for (intptr_t i = 0; i < length; i++) { | 179 for (intptr_t i = 0; i < length; i++) { |
181 ReadLibrary(library_offset(i)); | 180 LoadLibrary(library_offset(i)); |
182 } | 181 } |
183 | 182 |
184 for (intptr_t i = 0; i < length; i++) { | 183 for (intptr_t i = 0; i < length; i++) { |
185 Library& library = LookupLibrary(library_canonical_name(i)); | 184 Library& library = LookupLibrary(library_canonical_name(i)); |
186 if (!library.Loaded()) library.SetLoaded(); | 185 if (!library.Loaded()) library.SetLoaded(); |
187 } | 186 } |
188 | 187 |
189 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { | 188 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { |
190 // If 'main' is not found return a null library, this is the case | 189 // If 'main' is not found return a null library, this is the case |
191 // when bootstrapping is in progress. | 190 // when bootstrapping is in progress. |
(...skipping 12 matching lines...) Expand all Loading... |
204 } | 203 } |
205 | 204 |
206 // Either class finalization failed or we caught a compile error. | 205 // Either class finalization failed or we caught a compile error. |
207 // In both cases sticky error would be set. | 206 // In both cases sticky error would be set. |
208 Error& error = Error::Handle(Z); | 207 Error& error = Error::Handle(Z); |
209 error = thread_->sticky_error(); | 208 error = thread_->sticky_error(); |
210 thread_->clear_sticky_error(); | 209 thread_->clear_sticky_error(); |
211 return error; | 210 return error; |
212 } | 211 } |
213 | 212 |
214 void KernelReader::FindModifiedLibraries(Isolate* isolate, | 213 void KernelLoader::FindModifiedLibraries(Isolate* isolate, |
215 BitVector* modified_libs, | 214 BitVector* modified_libs, |
216 bool force_reload) { | 215 bool force_reload) { |
217 LongJumpScope jump; | 216 LongJumpScope jump; |
218 if (setjmp(*jump.Set()) == 0) { | 217 if (setjmp(*jump.Set()) == 0) { |
219 if (force_reload) { | 218 if (force_reload) { |
220 // If a reload is being forced we mark all libraries as having | 219 // If a reload is being forced we mark all libraries as having |
221 // been modified. | 220 // been modified. |
222 const GrowableObjectArray& libs = | 221 const GrowableObjectArray& libs = |
223 GrowableObjectArray::Handle(isolate->object_store()->libraries()); | 222 GrowableObjectArray::Handle(isolate->object_store()->libraries()); |
224 intptr_t num_libs = libs.Length(); | 223 intptr_t num_libs = libs.Length(); |
(...skipping 16 matching lines...) Expand all Loading... |
241 library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName); | 240 library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName); |
242 dart::Library& lib = LookupLibrary(library_helper.canonical_name_); | 241 dart::Library& lib = LookupLibrary(library_helper.canonical_name_); |
243 if (!lib.IsNull() && !lib.is_dart_scheme()) { | 242 if (!lib.IsNull() && !lib.is_dart_scheme()) { |
244 // This is a library that already exists so mark it as being modified. | 243 // This is a library that already exists so mark it as being modified. |
245 modified_libs->Add(lib.index()); | 244 modified_libs->Add(lib.index()); |
246 } | 245 } |
247 } | 246 } |
248 } | 247 } |
249 } | 248 } |
250 | 249 |
251 void KernelReader::ReadLibrary(intptr_t kernel_offset) { | 250 void KernelLoader::LoadLibrary(intptr_t kernel_offset) { |
252 builder_.SetOffset(kernel_offset); | 251 builder_.SetOffset(kernel_offset); |
253 LibraryHelper library_helper(&builder_); | 252 LibraryHelper library_helper(&builder_); |
254 library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName); | 253 library_helper.ReadUntilIncluding(LibraryHelper::kCanonicalName); |
255 Library& library = LookupLibrary(library_helper.canonical_name_); | 254 Library& library = LookupLibrary(library_helper.canonical_name_); |
256 // The Kernel library is external implies that it is already loaded. | 255 // The Kernel library is external implies that it is already loaded. |
257 ASSERT(!library_helper.IsExternal() || library.Loaded()); | 256 ASSERT(!library_helper.IsExternal() || library.Loaded()); |
258 if (library.Loaded()) return; | 257 if (library.Loaded()) return; |
259 | 258 |
260 library_helper.ReadUntilIncluding(LibraryHelper::kName); | 259 library_helper.ReadUntilIncluding(LibraryHelper::kName); |
261 library.SetName(H.DartSymbol(library_helper.name_index_)); | 260 library.SetName(H.DartSymbol(library_helper.name_index_)); |
(...skipping 20 matching lines...) Expand all Loading... |
282 library.set_toplevel_class(toplevel_class); | 281 library.set_toplevel_class(toplevel_class); |
283 | 282 |
284 const GrowableObjectArray& classes = | 283 const GrowableObjectArray& classes = |
285 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes()); | 284 GrowableObjectArray::Handle(Z, I->object_store()->pending_classes()); |
286 | 285 |
287 library_helper.ReadUntilExcluding(LibraryHelper::kClasses); | 286 library_helper.ReadUntilExcluding(LibraryHelper::kClasses); |
288 | 287 |
289 // Load all classes. | 288 // Load all classes. |
290 int class_count = builder_.ReadListLength(); // read list length. | 289 int class_count = builder_.ReadListLength(); // read list length. |
291 for (intptr_t i = 0; i < class_count; ++i) { | 290 for (intptr_t i = 0; i < class_count; ++i) { |
292 classes.Add(ReadClass(library, toplevel_class), Heap::kOld); | 291 classes.Add(LoadClass(library, toplevel_class), Heap::kOld); |
293 } | 292 } |
294 | 293 |
295 fields_.Clear(); | 294 fields_.Clear(); |
296 functions_.Clear(); | 295 functions_.Clear(); |
297 ActiveClassScope active_class_scope(&active_class_, &toplevel_class); | 296 ActiveClassScope active_class_scope(&active_class_, &toplevel_class); |
298 // Load toplevel fields. | 297 // Load toplevel fields. |
299 intptr_t field_count = builder_.ReadListLength(); // read list length. | 298 intptr_t field_count = builder_.ReadListLength(); // read list length. |
300 for (intptr_t i = 0; i < field_count; ++i) { | 299 for (intptr_t i = 0; i < field_count; ++i) { |
301 intptr_t field_offset = builder_.ReaderOffset(); | 300 intptr_t field_offset = builder_.ReaderOffset(); |
302 ActiveMemberScope active_member_scope(&active_class_, NULL); | 301 ActiveMemberScope active_member_scope(&active_class_, NULL); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 &kernel_data); | 333 &kernel_data); |
335 } | 334 } |
336 fields_.Add(&field); | 335 fields_.Add(&field); |
337 library.AddObject(field, name); | 336 library.AddObject(field, name); |
338 } | 337 } |
339 toplevel_class.AddFields(fields_); | 338 toplevel_class.AddFields(fields_); |
340 | 339 |
341 // Load toplevel procedures. | 340 // Load toplevel procedures. |
342 intptr_t procedure_count = builder_.ReadListLength(); // read list length. | 341 intptr_t procedure_count = builder_.ReadListLength(); // read list length. |
343 for (intptr_t i = 0; i < procedure_count; ++i) { | 342 for (intptr_t i = 0; i < procedure_count; ++i) { |
344 ReadProcedure(library, toplevel_class, false); | 343 LoadProcedure(library, toplevel_class, false); |
345 } | 344 } |
346 | 345 |
347 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray())); | 346 toplevel_class.SetFunctions(Array::Handle(MakeFunctionsArray())); |
348 | 347 |
349 classes.Add(toplevel_class, Heap::kOld); | 348 classes.Add(toplevel_class, Heap::kOld); |
350 } | 349 } |
351 | 350 |
352 void KernelReader::ReadPreliminaryClass(Class* klass, | 351 void KernelLoader::LoadPreliminaryClass(Class* klass, |
353 ClassHelper* class_helper, | 352 ClassHelper* class_helper, |
354 intptr_t type_parameter_count) { | 353 intptr_t type_parameter_count) { |
355 // Note: This assumes that ClassHelper is exactly at the position where | 354 // Note: This assumes that ClassHelper is exactly at the position where |
356 // the length of the type parameters have been read, and that the order in | 355 // the length of the type parameters have been read, and that the order in |
357 // the binary is as follows: [...], kTypeParameters, kSuperClass, kMixinType, | 356 // the binary is as follows: [...], kTypeParameters, kSuperClass, kMixinType, |
358 // kImplementedClasses, [...]. | 357 // kImplementedClasses, [...]. |
359 | 358 |
360 // Set type parameters. | 359 // Set type parameters. |
361 ReadAndSetupTypeParameters(*klass, type_parameter_count, *klass, | 360 LoadAndSetupTypeParameters(*klass, type_parameter_count, *klass, |
362 Function::Handle(Z)); | 361 Function::Handle(Z)); |
363 | 362 |
364 // Set super type. Some classes (e.g., Object) do not have one. | 363 // Set super type. Some classes (e.g., Object) do not have one. |
365 Tag type_tag = builder_.ReadTag(); // read super class type (part 1). | 364 Tag type_tag = builder_.ReadTag(); // read super class type (part 1). |
366 if (type_tag == kSomething) { | 365 if (type_tag == kSomething) { |
367 AbstractType& super_type = | 366 AbstractType& super_type = |
368 T.BuildTypeWithoutFinalization(); // read super class type (part 2). | 367 T.BuildTypeWithoutFinalization(); // read super class type (part 2). |
369 if (super_type.IsMalformed()) H.ReportError("Malformed super type"); | 368 if (super_type.IsMalformed()) H.ReportError("Malformed super type"); |
370 klass->set_super_type(super_type); | 369 klass->set_super_type(super_type); |
371 } | 370 } |
(...skipping 10 matching lines...) Expand all Loading... |
382 T.BuildTypeWithoutFinalization(); // read ith type. | 381 T.BuildTypeWithoutFinalization(); // read ith type. |
383 if (type.IsMalformed()) H.ReportError("Malformed interface type."); | 382 if (type.IsMalformed()) H.ReportError("Malformed interface type."); |
384 interfaces.SetAt(i, type); | 383 interfaces.SetAt(i, type); |
385 } | 384 } |
386 class_helper->SetJustRead(ClassHelper::kImplementedClasses); | 385 class_helper->SetJustRead(ClassHelper::kImplementedClasses); |
387 klass->set_interfaces(interfaces); | 386 klass->set_interfaces(interfaces); |
388 | 387 |
389 if (class_helper->is_abstract_) klass->set_is_abstract(); | 388 if (class_helper->is_abstract_) klass->set_is_abstract(); |
390 } | 389 } |
391 | 390 |
392 Class& KernelReader::ReadClass(const Library& library, | 391 Class& KernelLoader::LoadClass(const Library& library, |
393 const Class& toplevel_class) { | 392 const Class& toplevel_class) { |
394 ClassHelper class_helper(&builder_); | 393 ClassHelper class_helper(&builder_); |
395 intptr_t class_offset = builder_.ReaderOffset(); | 394 intptr_t class_offset = builder_.ReaderOffset(); |
396 class_helper.ReadUntilIncluding(ClassHelper::kCanonicalName); | 395 class_helper.ReadUntilIncluding(ClassHelper::kCanonicalName); |
397 Class& klass = LookupClass(class_helper.canonical_name_); | 396 Class& klass = LookupClass(class_helper.canonical_name_); |
398 | 397 |
399 // The class needs to have a script because all the functions in the class | 398 // The class needs to have a script because all the functions in the class |
400 // will inherit it. The predicate Function::IsOptimizable uses the absence of | 399 // will inherit it. The predicate Function::IsOptimizable uses the absence of |
401 // a script to detect test functions that should not be optimized. | 400 // a script to detect test functions that should not be optimized. |
402 if (klass.script() == Script::null()) { | 401 if (klass.script() == Script::null()) { |
403 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex); | 402 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex); |
404 klass.set_script(ScriptAt(class_helper.source_uri_index_)); | 403 klass.set_script(ScriptAt(class_helper.source_uri_index_)); |
405 } | 404 } |
406 if (klass.token_pos() == TokenPosition::kNoSource) { | 405 if (klass.token_pos() == TokenPosition::kNoSource) { |
407 class_helper.ReadUntilIncluding(ClassHelper::kPosition); | 406 class_helper.ReadUntilIncluding(ClassHelper::kPosition); |
408 klass.set_token_pos(class_helper.position_); | 407 klass.set_token_pos(class_helper.position_); |
409 } | 408 } |
410 | 409 |
411 class_helper.ReadUntilIncluding(ClassHelper::kAnnotations); | 410 class_helper.ReadUntilIncluding(ClassHelper::kAnnotations); |
412 intptr_t class_offset_after_annotations = builder_.ReaderOffset(); | 411 intptr_t class_offset_after_annotations = builder_.ReaderOffset(); |
413 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters); | 412 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters); |
414 intptr_t type_parameter_counts = | 413 intptr_t type_parameter_counts = |
415 builder_.ReadListLength(); // read type_parameters list length. | 414 builder_.ReadListLength(); // read type_parameters list length. |
416 | 415 |
417 ActiveClassScope active_class_scope(&active_class_, &klass); | 416 ActiveClassScope active_class_scope(&active_class_, &klass); |
418 if (!klass.is_cycle_free()) { | 417 if (!klass.is_cycle_free()) { |
419 ReadPreliminaryClass(&klass, &class_helper, type_parameter_counts); | 418 LoadPreliminaryClass(&klass, &class_helper, type_parameter_counts); |
420 } else { | 419 } else { |
421 for (intptr_t i = 0; i < type_parameter_counts; ++i) { | 420 for (intptr_t i = 0; i < type_parameter_counts; ++i) { |
422 builder_.SkipStringReference(); // read ith name index. | 421 builder_.SkipStringReference(); // read ith name index. |
423 builder_.SkipDartType(); // read ith bound. | 422 builder_.SkipDartType(); // read ith bound. |
424 } | 423 } |
425 class_helper.SetJustRead(ClassHelper::kTypeParameters); | 424 class_helper.SetJustRead(ClassHelper::kTypeParameters); |
426 } | 425 } |
427 | 426 |
428 fields_.Clear(); | 427 fields_.Clear(); |
429 functions_.Clear(); | 428 functions_.Clear(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 if (FLAG_enable_mirrors && constructor_helper.annotation_count_ > 0) { | 525 if (FLAG_enable_mirrors && constructor_helper.annotation_count_ > 0) { |
527 library.AddFunctionMetadata(function, TokenPosition::kNoSource, | 526 library.AddFunctionMetadata(function, TokenPosition::kNoSource, |
528 constructor_offset, &kernel_data); | 527 constructor_offset, &kernel_data); |
529 } | 528 } |
530 } | 529 } |
531 class_helper.SetJustRead(ClassHelper::kConstructors); | 530 class_helper.SetJustRead(ClassHelper::kConstructors); |
532 | 531 |
533 class_helper.ReadUntilExcluding(ClassHelper::kProcedures); | 532 class_helper.ReadUntilExcluding(ClassHelper::kProcedures); |
534 int procedure_count = builder_.ReadListLength(); // read list length. | 533 int procedure_count = builder_.ReadListLength(); // read list length. |
535 for (intptr_t i = 0; i < procedure_count; ++i) { | 534 for (intptr_t i = 0; i < procedure_count; ++i) { |
536 ReadProcedure(library, klass, true); | 535 LoadProcedure(library, klass, true); |
537 } | 536 } |
538 class_helper.SetJustRead(ClassHelper::kProcedures); | 537 class_helper.SetJustRead(ClassHelper::kProcedures); |
539 | 538 |
540 klass.SetFunctions(Array::Handle(MakeFunctionsArray())); | 539 klass.SetFunctions(Array::Handle(MakeFunctionsArray())); |
541 | 540 |
542 if (!klass.is_marked_for_parsing()) { | 541 if (!klass.is_marked_for_parsing()) { |
543 klass.set_is_marked_for_parsing(); | 542 klass.set_is_marked_for_parsing(); |
544 } | 543 } |
545 | 544 |
546 if (FLAG_enable_mirrors && class_helper.annotation_count_ > 0) { | 545 if (FLAG_enable_mirrors && class_helper.annotation_count_ > 0) { |
547 TypedData& header_data = builder_.reader_->CopyDataToVMHeap( | 546 TypedData& header_data = builder_.reader_->CopyDataToVMHeap( |
548 Z, class_offset, class_offset_after_annotations); | 547 Z, class_offset, class_offset_after_annotations); |
549 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, | 548 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, |
550 class_offset, &header_data); | 549 class_offset, &header_data); |
551 } | 550 } |
552 | 551 |
553 class_helper.ReadUntilExcluding(ClassHelper::kEnd); | 552 class_helper.ReadUntilExcluding(ClassHelper::kEnd); |
554 | 553 |
555 return klass; | 554 return klass; |
556 } | 555 } |
557 | 556 |
558 void KernelReader::ReadProcedure(const Library& library, | 557 void KernelLoader::LoadProcedure(const Library& library, |
559 const Class& owner, | 558 const Class& owner, |
560 bool in_class) { | 559 bool in_class) { |
561 intptr_t procedure_offset = builder_.ReaderOffset(); | 560 intptr_t procedure_offset = builder_.ReaderOffset(); |
562 ProcedureHelper procedure_helper(&builder_); | 561 ProcedureHelper procedure_helper(&builder_); |
563 | 562 |
564 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); | 563 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); |
565 const String& name = H.DartProcedureName(procedure_helper.canonical_name_); | 564 const String& name = H.DartProcedureName(procedure_helper.canonical_name_); |
566 bool is_method = in_class && !procedure_helper.IsStatic(); | 565 bool is_method = in_class && !procedure_helper.IsStatic(); |
567 bool is_abstract = procedure_helper.IsAbstract(); | 566 bool is_abstract = procedure_helper.IsAbstract(); |
568 bool is_external = procedure_helper.IsExternal(); | 567 bool is_external = procedure_helper.IsExternal(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 | 667 |
669 if (native_name != NULL) { | 668 if (native_name != NULL) { |
670 function.set_native_name(*native_name); | 669 function.set_native_name(*native_name); |
671 } | 670 } |
672 | 671 |
673 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kTypeParameters); | 672 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kTypeParameters); |
674 if (!function.IsFactory()) { | 673 if (!function.IsFactory()) { |
675 // Read type_parameters list length. | 674 // Read type_parameters list length. |
676 intptr_t type_parameter_count = builder_.ReadListLength(); | 675 intptr_t type_parameter_count = builder_.ReadListLength(); |
677 // Set type parameters. | 676 // Set type parameters. |
678 ReadAndSetupTypeParameters(function, type_parameter_count, Class::Handle(Z), | 677 LoadAndSetupTypeParameters(function, type_parameter_count, Class::Handle(Z), |
679 function); | 678 function); |
680 function_node_helper.SetJustRead(FunctionNodeHelper::kTypeParameters); | 679 function_node_helper.SetJustRead(FunctionNodeHelper::kTypeParameters); |
681 } | 680 } |
682 | 681 |
683 function_node_helper.ReadUntilExcluding( | 682 function_node_helper.ReadUntilExcluding( |
684 FunctionNodeHelper::kRequiredParameterCount); | 683 FunctionNodeHelper::kRequiredParameterCount); |
685 builder_.SetupFunctionParameters(owner, function, is_method, | 684 builder_.SetupFunctionParameters(owner, function, is_method, |
686 false, // is_closure | 685 false, // is_closure |
687 &function_node_helper); | 686 &function_node_helper); |
688 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); | 687 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
(...skipping 11 matching lines...) Expand all Loading... |
700 TypedData& kernel_data = builder_.reader_->CopyDataToVMHeap( | 699 TypedData& kernel_data = builder_.reader_->CopyDataToVMHeap( |
701 Z, procedure_offset, builder_.ReaderOffset()); | 700 Z, procedure_offset, builder_.ReaderOffset()); |
702 function.set_kernel_data(kernel_data); | 701 function.set_kernel_data(kernel_data); |
703 | 702 |
704 if (FLAG_enable_mirrors && annotation_count > 0) { | 703 if (FLAG_enable_mirrors && annotation_count > 0) { |
705 library.AddFunctionMetadata(function, TokenPosition::kNoSource, | 704 library.AddFunctionMetadata(function, TokenPosition::kNoSource, |
706 procedure_offset, &kernel_data); | 705 procedure_offset, &kernel_data); |
707 } | 706 } |
708 } | 707 } |
709 | 708 |
710 void KernelReader::ReadAndSetupTypeParameters( | 709 void KernelLoader::LoadAndSetupTypeParameters( |
711 const Object& set_on, | 710 const Object& set_on, |
712 intptr_t type_parameter_count, | 711 intptr_t type_parameter_count, |
713 const Class& parameterized_class, | 712 const Class& parameterized_class, |
714 const Function& parameterized_function) { | 713 const Function& parameterized_function) { |
715 ASSERT(type_parameter_count >= 0); | 714 ASSERT(type_parameter_count >= 0); |
716 if (type_parameter_count == 0) { | 715 if (type_parameter_count == 0) { |
717 return; | 716 return; |
718 } | 717 } |
719 // First setup the type parameters, so if any of the following code uses it | 718 // First setup the type parameters, so if any of the following code uses it |
720 // (in a recursive way) we're fine. | 719 // (in a recursive way) we're fine. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 AbstractType& bound = | 758 AbstractType& bound = |
760 T.BuildTypeWithoutFinalization(); // read ith bound. | 759 T.BuildTypeWithoutFinalization(); // read ith bound. |
761 if (bound.IsMalformedOrMalbounded()) { | 760 if (bound.IsMalformedOrMalbounded()) { |
762 bound = I->object_store()->object_type(); | 761 bound = I->object_store()->object_type(); |
763 } | 762 } |
764 parameter.set_bound(bound); | 763 parameter.set_bound(bound); |
765 } | 764 } |
766 } | 765 } |
767 } | 766 } |
768 | 767 |
769 const Object& KernelReader::ClassForScriptAt(const Class& klass, | 768 const Object& KernelLoader::ClassForScriptAt(const Class& klass, |
770 intptr_t source_uri_index) { | 769 intptr_t source_uri_index) { |
771 Script& correct_script = ScriptAt(source_uri_index); | 770 Script& correct_script = ScriptAt(source_uri_index); |
772 if (klass.script() != correct_script.raw()) { | 771 if (klass.script() != correct_script.raw()) { |
773 // Use cache for patch classes. This works best for in-order usages. | 772 // Use cache for patch classes. This works best for in-order usages. |
774 PatchClass& patch_class = PatchClass::ZoneHandle(Z); | 773 PatchClass& patch_class = PatchClass::ZoneHandle(Z); |
775 patch_class ^= patch_classes_.At(source_uri_index); | 774 patch_class ^= patch_classes_.At(source_uri_index); |
776 if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) { | 775 if (patch_class.IsNull() || patch_class.origin_class() != klass.raw()) { |
777 patch_class = PatchClass::New(klass, correct_script); | 776 patch_class = PatchClass::New(klass, correct_script); |
778 patch_classes_.SetAt(source_uri_index, patch_class); | 777 patch_classes_.SetAt(source_uri_index, patch_class); |
779 } | 778 } |
780 return patch_class; | 779 return patch_class; |
781 } | 780 } |
782 return klass; | 781 return klass; |
783 } | 782 } |
784 | 783 |
785 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) { | 784 Script& KernelLoader::ScriptAt(intptr_t index, StringIndex import_uri) { |
786 Script& script = Script::ZoneHandle(Z); | 785 Script& script = Script::ZoneHandle(Z); |
787 script ^= scripts_.At(index); | 786 script ^= scripts_.At(index); |
788 if (script.IsNull()) { | 787 if (script.IsNull()) { |
789 // Create script with correct uri(s). | 788 // Create script with correct uri(s). |
790 String& uri_string = builder_.SourceTableUriFor(index); | 789 String& uri_string = builder_.SourceTableUriFor(index); |
791 String& import_uri_string = | 790 String& import_uri_string = |
792 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld); | 791 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld); |
793 script = Script::New(import_uri_string, uri_string, | 792 script = Script::New(import_uri_string, uri_string, |
794 builder_.GetSourceFor(index), RawScript::kKernelTag); | 793 builder_.GetSourceFor(index), RawScript::kKernelTag); |
795 script.set_kernel_script_index(index); | 794 script.set_kernel_script_index(index); |
796 script.set_kernel_string_offsets(H.string_offsets()); | 795 script.set_kernel_string_offsets(H.string_offsets()); |
797 script.set_kernel_string_data(H.string_data()); | 796 script.set_kernel_string_data(H.string_data()); |
798 script.set_kernel_canonical_names(H.canonical_names()); | 797 script.set_kernel_canonical_names(H.canonical_names()); |
799 scripts_.SetAt(index, script); | 798 scripts_.SetAt(index, script); |
800 | 799 |
801 script.set_line_starts(builder_.GetLineStartsFor(index)); | 800 script.set_line_starts(builder_.GetLineStartsFor(index)); |
802 script.set_debug_positions(Array::Handle(Array::null())); | 801 script.set_debug_positions(Array::Handle(Array::null())); |
803 script.set_yield_positions(Array::Handle(Array::null())); | 802 script.set_yield_positions(Array::Handle(Array::null())); |
804 } | 803 } |
805 return script; | 804 return script; |
806 } | 805 } |
807 | 806 |
808 void KernelReader::GenerateFieldAccessors(const Class& klass, | 807 void KernelLoader::GenerateFieldAccessors(const Class& klass, |
809 const Field& field, | 808 const Field& field, |
810 FieldHelper* field_helper, | 809 FieldHelper* field_helper, |
811 intptr_t field_offset) { | 810 intptr_t field_offset) { |
812 Tag tag = builder_.PeekTag(); | 811 Tag tag = builder_.PeekTag(); |
813 if (field_helper->IsStatic() && tag == kNothing) { | 812 if (field_helper->IsStatic() && tag == kNothing) { |
814 // Static fields without an initializer are implicitly initialized to null. | 813 // Static fields without an initializer are implicitly initialized to null. |
815 // We do not need a getter. | 814 // We do not need a getter. |
816 field.SetStaticValue(Instance::Handle(Z), true); | 815 field.SetStaticValue(Instance::Handle(Z), true); |
817 return; | 816 return; |
818 } | 817 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 functions_.Add(&setter); | 884 functions_.Add(&setter); |
886 setter.set_kernel_data(TypedData::Handle(Z, field.kernel_data())); | 885 setter.set_kernel_data(TypedData::Handle(Z, field.kernel_data())); |
887 setter.set_end_token_pos(field_helper->end_position_); | 886 setter.set_end_token_pos(field_helper->end_position_); |
888 setter.set_kernel_offset(field_offset); | 887 setter.set_kernel_offset(field_offset); |
889 setter.set_result_type(Object::void_type()); | 888 setter.set_result_type(Object::void_type()); |
890 setter.set_is_debuggable(false); | 889 setter.set_is_debuggable(false); |
891 SetupFieldAccessorFunction(klass, setter); | 890 SetupFieldAccessorFunction(klass, setter); |
892 } | 891 } |
893 } | 892 } |
894 | 893 |
895 void KernelReader::SetupFieldAccessorFunction(const Class& klass, | 894 void KernelLoader::SetupFieldAccessorFunction(const Class& klass, |
896 const Function& function) { | 895 const Function& function) { |
897 bool is_setter = function.IsImplicitSetterFunction(); | 896 bool is_setter = function.IsImplicitSetterFunction(); |
898 bool is_method = !function.IsStaticFunction(); | 897 bool is_method = !function.IsStaticFunction(); |
899 intptr_t parameter_count = (is_method ? 1 : 0) + (is_setter ? 1 : 0); | 898 intptr_t parameter_count = (is_method ? 1 : 0) + (is_setter ? 1 : 0); |
900 | 899 |
901 function.SetNumOptionalParameters(0, false); | 900 function.SetNumOptionalParameters(0, false); |
902 function.set_num_fixed_parameters(parameter_count); | 901 function.set_num_fixed_parameters(parameter_count); |
903 function.set_parameter_types( | 902 function.set_parameter_types( |
904 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); | 903 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); |
905 function.set_parameter_names( | 904 function.set_parameter_names( |
906 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); | 905 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); |
907 | 906 |
908 intptr_t pos = 0; | 907 intptr_t pos = 0; |
909 if (is_method) { | 908 if (is_method) { |
910 function.SetParameterTypeAt(pos, T.ReceiverType(klass)); | 909 function.SetParameterTypeAt(pos, T.ReceiverType(klass)); |
911 function.SetParameterNameAt(pos, Symbols::This()); | 910 function.SetParameterNameAt(pos, Symbols::This()); |
912 pos++; | 911 pos++; |
913 } | 912 } |
914 if (is_setter) { | 913 if (is_setter) { |
915 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); | 914 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); |
916 function.SetParameterNameAt(pos, Symbols::Value()); | 915 function.SetParameterNameAt(pos, Symbols::Value()); |
917 pos++; | 916 pos++; |
918 } | 917 } |
919 } | 918 } |
920 | 919 |
921 Library& KernelReader::LookupLibrary(NameIndex library) { | 920 Library& KernelLoader::LookupLibrary(NameIndex library) { |
922 Library* handle = NULL; | 921 Library* handle = NULL; |
923 if (!libraries_.Lookup(library, &handle)) { | 922 if (!libraries_.Lookup(library, &handle)) { |
924 const String& url = H.DartSymbol(H.CanonicalNameString(library)); | 923 const String& url = H.DartSymbol(H.CanonicalNameString(library)); |
925 handle = &Library::Handle(Z, Library::LookupLibrary(thread_, url)); | 924 handle = &Library::Handle(Z, Library::LookupLibrary(thread_, url)); |
926 if (handle->IsNull()) { | 925 if (handle->IsNull()) { |
927 *handle = Library::New(url); | 926 *handle = Library::New(url); |
928 handle->Register(thread_); | 927 handle->Register(thread_); |
929 } | 928 } |
930 ASSERT(!handle->IsNull()); | 929 ASSERT(!handle->IsNull()); |
931 libraries_.Insert(library, handle); | 930 libraries_.Insert(library, handle); |
932 } | 931 } |
933 return *handle; | 932 return *handle; |
934 } | 933 } |
935 | 934 |
936 Class& KernelReader::LookupClass(NameIndex klass) { | 935 Class& KernelLoader::LookupClass(NameIndex klass) { |
937 Class* handle = NULL; | 936 Class* handle = NULL; |
938 if (!classes_.Lookup(klass, &handle)) { | 937 if (!classes_.Lookup(klass, &handle)) { |
939 Library& library = LookupLibrary(H.CanonicalNameParent(klass)); | 938 Library& library = LookupLibrary(H.CanonicalNameParent(klass)); |
940 const String& name = H.DartClassName(klass); | 939 const String& name = H.DartClassName(klass); |
941 handle = &Class::Handle(Z, library.LookupClass(name)); | 940 handle = &Class::Handle(Z, library.LookupClass(name)); |
942 if (handle->IsNull()) { | 941 if (handle->IsNull()) { |
943 *handle = Class::New(library, name, Script::Handle(Z), | 942 *handle = Class::New(library, name, Script::Handle(Z), |
944 TokenPosition::kNoSource); | 943 TokenPosition::kNoSource); |
945 library.AddClass(*handle); | 944 library.AddClass(*handle); |
946 } | 945 } |
947 // Insert the class in the cache before calling ReadPreliminaryClass so | 946 // Insert the class in the cache before calling ReadPreliminaryClass so |
948 // we do not risk allocating the class again by calling LookupClass | 947 // we do not risk allocating the class again by calling LookupClass |
949 // recursively from ReadPreliminaryClass for the same class. | 948 // recursively from ReadPreliminaryClass for the same class. |
950 classes_.Insert(klass, handle); | 949 classes_.Insert(klass, handle); |
951 } | 950 } |
952 return *handle; | 951 return *handle; |
953 } | 952 } |
954 | 953 |
955 RawFunction::Kind KernelReader::GetFunctionType( | 954 RawFunction::Kind KernelLoader::GetFunctionType( |
956 ProcedureHelper::Kind procedure_kind) { | 955 ProcedureHelper::Kind procedure_kind) { |
957 intptr_t lookuptable[] = { | 956 intptr_t lookuptable[] = { |
958 RawFunction::kRegularFunction, // Procedure::kMethod | 957 RawFunction::kRegularFunction, // Procedure::kMethod |
959 RawFunction::kGetterFunction, // Procedure::kGetter | 958 RawFunction::kGetterFunction, // Procedure::kGetter |
960 RawFunction::kSetterFunction, // Procedure::kSetter | 959 RawFunction::kSetterFunction, // Procedure::kSetter |
961 RawFunction::kRegularFunction, // Procedure::kOperator | 960 RawFunction::kRegularFunction, // Procedure::kOperator |
962 RawFunction::kConstructor, // Procedure::kFactory | 961 RawFunction::kConstructor, // Procedure::kFactory |
963 }; | 962 }; |
964 intptr_t kind = static_cast<int>(procedure_kind); | 963 intptr_t kind = static_cast<int>(procedure_kind); |
965 ASSERT(0 <= kind && kind <= ProcedureHelper::kFactory); | 964 ASSERT(0 <= kind && kind <= ProcedureHelper::kFactory); |
966 return static_cast<RawFunction::Kind>(lookuptable[kind]); | 965 return static_cast<RawFunction::Kind>(lookuptable[kind]); |
967 } | 966 } |
968 | 967 |
969 bool KernelReader::FieldHasFunctionLiteralInitializer(const Field& field, | |
970 TokenPosition* start, | |
971 TokenPosition* end) { | |
972 Zone* zone = Thread::Current()->zone(); | |
973 const Script& script = Script::Handle(zone, field.Script()); | |
974 | |
975 TranslationHelper translation_helper( | |
976 Thread::Current(), script.kernel_string_offsets(), | |
977 script.kernel_string_data(), script.kernel_canonical_names()); | |
978 | |
979 StreamingFlowGraphBuilder builder( | |
980 &translation_helper, zone, field.kernel_offset(), | |
981 TypedData::Handle(zone, field.kernel_data())); | |
982 kernel::FieldHelper field_helper(&builder); | |
983 field_helper.ReadUntilExcluding(kernel::FieldHelper::kEnd, true); | |
984 return field_helper.FieldHasFunctionLiteralInitializer(start, end); | |
985 } | |
986 | |
987 ParsedFunction* ParseStaticFieldInitializer(Zone* zone, const Field& field) { | 968 ParsedFunction* ParseStaticFieldInitializer(Zone* zone, const Field& field) { |
988 Thread* thread = Thread::Current(); | 969 Thread* thread = Thread::Current(); |
989 | 970 |
990 String& init_name = String::Handle(zone, field.name()); | 971 String& init_name = String::Handle(zone, field.name()); |
991 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name); | 972 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name); |
992 | 973 |
993 // Create a static initializer. | 974 // Create a static initializer. |
994 const Object& owner = Object::Handle(field.RawOwner()); | 975 const Object& owner = Object::Handle(field.RawOwner()); |
995 const Function& initializer_fun = Function::ZoneHandle( | 976 const Function& initializer_fun = Function::ZoneHandle( |
996 zone, Function::New(init_name, RawFunction::kImplicitStaticFinalGetter, | 977 zone, Function::New(init_name, RawFunction::kImplicitStaticFinalGetter, |
997 true, // is_static | 978 true, // is_static |
998 false, // is_const | 979 false, // is_const |
999 false, // is_abstract | 980 false, // is_abstract |
1000 false, // is_external | 981 false, // is_external |
1001 false, // is_native | 982 false, // is_native |
1002 owner, TokenPosition::kNoSource)); | 983 owner, TokenPosition::kNoSource)); |
1003 initializer_fun.set_kernel_data(TypedData::Handle(zone, field.kernel_data())); | 984 initializer_fun.set_kernel_data(TypedData::Handle(zone, field.kernel_data())); |
1004 initializer_fun.set_kernel_offset(field.kernel_offset()); | 985 initializer_fun.set_kernel_offset(field.kernel_offset()); |
1005 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type())); | 986 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type())); |
1006 initializer_fun.set_is_debuggable(false); | 987 initializer_fun.set_is_debuggable(false); |
1007 initializer_fun.set_is_reflectable(false); | 988 initializer_fun.set_is_reflectable(false); |
1008 initializer_fun.set_is_inlinable(false); | 989 initializer_fun.set_is_inlinable(false); |
1009 return new (zone) ParsedFunction(thread, initializer_fun); | 990 return new (zone) ParsedFunction(thread, initializer_fun); |
1010 } | 991 } |
1011 | 992 |
1012 } // namespace kernel | 993 } // namespace kernel |
1013 } // namespace dart | 994 } // namespace dart |
1014 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 995 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |