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 // objects before reading the bounds. | 80 // objects before reading the bounds. |
81 int length = reader->ReadListLength(); | 81 int length = reader->ReadListLength(); |
82 EnsureInitialized(length); | 82 EnsureInitialized(length); |
83 | 83 |
84 // Make all [TypeParameter]s available in scope. | 84 // Make all [TypeParameter]s available in scope. |
85 for (intptr_t i = 0; i < length; i++) { | 85 for (intptr_t i = 0; i < length; i++) { |
86 TypeParameter* parameter = (*this)[i] = new TypeParameter(); | 86 TypeParameter* parameter = (*this)[i] = new TypeParameter(); |
87 reader->helper()->type_parameters().Push(parameter); | 87 reader->helper()->type_parameters().Push(parameter); |
88 } | 88 } |
89 | 89 |
90 // Read all [TypeParameter]s and their bounds. | 90 if (length > 0) { |
91 for (intptr_t i = 0; i < length; i++) { | 91 // Read all [TypeParameter]s and their bounds. |
92 (*this)[i]->ReadFrom(reader); | 92 for (intptr_t i = 0; i < length; i++) { |
| 93 (*this)[i]->ReadFrom(reader); |
| 94 } |
| 95 first_offset = (*this)[0]->kernel_offset_; |
93 } | 96 } |
94 } | 97 } |
95 | 98 |
96 | 99 |
97 NamedParameter* NamedParameter::ReadFrom(Reader* reader) { | 100 NamedParameter* NamedParameter::ReadFrom(Reader* reader) { |
98 TRACE_READ_OFFSET(); | 101 TRACE_READ_OFFSET(); |
99 StringIndex name_index(reader->ReadUInt()); | 102 StringIndex name_index(reader->ReadUInt()); |
100 DartType* type = DartType::ReadFrom(reader); | 103 DartType* type = DartType::ReadFrom(reader); |
101 return new NamedParameter(name_index, type); | 104 return new NamedParameter(name_index, type); |
102 } | 105 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 Field* Field::ReadFrom(Reader* reader) { | 318 Field* Field::ReadFrom(Reader* reader) { |
316 TRACE_READ_OFFSET(); | 319 TRACE_READ_OFFSET(); |
317 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. | 320 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. |
318 Tag tag = reader->ReadTag(); | 321 Tag tag = reader->ReadTag(); |
319 ASSERT(tag == kField); | 322 ASSERT(tag == kField); |
320 | 323 |
321 canonical_name_ = reader->ReadCanonicalNameReference(); | 324 canonical_name_ = reader->ReadCanonicalNameReference(); |
322 position_ = reader->ReadPosition(false); | 325 position_ = reader->ReadPosition(false); |
323 end_position_ = reader->ReadPosition(false); | 326 end_position_ = reader->ReadPosition(false); |
324 flags_ = reader->ReadFlags(); | 327 flags_ = reader->ReadFlags(); |
| 328 reader->ReadUInt(); // parent class binary offset (or 0). |
325 name_ = Name::ReadFrom(reader); | 329 name_ = Name::ReadFrom(reader); |
326 source_uri_index_ = reader->ReadUInt(); | 330 source_uri_index_ = reader->ReadUInt(); |
327 reader->set_current_script_id(source_uri_index_); | 331 reader->set_current_script_id(source_uri_index_); |
328 reader->record_token_position(position_); | 332 reader->record_token_position(position_); |
329 reader->record_token_position(end_position_); | 333 reader->record_token_position(end_position_); |
330 annotations_.ReadFromStatic<Expression>(reader); | 334 annotations_.ReadFromStatic<Expression>(reader); |
331 type_ = DartType::ReadFrom(reader); | 335 type_ = DartType::ReadFrom(reader); |
332 initializer_ = reader->ReadOptional<Expression>(); | 336 initializer_ = reader->ReadOptional<Expression>(); |
333 | 337 |
334 can_stream_ = (initializer_ == NULL || initializer_->can_stream()) && | 338 can_stream_ = (initializer_ == NULL || initializer_->can_stream()) && |
335 annotations_.CanStream(); | 339 annotations_.CanStream(); |
336 | 340 |
337 return this; | 341 return this; |
338 } | 342 } |
339 | 343 |
340 | 344 |
341 Constructor* Constructor::ReadFrom(Reader* reader) { | 345 Constructor* Constructor::ReadFrom(Reader* reader) { |
342 TRACE_READ_OFFSET(); | 346 TRACE_READ_OFFSET(); |
| 347 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. |
343 Tag tag = reader->ReadTag(); | 348 Tag tag = reader->ReadTag(); |
344 ASSERT(tag == kConstructor); | 349 ASSERT(tag == kConstructor); |
345 | 350 |
346 canonical_name_ = reader->ReadCanonicalNameReference(); | 351 canonical_name_ = reader->ReadCanonicalNameReference(); |
347 VariableScope<ReaderHelper> parameters(reader->helper()); | 352 VariableScope<ReaderHelper> parameters(reader->helper()); |
348 position_ = reader->ReadPosition(); | 353 position_ = reader->ReadPosition(); |
349 end_position_ = reader->ReadPosition(); | 354 end_position_ = reader->ReadPosition(); |
350 flags_ = reader->ReadFlags(); | 355 flags_ = reader->ReadFlags(); |
| 356 reader->ReadUInt(); // parent class binary offset. |
351 name_ = Name::ReadFrom(reader); | 357 name_ = Name::ReadFrom(reader); |
352 annotations_.ReadFromStatic<Expression>(reader); | 358 annotations_.ReadFromStatic<Expression>(reader); |
353 function_ = FunctionNode::ReadFrom(reader); | 359 function_ = FunctionNode::ReadFrom(reader); |
354 initializers_.ReadFromStatic<Initializer>(reader); | 360 initializers_.ReadFromStatic<Initializer>(reader); |
355 | 361 |
356 can_stream_ = annotations_.CanStream() && function_->can_stream() && | 362 can_stream_ = annotations_.CanStream() && function_->can_stream() && |
357 initializers_.CanStream(); | 363 initializers_.CanStream(); |
358 | 364 |
359 return this; | 365 return this; |
360 } | 366 } |
361 | 367 |
362 | 368 |
363 Procedure* Procedure::ReadFrom(Reader* reader) { | 369 Procedure* Procedure::ReadFrom(Reader* reader) { |
364 TRACE_READ_OFFSET(); | 370 TRACE_READ_OFFSET(); |
| 371 kernel_offset_ = reader->offset(); // Notice the ReadTag() below. |
365 Tag tag = reader->ReadTag(); | 372 Tag tag = reader->ReadTag(); |
366 ASSERT(tag == kProcedure); | 373 ASSERT(tag == kProcedure); |
367 | 374 |
368 canonical_name_ = reader->ReadCanonicalNameReference(); | 375 canonical_name_ = reader->ReadCanonicalNameReference(); |
369 VariableScope<ReaderHelper> parameters(reader->helper()); | 376 VariableScope<ReaderHelper> parameters(reader->helper()); |
370 position_ = reader->ReadPosition(false); | 377 position_ = reader->ReadPosition(false); |
371 end_position_ = reader->ReadPosition(false); | 378 end_position_ = reader->ReadPosition(false); |
372 kind_ = static_cast<ProcedureKind>(reader->ReadByte()); | 379 kind_ = static_cast<ProcedureKind>(reader->ReadByte()); |
373 flags_ = reader->ReadFlags(); | 380 flags_ = reader->ReadFlags(); |
| 381 reader->ReadUInt(); // parent class binary offset (or 0). |
374 name_ = Name::ReadFrom(reader); | 382 name_ = Name::ReadFrom(reader); |
375 source_uri_index_ = reader->ReadUInt(); | 383 source_uri_index_ = reader->ReadUInt(); |
376 reader->set_current_script_id(source_uri_index_); | 384 reader->set_current_script_id(source_uri_index_); |
377 reader->record_token_position(position_); | 385 reader->record_token_position(position_); |
378 reader->record_token_position(end_position_); | 386 reader->record_token_position(end_position_); |
379 annotations_.ReadFromStatic<Expression>(reader); | 387 annotations_.ReadFromStatic<Expression>(reader); |
380 function_ = reader->ReadOptional<FunctionNode>(); | 388 function_ = reader->ReadOptional<FunctionNode>(); |
381 | 389 |
382 can_stream_ = annotations_.CanStream() && | 390 can_stream_ = annotations_.CanStream() && |
383 (function_ == NULL || function_->can_stream()); | 391 (function_ == NULL || function_->can_stream()); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 } | 587 } |
580 | 588 |
581 | 589 |
582 VariableGet* VariableGet::ReadFrom(Reader* reader) { | 590 VariableGet* VariableGet::ReadFrom(Reader* reader) { |
583 TRACE_READ_OFFSET(); | 591 TRACE_READ_OFFSET(); |
584 VariableGet* get = new VariableGet(); | 592 VariableGet* get = new VariableGet(); |
585 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 593 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
586 get->position_ = reader->ReadPosition(); | 594 get->position_ = reader->ReadPosition(); |
587 get->variable_kernel_offset_ = reader->ReadUInt(); | 595 get->variable_kernel_offset_ = reader->ReadUInt(); |
588 get->variable_ = reader->helper()->variables().Lookup(reader->ReadUInt()); | 596 get->variable_ = reader->helper()->variables().Lookup(reader->ReadUInt()); |
589 ASSERT(get->variable_->kernel_offset() == get->variable_kernel_offset_); | 597 ASSERT(get->variable_->kernel_offset_no_tag() == |
| 598 get->variable_kernel_offset_); |
590 reader->ReadOptional<DartType>(); // Unused promoted type. | 599 reader->ReadOptional<DartType>(); // Unused promoted type. |
591 return get; | 600 return get; |
592 } | 601 } |
593 | 602 |
594 | 603 |
595 VariableGet* VariableGet::ReadFrom(Reader* reader, uint8_t payload) { | 604 VariableGet* VariableGet::ReadFrom(Reader* reader, uint8_t payload) { |
596 TRACE_READ_OFFSET(); | 605 TRACE_READ_OFFSET(); |
597 VariableGet* get = new VariableGet(); | 606 VariableGet* get = new VariableGet(); |
598 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 607 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
599 get->position_ = reader->ReadPosition(); | 608 get->position_ = reader->ReadPosition(); |
600 get->variable_kernel_offset_ = reader->ReadUInt(); | 609 get->variable_kernel_offset_ = reader->ReadUInt(); |
601 get->variable_ = reader->helper()->variables().Lookup(payload); | 610 get->variable_ = reader->helper()->variables().Lookup(payload); |
602 ASSERT(get->variable_->kernel_offset() == get->variable_kernel_offset_); | 611 ASSERT(get->variable_->kernel_offset_no_tag() == |
| 612 get->variable_kernel_offset_); |
603 return get; | 613 return get; |
604 } | 614 } |
605 | 615 |
606 | 616 |
607 VariableSet* VariableSet::ReadFrom(Reader* reader) { | 617 VariableSet* VariableSet::ReadFrom(Reader* reader) { |
608 TRACE_READ_OFFSET(); | 618 TRACE_READ_OFFSET(); |
609 VariableSet* set = new VariableSet(); | 619 VariableSet* set = new VariableSet(); |
610 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 620 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
611 set->position_ = reader->ReadPosition(); | 621 set->position_ = reader->ReadPosition(); |
612 set->variable_kernel_offset_ = reader->ReadUInt(); | 622 set->variable_kernel_offset_ = reader->ReadUInt(); |
613 set->variable_ = reader->helper()->variables().Lookup(reader->ReadUInt()); | 623 set->variable_ = reader->helper()->variables().Lookup(reader->ReadUInt()); |
614 ASSERT(set->variable_->kernel_offset() == set->variable_kernel_offset_); | 624 ASSERT(set->variable_->kernel_offset_no_tag() == |
| 625 set->variable_kernel_offset_); |
615 set->expression_ = Expression::ReadFrom(reader); | 626 set->expression_ = Expression::ReadFrom(reader); |
616 | 627 |
617 set->can_stream_ = set->expression_->can_stream(); | 628 set->can_stream_ = set->expression_->can_stream(); |
618 | 629 |
619 return set; | 630 return set; |
620 } | 631 } |
621 | 632 |
622 | 633 |
623 VariableSet* VariableSet::ReadFrom(Reader* reader, uint8_t payload) { | 634 VariableSet* VariableSet::ReadFrom(Reader* reader, uint8_t payload) { |
624 TRACE_READ_OFFSET(); | 635 TRACE_READ_OFFSET(); |
625 VariableSet* set = new VariableSet(); | 636 VariableSet* set = new VariableSet(); |
626 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. | 637 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte. |
627 set->variable_ = reader->helper()->variables().Lookup(payload); | 638 set->variable_ = reader->helper()->variables().Lookup(payload); |
628 set->position_ = reader->ReadPosition(); | 639 set->position_ = reader->ReadPosition(); |
629 set->variable_kernel_offset_ = reader->ReadUInt(); | 640 set->variable_kernel_offset_ = reader->ReadUInt(); |
630 ASSERT(set->variable_->kernel_offset() == set->variable_kernel_offset_); | 641 ASSERT(set->variable_->kernel_offset_no_tag() == |
| 642 set->variable_kernel_offset_); |
631 set->expression_ = Expression::ReadFrom(reader); | 643 set->expression_ = Expression::ReadFrom(reader); |
632 | 644 |
633 set->can_stream_ = set->expression_->can_stream(); | 645 set->can_stream_ = set->expression_->can_stream(); |
634 | 646 |
635 return set; | 647 return set; |
636 } | 648 } |
637 | 649 |
638 | 650 |
639 PropertyGet* PropertyGet::ReadFrom(Reader* reader) { | 651 PropertyGet* PropertyGet::ReadFrom(Reader* reader) { |
640 TRACE_READ_OFFSET(); | 652 TRACE_READ_OFFSET(); |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 | 1547 |
1536 | 1548 |
1537 VariableDeclaration* VariableDeclaration::ReadFromImpl(Reader* reader, | 1549 VariableDeclaration* VariableDeclaration::ReadFromImpl(Reader* reader, |
1538 bool read_tag) { | 1550 bool read_tag) { |
1539 TRACE_READ_OFFSET(); | 1551 TRACE_READ_OFFSET(); |
1540 PositionScope scope(reader); | 1552 PositionScope scope(reader); |
1541 | 1553 |
1542 VariableDeclaration* decl = new VariableDeclaration(); | 1554 VariableDeclaration* decl = new VariableDeclaration(); |
1543 // -1 or -0 depending on whether there's a tag or not. | 1555 // -1 or -0 depending on whether there's a tag or not. |
1544 decl->kernel_offset_ = reader->offset() - (read_tag ? 1 : 0); | 1556 decl->kernel_offset_ = reader->offset() - (read_tag ? 1 : 0); |
| 1557 decl->kernel_offset_no_tag_ = reader->offset(); |
1545 decl->position_ = reader->ReadPosition(); | 1558 decl->position_ = reader->ReadPosition(); |
1546 decl->equals_position_ = reader->ReadPosition(); | 1559 decl->equals_position_ = reader->ReadPosition(); |
1547 decl->flags_ = reader->ReadFlags(); | 1560 decl->flags_ = reader->ReadFlags(); |
1548 decl->name_index_ = StringIndex(reader->ReadUInt()); | 1561 decl->name_index_ = StringIndex(reader->ReadUInt()); |
1549 decl->type_ = DartType::ReadFrom(reader); | 1562 decl->type_ = DartType::ReadFrom(reader); |
1550 decl->initializer_ = reader->ReadOptional<Expression>(); | 1563 decl->initializer_ = reader->ReadOptional<Expression>(); |
1551 | 1564 |
1552 // Go to next token position so it ends *after* the last potentially | 1565 // Go to next token position so it ends *after* the last potentially |
1553 // debuggable position in the initializer. | 1566 // debuggable position in the initializer. |
1554 TokenPosition position = reader->max_position(); | 1567 TokenPosition position = reader->max_position(); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 | 1787 |
1775 return program; | 1788 return program; |
1776 } | 1789 } |
1777 | 1790 |
1778 | 1791 |
1779 FunctionNode* FunctionNode::ReadFrom(Reader* reader) { | 1792 FunctionNode* FunctionNode::ReadFrom(Reader* reader) { |
1780 TRACE_READ_OFFSET(); | 1793 TRACE_READ_OFFSET(); |
1781 TypeParameterScope<ReaderHelper> scope(reader->helper()); | 1794 TypeParameterScope<ReaderHelper> scope(reader->helper()); |
1782 | 1795 |
1783 FunctionNode* function = new FunctionNode(); | 1796 FunctionNode* function = new FunctionNode(); |
1784 function->kernel_offset_ = reader->offset(); // FunctionNode has no tag. | 1797 // FunctionNode tag not read yet. |
| 1798 function->kernel_offset_ = reader->offset(); |
| 1799 Tag tag = reader->ReadTag(); |
| 1800 ASSERT(tag == kFunctionNode); |
1785 function->position_ = reader->ReadPosition(); | 1801 function->position_ = reader->ReadPosition(); |
1786 function->end_position_ = reader->ReadPosition(); | 1802 function->end_position_ = reader->ReadPosition(); |
1787 function->async_marker_ = | 1803 function->async_marker_ = |
1788 static_cast<FunctionNode::AsyncMarker>(reader->ReadByte()); | 1804 static_cast<FunctionNode::AsyncMarker>(reader->ReadByte()); |
1789 function->dart_async_marker_ = | 1805 function->dart_async_marker_ = |
1790 static_cast<FunctionNode::AsyncMarker>(reader->ReadByte()); | 1806 static_cast<FunctionNode::AsyncMarker>(reader->ReadByte()); |
1791 function->type_parameters().ReadFrom(reader); | 1807 function->type_parameters().ReadFrom(reader); |
1792 function->required_parameter_count_ = reader->ReadUInt(); | 1808 function->required_parameter_count_ = reader->ReadUInt(); |
1793 function->positional_parameters().ReadFromStatic<VariableDeclarationImpl>( | 1809 function->positional_parameters().ReadFromStatic<VariableDeclarationImpl>( |
1794 reader); | 1810 reader); |
(...skipping 28 matching lines...) Expand all Loading... |
1823 | 1839 |
1824 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, | 1840 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, |
1825 intptr_t buffer_length) { | 1841 intptr_t buffer_length) { |
1826 kernel::Reader reader(buffer, buffer_length); | 1842 kernel::Reader reader(buffer, buffer_length); |
1827 return kernel::Program::ReadFrom(&reader); | 1843 return kernel::Program::ReadFrom(&reader); |
1828 } | 1844 } |
1829 | 1845 |
1830 | 1846 |
1831 } // namespace dart | 1847 } // namespace dart |
1832 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1848 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |