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 #if !defined(DART_PRECOMPILED_RUNTIME) | 4 #if !defined(DART_PRECOMPILED_RUNTIME) |
5 | 5 |
6 #include "vm/kernel_binary.h" | 6 #include "vm/kernel_binary.h" |
7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
9 #include "vm/growable_array.h" | 9 #include "vm/growable_array.h" |
10 #include "vm/kernel.h" | 10 #include "vm/kernel.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 reader->helper()->type_parameters().Push(parameter); | 80 reader->helper()->type_parameters().Push(parameter); |
81 } | 81 } |
82 | 82 |
83 // Read all [TypeParameter]s and their bounds. | 83 // Read all [TypeParameter]s and their bounds. |
84 for (intptr_t i = 0; i < length; i++) { | 84 for (intptr_t i = 0; i < length; i++) { |
85 (*this)[i]->ReadFrom(reader); | 85 (*this)[i]->ReadFrom(reader); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 | 89 |
90 template <typename A, typename B> | 90 NamedParameter* NamedParameter::ReadFrom(Reader* reader) { |
91 Tuple<A, B>* Tuple<A, B>::ReadFrom(Reader* reader) { | |
92 TRACE_READ_OFFSET(); | 91 TRACE_READ_OFFSET(); |
93 A* first = A::ReadFrom(reader); | 92 intptr_t name_index = reader->ReadUInt(); |
94 B* second = B::ReadFrom(reader); | 93 DartType* type = DartType::ReadFrom(reader); |
95 return new Tuple<A, B>(first, second); | 94 return new NamedParameter(name_index, type); |
96 } | 95 } |
97 | 96 |
98 | 97 |
99 template <typename B, typename S> | 98 template <typename B, typename S> |
100 class DowncastReader { | 99 class DowncastReader { |
101 public: | 100 public: |
102 static S* ReadFrom(Reader* reader) { | 101 static S* ReadFrom(Reader* reader) { |
103 TRACE_READ_OFFSET(); | 102 TRACE_READ_OFFSET(); |
104 return S::Cast(B::ReadFrom(reader)); | 103 return S::Cast(B::ReadFrom(reader)); |
105 } | 104 } |
106 }; | 105 }; |
107 | 106 |
108 | 107 |
109 class VariableDeclarationImpl { | 108 class VariableDeclarationImpl { |
110 public: | 109 public: |
111 static VariableDeclaration* ReadFrom(Reader* reader) { | 110 static VariableDeclaration* ReadFrom(Reader* reader) { |
112 TRACE_READ_OFFSET(); | 111 TRACE_READ_OFFSET(); |
113 return VariableDeclaration::ReadFromImpl(reader, false); | 112 return VariableDeclaration::ReadFromImpl(reader, false); |
114 } | 113 } |
115 }; | 114 }; |
116 | 115 |
117 | 116 |
118 String* String::ReadFrom(Reader* reader) { | |
119 TRACE_READ_OFFSET(); | |
120 return Reference::ReadStringFrom(reader); | |
121 } | |
122 | |
123 | |
124 String* String::ReadRaw(Reader* reader, intptr_t size) { | |
125 ASSERT(reader->string_data_offset() >= 0); | |
126 String* result = | |
127 new String(reader->offset() - reader->string_data_offset(), size); | |
128 reader->Consume(size); | |
129 return result; | |
130 } | |
131 | |
132 | |
133 void StringTable::ReadFrom(Reader* reader) { | |
134 TRACE_READ_OFFSET(); | |
135 // Read the table of end offsets. | |
136 intptr_t length = reader->ReadUInt(); | |
137 intptr_t* end_offsets = new intptr_t[length]; | |
138 for (intptr_t i = 0; i < length; ++i) { | |
139 end_offsets[i] = reader->ReadUInt(); | |
140 } | |
141 // Read the UTF-8 encoded strings. | |
142 reader->MarkStringDataOffset(); | |
143 strings_.EnsureInitialized(length); | |
144 intptr_t start_offset = 0; | |
145 for (intptr_t i = 0; i < length; ++i) { | |
146 ASSERT(strings_[i] == NULL); | |
147 strings_[i] = String::ReadRaw(reader, end_offsets[i] - start_offset); | |
148 start_offset = end_offsets[i]; | |
149 } | |
150 delete[] end_offsets; | |
151 } | |
152 | |
153 | |
154 void SourceTable::ReadFrom(Reader* reader) { | 117 void SourceTable::ReadFrom(Reader* reader) { |
155 size_ = reader->ReadUInt(); | 118 size_ = reader->ReadUInt(); |
156 sources_ = new Source[size_]; | 119 sources_ = new Source[size_]; |
157 | 120 |
158 // Build a table of the URI offsets. | 121 // Build a table of the URI offsets. |
159 intptr_t* end_offsets = new intptr_t[size_]; | 122 intptr_t* end_offsets = new intptr_t[size_]; |
160 for (intptr_t i = 0; i < size_; ++i) { | 123 for (intptr_t i = 0; i < size_; ++i) { |
161 end_offsets[i] = reader->ReadUInt(); | 124 end_offsets[i] = reader->ReadUInt(); |
162 } | 125 } |
163 | 126 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 162 |
200 | 163 |
201 Library* Library::ReadFrom(Reader* reader) { | 164 Library* Library::ReadFrom(Reader* reader) { |
202 TRACE_READ_OFFSET(); | 165 TRACE_READ_OFFSET(); |
203 int flags = reader->ReadFlags(); | 166 int flags = reader->ReadFlags(); |
204 ASSERT(flags == 0); // external libraries not supported | 167 ASSERT(flags == 0); // external libraries not supported |
205 kernel_data_ = reader->buffer(); | 168 kernel_data_ = reader->buffer(); |
206 kernel_data_size_ = reader->size(); | 169 kernel_data_size_ = reader->size(); |
207 | 170 |
208 canonical_name_ = reader->ReadCanonicalNameReference(); | 171 canonical_name_ = reader->ReadCanonicalNameReference(); |
209 name_ = Reference::ReadStringFrom(reader); | 172 name_index_ = reader->ReadUInt(); |
210 import_uri_ = canonical_name_->name(); | 173 import_uri_index_ = canonical_name_->name(); |
211 source_uri_index_ = reader->ReadUInt(); | 174 source_uri_index_ = reader->ReadUInt(); |
212 reader->set_current_script_id(source_uri_index_); | 175 reader->set_current_script_id(source_uri_index_); |
213 | 176 |
214 int num_imports = reader->ReadUInt(); | 177 int num_imports = reader->ReadUInt(); |
215 if (num_imports != 0) { | 178 if (num_imports != 0) { |
216 FATAL("Deferred imports not implemented in VM"); | 179 FATAL("Deferred imports not implemented in VM"); |
217 } | 180 } |
218 int num_typedefs = reader->ReadUInt(); | 181 int num_typedefs = reader->ReadUInt(); |
219 typedefs().EnsureInitialized(num_typedefs); | 182 typedefs().EnsureInitialized(num_typedefs); |
220 for (intptr_t i = 0; i < num_typedefs; i++) { | 183 for (intptr_t i = 0; i < num_typedefs; i++) { |
(...skipping 12 matching lines...) Expand all Loading... |
233 procedures().ReadFrom<Procedure>(reader, this); | 196 procedures().ReadFrom<Procedure>(reader, this); |
234 return this; | 197 return this; |
235 } | 198 } |
236 | 199 |
237 | 200 |
238 Typedef* Typedef::ReadFrom(Reader* reader) { | 201 Typedef* Typedef::ReadFrom(Reader* reader) { |
239 TRACE_READ_OFFSET(); | 202 TRACE_READ_OFFSET(); |
240 | 203 |
241 canonical_name_ = reader->ReadCanonicalNameReference(); | 204 canonical_name_ = reader->ReadCanonicalNameReference(); |
242 position_ = reader->ReadPosition(false); | 205 position_ = reader->ReadPosition(false); |
243 name_ = Reference::ReadStringFrom(reader); | 206 name_index_ = reader->ReadUInt(); |
244 source_uri_index_ = reader->ReadUInt(); | 207 source_uri_index_ = reader->ReadUInt(); |
245 type_parameters_.ReadFrom(reader); | 208 type_parameters_.ReadFrom(reader); |
246 type_ = DartType::ReadFrom(reader); | 209 type_ = DartType::ReadFrom(reader); |
247 | 210 |
248 return this; | 211 return this; |
249 } | 212 } |
250 | 213 |
251 | 214 |
252 Class* Class::ReadFrom(Reader* reader) { | 215 Class* Class::ReadFrom(Reader* reader) { |
253 TRACE_READ_OFFSET(); | 216 TRACE_READ_OFFSET(); |
254 | 217 |
255 canonical_name_ = reader->ReadCanonicalNameReference(); | 218 canonical_name_ = reader->ReadCanonicalNameReference(); |
256 position_ = reader->ReadPosition(false); | 219 position_ = reader->ReadPosition(false); |
257 is_abstract_ = reader->ReadBool(); | 220 is_abstract_ = reader->ReadBool(); |
258 name_ = Reference::ReadStringFrom(reader); | 221 name_index_ = reader->ReadUInt(); |
259 source_uri_index_ = reader->ReadUInt(); | 222 source_uri_index_ = reader->ReadUInt(); |
260 reader->set_current_script_id(source_uri_index_); | 223 reader->set_current_script_id(source_uri_index_); |
261 reader->record_token_position(position_); | 224 reader->record_token_position(position_); |
262 annotations_.ReadFromStatic<Expression>(reader); | 225 annotations_.ReadFromStatic<Expression>(reader); |
263 | 226 |
264 return this; | 227 return this; |
265 } | 228 } |
266 | 229 |
267 | 230 |
268 NormalClass* NormalClass::ReadFrom(Reader* reader) { | 231 NormalClass* NormalClass::ReadFrom(Reader* reader) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 if (canonical_name == NULL) { | 302 if (canonical_name == NULL) { |
340 FATAL("Expected a valid typedef reference, but got `null`"); | 303 FATAL("Expected a valid typedef reference, but got `null`"); |
341 } | 304 } |
342 | 305 |
343 canonical_name->set_referenced(true); | 306 canonical_name->set_referenced(true); |
344 | 307 |
345 return canonical_name; | 308 return canonical_name; |
346 } | 309 } |
347 | 310 |
348 | 311 |
349 String* Reference::ReadStringFrom(Reader* reader) { | |
350 int index = reader->ReadUInt(); | |
351 return reader->helper()->program()->string_table().strings()[index]; | |
352 } | |
353 | |
354 | |
355 Field* Field::ReadFrom(Reader* reader) { | 312 Field* Field::ReadFrom(Reader* reader) { |
356 TRACE_READ_OFFSET(); | 313 TRACE_READ_OFFSET(); |
357 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. | 314 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. |
358 Tag tag = reader->ReadTag(); | 315 Tag tag = reader->ReadTag(); |
359 ASSERT(tag == kField); | 316 ASSERT(tag == kField); |
360 | 317 |
361 canonical_name_ = reader->ReadCanonicalNameReference(); | 318 canonical_name_ = reader->ReadCanonicalNameReference(); |
362 position_ = reader->ReadPosition(false); | 319 position_ = reader->ReadPosition(false); |
363 end_position_ = reader->ReadPosition(false); | 320 end_position_ = reader->ReadPosition(false); |
364 flags_ = reader->ReadFlags(); | 321 flags_ = reader->ReadFlags(); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 Arguments* arguments = new Arguments(); | 669 Arguments* arguments = new Arguments(); |
713 arguments->types().ReadFromStatic<DartType>(reader); | 670 arguments->types().ReadFromStatic<DartType>(reader); |
714 arguments->positional().ReadFromStatic<Expression>(reader); | 671 arguments->positional().ReadFromStatic<Expression>(reader); |
715 arguments->named().ReadFromStatic<NamedExpression>(reader); | 672 arguments->named().ReadFromStatic<NamedExpression>(reader); |
716 return arguments; | 673 return arguments; |
717 } | 674 } |
718 | 675 |
719 | 676 |
720 NamedExpression* NamedExpression::ReadFrom(Reader* reader) { | 677 NamedExpression* NamedExpression::ReadFrom(Reader* reader) { |
721 TRACE_READ_OFFSET(); | 678 TRACE_READ_OFFSET(); |
722 String* name = Reference::ReadStringFrom(reader); | 679 intptr_t name_index = reader->ReadUInt(); |
723 Expression* expression = Expression::ReadFrom(reader); | 680 Expression* expression = Expression::ReadFrom(reader); |
724 return new NamedExpression(name, expression); | 681 return new NamedExpression(name_index, expression); |
725 } | 682 } |
726 | 683 |
727 | 684 |
728 MethodInvocation* MethodInvocation::ReadFrom(Reader* reader) { | 685 MethodInvocation* MethodInvocation::ReadFrom(Reader* reader) { |
729 TRACE_READ_OFFSET(); | 686 TRACE_READ_OFFSET(); |
730 MethodInvocation* invocation = new MethodInvocation(); | 687 MethodInvocation* invocation = new MethodInvocation(); |
731 invocation->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 688 invocation->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
732 invocation->position_ = reader->ReadPosition(); | 689 invocation->position_ = reader->ReadPosition(); |
733 invocation->receiver_ = Expression::ReadFrom(reader); | 690 invocation->receiver_ = Expression::ReadFrom(reader); |
734 invocation->name_ = Name::ReadFrom(reader); | 691 invocation->name_ = Name::ReadFrom(reader); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 expr->position_ = reader->ReadPosition(); | 792 expr->position_ = reader->ReadPosition(); |
836 expr->operand_ = Expression::ReadFrom(reader); | 793 expr->operand_ = Expression::ReadFrom(reader); |
837 expr->type_ = DartType::ReadFrom(reader); | 794 expr->type_ = DartType::ReadFrom(reader); |
838 return expr; | 795 return expr; |
839 } | 796 } |
840 | 797 |
841 | 798 |
842 StringLiteral* StringLiteral::ReadFrom(Reader* reader) { | 799 StringLiteral* StringLiteral::ReadFrom(Reader* reader) { |
843 TRACE_READ_OFFSET(); | 800 TRACE_READ_OFFSET(); |
844 intptr_t offset = reader->offset() - 1; // -1 to include tag byte. | 801 intptr_t offset = reader->offset() - 1; // -1 to include tag byte. |
845 StringLiteral* lit = new StringLiteral(Reference::ReadStringFrom(reader)); | 802 StringLiteral* lit = new StringLiteral(reader->ReadUInt()); |
846 lit->kernel_offset_ = offset; | 803 lit->kernel_offset_ = offset; |
847 return lit; | 804 return lit; |
848 } | 805 } |
849 | 806 |
850 | 807 |
851 BigintLiteral* BigintLiteral::ReadFrom(Reader* reader) { | 808 BigintLiteral* BigintLiteral::ReadFrom(Reader* reader) { |
852 TRACE_READ_OFFSET(); | 809 TRACE_READ_OFFSET(); |
853 intptr_t offset = reader->offset() - 1; // -1 to include tag byte. | 810 intptr_t offset = reader->offset() - 1; // -1 to include tag byte. |
854 BigintLiteral* lit = new BigintLiteral(Reference::ReadStringFrom(reader)); | 811 BigintLiteral* lit = new BigintLiteral(reader->ReadUInt()); |
855 lit->kernel_offset_ = offset; | 812 lit->kernel_offset_ = offset; |
856 return lit; | 813 return lit; |
857 } | 814 } |
858 | 815 |
859 | 816 |
860 IntLiteral* IntLiteral::ReadFrom(Reader* reader, bool is_negative) { | 817 IntLiteral* IntLiteral::ReadFrom(Reader* reader, bool is_negative) { |
861 TRACE_READ_OFFSET(); | 818 TRACE_READ_OFFSET(); |
862 IntLiteral* literal = new IntLiteral(); | 819 IntLiteral* literal = new IntLiteral(); |
863 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 820 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
864 literal->value_ = is_negative ? -static_cast<int64_t>(reader->ReadUInt()) | 821 literal->value_ = is_negative ? -static_cast<int64_t>(reader->ReadUInt()) |
865 : reader->ReadUInt(); | 822 : reader->ReadUInt(); |
866 return literal; | 823 return literal; |
867 } | 824 } |
868 | 825 |
869 | 826 |
870 IntLiteral* IntLiteral::ReadFrom(Reader* reader, uint8_t payload) { | 827 IntLiteral* IntLiteral::ReadFrom(Reader* reader, uint8_t payload) { |
871 TRACE_READ_OFFSET(); | 828 TRACE_READ_OFFSET(); |
872 IntLiteral* literal = new IntLiteral(); | 829 IntLiteral* literal = new IntLiteral(); |
873 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 830 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
874 literal->value_ = static_cast<int32_t>(payload) - SpecializedIntLiteralBias; | 831 literal->value_ = static_cast<int32_t>(payload) - SpecializedIntLiteralBias; |
875 return literal; | 832 return literal; |
876 } | 833 } |
877 | 834 |
878 | 835 |
879 DoubleLiteral* DoubleLiteral::ReadFrom(Reader* reader) { | 836 DoubleLiteral* DoubleLiteral::ReadFrom(Reader* reader) { |
880 TRACE_READ_OFFSET(); | 837 TRACE_READ_OFFSET(); |
881 DoubleLiteral* literal = new DoubleLiteral(); | 838 DoubleLiteral* literal = new DoubleLiteral(); |
882 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 839 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
883 literal->value_ = Reference::ReadStringFrom(reader); | 840 literal->value_index_ = reader->ReadUInt(); |
884 return literal; | 841 return literal; |
885 } | 842 } |
886 | 843 |
887 | 844 |
888 BoolLiteral* BoolLiteral::ReadFrom(Reader* reader, bool value) { | 845 BoolLiteral* BoolLiteral::ReadFrom(Reader* reader, bool value) { |
889 TRACE_READ_OFFSET(); | 846 TRACE_READ_OFFSET(); |
890 BoolLiteral* lit = new BoolLiteral(); | 847 BoolLiteral* lit = new BoolLiteral(); |
891 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 848 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
892 lit->value_ = value; | 849 lit->value_ = value; |
893 return lit; | 850 return lit; |
894 } | 851 } |
895 | 852 |
896 | 853 |
897 NullLiteral* NullLiteral::ReadFrom(Reader* reader) { | 854 NullLiteral* NullLiteral::ReadFrom(Reader* reader) { |
898 TRACE_READ_OFFSET(); | 855 TRACE_READ_OFFSET(); |
899 NullLiteral* lit = new NullLiteral(); | 856 NullLiteral* lit = new NullLiteral(); |
900 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 857 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
901 return lit; | 858 return lit; |
902 } | 859 } |
903 | 860 |
904 | 861 |
905 SymbolLiteral* SymbolLiteral::ReadFrom(Reader* reader) { | 862 SymbolLiteral* SymbolLiteral::ReadFrom(Reader* reader) { |
906 TRACE_READ_OFFSET(); | 863 TRACE_READ_OFFSET(); |
907 SymbolLiteral* lit = new SymbolLiteral(); | 864 SymbolLiteral* lit = new SymbolLiteral(); |
908 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 865 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
909 lit->value_ = Reference::ReadStringFrom(reader); | 866 lit->value_index_ = reader->ReadUInt(); |
910 return lit; | 867 return lit; |
911 } | 868 } |
912 | 869 |
913 | 870 |
914 TypeLiteral* TypeLiteral::ReadFrom(Reader* reader) { | 871 TypeLiteral* TypeLiteral::ReadFrom(Reader* reader) { |
915 TRACE_READ_OFFSET(); | 872 TRACE_READ_OFFSET(); |
916 TypeLiteral* literal = new TypeLiteral(); | 873 TypeLiteral* literal = new TypeLiteral(); |
917 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 874 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
918 literal->type_ = DartType::ReadFrom(reader); | 875 literal->type_ = DartType::ReadFrom(reader); |
919 return literal; | 876 return literal; |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 bool read_tag) { | 1334 bool read_tag) { |
1378 TRACE_READ_OFFSET(); | 1335 TRACE_READ_OFFSET(); |
1379 PositionScope scope(reader); | 1336 PositionScope scope(reader); |
1380 | 1337 |
1381 VariableDeclaration* decl = new VariableDeclaration(); | 1338 VariableDeclaration* decl = new VariableDeclaration(); |
1382 // -1 or -0 depending on whether there's a tag or not. | 1339 // -1 or -0 depending on whether there's a tag or not. |
1383 decl->kernel_offset_ = reader->offset() - (read_tag ? 1 : 0); | 1340 decl->kernel_offset_ = reader->offset() - (read_tag ? 1 : 0); |
1384 decl->position_ = reader->ReadPosition(); | 1341 decl->position_ = reader->ReadPosition(); |
1385 decl->equals_position_ = reader->ReadPosition(); | 1342 decl->equals_position_ = reader->ReadPosition(); |
1386 decl->flags_ = reader->ReadFlags(); | 1343 decl->flags_ = reader->ReadFlags(); |
1387 decl->name_ = Reference::ReadStringFrom(reader); | 1344 decl->name_index_ = reader->ReadUInt(); |
1388 decl->type_ = DartType::ReadFrom(reader); | 1345 decl->type_ = DartType::ReadFrom(reader); |
1389 decl->initializer_ = reader->ReadOptional<Expression>(); | 1346 decl->initializer_ = reader->ReadOptional<Expression>(); |
1390 | 1347 |
1391 // Go to next token position so it ends *after* the last potentially | 1348 // Go to next token position so it ends *after* the last potentially |
1392 // debuggable position in the initializer. | 1349 // debuggable position in the initializer. |
1393 TokenPosition position = reader->max_position(); | 1350 TokenPosition position = reader->max_position(); |
1394 if (position.IsReal()) position.Next(); | 1351 if (position.IsReal()) position.Next(); |
1395 decl->end_position_ = position; | 1352 decl->end_position_ = position; |
1396 reader->helper()->variables().Push(decl); | 1353 reader->helper()->variables().Push(decl); |
1397 | 1354 |
1398 return decl; | 1355 return decl; |
1399 } | 1356 } |
1400 | 1357 |
1401 | 1358 |
1402 FunctionDeclaration* FunctionDeclaration::ReadFrom(Reader* reader) { | 1359 FunctionDeclaration* FunctionDeclaration::ReadFrom(Reader* reader) { |
1403 TRACE_READ_OFFSET(); | 1360 TRACE_READ_OFFSET(); |
1404 FunctionDeclaration* decl = new FunctionDeclaration(); | 1361 FunctionDeclaration* decl = new FunctionDeclaration(); |
1405 decl->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 1362 decl->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
1406 decl->position_ = reader->ReadPosition(); | 1363 decl->position_ = reader->ReadPosition(); |
1407 decl->variable_ = VariableDeclaration::ReadFromImpl(reader, false); | 1364 decl->variable_ = VariableDeclaration::ReadFromImpl(reader, false); |
1408 VariableScope<ReaderHelper> parameters(reader->helper()); | 1365 VariableScope<ReaderHelper> parameters(reader->helper()); |
1409 decl->function_ = FunctionNode::ReadFrom(reader); | 1366 decl->function_ = FunctionNode::ReadFrom(reader); |
1410 return decl; | 1367 return decl; |
1411 } | 1368 } |
1412 | 1369 |
1413 | 1370 |
1414 Name* Name::ReadFrom(Reader* reader) { | 1371 Name* Name::ReadFrom(Reader* reader) { |
1415 String* name = Reference::ReadStringFrom(reader); | 1372 intptr_t name_index = reader->ReadUInt(); |
1416 if (name->size() >= 1 && reader->CharacterAt(name, 0) == '_') { | 1373 if ((reader->StringLength(name_index) >= 1) && |
| 1374 (reader->CharacterAt(name_index, 0) == '_')) { |
1417 CanonicalName* library_reference = reader->ReadCanonicalNameReference(); | 1375 CanonicalName* library_reference = reader->ReadCanonicalNameReference(); |
1418 return new Name(name, library_reference); | 1376 return new Name(name_index, library_reference); |
1419 } else { | 1377 } else { |
1420 return new Name(name, NULL); | 1378 return new Name(name_index, NULL); |
1421 } | 1379 } |
1422 } | 1380 } |
1423 | 1381 |
1424 | 1382 |
1425 DartType* DartType::ReadFrom(Reader* reader) { | 1383 DartType* DartType::ReadFrom(Reader* reader) { |
1426 TRACE_READ_OFFSET(); | 1384 TRACE_READ_OFFSET(); |
1427 Tag tag = reader->ReadTag(); | 1385 Tag tag = reader->ReadTag(); |
1428 switch (tag) { | 1386 switch (tag) { |
1429 case kInvalidType: | 1387 case kInvalidType: |
1430 return InvalidType::ReadFrom(reader); | 1388 return InvalidType::ReadFrom(reader); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 } | 1458 } |
1501 | 1459 |
1502 | 1460 |
1503 FunctionType* FunctionType::ReadFrom(Reader* reader) { | 1461 FunctionType* FunctionType::ReadFrom(Reader* reader) { |
1504 TRACE_READ_OFFSET(); | 1462 TRACE_READ_OFFSET(); |
1505 FunctionType* type = new FunctionType(); | 1463 FunctionType* type = new FunctionType(); |
1506 TypeParameterScope<ReaderHelper> scope(reader->helper()); | 1464 TypeParameterScope<ReaderHelper> scope(reader->helper()); |
1507 type->type_parameters().ReadFrom(reader); | 1465 type->type_parameters().ReadFrom(reader); |
1508 type->required_parameter_count_ = reader->ReadUInt(); | 1466 type->required_parameter_count_ = reader->ReadUInt(); |
1509 type->positional_parameters().ReadFromStatic<DartType>(reader); | 1467 type->positional_parameters().ReadFromStatic<DartType>(reader); |
1510 type->named_parameters().ReadFromStatic<Tuple<String, DartType> >(reader); | 1468 type->named_parameters().ReadFromStatic<NamedParameter>(reader); |
1511 type->return_type_ = DartType::ReadFrom(reader); | 1469 type->return_type_ = DartType::ReadFrom(reader); |
1512 return type; | 1470 return type; |
1513 } | 1471 } |
1514 | 1472 |
1515 | 1473 |
1516 FunctionType* FunctionType::ReadFrom(Reader* reader, bool _is_simple_) { | 1474 FunctionType* FunctionType::ReadFrom(Reader* reader, bool _is_simple_) { |
1517 TRACE_READ_OFFSET(); | 1475 TRACE_READ_OFFSET(); |
1518 FunctionType* type = new FunctionType(); | 1476 FunctionType* type = new FunctionType(); |
1519 ASSERT(_is_simple_); | 1477 ASSERT(_is_simple_); |
1520 type->positional_parameters().ReadFromStatic<DartType>(reader); | 1478 type->positional_parameters().ReadFromStatic<DartType>(reader); |
(...skipping 21 matching lines...) Expand all Loading... |
1542 | 1500 |
1543 Program* Program::ReadFrom(Reader* reader) { | 1501 Program* Program::ReadFrom(Reader* reader) { |
1544 TRACE_READ_OFFSET(); | 1502 TRACE_READ_OFFSET(); |
1545 uint32_t magic = reader->ReadUInt32(); | 1503 uint32_t magic = reader->ReadUInt32(); |
1546 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier"); | 1504 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier"); |
1547 | 1505 |
1548 Program* program = new Program(); | 1506 Program* program = new Program(); |
1549 program->canonical_name_root_ = CanonicalName::NewRoot(); | 1507 program->canonical_name_root_ = CanonicalName::NewRoot(); |
1550 reader->helper()->set_program(program); | 1508 reader->helper()->set_program(program); |
1551 | 1509 |
1552 program->string_table_.ReadFrom(reader); | 1510 // Skip the table of string end offsets. |
1553 program->string_data_offset_ = reader->string_data_offset(); | 1511 reader->MarkStringTableOffset(); |
1554 ASSERT(program->string_data_offset_ >= 0); | 1512 intptr_t length = reader->ReadUInt(); |
| 1513 reader->string_offsets_ = new intptr_t[length + 1]; |
| 1514 intptr_t offset = 0; |
| 1515 for (intptr_t i = 0; i < length; ++i) { |
| 1516 reader->string_offsets_[i] = offset; |
| 1517 offset = reader->ReadUInt(); |
| 1518 } |
| 1519 reader->string_offsets_[length] = offset; |
| 1520 // Skip the UTF-8 encoded strings. |
| 1521 reader->MarkStringDataOffset(); |
| 1522 reader->Consume(offset); |
| 1523 |
| 1524 program->string_table_offset_ = reader->string_table_offset(); |
| 1525 ASSERT(program->string_table_offset_ >= 0); |
1555 program->source_table_.ReadFrom(reader); | 1526 program->source_table_.ReadFrom(reader); |
1556 | 1527 |
1557 int canonical_names = reader->ReadUInt(); | 1528 int canonical_names = reader->ReadUInt(); |
1558 reader->helper()->SetCanonicalNameCount(canonical_names); | 1529 reader->helper()->SetCanonicalNameCount(canonical_names); |
1559 for (int i = 0; i < canonical_names; ++i) { | 1530 for (int i = 0; i < canonical_names; ++i) { |
1560 int biased_parent_index = reader->ReadUInt(); | 1531 int biased_parent_index = reader->ReadUInt(); |
1561 CanonicalName* parent; | 1532 CanonicalName* parent; |
1562 if (biased_parent_index != 0) { | 1533 if (biased_parent_index != 0) { |
1563 parent = reader->helper()->GetCanonicalName(biased_parent_index - 1); | 1534 parent = reader->helper()->GetCanonicalName(biased_parent_index - 1); |
1564 } else { | 1535 } else { |
1565 parent = program->canonical_name_root(); | 1536 parent = program->canonical_name_root(); |
1566 } | 1537 } |
1567 ASSERT(parent != NULL); | 1538 ASSERT(parent != NULL); |
1568 int name_index = reader->ReadUInt(); | 1539 intptr_t name_index = reader->ReadUInt(); |
1569 String* name = program->string_table().strings()[name_index]; | 1540 CanonicalName* canonical_name = parent->AddChild(name_index); |
1570 CanonicalName* canonical_name = parent->AddChild(name); | |
1571 reader->helper()->SetCanonicalName(i, canonical_name); | 1541 reader->helper()->SetCanonicalName(i, canonical_name); |
1572 } | 1542 } |
1573 | 1543 |
1574 int libraries = reader->ReadUInt(); | 1544 int libraries = reader->ReadUInt(); |
1575 program->libraries().EnsureInitialized(libraries); | 1545 program->libraries().EnsureInitialized(libraries); |
1576 for (intptr_t i = 0; i < libraries; i++) { | 1546 for (intptr_t i = 0; i < libraries; i++) { |
1577 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); | 1547 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader); |
1578 } | 1548 } |
1579 | 1549 |
1580 program->main_method_reference_ = | 1550 program->main_method_reference_ = |
(...skipping 25 matching lines...) Expand all Loading... |
1606 LabelScope<ReaderHelper, BlockStack<LabeledStatement> > labels( | 1576 LabelScope<ReaderHelper, BlockStack<LabeledStatement> > labels( |
1607 reader->helper()); | 1577 reader->helper()); |
1608 VariableScope<ReaderHelper> vars(reader->helper()); | 1578 VariableScope<ReaderHelper> vars(reader->helper()); |
1609 function->body_ = reader->ReadOptional<Statement>(); | 1579 function->body_ = reader->ReadOptional<Statement>(); |
1610 return function; | 1580 return function; |
1611 } | 1581 } |
1612 | 1582 |
1613 | 1583 |
1614 TypeParameter* TypeParameter::ReadFrom(Reader* reader) { | 1584 TypeParameter* TypeParameter::ReadFrom(Reader* reader) { |
1615 TRACE_READ_OFFSET(); | 1585 TRACE_READ_OFFSET(); |
1616 name_ = Reference::ReadStringFrom(reader); | 1586 name_index_ = reader->ReadUInt(); |
1617 bound_ = DartType::ReadFrom(reader); | 1587 bound_ = DartType::ReadFrom(reader); |
1618 return this; | 1588 return this; |
1619 } | 1589 } |
1620 | 1590 |
1621 | 1591 |
1622 } // namespace kernel | 1592 } // namespace kernel |
1623 | 1593 |
1624 | 1594 |
1625 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, | 1595 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, |
1626 intptr_t buffer_length) { | 1596 intptr_t buffer_length) { |
1627 kernel::Reader reader(buffer, buffer_length); | 1597 kernel::Reader reader(buffer, buffer_length); |
1628 return kernel::Program::ReadFrom(&reader); | 1598 return kernel::Program::ReadFrom(&reader); |
1629 } | 1599 } |
1630 | 1600 |
1631 | 1601 |
1632 } // namespace dart | 1602 } // namespace dart |
1633 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1603 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |