Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: runtime/vm/kernel_reader.cc

Issue 2972343002: [kernel] Insert kernel bodies into VM heap (Closed)
Patch Set: Rebased Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/kernel_binary.h" 10 #include "vm/kernel_binary.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 TypedData& offsets = TypedData::Handle( 146 TypedData& offsets = TypedData::Handle(
147 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld)); 147 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld));
148 offsets.SetUint32(0, 0); 148 offsets.SetUint32(0, 0);
149 intptr_t end_offset = 0; 149 intptr_t end_offset = 0;
150 for (intptr_t i = 1; i < count; ++i) { 150 for (intptr_t i = 1; i < count; ++i) {
151 end_offset = reader.ReadUInt(); 151 end_offset = reader.ReadUInt();
152 offsets.SetUint32(i << 2, end_offset); 152 offsets.SetUint32(i << 2, end_offset);
153 } 153 }
154 154
155 // Copy the string data out of the binary and into the VM's heap. 155 // Copy the string data out of the binary and into the VM's heap.
156 TypedData& data = TypedData::Handle( 156 TypedData& data =
157 Z, TypedData::New(kTypedDataUint8ArrayCid, end_offset, Heap::kOld)); 157 reader.CopyDataToVMHeap(Z, reader.offset(), reader.offset() + end_offset);
158 {
159 NoSafepointScope no_safepoint;
160 memmove(data.DataAddr(0), reader.buffer() + reader.offset(), end_offset);
161 }
162 158
163 // Copy the canonical names into the VM's heap. Encode them as unsigned, so 159 // Copy the canonical names into the VM's heap. Encode them as unsigned, so
164 // the parent indexes are adjusted when extracted. 160 // the parent indexes are adjusted when extracted.
165 reader.set_offset(program->name_table_offset()); 161 reader.set_offset(program->name_table_offset());
166 count = reader.ReadUInt() * 2; 162 count = reader.ReadUInt() * 2;
167 TypedData& names = TypedData::Handle( 163 TypedData& names = TypedData::Handle(
168 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld)); 164 Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld));
169 for (intptr_t i = 0; i < count; ++i) { 165 for (intptr_t i = 0; i < count; ++i) {
170 names.SetUint32(i << 2, reader.ReadUInt()); 166 names.SetUint32(i << 2, reader.ReadUInt());
171 } 167 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ClassForScriptAt(toplevel_class, field_helper.source_uri_index_); 269 ClassForScriptAt(toplevel_class, field_helper.source_uri_index_);
274 dart::Field& field = dart::Field::Handle( 270 dart::Field& field = dart::Field::Handle(
275 Z, dart::Field::NewTopLevel(name, field_helper.IsFinal(), 271 Z, dart::Field::NewTopLevel(name, field_helper.IsFinal(),
276 field_helper.IsConst(), script_class, 272 field_helper.IsConst(), script_class,
277 field_helper.position_)); 273 field_helper.position_));
278 field.set_kernel_offset(field_offset); 274 field.set_kernel_offset(field_offset);
279 const AbstractType& type = T.BuildType(); // read type. 275 const AbstractType& type = T.BuildType(); // read type.
280 field.SetFieldType(type); 276 field.SetFieldType(type);
281 field_helper.SetJustRead(FieldHelper::kType); 277 field_helper.SetJustRead(FieldHelper::kType);
282 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); 278 field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
279 intptr_t field_initializer_offset = builder_.ReaderOffset();
283 field.set_has_initializer(builder_.PeekTag() == kSomething); 280 field.set_has_initializer(builder_.PeekTag() == kSomething);
284 GenerateFieldAccessors(toplevel_class, field, &field_helper, field_offset);
285 field_helper.ReadUntilExcluding(FieldHelper::kEnd); 281 field_helper.ReadUntilExcluding(FieldHelper::kEnd);
282 TypedData& body_data = builder_.reader_->CopyDataToVMHeap(
283 Z, field_offset, builder_.ReaderOffset());
284 field.set_kernel_body(body_data);
285 {
286 // GenerateFieldAccessors reads (some of) the initializer.
287 AlternativeReadingScope alt(builder_.reader_, field_initializer_offset);
288 GenerateFieldAccessors(toplevel_class, field, &field_helper,
289 field_offset);
290 }
286 if (FLAG_enable_mirrors && field_helper.annotation_count_ > 0) { 291 if (FLAG_enable_mirrors && field_helper.annotation_count_ > 0) {
287 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset); 292 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset,
293 &body_data);
288 } 294 }
289 fields_.Add(&field); 295 fields_.Add(&field);
290 library.AddObject(field, name); 296 library.AddObject(field, name);
291 } 297 }
292 toplevel_class.AddFields(fields_); 298 toplevel_class.AddFields(fields_);
293 299
294 // Load toplevel procedures. 300 // Load toplevel procedures.
295 intptr_t procedure_count = builder_.ReadListLength(); // read list length. 301 intptr_t procedure_count = builder_.ReadListLength(); // read list length.
296 for (intptr_t i = 0; i < procedure_count; ++i) { 302 for (intptr_t i = 0; i < procedure_count; ++i) {
297 ReadProcedure(library, toplevel_class, false); 303 ReadProcedure(library, toplevel_class, false);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // a script to detect test functions that should not be optimized. 360 // a script to detect test functions that should not be optimized.
355 if (klass.script() == Script::null()) { 361 if (klass.script() == Script::null()) {
356 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex); 362 class_helper.ReadUntilIncluding(ClassHelper::kSourceUriIndex);
357 klass.set_script(ScriptAt(class_helper.source_uri_index_)); 363 klass.set_script(ScriptAt(class_helper.source_uri_index_));
358 } 364 }
359 if (klass.token_pos() == TokenPosition::kNoSource) { 365 if (klass.token_pos() == TokenPosition::kNoSource) {
360 class_helper.ReadUntilIncluding(ClassHelper::kPosition); 366 class_helper.ReadUntilIncluding(ClassHelper::kPosition);
361 klass.set_token_pos(class_helper.position_); 367 klass.set_token_pos(class_helper.position_);
362 } 368 }
363 369
370 class_helper.ReadUntilIncluding(ClassHelper::kAnnotations);
371 intptr_t class_offset_after_annotations = builder_.ReaderOffset();
364 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters); 372 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters);
365 intptr_t type_parameter_counts = 373 intptr_t type_parameter_counts =
366 builder_.ReadListLength(); // read type_parameters list length. 374 builder_.ReadListLength(); // read type_parameters list length.
367 375
368 ActiveClassScope active_class_scope(&active_class_, &klass); 376 ActiveClassScope active_class_scope(&active_class_, &klass);
369 if (!klass.is_cycle_free()) { 377 if (!klass.is_cycle_free()) {
370 ReadPreliminaryClass(&klass, &class_helper, type_parameter_counts); 378 ReadPreliminaryClass(&klass, &class_helper, type_parameter_counts);
371 } else { 379 } else {
372 for (intptr_t i = 0; i < type_parameter_counts; ++i) { 380 for (intptr_t i = 0; i < type_parameter_counts; ++i) {
373 builder_.SkipStringReference(); // read ith name index. 381 builder_.SkipStringReference(); // read ith name index.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 Z, 418 Z,
411 dart::Field::New(name, field_helper.IsStatic(), 419 dart::Field::New(name, field_helper.IsStatic(),
412 // In the VM all const fields are implicitly final 420 // In the VM all const fields are implicitly final
413 // whereas in Kernel they are not final because they 421 // whereas in Kernel they are not final because they
414 // are not explicitly declared that way. 422 // are not explicitly declared that way.
415 field_helper.IsFinal() || field_helper.IsConst(), 423 field_helper.IsFinal() || field_helper.IsConst(),
416 field_helper.IsConst(), is_reflectable, script_class, 424 field_helper.IsConst(), is_reflectable, script_class,
417 type, field_helper.position_)); 425 type, field_helper.position_));
418 field.set_kernel_offset(field_offset); 426 field.set_kernel_offset(field_offset);
419 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); 427 field_helper.ReadUntilExcluding(FieldHelper::kInitializer);
428 intptr_t field_initializer_offset = builder_.ReaderOffset();
420 field.set_has_initializer(builder_.PeekTag() == kSomething); 429 field.set_has_initializer(builder_.PeekTag() == kSomething);
421 GenerateFieldAccessors(klass, field, &field_helper, field_offset);
422 field_helper.ReadUntilExcluding(FieldHelper::kEnd); 430 field_helper.ReadUntilExcluding(FieldHelper::kEnd);
431 TypedData& body_data = builder_.reader_->CopyDataToVMHeap(
432 Z, field_offset, builder_.ReaderOffset());
433 field.set_kernel_body(body_data);
Kevin Millikin (Google) 2017/08/09 12:08:52 kernel_body (and body_data) are not the correct na
jensj 2017/08/10 07:37:34 Done.
434 {
435 // GenerateFieldAccessors reads (some of) the initializer.
436 AlternativeReadingScope alt(builder_.reader_, field_initializer_offset);
437 GenerateFieldAccessors(klass, field, &field_helper, field_offset);
438 }
423 if (FLAG_enable_mirrors && field_helper.annotation_count_ > 0) { 439 if (FLAG_enable_mirrors && field_helper.annotation_count_ > 0) {
424 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset); 440 library.AddFieldMetadata(field, TokenPosition::kNoSource, field_offset,
441 &body_data);
425 } 442 }
426 fields_.Add(&field); 443 fields_.Add(&field);
427 } 444 }
428 klass.AddFields(fields_); 445 klass.AddFields(fields_);
429 class_helper.SetJustRead(ClassHelper::kFields); 446 class_helper.SetJustRead(ClassHelper::kFields);
430 } 447 }
431 448
432 class_helper.ReadUntilExcluding(ClassHelper::kConstructors); 449 class_helper.ReadUntilExcluding(ClassHelper::kConstructors);
433 int constructor_count = builder_.ReadListLength(); // read list length. 450 int constructor_count = builder_.ReadListLength(); // read list length.
434 for (intptr_t i = 0; i < constructor_count; ++i) { 451 for (intptr_t i = 0; i < constructor_count; ++i) {
(...skipping 20 matching lines...) Expand all
455 FunctionNodeHelper function_node_helper(&builder_); 472 FunctionNodeHelper function_node_helper(&builder_);
456 function_node_helper.ReadUntilExcluding( 473 function_node_helper.ReadUntilExcluding(
457 FunctionNodeHelper::kRequiredParameterCount); 474 FunctionNodeHelper::kRequiredParameterCount);
458 builder_.SetupFunctionParameters(klass, function, 475 builder_.SetupFunctionParameters(klass, function,
459 true, // is_method 476 true, // is_method
460 false, // is_closure 477 false, // is_closure
461 &function_node_helper); 478 &function_node_helper);
462 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); 479 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd);
463 constructor_helper.SetJustRead(ConstructorHelper::kFunction); 480 constructor_helper.SetJustRead(ConstructorHelper::kFunction);
464 constructor_helper.ReadUntilExcluding(ConstructorHelper::kEnd); 481 constructor_helper.ReadUntilExcluding(ConstructorHelper::kEnd);
482 TypedData& body_data = builder_.reader_->CopyDataToVMHeap(
483 Z, constructor_offset, builder_.ReaderOffset());
484 function.set_kernel_body(body_data);
Kevin Millikin (Google) 2017/08/09 12:08:52 kernel_body (and body_data) are misleading names.
jensj 2017/08/10 07:37:34 Done.
465 485
466 if (FLAG_enable_mirrors && constructor_helper.annotation_count_ > 0) { 486 if (FLAG_enable_mirrors && constructor_helper.annotation_count_ > 0) {
467 library.AddFunctionMetadata(function, TokenPosition::kNoSource, 487 library.AddFunctionMetadata(function, TokenPosition::kNoSource,
468 constructor_offset); 488 constructor_offset, &body_data);
469 } 489 }
470 } 490 }
471 class_helper.SetJustRead(ClassHelper::kConstructors); 491 class_helper.SetJustRead(ClassHelper::kConstructors);
472 492
473 class_helper.ReadUntilExcluding(ClassHelper::kProcedures); 493 class_helper.ReadUntilExcluding(ClassHelper::kProcedures);
474 int procedure_count = builder_.ReadListLength(); // read list length. 494 int procedure_count = builder_.ReadListLength(); // read list length.
475 for (intptr_t i = 0; i < procedure_count; ++i) { 495 for (intptr_t i = 0; i < procedure_count; ++i) {
476 ReadProcedure(library, klass, true); 496 ReadProcedure(library, klass, true);
477 } 497 }
478 class_helper.SetJustRead(ClassHelper::kProcedures); 498 class_helper.SetJustRead(ClassHelper::kProcedures);
479 499
480 klass.SetFunctions(Array::Handle(MakeFunctionsArray())); 500 klass.SetFunctions(Array::Handle(MakeFunctionsArray()));
481 501
482 if (!klass.is_marked_for_parsing()) { 502 if (!klass.is_marked_for_parsing()) {
483 klass.set_is_marked_for_parsing(); 503 klass.set_is_marked_for_parsing();
484 } 504 }
485 505
486 if (FLAG_enable_mirrors && class_helper.annotation_count_ > 0) { 506 if (FLAG_enable_mirrors && class_helper.annotation_count_ > 0) {
507 TypedData& header_data = builder_.reader_->CopyDataToVMHeap(
508 Z, class_offset, class_offset_after_annotations);
487 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource, 509 library.AddClassMetadata(klass, toplevel_class, TokenPosition::kNoSource,
488 class_offset); 510 class_offset, &header_data);
489 } 511 }
490 512
491 class_helper.ReadUntilExcluding(ClassHelper::kEnd); 513 class_helper.ReadUntilExcluding(ClassHelper::kEnd);
492 514
493 return klass; 515 return klass;
494 } 516 }
495 517
496 void KernelReader::ReadProcedure(const dart::Library& library, 518 void KernelReader::ReadProcedure(const dart::Library& library,
497 const dart::Class& owner, 519 const dart::Class& owner,
498 bool in_class) { 520 bool in_class) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); 649 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd);
628 procedure_helper.SetJustRead(ProcedureHelper::kFunction); 650 procedure_helper.SetJustRead(ProcedureHelper::kFunction);
629 651
630 if (!in_class) { 652 if (!in_class) {
631 library.AddObject(function, name); 653 library.AddObject(function, name);
632 ASSERT(!Object::Handle( 654 ASSERT(!Object::Handle(
633 Z, library.LookupObjectAllowPrivate( 655 Z, library.LookupObjectAllowPrivate(
634 H.DartProcedureName(procedure_helper.canonical_name_))) 656 H.DartProcedureName(procedure_helper.canonical_name_)))
635 .IsNull()); 657 .IsNull());
636 } 658 }
659
660 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd);
661 TypedData& body_data = builder_.reader_->CopyDataToVMHeap(
662 Z, procedure_offset, builder_.ReaderOffset());
663 function.set_kernel_body(body_data);
664
637 if (FLAG_enable_mirrors && annotation_count > 0) { 665 if (FLAG_enable_mirrors && annotation_count > 0) {
638 library.AddFunctionMetadata(function, TokenPosition::kNoSource, 666 library.AddFunctionMetadata(function, TokenPosition::kNoSource,
639 procedure_offset); 667 procedure_offset, &body_data);
640 } 668 }
641
642 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd);
643 } 669 }
644 670
645 template <typename U> 671 template <typename U>
646 void KernelReader::ReadAndSetupTypeParameters( 672 void KernelReader::ReadAndSetupTypeParameters(
647 U* set_on, 673 U* set_on,
648 intptr_t type_parameter_count, 674 intptr_t type_parameter_count,
649 const Class& parameterized_class, 675 const Class& parameterized_class,
650 const Function& parameterized_function) { 676 const Function& parameterized_function) {
651 if (type_parameter_count > 0) { 677 if (type_parameter_count > 0) {
652 // First setup the type parameters, so if any of the following code uses it 678 // First setup the type parameters, so if any of the following code uses it
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 734
709 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) { 735 Script& KernelReader::ScriptAt(intptr_t index, StringIndex import_uri) {
710 Script& script = Script::ZoneHandle(Z); 736 Script& script = Script::ZoneHandle(Z);
711 script ^= scripts_.At(index); 737 script ^= scripts_.At(index);
712 if (script.IsNull()) { 738 if (script.IsNull()) {
713 // Create script with correct uri(s). 739 // Create script with correct uri(s).
714 dart::String& uri_string = builder_.SourceTableUriFor(index); 740 dart::String& uri_string = builder_.SourceTableUriFor(index);
715 dart::String& import_uri_string = 741 dart::String& import_uri_string =
716 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld); 742 import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld);
717 script = Script::New(import_uri_string, uri_string, 743 script = Script::New(import_uri_string, uri_string,
718 String::Handle(String::null()), RawScript::kKernelTag); 744 builder_.GetSourceFor(index), RawScript::kKernelTag);
719 script.set_kernel_data(program_->kernel_data());
720 script.set_kernel_data_size(program_->kernel_data_size());
721 script.set_kernel_script_index(index); 745 script.set_kernel_script_index(index);
722 script.set_kernel_string_offsets(H.string_offsets()); 746 script.set_kernel_string_offsets(H.string_offsets());
723 script.set_kernel_string_data(H.string_data()); 747 script.set_kernel_string_data(H.string_data());
724 script.set_kernel_canonical_names(H.canonical_names()); 748 script.set_kernel_canonical_names(H.canonical_names());
725 scripts_.SetAt(index, script); 749 scripts_.SetAt(index, script);
726 750
727 script.set_line_starts(Array::Handle(Array::null())); 751 script.set_line_starts(builder_.GetLineStartsFor(index));
728 script.set_debug_positions(Array::Handle(Array::null())); 752 script.set_debug_positions(Array::Handle(Array::null()));
729 script.set_yield_positions(Array::Handle(Array::null())); 753 script.set_yield_positions(Array::Handle(Array::null()));
730 } 754 }
731 return script; 755 return script;
732 } 756 }
733 757
734 void KernelReader::GenerateFieldAccessors(const dart::Class& klass, 758 void KernelReader::GenerateFieldAccessors(const dart::Class& klass,
735 const dart::Field& field, 759 const dart::Field& field,
736 FieldHelper* field_helper, 760 FieldHelper* field_helper,
737 intptr_t field_offset) { 761 intptr_t field_offset) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 // that are const (not just final) and they have is_const for 807 // that are const (not just final) and they have is_const for
784 // non-static 808 // non-static
785 // fields that are final. 809 // fields that are final.
786 field_helper->IsStatic() ? field_helper->IsConst() 810 field_helper->IsStatic() ? field_helper->IsConst()
787 : field_helper->IsFinal(), 811 : field_helper->IsFinal(),
788 false, // is_abstract 812 false, // is_abstract
789 false, // is_external 813 false, // is_external
790 false, // is_native 814 false, // is_native
791 script_class, field_helper->position_)); 815 script_class, field_helper->position_));
792 functions_.Add(&getter); 816 functions_.Add(&getter);
817 getter.set_kernel_body(TypedData::Handle(Z, field.kernel_body()));
793 getter.set_end_token_pos(field_helper->end_position_); 818 getter.set_end_token_pos(field_helper->end_position_);
794 getter.set_kernel_offset(field_offset); 819 getter.set_kernel_offset(field_offset);
795 getter.set_result_type(AbstractType::Handle(Z, field.type())); 820 getter.set_result_type(AbstractType::Handle(Z, field.type()));
796 getter.set_is_debuggable(false); 821 getter.set_is_debuggable(false);
797 SetupFieldAccessorFunction(klass, getter); 822 SetupFieldAccessorFunction(klass, getter);
798 823
799 if (!field_helper->IsStatic() && !field_helper->IsFinal()) { 824 if (!field_helper->IsStatic() && !field_helper->IsFinal()) {
800 // Only static fields can be const. 825 // Only static fields can be const.
801 ASSERT(!field_helper->IsConst()); 826 ASSERT(!field_helper->IsConst());
802 const dart::String& setter_name = 827 const dart::String& setter_name =
803 H.DartSetterName(field_helper->canonical_name_); 828 H.DartSetterName(field_helper->canonical_name_);
804 Function& setter = Function::ZoneHandle( 829 Function& setter = Function::ZoneHandle(
805 Z, Function::New(setter_name, RawFunction::kImplicitSetter, 830 Z, Function::New(setter_name, RawFunction::kImplicitSetter,
806 false, // is_static 831 false, // is_static
807 false, // is_const 832 false, // is_const
808 false, // is_abstract 833 false, // is_abstract
809 false, // is_external 834 false, // is_external
810 false, // is_native 835 false, // is_native
811 script_class, field_helper->position_)); 836 script_class, field_helper->position_));
812 functions_.Add(&setter); 837 functions_.Add(&setter);
838 setter.set_kernel_body(TypedData::Handle(Z, field.kernel_body()));
813 setter.set_end_token_pos(field_helper->end_position_); 839 setter.set_end_token_pos(field_helper->end_position_);
814 setter.set_kernel_offset(field_offset); 840 setter.set_kernel_offset(field_offset);
815 setter.set_result_type(Object::void_type()); 841 setter.set_result_type(Object::void_type());
816 setter.set_is_debuggable(false); 842 setter.set_is_debuggable(false);
817 SetupFieldAccessorFunction(klass, setter); 843 SetupFieldAccessorFunction(klass, setter);
818 } 844 }
819 } 845 }
820 846
821 void KernelReader::SetupFieldAccessorFunction(const dart::Class& klass, 847 void KernelReader::SetupFieldAccessorFunction(const dart::Class& klass,
822 const dart::Function& function) { 848 const dart::Function& function) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 bool KernelReader::FieldHasFunctionLiteralInitializer(const dart::Field& field, 926 bool KernelReader::FieldHasFunctionLiteralInitializer(const dart::Field& field,
901 TokenPosition* start, 927 TokenPosition* start,
902 TokenPosition* end) { 928 TokenPosition* end) {
903 dart::Zone* zone = Thread::Current()->zone(); 929 dart::Zone* zone = Thread::Current()->zone();
904 const Script& script = Script::Handle(zone, field.Script()); 930 const Script& script = Script::Handle(zone, field.Script());
905 931
906 TranslationHelper translation_helper( 932 TranslationHelper translation_helper(
907 Thread::Current(), script.kernel_string_offsets(), 933 Thread::Current(), script.kernel_string_offsets(),
908 script.kernel_string_data(), script.kernel_canonical_names()); 934 script.kernel_string_data(), script.kernel_canonical_names());
909 935
910 kernel::StreamingFlowGraphBuilder* builder = 936 StreamingFlowGraphBuilder builder(
911 new kernel::StreamingFlowGraphBuilder(&translation_helper, zone, 937 &translation_helper, zone, field.kernel_offset(),
912 script.kernel_data(), 938 TypedData::Handle(zone, field.kernel_body()));
913 script.kernel_data_size()); 939 kernel::FieldHelper field_helper(&builder);
914
915 kernel::FieldHelper field_helper(builder, field.kernel_offset());
916 field_helper.ReadUntilExcluding(kernel::FieldHelper::kEnd, true); 940 field_helper.ReadUntilExcluding(kernel::FieldHelper::kEnd, true);
917 bool result = field_helper.FieldHasFunctionLiteralInitializer(start, end); 941 return field_helper.FieldHasFunctionLiteralInitializer(start, end);
918
919 delete builder;
920 return result;
921 } 942 }
922 943
923 ParsedFunction* ParseStaticFieldInitializer(Zone* zone, 944 ParsedFunction* ParseStaticFieldInitializer(Zone* zone,
924 const dart::Field& field) { 945 const dart::Field& field) {
925 Thread* thread = Thread::Current(); 946 Thread* thread = Thread::Current();
926 947
927 dart::String& init_name = dart::String::Handle(zone, field.name()); 948 dart::String& init_name = dart::String::Handle(zone, field.name());
928 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name); 949 init_name = Symbols::FromConcat(thread, Symbols::InitPrefix(), init_name);
929 950
930 // Create a static initializer. 951 // Create a static initializer.
931 const Object& owner = Object::Handle(field.RawOwner()); 952 const Object& owner = Object::Handle(field.RawOwner());
932 const Function& initializer_fun = Function::ZoneHandle( 953 const Function& initializer_fun = Function::ZoneHandle(
933 zone, 954 zone,
934 dart::Function::New(init_name, RawFunction::kImplicitStaticFinalGetter, 955 dart::Function::New(init_name, RawFunction::kImplicitStaticFinalGetter,
935 true, // is_static 956 true, // is_static
936 false, // is_const 957 false, // is_const
937 false, // is_abstract 958 false, // is_abstract
938 false, // is_external 959 false, // is_external
939 false, // is_native 960 false, // is_native
940 owner, TokenPosition::kNoSource)); 961 owner, TokenPosition::kNoSource));
962 initializer_fun.set_kernel_body(TypedData::Handle(zone, field.kernel_body()));
941 initializer_fun.set_kernel_offset(field.kernel_offset()); 963 initializer_fun.set_kernel_offset(field.kernel_offset());
942 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type())); 964 initializer_fun.set_result_type(AbstractType::Handle(zone, field.type()));
943 initializer_fun.set_is_debuggable(false); 965 initializer_fun.set_is_debuggable(false);
944 initializer_fun.set_is_reflectable(false); 966 initializer_fun.set_is_reflectable(false);
945 initializer_fun.set_is_inlinable(false); 967 initializer_fun.set_is_inlinable(false);
946 return new (zone) ParsedFunction(thread, initializer_fun); 968 return new (zone) ParsedFunction(thread, initializer_fun);
947 } 969 }
948 970
949 } // namespace kernel 971 } // namespace kernel
950 } // namespace dart 972 } // namespace dart
951 #endif // !defined(DART_PRECOMPILED_RUNTIME) 973 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698