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

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

Issue 2665723002: Implement canonical name scheme in kernel. (Closed)
Patch Set: Address Kevin's comments Created 3 years, 10 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
« no previous file with comments | « runtime/vm/kernel.cc ('k') | utils/kernel-service/kernel-service.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if !defined(DART_PRECOMPILED_RUNTIME) 4 #if !defined(DART_PRECOMPILED_RUNTIME)
5 5
6 #include "platform/globals.h" 6 #include "platform/globals.h"
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/growable_array.h" 8 #include "vm/growable_array.h"
9 #include "vm/kernel.h" 9 #include "vm/kernel.h"
10 #include "vm/kernel_to_il.h" 10 #include "vm/kernel_to_il.h"
(...skipping 15 matching lines...) Expand all
26 26
27 27
28 static const uint32_t kMagicProgramFile = 0x90ABCDEFu; 28 static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
29 29
30 30
31 // Keep in sync with package:dynamo/lib/binary/tag.dart 31 // Keep in sync with package:dynamo/lib/binary/tag.dart
32 enum Tag { 32 enum Tag {
33 kNothing = 0, 33 kNothing = 0,
34 kSomething = 1, 34 kSomething = 1,
35 35
36 kNormalClass = 2, 36 kClass = 2,
37 kMixinClass = 3,
38 37
39 kField = 4, 38 kField = 4,
40 kConstructor = 5, 39 kConstructor = 5,
41 kProcedure = 6, 40 kProcedure = 6,
42 41
43 kInvalidInitializer = 7, 42 kInvalidInitializer = 7,
44 kFieldInitializer = 8, 43 kFieldInitializer = 8,
45 kSuperInitializer = 9, 44 kSuperInitializer = 9,
46 kRedirectingInitializer = 10, 45 kRedirectingInitializer = 10,
47 kLocalInitializer = 11, 46 kLocalInitializer = 11,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 115
117 kInvalidType = 90, 116 kInvalidType = 90,
118 kDynamicType = 91, 117 kDynamicType = 91,
119 kVoidType = 92, 118 kVoidType = 92,
120 kInterfaceType = 93, 119 kInterfaceType = 93,
121 kFunctionType = 94, 120 kFunctionType = 94,
122 kTypeParameterType = 95, 121 kTypeParameterType = 95,
123 kSimpleInterfaceType = 96, 122 kSimpleInterfaceType = 96,
124 kSimpleFunctionType = 97, 123 kSimpleFunctionType = 97,
125 124
126 kNullReference = 99,
127 kNormalClassReference = 100,
128 kMixinClassReference = 101,
129
130 kLibraryFieldReference = 102,
131 kClassFieldReference = 103,
132 kClassConstructorReference = 104,
133 kLibraryProcedureReference = 105,
134 kClassProcedureReference = 106,
135
136 kSpecializedTagHighBit = 0x80, // 10000000 125 kSpecializedTagHighBit = 0x80, // 10000000
137 kSpecializedTagMask = 0xF8, // 11111000 126 kSpecializedTagMask = 0xF8, // 11111000
138 kSpecializedPayloadMask = 0x7, // 00000111 127 kSpecializedPayloadMask = 0x7, // 00000111
139 128
140 kSpecializedVariableGet = 128, 129 kSpecializedVariableGet = 128,
141 kSpecializedVariableSet = 136, 130 kSpecializedVariableSet = 136,
142 kSpecialIntLiteral = 144, 131 kSpecialIntLiteral = 144,
143 }; 132 };
144 133
145 134
(...skipping 20 matching lines...) Expand all
166 ASSERT(index < variables_.length()); 155 ASSERT(index < variables_.length());
167 return variables_[index]; 156 return variables_[index];
168 } 157 }
169 158
170 void Push(T* v) { 159 void Push(T* v) {
171 variables_.Add(v); 160 variables_.Add(v);
172 current_count_++; 161 current_count_++;
173 } 162 }
174 163
175 void Push(List<T>* decl) { 164 void Push(List<T>* decl) {
176 for (int i = 0; i < decl->length(); i++) { 165 for (intptr_t i = 0; i < decl->length(); i++) {
177 variables_.Add(decl[i]); 166 variables_.Add(decl[i]);
178 current_count_++; 167 current_count_++;
179 } 168 }
180 } 169 }
181 170
182 void Pop(T* decl) { 171 void Pop(T* decl) {
183 variables_.RemoveLast(); 172 variables_.RemoveLast();
184 current_count_--; 173 current_count_--;
185 } 174 }
186 175
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 current_count_++; 215 current_count_++;
227 } 216 }
228 217
229 void Set(T* v, int index) { 218 void Set(T* v, int index) {
230 typename MallocMap<T, int>::Pair* entry = variables_.LookupPair(v); 219 typename MallocMap<T, int>::Pair* entry = variables_.LookupPair(v);
231 ASSERT(entry != NULL); 220 ASSERT(entry != NULL);
232 entry->value = index; 221 entry->value = index;
233 } 222 }
234 223
235 void Push(List<T>* decl) { 224 void Push(List<T>* decl) {
236 for (int i = 0; i < decl->length(); i++) { 225 for (intptr_t i = 0; i < decl->length(); i++) {
237 Push(decl[i]); 226 Push(decl[i]);
238 } 227 }
239 } 228 }
240 229
241 void Pop(T* v) { 230 void Pop(T* v) {
242 current_count_--; 231 current_count_--;
243 stack_height_--; 232 stack_height_--;
244 } 233 }
245 234
246 private: 235 private:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 Program* program() { return program_; } 303 Program* program() { return program_; }
315 void set_program(Program* program) { program_ = program; } 304 void set_program(Program* program) { program_ = program; }
316 305
317 BlockStack<VariableDeclaration>& variables() { return scope_; } 306 BlockStack<VariableDeclaration>& variables() { return scope_; }
318 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; } 307 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; }
319 BlockStack<SwitchCase>& switch_cases() { return switch_cases_; } 308 BlockStack<SwitchCase>& switch_cases() { return switch_cases_; }
320 309
321 BlockStack<LabeledStatement>* labels() { return labels_; } 310 BlockStack<LabeledStatement>* labels() { return labels_; }
322 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; } 311 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; }
323 312
313 CanonicalName* GetCanonicalName(int index) { return canonical_names_[index]; }
314 void SetCanonicalName(int index, CanonicalName* name) {
315 canonical_names_[index] = name;
316 }
317 void SetCanonicalNameCount(int count) { canonical_names_.SetLength(count); }
318
324 private: 319 private:
325 Program* program_; 320 Program* program_;
321 MallocGrowableArray<Ref<CanonicalName> > canonical_names_;
326 BlockStack<VariableDeclaration> scope_; 322 BlockStack<VariableDeclaration> scope_;
327 BlockStack<TypeParameter> type_parameters_; 323 BlockStack<TypeParameter> type_parameters_;
328 BlockStack<SwitchCase> switch_cases_; 324 BlockStack<SwitchCase> switch_cases_;
329 BlockStack<LabeledStatement>* labels_; 325 BlockStack<LabeledStatement>* labels_;
330 }; 326 };
331 327
332 328
333 class Reader { 329 class Reader {
334 public: 330 public:
335 Reader(const uint8_t* buffer, int64_t size) 331 Reader(const uint8_t* buffer, int64_t size)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 return RT::ReadFrom(this); 479 return RT::ReadFrom(this);
484 } 480 }
485 481
486 template <typename T> 482 template <typename T>
487 T* ReadOptional() { 483 T* ReadOptional() {
488 return ReadOptional<T, T>(); 484 return ReadOptional<T, T>();
489 } 485 }
490 486
491 ReaderHelper* helper() { return &builder_; } 487 ReaderHelper* helper() { return &builder_; }
492 488
489 CanonicalName* ReadCanonicalNameReference() {
490 int index = ReadUInt();
491 if (index == 0) return NULL;
492 CanonicalName* name = builder_.GetCanonicalName(index - 1);
493 ASSERT(name != NULL);
494 return name;
495 }
496
497 CanonicalName* ReadDefiningCanonicalNameReference(LinkedNode* node_to_link) {
498 CanonicalName* name = ReadCanonicalNameReference();
499 ASSERT(name != NULL);
500 name->BindTo(node_to_link);
501 return name;
502 }
503
493 private: 504 private:
494 const uint8_t* buffer_; 505 const uint8_t* buffer_;
495 int64_t size_; 506 int64_t size_;
496 int64_t offset_; 507 int64_t offset_;
497 ReaderHelper builder_; 508 ReaderHelper builder_;
498 TokenPosition max_position_; 509 TokenPosition max_position_;
499 TokenPosition min_position_; 510 TokenPosition min_position_;
500 intptr_t current_script_id_; 511 intptr_t current_script_id_;
501 512
502 friend class PositionScope; 513 friend class PositionScope;
(...skipping 30 matching lines...) Expand all
533 }; 544 };
534 545
535 template <typename T> 546 template <typename T>
536 template <typename IT> 547 template <typename IT>
537 void List<T>::ReadFrom(Reader* reader, TreeNode* parent) { 548 void List<T>::ReadFrom(Reader* reader, TreeNode* parent) {
538 TRACE_READ_OFFSET(); 549 TRACE_READ_OFFSET();
539 ASSERT(parent != NULL); 550 ASSERT(parent != NULL);
540 int length = reader->ReadListLength(); 551 int length = reader->ReadListLength();
541 EnsureInitialized(length); 552 EnsureInitialized(length);
542 553
543 for (int i = 0; i < length_; i++) { 554 for (intptr_t i = 0; i < length_; i++) {
544 IT* object = GetOrCreate<IT>(i, parent); 555 IT* object = GetOrCreate<IT>(i, parent);
545 object->ReadFrom(reader); 556 object->ReadFrom(reader);
546 } 557 }
547 } 558 }
548 559
549 560
550 template <typename T> 561 template <typename T>
551 template <typename IT> 562 template <typename IT>
552 void List<T>::ReadFrom(Reader* reader) { 563 void List<T>::ReadFrom(Reader* reader) {
553 TRACE_READ_OFFSET(); 564 TRACE_READ_OFFSET();
554 int length = reader->ReadListLength(); 565 int length = reader->ReadListLength();
555 EnsureInitialized(length); 566 EnsureInitialized(length);
556 567
557 for (int i = 0; i < length_; i++) { 568 for (intptr_t i = 0; i < length_; i++) {
558 GetOrCreate<IT>(i)->ReadFrom(reader); 569 GetOrCreate<IT>(i)->ReadFrom(reader);
559 } 570 }
560 } 571 }
561 572
562 573
563 template <typename T> 574 template <typename T>
564 template <typename IT> 575 template <typename IT>
565 void List<T>::ReadFromStatic(Reader* reader) { 576 void List<T>::ReadFromStatic(Reader* reader) {
566 TRACE_READ_OFFSET(); 577 TRACE_READ_OFFSET();
567 int length = reader->ReadListLength(); 578 int length = reader->ReadListLength();
568 EnsureInitialized(length); 579 EnsureInitialized(length);
569 580
570 for (int i = 0; i < length_; i++) { 581 for (intptr_t i = 0; i < length_; i++) {
571 ASSERT(array_[i] == NULL); 582 ASSERT(array_[i] == NULL);
572 array_[i] = IT::ReadFrom(reader); 583 array_[i] = IT::ReadFrom(reader);
573 } 584 }
574 } 585 }
575 586
576 void TypeParameterList::ReadFrom(Reader* reader) { 587 void TypeParameterList::ReadFrom(Reader* reader) {
577 // It is possible for the bound of the first type parameter to refer to 588 // It is possible for the bound of the first type parameter to refer to
578 // the second type parameter. This means we need to create [TypeParameter] 589 // the second type parameter. This means we need to create [TypeParameter]
579 // objects before reading the bounds. 590 // objects before reading the bounds.
580 int length = reader->ReadListLength(); 591 int length = reader->ReadListLength();
581 EnsureInitialized(length); 592 EnsureInitialized(length);
582 593
583 // Make all [TypeParameter]s available in scope. 594 // Make all [TypeParameter]s available in scope.
584 for (int i = 0; i < length; i++) { 595 for (intptr_t i = 0; i < length; i++) {
585 TypeParameter* parameter = (*this)[i] = new TypeParameter(); 596 TypeParameter* parameter = (*this)[i] = new TypeParameter();
586 reader->helper()->type_parameters().Push(parameter); 597 reader->helper()->type_parameters().Push(parameter);
587 } 598 }
588 599
589 // Read all [TypeParameter]s and their bounds. 600 // Read all [TypeParameter]s and their bounds.
590 for (int i = 0; i < length; i++) { 601 for (intptr_t i = 0; i < length; i++) {
591 (*this)[i]->ReadFrom(reader); 602 (*this)[i]->ReadFrom(reader);
592 } 603 }
593 } 604 }
594 605
595 606
596 template <typename A, typename B> 607 template <typename A, typename B>
597 Tuple<A, B>* Tuple<A, B>::ReadFrom(Reader* reader) { 608 Tuple<A, B>* Tuple<A, B>::ReadFrom(Reader* reader) {
598 TRACE_READ_OFFSET(); 609 TRACE_READ_OFFSET();
599 A* first = A::ReadFrom(reader); 610 A* first = A::ReadFrom(reader);
600 B* second = B::ReadFrom(reader); 611 B* second = B::ReadFrom(reader);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } 677 }
667 line_starts_[i] = line_starts; 678 line_starts_[i] = line_starts;
668 } 679 }
669 } 680 }
670 681
671 682
672 Library* Library::ReadFrom(Reader* reader) { 683 Library* Library::ReadFrom(Reader* reader) {
673 TRACE_READ_OFFSET(); 684 TRACE_READ_OFFSET();
674 int flags = reader->ReadFlags(); 685 int flags = reader->ReadFlags();
675 ASSERT(flags == 0); // external libraries not supported 686 ASSERT(flags == 0); // external libraries not supported
687
688 CanonicalName* canonical_name =
689 reader->ReadDefiningCanonicalNameReference(this);
690
676 name_ = Reference::ReadStringFrom(reader); 691 name_ = Reference::ReadStringFrom(reader);
677 import_uri_ = Reference::ReadStringFrom(reader); 692 import_uri_ = canonical_name->name();
678 source_uri_index_ = reader->ReadUInt(); 693 source_uri_index_ = reader->ReadUInt();
679 reader->set_current_script_id(source_uri_index_); 694 reader->set_current_script_id(source_uri_index_);
680 695
681 int num_imports = reader->ReadUInt(); 696 int num_imports = reader->ReadUInt();
682 if (num_imports != 0) { 697 if (num_imports != 0) {
683 FATAL("Deferred imports not implemented in VM"); 698 FATAL("Deferred imports not implemented in VM");
684 } 699 }
685 int num_classes = reader->ReadUInt(); 700 int num_classes = reader->ReadUInt();
686 classes().EnsureInitialized(num_classes); 701 classes().EnsureInitialized(num_classes);
687 for (int i = 0; i < num_classes; i++) { 702 for (intptr_t i = 0; i < num_classes; i++) {
688 Tag tag = reader->ReadTag(); 703 Tag tag = reader->ReadTag();
689 if (tag == kNormalClass) { 704 ASSERT(tag == kClass);
690 NormalClass* klass = classes().GetOrCreate<NormalClass>(i, this); 705 NormalClass* klass = classes().GetOrCreate<NormalClass>(i, this);
691 klass->ReadFrom(reader); 706 klass->ReadFrom(reader);
692 } else {
693 ASSERT(tag == kMixinClass);
694 MixinClass* klass = classes().GetOrCreate<MixinClass>(i, this);
695 klass->ReadFrom(reader);
696 }
697 } 707 }
698 708
699 fields().ReadFrom<Field>(reader, this); 709 fields().ReadFrom<Field>(reader, this);
700 procedures().ReadFrom<Procedure>(reader, this); 710 procedures().ReadFrom<Procedure>(reader, this);
701 return this; 711 return this;
702 } 712 }
703 713
704 714
705 Class* Class::ReadFrom(Reader* reader) { 715 Class* Class::ReadFrom(Reader* reader) {
706 TRACE_READ_OFFSET(); 716 TRACE_READ_OFFSET();
707 717
718 reader->ReadDefiningCanonicalNameReference(this);
708 position_ = reader->ReadPosition(false); 719 position_ = reader->ReadPosition(false);
709 is_abstract_ = reader->ReadBool(); 720 is_abstract_ = reader->ReadBool();
710 name_ = Reference::ReadStringFrom(reader); 721 name_ = Reference::ReadStringFrom(reader);
711 source_uri_index_ = reader->ReadUInt(); 722 source_uri_index_ = reader->ReadUInt();
712 reader->set_current_script_id(source_uri_index_); 723 reader->set_current_script_id(source_uri_index_);
713 reader->record_token_position(position_); 724 reader->record_token_position(position_);
714 annotations_.ReadFromStatic<Expression>(reader); 725 annotations_.ReadFromStatic<Expression>(reader);
715 726
716 return this; 727 return this;
717 } 728 }
718 729
719 730
720 NormalClass* NormalClass::ReadFrom(Reader* reader) { 731 NormalClass* NormalClass::ReadFrom(Reader* reader) {
721 TRACE_READ_OFFSET(); 732 TRACE_READ_OFFSET();
722 Class::ReadFrom(reader); 733 Class::ReadFrom(reader);
723 TypeParameterScope<ReaderHelper> scope(reader->helper()); 734 TypeParameterScope<ReaderHelper> scope(reader->helper());
724 735
725 type_parameters_.ReadFrom(reader); 736 type_parameters_.ReadFrom(reader);
726 DartType* type = reader->ReadOptional<DartType>(); 737 DartType* type = reader->ReadOptional<DartType>();
727 738
728 super_class_ = InterfaceType::Cast(type); 739 super_class_ = InterfaceType::Cast(type);
740 reader->ReadOptional<DartType>(); // Mixed-in type is unused.
729 implemented_classes_.ReadFromStatic<DowncastReader<DartType, InterfaceType> >( 741 implemented_classes_.ReadFromStatic<DowncastReader<DartType, InterfaceType> >(
730 reader); 742 reader);
731 fields_.ReadFrom<Field>(reader, this); 743 fields_.ReadFrom<Field>(reader, this);
732 constructors_.ReadFrom<Constructor>(reader, this); 744 constructors_.ReadFrom<Constructor>(reader, this);
733 procedures_.ReadFrom<Procedure>(reader, this); 745 procedures_.ReadFrom<Procedure>(reader, this);
734 746
735 return this; 747 return this;
736 } 748 }
737 749
738 750
739 MixinClass* MixinClass::ReadFrom(Reader* reader) { 751 MixinClass* MixinClass::ReadFrom(Reader* reader) {
740 TRACE_READ_OFFSET(); 752 TRACE_READ_OFFSET();
741 TypeParameterScope<ReaderHelper> scope(reader->helper()); 753 TypeParameterScope<ReaderHelper> scope(reader->helper());
742 754
743 Class::ReadFrom(reader); 755 Class::ReadFrom(reader);
744 type_parameters_.ReadFrom(reader); 756 type_parameters_.ReadFrom(reader);
745 first_ = InterfaceType::Cast(DartType::ReadFrom(reader)); 757 first_ = InterfaceType::Cast(DartType::ReadFrom(reader));
746 second_ = InterfaceType::Cast(DartType::ReadFrom(reader)); 758 second_ = InterfaceType::Cast(DartType::ReadFrom(reader));
747 implemented_classes_.ReadFromStatic<DowncastReader<DartType, InterfaceType> >( 759 implemented_classes_.ReadFromStatic<DowncastReader<DartType, InterfaceType> >(
748 reader); 760 reader);
749 constructors_.ReadFrom<Constructor>(reader, this); 761 constructors_.ReadFrom<Constructor>(reader, this);
750 return this; 762 return this;
751 } 763 }
752 764
753 765
754 Member* Reference::ReadMemberFrom(Reader* reader, bool allow_null) { 766 CanonicalName* Reference::ReadMemberFrom(Reader* reader, bool allow_null) {
755 TRACE_READ_OFFSET(); 767 TRACE_READ_OFFSET();
756 768
757 Program* program = reader->helper()->program(); 769 CanonicalName* canonical_name = reader->ReadCanonicalNameReference();
758 Tag tag = reader->ReadTag(); 770 if (canonical_name == NULL && !allow_null) {
759 switch (tag) { 771 FATAL("Expected a valid member reference, but got `null`");
760 case kLibraryFieldReference: {
761 int library_idx = reader->ReadUInt();
762 int field_idx = reader->ReadUInt();
763 Library* library = program->libraries().GetOrCreate<Library>(library_idx);
764 return library->fields().GetOrCreate<Field>(field_idx, library);
765 }
766 case kLibraryProcedureReference: {
767 int library_idx = reader->ReadUInt();
768 int procedure_idx = reader->ReadUInt();
769 Library* library = program->libraries().GetOrCreate<Library>(library_idx);
770 return library->procedures().GetOrCreate<Procedure>(procedure_idx,
771 library);
772 }
773 case kClassFieldReference:
774 case kClassConstructorReference:
775 case kClassProcedureReference: {
776 Class* klass = Reference::ReadClassFrom(reader);
777 if (tag == kClassFieldReference) {
778 int field_idx = reader->ReadUInt();
779 return klass->fields().GetOrCreate<Field>(field_idx, klass);
780 } else if (tag == kClassConstructorReference) {
781 int constructor_idx = reader->ReadUInt();
782 return klass->constructors().GetOrCreate<Constructor>(constructor_idx,
783 klass);
784 } else {
785 ASSERT(tag == kClassProcedureReference);
786 int procedure_idx = reader->ReadUInt();
787 return klass->procedures().GetOrCreate<Procedure>(procedure_idx, klass);
788 }
789 }
790 case kNullReference:
791 if (allow_null) {
792 return NULL;
793 } else {
794 FATAL("Expected a valid member reference, but got `null`");
795 }
796 default:
797 UNREACHABLE();
798 break;
799 } 772 }
800 773
801 UNREACHABLE(); 774 if (canonical_name != NULL) {
802 return NULL; 775 canonical_name->set_referenced(true);
776 }
777
778 return canonical_name;
803 } 779 }
804 780
805 781
806 Class* Reference::ReadClassFrom(Reader* reader, bool allow_null) { 782 CanonicalName* Reference::ReadClassFrom(Reader* reader, bool allow_null) {
807 TRACE_READ_OFFSET(); 783 TRACE_READ_OFFSET();
808 Program* program = reader->helper()->program();
809 784
810 Tag klass_member_tag = reader->ReadTag(); 785 CanonicalName* canonical_name = reader->ReadCanonicalNameReference();
811 if (klass_member_tag == kNullReference) { 786 if (canonical_name == NULL && !allow_null) {
812 if (allow_null) { 787 FATAL("Expected a valid class reference, but got `null`");
813 return NULL;
814 } else {
815 FATAL("Expected a valid class reference but got `null`.");
816 }
817 } 788 }
818 int library_idx = reader->ReadUInt();
819 int class_idx = reader->ReadUInt();
820 789
821 Library* library = program->libraries().GetOrCreate<Library>(library_idx); 790 if (canonical_name != NULL) {
822 Class* klass; 791 canonical_name->set_referenced(true);
823 if (klass_member_tag == kNormalClassReference) {
824 klass = library->classes().GetOrCreate<NormalClass>(class_idx, library);
825 } else {
826 ASSERT(klass_member_tag == kMixinClassReference);
827 klass = library->classes().GetOrCreate<MixinClass>(class_idx, library);
828 } 792 }
829 return klass; 793
794 return canonical_name;
830 } 795 }
831 796
832 797
833 String* Reference::ReadStringFrom(Reader* reader) { 798 String* Reference::ReadStringFrom(Reader* reader) {
834 int index = reader->ReadUInt(); 799 int index = reader->ReadUInt();
835 return reader->helper()->program()->string_table().strings()[index]; 800 return reader->helper()->program()->string_table().strings()[index];
836 } 801 }
837 802
838 803
839 Field* Field::ReadFrom(Reader* reader) { 804 Field* Field::ReadFrom(Reader* reader) {
840 TRACE_READ_OFFSET(); 805 TRACE_READ_OFFSET();
841 Tag tag = reader->ReadTag(); 806 Tag tag = reader->ReadTag();
842 ASSERT(tag == kField); 807 ASSERT(tag == kField);
843 808
809 reader->ReadDefiningCanonicalNameReference(this);
844 position_ = reader->ReadPosition(false); 810 position_ = reader->ReadPosition(false);
845 end_position_ = reader->ReadPosition(false); 811 end_position_ = reader->ReadPosition(false);
846 flags_ = reader->ReadFlags(); 812 flags_ = reader->ReadFlags();
847 name_ = Name::ReadFrom(reader); 813 name_ = Name::ReadFrom(reader);
848 source_uri_index_ = reader->ReadUInt(); 814 source_uri_index_ = reader->ReadUInt();
849 reader->set_current_script_id(source_uri_index_); 815 reader->set_current_script_id(source_uri_index_);
850 reader->record_token_position(position_); 816 reader->record_token_position(position_);
851 reader->record_token_position(end_position_); 817 reader->record_token_position(end_position_);
852 annotations_.ReadFromStatic<Expression>(reader); 818 annotations_.ReadFromStatic<Expression>(reader);
853 type_ = DartType::ReadFrom(reader); 819 type_ = DartType::ReadFrom(reader);
854 inferred_value_ = reader->ReadOptional<InferredValue>(); 820 inferred_value_ = reader->ReadOptional<InferredValue>();
855 initializer_ = reader->ReadOptional<Expression>(); 821 initializer_ = reader->ReadOptional<Expression>();
856 return this; 822 return this;
857 } 823 }
858 824
859 825
860 Constructor* Constructor::ReadFrom(Reader* reader) { 826 Constructor* Constructor::ReadFrom(Reader* reader) {
861 TRACE_READ_OFFSET(); 827 TRACE_READ_OFFSET();
862 Tag tag = reader->ReadTag(); 828 Tag tag = reader->ReadTag();
863 ASSERT(tag == kConstructor); 829 ASSERT(tag == kConstructor);
864 830
831 reader->ReadDefiningCanonicalNameReference(this);
865 VariableScope<ReaderHelper> parameters(reader->helper()); 832 VariableScope<ReaderHelper> parameters(reader->helper());
866 position_ = reader->ReadPosition(); 833 position_ = reader->ReadPosition();
867 end_position_ = reader->ReadPosition(); 834 end_position_ = reader->ReadPosition();
868 flags_ = reader->ReadFlags(); 835 flags_ = reader->ReadFlags();
869 name_ = Name::ReadFrom(reader); 836 name_ = Name::ReadFrom(reader);
870 annotations_.ReadFromStatic<Expression>(reader); 837 annotations_.ReadFromStatic<Expression>(reader);
871 function_ = FunctionNode::ReadFrom(reader); 838 function_ = FunctionNode::ReadFrom(reader);
872 initializers_.ReadFromStatic<Initializer>(reader); 839 initializers_.ReadFromStatic<Initializer>(reader);
873 return this; 840 return this;
874 } 841 }
875 842
876 843
877 Procedure* Procedure::ReadFrom(Reader* reader) { 844 Procedure* Procedure::ReadFrom(Reader* reader) {
878 TRACE_READ_OFFSET(); 845 TRACE_READ_OFFSET();
879 Tag tag = reader->ReadTag(); 846 Tag tag = reader->ReadTag();
880 ASSERT(tag == kProcedure); 847 ASSERT(tag == kProcedure);
881 848
849 reader->ReadDefiningCanonicalNameReference(this);
882 VariableScope<ReaderHelper> parameters(reader->helper()); 850 VariableScope<ReaderHelper> parameters(reader->helper());
883 position_ = reader->ReadPosition(false); 851 position_ = reader->ReadPosition(false);
884 end_position_ = reader->ReadPosition(false); 852 end_position_ = reader->ReadPosition(false);
885 kind_ = static_cast<ProcedureKind>(reader->ReadByte()); 853 kind_ = static_cast<ProcedureKind>(reader->ReadByte());
886 flags_ = reader->ReadFlags(); 854 flags_ = reader->ReadFlags();
887 name_ = Name::ReadFrom(reader); 855 name_ = Name::ReadFrom(reader);
888 source_uri_index_ = reader->ReadUInt(); 856 source_uri_index_ = reader->ReadUInt();
889 reader->set_current_script_id(source_uri_index_); 857 reader->set_current_script_id(source_uri_index_);
890 reader->record_token_position(position_); 858 reader->record_token_position(position_);
891 reader->record_token_position(end_position_); 859 reader->record_token_position(end_position_);
(...skipping 26 matching lines...) Expand all
918 886
919 InvalidInitializer* InvalidInitializer::ReadFromImpl(Reader* reader) { 887 InvalidInitializer* InvalidInitializer::ReadFromImpl(Reader* reader) {
920 TRACE_READ_OFFSET(); 888 TRACE_READ_OFFSET();
921 return new InvalidInitializer(); 889 return new InvalidInitializer();
922 } 890 }
923 891
924 892
925 FieldInitializer* FieldInitializer::ReadFromImpl(Reader* reader) { 893 FieldInitializer* FieldInitializer::ReadFromImpl(Reader* reader) {
926 TRACE_READ_OFFSET(); 894 TRACE_READ_OFFSET();
927 FieldInitializer* initializer = new FieldInitializer(); 895 FieldInitializer* initializer = new FieldInitializer();
928 initializer->field_ = Field::Cast(Reference::ReadMemberFrom(reader)); 896 initializer->field_reference_ = Reference::ReadMemberFrom(reader);
929 initializer->value_ = Expression::ReadFrom(reader); 897 initializer->value_ = Expression::ReadFrom(reader);
930 return initializer; 898 return initializer;
931 } 899 }
932 900
933 901
934 SuperInitializer* SuperInitializer::ReadFromImpl(Reader* reader) { 902 SuperInitializer* SuperInitializer::ReadFromImpl(Reader* reader) {
935 TRACE_READ_OFFSET(); 903 TRACE_READ_OFFSET();
936 SuperInitializer* init = new SuperInitializer(); 904 SuperInitializer* init = new SuperInitializer();
937 init->target_ = Constructor::Cast(Reference::ReadMemberFrom(reader)); 905 init->target_reference_ = Reference::ReadMemberFrom(reader);
938 init->arguments_ = Arguments::ReadFrom(reader); 906 init->arguments_ = Arguments::ReadFrom(reader);
939 return init; 907 return init;
940 } 908 }
941 909
942 910
943 RedirectingInitializer* RedirectingInitializer::ReadFromImpl(Reader* reader) { 911 RedirectingInitializer* RedirectingInitializer::ReadFromImpl(Reader* reader) {
944 TRACE_READ_OFFSET(); 912 TRACE_READ_OFFSET();
945 RedirectingInitializer* init = new RedirectingInitializer(); 913 RedirectingInitializer* init = new RedirectingInitializer();
946 init->target_ = Constructor::Cast(Reference::ReadMemberFrom(reader)); 914 init->target_reference_ = Reference::ReadMemberFrom(reader);
947 init->arguments_ = Arguments::ReadFrom(reader); 915 init->arguments_ = Arguments::ReadFrom(reader);
948 return init; 916 return init;
949 } 917 }
950 918
951 919
952 LocalInitializer* LocalInitializer::ReadFromImpl(Reader* reader) { 920 LocalInitializer* LocalInitializer::ReadFromImpl(Reader* reader) {
953 TRACE_READ_OFFSET(); 921 TRACE_READ_OFFSET();
954 LocalInitializer* init = new LocalInitializer(); 922 LocalInitializer* init = new LocalInitializer();
955 init->variable_ = VariableDeclaration::ReadFromImpl(reader); 923 init->variable_ = VariableDeclaration::ReadFromImpl(reader);
956 return init; 924 return init;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 return set; 1069 return set;
1102 } 1070 }
1103 1071
1104 1072
1105 PropertyGet* PropertyGet::ReadFrom(Reader* reader) { 1073 PropertyGet* PropertyGet::ReadFrom(Reader* reader) {
1106 TRACE_READ_OFFSET(); 1074 TRACE_READ_OFFSET();
1107 PropertyGet* get = new PropertyGet(); 1075 PropertyGet* get = new PropertyGet();
1108 get->position_ = reader->ReadPosition(); 1076 get->position_ = reader->ReadPosition();
1109 get->receiver_ = Expression::ReadFrom(reader); 1077 get->receiver_ = Expression::ReadFrom(reader);
1110 get->name_ = Name::ReadFrom(reader); 1078 get->name_ = Name::ReadFrom(reader);
1111 get->interfaceTarget_ = Reference::ReadMemberFrom(reader, true); 1079 get->interface_target_reference_ = Reference::ReadMemberFrom(reader, true);
1112 return get; 1080 return get;
1113 } 1081 }
1114 1082
1115 1083
1116 PropertySet* PropertySet::ReadFrom(Reader* reader) { 1084 PropertySet* PropertySet::ReadFrom(Reader* reader) {
1117 TRACE_READ_OFFSET(); 1085 TRACE_READ_OFFSET();
1118 PropertySet* set = new PropertySet(); 1086 PropertySet* set = new PropertySet();
1119 set->position_ = reader->ReadPosition(); 1087 set->position_ = reader->ReadPosition();
1120 set->receiver_ = Expression::ReadFrom(reader); 1088 set->receiver_ = Expression::ReadFrom(reader);
1121 set->name_ = Name::ReadFrom(reader); 1089 set->name_ = Name::ReadFrom(reader);
1122 set->value_ = Expression::ReadFrom(reader); 1090 set->value_ = Expression::ReadFrom(reader);
1123 set->interfaceTarget_ = Reference::ReadMemberFrom(reader, true); 1091 set->interface_target_reference_ = Reference::ReadMemberFrom(reader, true);
1124 return set; 1092 return set;
1125 } 1093 }
1126 1094
1127 1095
1128 DirectPropertyGet* DirectPropertyGet::ReadFrom(Reader* reader) { 1096 DirectPropertyGet* DirectPropertyGet::ReadFrom(Reader* reader) {
1129 TRACE_READ_OFFSET(); 1097 TRACE_READ_OFFSET();
1130 DirectPropertyGet* get = new DirectPropertyGet(); 1098 DirectPropertyGet* get = new DirectPropertyGet();
1131 get->receiver_ = Expression::ReadFrom(reader); 1099 get->receiver_ = Expression::ReadFrom(reader);
1132 get->target_ = Reference::ReadMemberFrom(reader); 1100 get->target_reference_ = Reference::ReadMemberFrom(reader);
1133 return get; 1101 return get;
1134 } 1102 }
1135 1103
1136 1104
1137 DirectPropertySet* DirectPropertySet::ReadFrom(Reader* reader) { 1105 DirectPropertySet* DirectPropertySet::ReadFrom(Reader* reader) {
1138 TRACE_READ_OFFSET(); 1106 TRACE_READ_OFFSET();
1139 DirectPropertySet* set = new DirectPropertySet(); 1107 DirectPropertySet* set = new DirectPropertySet();
1140 set->receiver_ = Expression::ReadFrom(reader); 1108 set->receiver_ = Expression::ReadFrom(reader);
1141 set->target_ = Reference::ReadMemberFrom(reader); 1109 set->target_reference_ = Reference::ReadMemberFrom(reader);
1142 set->value_ = Expression::ReadFrom(reader); 1110 set->value_ = Expression::ReadFrom(reader);
1143 return set; 1111 return set;
1144 } 1112 }
1145 1113
1146 1114
1147 StaticGet* StaticGet::ReadFrom(Reader* reader) { 1115 StaticGet* StaticGet::ReadFrom(Reader* reader) {
1148 TRACE_READ_OFFSET(); 1116 TRACE_READ_OFFSET();
1149 StaticGet* get = new StaticGet(); 1117 StaticGet* get = new StaticGet();
1150 get->position_ = reader->ReadPosition(); 1118 get->position_ = reader->ReadPosition();
1151 get->target_ = Reference::ReadMemberFrom(reader); 1119 get->target_reference_ = Reference::ReadMemberFrom(reader);
1152 return get; 1120 return get;
1153 } 1121 }
1154 1122
1155 1123
1156 StaticSet* StaticSet::ReadFrom(Reader* reader) { 1124 StaticSet* StaticSet::ReadFrom(Reader* reader) {
1157 TRACE_READ_OFFSET(); 1125 TRACE_READ_OFFSET();
1158 StaticSet* set = new StaticSet(); 1126 StaticSet* set = new StaticSet();
1159 set->target_ = Reference::ReadMemberFrom(reader); 1127 set->target_reference_ = Reference::ReadMemberFrom(reader);
1160 set->expression_ = Expression::ReadFrom(reader); 1128 set->expression_ = Expression::ReadFrom(reader);
1161 return set; 1129 return set;
1162 } 1130 }
1163 1131
1164 1132
1165 Arguments* Arguments::ReadFrom(Reader* reader) { 1133 Arguments* Arguments::ReadFrom(Reader* reader) {
1166 TRACE_READ_OFFSET(); 1134 TRACE_READ_OFFSET();
1167 Arguments* arguments = new Arguments(); 1135 Arguments* arguments = new Arguments();
1168 arguments->types().ReadFromStatic<DartType>(reader); 1136 arguments->types().ReadFromStatic<DartType>(reader);
1169 arguments->positional().ReadFromStatic<Expression>(reader); 1137 arguments->positional().ReadFromStatic<Expression>(reader);
(...skipping 10 matching lines...) Expand all
1180 } 1148 }
1181 1149
1182 1150
1183 MethodInvocation* MethodInvocation::ReadFrom(Reader* reader) { 1151 MethodInvocation* MethodInvocation::ReadFrom(Reader* reader) {
1184 TRACE_READ_OFFSET(); 1152 TRACE_READ_OFFSET();
1185 MethodInvocation* invocation = new MethodInvocation(); 1153 MethodInvocation* invocation = new MethodInvocation();
1186 invocation->position_ = reader->ReadPosition(); 1154 invocation->position_ = reader->ReadPosition();
1187 invocation->receiver_ = Expression::ReadFrom(reader); 1155 invocation->receiver_ = Expression::ReadFrom(reader);
1188 invocation->name_ = Name::ReadFrom(reader); 1156 invocation->name_ = Name::ReadFrom(reader);
1189 invocation->arguments_ = Arguments::ReadFrom(reader); 1157 invocation->arguments_ = Arguments::ReadFrom(reader);
1190 invocation->interfaceTarget_ = Reference::ReadMemberFrom(reader, true); 1158 invocation->interface_target_reference_ =
1159 Reference::ReadMemberFrom(reader, true);
1191 return invocation; 1160 return invocation;
1192 } 1161 }
1193 1162
1194 1163
1195 DirectMethodInvocation* DirectMethodInvocation::ReadFrom(Reader* reader) { 1164 DirectMethodInvocation* DirectMethodInvocation::ReadFrom(Reader* reader) {
1196 TRACE_READ_OFFSET(); 1165 TRACE_READ_OFFSET();
1197 DirectMethodInvocation* invocation = new DirectMethodInvocation(); 1166 DirectMethodInvocation* invocation = new DirectMethodInvocation();
1198 invocation->receiver_ = Expression::ReadFrom(reader); 1167 invocation->receiver_ = Expression::ReadFrom(reader);
1199 invocation->target_ = Procedure::Cast(Reference::ReadMemberFrom(reader)); 1168 invocation->target_reference_ = Reference::ReadMemberFrom(reader);
1200 invocation->arguments_ = Arguments::ReadFrom(reader); 1169 invocation->arguments_ = Arguments::ReadFrom(reader);
1201 return invocation; 1170 return invocation;
1202 } 1171 }
1203 1172
1204 1173
1205 StaticInvocation* StaticInvocation::ReadFrom(Reader* reader, bool is_const) { 1174 StaticInvocation* StaticInvocation::ReadFrom(Reader* reader, bool is_const) {
1206 TRACE_READ_OFFSET(); 1175 TRACE_READ_OFFSET();
1207 StaticInvocation* invocation = new StaticInvocation(); 1176 StaticInvocation* invocation = new StaticInvocation();
1208 invocation->is_const_ = is_const; 1177 invocation->is_const_ = is_const;
1209 invocation->position_ = reader->ReadPosition(); 1178 invocation->position_ = reader->ReadPosition();
1210 invocation->procedure_ = Procedure::Cast(Reference::ReadMemberFrom(reader)); 1179 invocation->procedure_reference_ = Reference::ReadMemberFrom(reader);
1211 invocation->arguments_ = Arguments::ReadFrom(reader); 1180 invocation->arguments_ = Arguments::ReadFrom(reader);
1212 return invocation; 1181 return invocation;
1213 } 1182 }
1214 1183
1215 1184
1216 ConstructorInvocation* ConstructorInvocation::ReadFrom(Reader* reader, 1185 ConstructorInvocation* ConstructorInvocation::ReadFrom(Reader* reader,
1217 bool is_const) { 1186 bool is_const) {
1218 TRACE_READ_OFFSET(); 1187 TRACE_READ_OFFSET();
1219 ConstructorInvocation* invocation = new ConstructorInvocation(); 1188 ConstructorInvocation* invocation = new ConstructorInvocation();
1220 invocation->is_const_ = is_const; 1189 invocation->is_const_ = is_const;
1221 invocation->position_ = reader->ReadPosition(); 1190 invocation->position_ = reader->ReadPosition();
1222 invocation->target_ = Constructor::Cast(Reference::ReadMemberFrom(reader)); 1191 invocation->target_reference_ = Reference::ReadMemberFrom(reader);
1223 invocation->arguments_ = Arguments::ReadFrom(reader); 1192 invocation->arguments_ = Arguments::ReadFrom(reader);
1224 return invocation; 1193 return invocation;
1225 } 1194 }
1226 1195
1227 1196
1228 Not* Not::ReadFrom(Reader* reader) { 1197 Not* Not::ReadFrom(Reader* reader) {
1229 TRACE_READ_OFFSET(); 1198 TRACE_READ_OFFSET();
1230 Not* n = new Not(); 1199 Not* n = new Not();
1231 n->expression_ = Expression::ReadFrom(reader); 1200 n->expression_ = Expression::ReadFrom(reader);
1232 return n; 1201 return n;
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 1567
1599 SwitchStatement* SwitchStatement::ReadFrom(Reader* reader) { 1568 SwitchStatement* SwitchStatement::ReadFrom(Reader* reader) {
1600 TRACE_READ_OFFSET(); 1569 TRACE_READ_OFFSET();
1601 SwitchCaseScope<ReaderHelper> scope(reader->helper()); 1570 SwitchCaseScope<ReaderHelper> scope(reader->helper());
1602 SwitchStatement* stmt = new SwitchStatement(); 1571 SwitchStatement* stmt = new SwitchStatement();
1603 stmt->condition_ = Expression::ReadFrom(reader); 1572 stmt->condition_ = Expression::ReadFrom(reader);
1604 // We need to explicitly create empty [SwitchCase]s first in order to add them 1573 // We need to explicitly create empty [SwitchCase]s first in order to add them
1605 // to the [SwitchCaseScope]. This is necessary since a [Statement] in a switch 1574 // to the [SwitchCaseScope]. This is necessary since a [Statement] in a switch
1606 // case can refer to one defined later on. 1575 // case can refer to one defined later on.
1607 int count = reader->ReadUInt(); 1576 int count = reader->ReadUInt();
1608 for (int i = 0; i < count; i++) { 1577 for (intptr_t i = 0; i < count; i++) {
1609 SwitchCase* sc = stmt->cases_.GetOrCreate<SwitchCase>(i); 1578 SwitchCase* sc = stmt->cases_.GetOrCreate<SwitchCase>(i);
1610 reader->helper()->switch_cases().Push(sc); 1579 reader->helper()->switch_cases().Push(sc);
1611 } 1580 }
1612 for (int i = 0; i < count; i++) { 1581 for (intptr_t i = 0; i < count; i++) {
1613 SwitchCase* sc = stmt->cases_[i]; 1582 SwitchCase* sc = stmt->cases_[i];
1614 sc->ReadFrom(reader); 1583 sc->ReadFrom(reader);
1615 } 1584 }
1616 return stmt; 1585 return stmt;
1617 } 1586 }
1618 1587
1619 1588
1620 SwitchCase* SwitchCase::ReadFrom(Reader* reader) { 1589 SwitchCase* SwitchCase::ReadFrom(Reader* reader) {
1621 TRACE_READ_OFFSET(); 1590 TRACE_READ_OFFSET();
1622 expressions_.ReadFromStatic<Expression>(reader); 1591 expressions_.ReadFromStatic<Expression>(reader);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 decl->variable_ = VariableDeclaration::ReadFromImpl(reader); 1712 decl->variable_ = VariableDeclaration::ReadFromImpl(reader);
1744 VariableScope<ReaderHelper> parameters(reader->helper()); 1713 VariableScope<ReaderHelper> parameters(reader->helper());
1745 decl->function_ = FunctionNode::ReadFrom(reader); 1714 decl->function_ = FunctionNode::ReadFrom(reader);
1746 return decl; 1715 return decl;
1747 } 1716 }
1748 1717
1749 1718
1750 Name* Name::ReadFrom(Reader* reader) { 1719 Name* Name::ReadFrom(Reader* reader) {
1751 String* string = Reference::ReadStringFrom(reader); 1720 String* string = Reference::ReadStringFrom(reader);
1752 if (string->size() >= 1 && string->buffer()[0] == '_') { 1721 if (string->size() >= 1 && string->buffer()[0] == '_') {
1753 int lib_index = reader->ReadUInt(); 1722 CanonicalName* library_reference = reader->ReadCanonicalNameReference();
1754 Library* library = 1723 return new Name(string, library_reference);
1755 reader->helper()->program()->libraries().GetOrCreate<Library>(
1756 lib_index);
1757 return new Name(string, library);
1758 } else { 1724 } else {
1759 return new Name(string, NULL); 1725 return new Name(string, NULL);
1760 } 1726 }
1761 } 1727 }
1762 1728
1763 1729
1764 InferredValue* InferredValue::ReadFrom(Reader* reader) { 1730 InferredValue* InferredValue::ReadFrom(Reader* reader) {
1765 InferredValue* type = new InferredValue(); 1731 InferredValue* type = new InferredValue();
1766 type->klass_ = Reference::ReadClassFrom(reader, true); 1732 type->klass_reference_ = Reference::ReadClassFrom(reader, true);
1767 type->kind_ = static_cast<BaseClassKind>(reader->ReadByte()); 1733 type->kind_ = static_cast<BaseClassKind>(reader->ReadByte());
1768 type->value_bits_ = reader->ReadByte(); 1734 type->value_bits_ = reader->ReadByte();
1769 return type; 1735 return type;
1770 } 1736 }
1771 1737
1772 1738
1773 DartType* DartType::ReadFrom(Reader* reader) { 1739 DartType* DartType::ReadFrom(Reader* reader) {
1774 TRACE_READ_OFFSET(); 1740 TRACE_READ_OFFSET();
1775 Tag tag = reader->ReadTag(); 1741 Tag tag = reader->ReadTag();
1776 switch (tag) { 1742 switch (tag) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 1777
1812 1778
1813 VoidType* VoidType::ReadFrom(Reader* reader) { 1779 VoidType* VoidType::ReadFrom(Reader* reader) {
1814 TRACE_READ_OFFSET(); 1780 TRACE_READ_OFFSET();
1815 return new VoidType(); 1781 return new VoidType();
1816 } 1782 }
1817 1783
1818 1784
1819 InterfaceType* InterfaceType::ReadFrom(Reader* reader) { 1785 InterfaceType* InterfaceType::ReadFrom(Reader* reader) {
1820 TRACE_READ_OFFSET(); 1786 TRACE_READ_OFFSET();
1821 Class* klass = Reference::ReadClassFrom(reader); 1787 CanonicalName* klass_name = Reference::ReadClassFrom(reader);
1822 InterfaceType* type = new InterfaceType(klass); 1788 InterfaceType* type = new InterfaceType(klass_name);
1823 type->type_arguments().ReadFromStatic<DartType>(reader); 1789 type->type_arguments().ReadFromStatic<DartType>(reader);
1824 return type; 1790 return type;
1825 } 1791 }
1826 1792
1827 1793
1828 InterfaceType* InterfaceType::ReadFrom(Reader* reader, 1794 InterfaceType* InterfaceType::ReadFrom(Reader* reader,
1829 bool _without_type_arguments_) { 1795 bool _without_type_arguments_) {
1830 TRACE_READ_OFFSET(); 1796 TRACE_READ_OFFSET();
1831 Class* klass = Reference::ReadClassFrom(reader); 1797 CanonicalName* klass_name = Reference::ReadClassFrom(reader);
1832 InterfaceType* type = new InterfaceType(klass); 1798 InterfaceType* type = new InterfaceType(klass_name);
1833 ASSERT(_without_type_arguments_); 1799 ASSERT(_without_type_arguments_);
1834 return type; 1800 return type;
1835 } 1801 }
1836 1802
1837 1803
1838 FunctionType* FunctionType::ReadFrom(Reader* reader) { 1804 FunctionType* FunctionType::ReadFrom(Reader* reader) {
1839 TRACE_READ_OFFSET(); 1805 TRACE_READ_OFFSET();
1840 FunctionType* type = new FunctionType(); 1806 FunctionType* type = new FunctionType();
1841 TypeParameterScope<ReaderHelper> scope(reader->helper()); 1807 TypeParameterScope<ReaderHelper> scope(reader->helper());
1842 type->type_parameters().ReadFrom(reader); 1808 type->type_parameters().ReadFrom(reader);
(...skipping 24 matching lines...) Expand all
1867 return type; 1833 return type;
1868 } 1834 }
1869 1835
1870 1836
1871 Program* Program::ReadFrom(Reader* reader) { 1837 Program* Program::ReadFrom(Reader* reader) {
1872 TRACE_READ_OFFSET(); 1838 TRACE_READ_OFFSET();
1873 uint32_t magic = reader->ReadUInt32(); 1839 uint32_t magic = reader->ReadUInt32();
1874 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier"); 1840 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier");
1875 1841
1876 Program* program = new Program(); 1842 Program* program = new Program();
1843 program->canonical_name_root_ = CanonicalName::NewRoot();
1877 reader->helper()->set_program(program); 1844 reader->helper()->set_program(program);
1878 1845
1879 program->string_table_.ReadFrom(reader); 1846 program->string_table_.ReadFrom(reader);
1880 program->source_uri_table_.ReadFrom(reader); 1847 program->source_uri_table_.ReadFrom(reader);
1881 program->source_table_.ReadFrom(reader); 1848 program->source_table_.ReadFrom(reader);
1882 1849
1850 int canonical_names = reader->ReadUInt();
1851 reader->helper()->SetCanonicalNameCount(canonical_names);
1852 for (int i = 0; i < canonical_names; ++i) {
1853 int biased_parent_index = reader->ReadUInt();
1854 CanonicalName* parent;
1855 if (biased_parent_index != 0) {
1856 parent = reader->helper()->GetCanonicalName(biased_parent_index - 1);
1857 } else {
1858 parent = program->canonical_name_root();
1859 }
1860 ASSERT(parent != NULL);
1861 int name_index = reader->ReadUInt();
1862 String* name = program->string_table().strings()[name_index];
1863 CanonicalName* canonical_name = parent->AddChild(name);
1864 reader->helper()->SetCanonicalName(i, canonical_name);
1865 }
1866
1883 int libraries = reader->ReadUInt(); 1867 int libraries = reader->ReadUInt();
1884 program->libraries().EnsureInitialized(libraries); 1868 program->libraries().EnsureInitialized(libraries);
1885 for (int i = 0; i < libraries; i++) { 1869 for (intptr_t i = 0; i < libraries; i++) {
1886 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); 1870 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader);
1887 } 1871 }
1888 1872
1889 program->main_method_ = Procedure::Cast(Reference::ReadMemberFrom(reader)); 1873 program->main_method_reference_ = Reference::ReadMemberFrom(reader);
1874
1875 #ifdef DEBUG
1876 for (intptr_t i = 0; i < canonical_names; ++i) {
1877 CanonicalName* name = reader->helper()->GetCanonicalName(i);
1878 if (name->is_referenced() && name->definition() == NULL) {
1879 FATAL("Missing definition for canonical name");
1880 }
1881 }
1882 #endif
1890 1883
1891 return program; 1884 return program;
1892 } 1885 }
1893 1886
1894 1887
1895 FunctionNode* FunctionNode::ReadFrom(Reader* reader) { 1888 FunctionNode* FunctionNode::ReadFrom(Reader* reader) {
1896 TRACE_READ_OFFSET(); 1889 TRACE_READ_OFFSET();
1897 TypeParameterScope<ReaderHelper> scope(reader->helper()); 1890 TypeParameterScope<ReaderHelper> scope(reader->helper());
1898 1891
1899 FunctionNode* function = new FunctionNode(); 1892 FunctionNode* function = new FunctionNode();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 1924
1932 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, 1925 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer,
1933 intptr_t buffer_length) { 1926 intptr_t buffer_length) {
1934 kernel::Reader reader(buffer, buffer_length); 1927 kernel::Reader reader(buffer, buffer_length);
1935 return kernel::Program::ReadFrom(&reader); 1928 return kernel::Program::ReadFrom(&reader);
1936 } 1929 }
1937 1930
1938 1931
1939 } // namespace dart 1932 } // namespace dart
1940 #endif // !defined(DART_PRECOMPILED_RUNTIME) 1933 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel.cc ('k') | utils/kernel-service/kernel-service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698