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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 canonical_name_ = reader->ReadCanonicalNameReference(); | 208 canonical_name_ = reader->ReadCanonicalNameReference(); |
209 name_ = Reference::ReadStringFrom(reader); | 209 name_ = Reference::ReadStringFrom(reader); |
210 import_uri_ = canonical_name_->name(); | 210 import_uri_ = canonical_name_->name(); |
211 source_uri_index_ = reader->ReadUInt(); | 211 source_uri_index_ = reader->ReadUInt(); |
212 reader->set_current_script_id(source_uri_index_); | 212 reader->set_current_script_id(source_uri_index_); |
213 | 213 |
214 int num_imports = reader->ReadUInt(); | 214 int num_imports = reader->ReadUInt(); |
215 if (num_imports != 0) { | 215 if (num_imports != 0) { |
216 FATAL("Deferred imports not implemented in VM"); | 216 FATAL("Deferred imports not implemented in VM"); |
217 } | 217 } |
| 218 int num_typedefs = reader->ReadUInt(); |
| 219 typedefs().EnsureInitialized(num_typedefs); |
| 220 for (intptr_t i = 0; i < num_typedefs; i++) { |
| 221 typedefs().GetOrCreate<Typedef>(i, this)->ReadFrom(reader); |
| 222 } |
218 int num_classes = reader->ReadUInt(); | 223 int num_classes = reader->ReadUInt(); |
219 classes().EnsureInitialized(num_classes); | 224 classes().EnsureInitialized(num_classes); |
220 for (intptr_t i = 0; i < num_classes; i++) { | 225 for (intptr_t i = 0; i < num_classes; i++) { |
221 Tag tag = reader->ReadTag(); | 226 Tag tag = reader->ReadTag(); |
222 ASSERT(tag == kClass); | 227 ASSERT(tag == kClass); |
223 NormalClass* klass = classes().GetOrCreate<NormalClass>(i, this); | 228 NormalClass* klass = classes().GetOrCreate<NormalClass>(i, this); |
224 klass->ReadFrom(reader); | 229 klass->ReadFrom(reader); |
225 } | 230 } |
226 | 231 |
227 fields().ReadFrom<Field>(reader, this); | 232 fields().ReadFrom<Field>(reader, this); |
228 procedures().ReadFrom<Procedure>(reader, this); | 233 procedures().ReadFrom<Procedure>(reader, this); |
229 return this; | 234 return this; |
230 } | 235 } |
231 | 236 |
232 | 237 |
| 238 Typedef* Typedef::ReadFrom(Reader* reader) { |
| 239 TRACE_READ_OFFSET(); |
| 240 |
| 241 canonical_name_ = reader->ReadCanonicalNameReference(); |
| 242 position_ = reader->ReadPosition(false); |
| 243 name_ = Reference::ReadStringFrom(reader); |
| 244 source_uri_index_ = reader->ReadUInt(); |
| 245 type_parameters_.ReadFrom(reader); |
| 246 type_ = DartType::ReadFrom(reader); |
| 247 |
| 248 return this; |
| 249 } |
| 250 |
| 251 |
233 Class* Class::ReadFrom(Reader* reader) { | 252 Class* Class::ReadFrom(Reader* reader) { |
234 TRACE_READ_OFFSET(); | 253 TRACE_READ_OFFSET(); |
235 | 254 |
236 canonical_name_ = reader->ReadCanonicalNameReference(); | 255 canonical_name_ = reader->ReadCanonicalNameReference(); |
237 position_ = reader->ReadPosition(false); | 256 position_ = reader->ReadPosition(false); |
238 is_abstract_ = reader->ReadBool(); | 257 is_abstract_ = reader->ReadBool(); |
239 name_ = Reference::ReadStringFrom(reader); | 258 name_ = Reference::ReadStringFrom(reader); |
240 source_uri_index_ = reader->ReadUInt(); | 259 source_uri_index_ = reader->ReadUInt(); |
241 reader->set_current_script_id(source_uri_index_); | 260 reader->set_current_script_id(source_uri_index_); |
242 reader->record_token_position(position_); | 261 reader->record_token_position(position_); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 325 } |
307 | 326 |
308 if (canonical_name != NULL) { | 327 if (canonical_name != NULL) { |
309 canonical_name->set_referenced(true); | 328 canonical_name->set_referenced(true); |
310 } | 329 } |
311 | 330 |
312 return canonical_name; | 331 return canonical_name; |
313 } | 332 } |
314 | 333 |
315 | 334 |
| 335 CanonicalName* Reference::ReadTypedefFrom(Reader* reader) { |
| 336 TRACE_READ_OFFSET(); |
| 337 |
| 338 CanonicalName* canonical_name = reader->ReadCanonicalNameReference(); |
| 339 if (canonical_name == NULL) { |
| 340 FATAL("Expected a valid typedef reference, but got `null`"); |
| 341 } |
| 342 |
| 343 canonical_name->set_referenced(true); |
| 344 |
| 345 return canonical_name; |
| 346 } |
| 347 |
| 348 |
316 String* Reference::ReadStringFrom(Reader* reader) { | 349 String* Reference::ReadStringFrom(Reader* reader) { |
317 int index = reader->ReadUInt(); | 350 int index = reader->ReadUInt(); |
318 return reader->helper()->program()->string_table().strings()[index]; | 351 return reader->helper()->program()->string_table().strings()[index]; |
319 } | 352 } |
320 | 353 |
321 | 354 |
322 Field* Field::ReadFrom(Reader* reader) { | 355 Field* Field::ReadFrom(Reader* reader) { |
323 TRACE_READ_OFFSET(); | 356 TRACE_READ_OFFSET(); |
324 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. | 357 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. |
325 Tag tag = reader->ReadTag(); | 358 Tag tag = reader->ReadTag(); |
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 case kSimpleInterfaceType: | 1437 case kSimpleInterfaceType: |
1405 return InterfaceType::ReadFrom(reader, true); | 1438 return InterfaceType::ReadFrom(reader, true); |
1406 case kFunctionType: | 1439 case kFunctionType: |
1407 return FunctionType::ReadFrom(reader); | 1440 return FunctionType::ReadFrom(reader); |
1408 case kSimpleFunctionType: | 1441 case kSimpleFunctionType: |
1409 return FunctionType::ReadFrom(reader, true); | 1442 return FunctionType::ReadFrom(reader, true); |
1410 case kTypeParameterType: | 1443 case kTypeParameterType: |
1411 return TypeParameterType::ReadFrom(reader); | 1444 return TypeParameterType::ReadFrom(reader); |
1412 case kVectorType: | 1445 case kVectorType: |
1413 return VectorType::ReadFrom(reader); | 1446 return VectorType::ReadFrom(reader); |
| 1447 case kTypedefType: |
| 1448 return TypedefType::ReadFrom(reader); |
1414 default: | 1449 default: |
1415 UNREACHABLE(); | 1450 UNREACHABLE(); |
1416 } | 1451 } |
1417 UNREACHABLE(); | 1452 UNREACHABLE(); |
1418 return NULL; | 1453 return NULL; |
1419 } | 1454 } |
1420 | 1455 |
1421 | 1456 |
1422 InvalidType* InvalidType::ReadFrom(Reader* reader) { | 1457 InvalidType* InvalidType::ReadFrom(Reader* reader) { |
1423 TRACE_READ_OFFSET(); | 1458 TRACE_READ_OFFSET(); |
(...skipping 25 matching lines...) Expand all Loading... |
1449 InterfaceType* InterfaceType::ReadFrom(Reader* reader, | 1484 InterfaceType* InterfaceType::ReadFrom(Reader* reader, |
1450 bool _without_type_arguments_) { | 1485 bool _without_type_arguments_) { |
1451 TRACE_READ_OFFSET(); | 1486 TRACE_READ_OFFSET(); |
1452 CanonicalName* klass_name = Reference::ReadClassFrom(reader); | 1487 CanonicalName* klass_name = Reference::ReadClassFrom(reader); |
1453 InterfaceType* type = new InterfaceType(klass_name); | 1488 InterfaceType* type = new InterfaceType(klass_name); |
1454 ASSERT(_without_type_arguments_); | 1489 ASSERT(_without_type_arguments_); |
1455 return type; | 1490 return type; |
1456 } | 1491 } |
1457 | 1492 |
1458 | 1493 |
| 1494 TypedefType* TypedefType::ReadFrom(Reader* reader) { |
| 1495 TRACE_READ_OFFSET(); |
| 1496 CanonicalName* typedef_name = Reference::ReadTypedefFrom(reader); |
| 1497 TypedefType* type = new TypedefType(typedef_name); |
| 1498 type->type_arguments().ReadFromStatic<DartType>(reader); |
| 1499 return type; |
| 1500 } |
| 1501 |
| 1502 |
1459 FunctionType* FunctionType::ReadFrom(Reader* reader) { | 1503 FunctionType* FunctionType::ReadFrom(Reader* reader) { |
1460 TRACE_READ_OFFSET(); | 1504 TRACE_READ_OFFSET(); |
1461 FunctionType* type = new FunctionType(); | 1505 FunctionType* type = new FunctionType(); |
1462 TypeParameterScope<ReaderHelper> scope(reader->helper()); | 1506 TypeParameterScope<ReaderHelper> scope(reader->helper()); |
1463 type->type_parameters().ReadFrom(reader); | 1507 type->type_parameters().ReadFrom(reader); |
1464 type->required_parameter_count_ = reader->ReadUInt(); | 1508 type->required_parameter_count_ = reader->ReadUInt(); |
1465 type->positional_parameters().ReadFromStatic<DartType>(reader); | 1509 type->positional_parameters().ReadFromStatic<DartType>(reader); |
1466 type->named_parameters().ReadFromStatic<Tuple<String, DartType> >(reader); | 1510 type->named_parameters().ReadFromStatic<Tuple<String, DartType> >(reader); |
1467 type->return_type_ = DartType::ReadFrom(reader); | 1511 type->return_type_ = DartType::ReadFrom(reader); |
1468 return type; | 1512 return type; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 | 1624 |
1581 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, | 1625 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, |
1582 intptr_t buffer_length) { | 1626 intptr_t buffer_length) { |
1583 kernel::Reader reader(buffer, buffer_length); | 1627 kernel::Reader reader(buffer, buffer_length); |
1584 return kernel::Program::ReadFrom(&reader); | 1628 return kernel::Program::ReadFrom(&reader); |
1585 } | 1629 } |
1586 | 1630 |
1587 | 1631 |
1588 } // namespace dart | 1632 } // namespace dart |
1589 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1633 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |