| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_VM_KERNEL_BINARY_H_ | 5 #ifndef RUNTIME_VM_KERNEL_BINARY_H_ |
| 6 #define RUNTIME_VM_KERNEL_BINARY_H_ | 6 #define RUNTIME_VM_KERNEL_BINARY_H_ |
| 7 | 7 |
| 8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 486 |
| 487 template <typename T> | 487 template <typename T> |
| 488 T* ReadOptional() { | 488 T* ReadOptional() { |
| 489 return ReadOptional<T, T>(); | 489 return ReadOptional<T, T>(); |
| 490 } | 490 } |
| 491 | 491 |
| 492 ReaderHelper* helper() { return &builder_; } | 492 ReaderHelper* helper() { return &builder_; } |
| 493 | 493 |
| 494 // A canonical name reference of -1 indicates none (for optional names), not | 494 // A canonical name reference of -1 indicates none (for optional names), not |
| 495 // the root name as in the canonical name table. | 495 // the root name as in the canonical name table. |
| 496 intptr_t ReadCanonicalNameReference() { return ReadUInt() - 1; } | 496 NameIndex ReadCanonicalNameReference() { return NameIndex(ReadUInt() - 1); } |
| 497 | 497 |
| 498 intptr_t offset() { return offset_; } | 498 intptr_t offset() { return offset_; } |
| 499 void set_offset(intptr_t offset) { offset_ = offset; } | 499 void set_offset(intptr_t offset) { offset_ = offset; } |
| 500 intptr_t size() { return size_; } | 500 intptr_t size() { return size_; } |
| 501 | 501 |
| 502 const uint8_t* buffer() { return buffer_; } | 502 const uint8_t* buffer() { return buffer_; } |
| 503 | 503 |
| 504 intptr_t string_data_offset() { return string_data_offset_; } | 504 intptr_t string_data_offset() { return string_data_offset_; } |
| 505 void MarkStringDataOffset() { | 505 void MarkStringDataOffset() { |
| 506 ASSERT(string_data_offset_ == -1); | 506 ASSERT(string_data_offset_ == -1); |
| 507 string_data_offset_ = offset_; | 507 string_data_offset_ = offset_; |
| 508 } | 508 } |
| 509 | 509 |
| 510 intptr_t StringLength(intptr_t string_index) { | 510 intptr_t StringLength(StringIndex index) { |
| 511 return string_offsets_[string_index + 1] - string_offsets_[string_index]; | 511 return string_offsets_[index + 1] - string_offsets_[index]; |
| 512 } | 512 } |
| 513 | 513 |
| 514 uint8_t CharacterAt(intptr_t string_index, intptr_t index) { | 514 uint8_t CharacterAt(StringIndex string_index, intptr_t index) { |
| 515 ASSERT(index < StringLength(string_index)); | 515 ASSERT(index < StringLength(string_index)); |
| 516 return buffer_[string_data_offset_ + string_offsets_[string_index] + index]; | 516 return buffer_[string_data_offset_ + string_offsets_[string_index] + index]; |
| 517 } | 517 } |
| 518 | 518 |
| 519 // The canonical name index of a canonical name's parent (-1 indicates that | 519 // The canonical name index of a canonical name's parent (-1 indicates that |
| 520 // the parent is the root name). | 520 // the parent is the root name). |
| 521 intptr_t CanonicalNameParent(intptr_t name_index) { | 521 NameIndex CanonicalNameParent(NameIndex index) { |
| 522 return canonical_name_parents_[name_index]; | 522 return canonical_name_parents_[index]; |
| 523 } | 523 } |
| 524 | 524 |
| 525 // The string index of a canonical name's name string. | 525 // The string index of a canonical name's name string. |
| 526 intptr_t CanonicalNameString(intptr_t name_index) { | 526 StringIndex CanonicalNameString(NameIndex index) { |
| 527 return canonical_name_strings_[name_index]; | 527 return canonical_name_strings_[index]; |
| 528 } | 528 } |
| 529 | 529 |
| 530 private: | 530 private: |
| 531 const uint8_t* buffer_; | 531 const uint8_t* buffer_; |
| 532 intptr_t size_; | 532 intptr_t size_; |
| 533 intptr_t offset_; | 533 intptr_t offset_; |
| 534 ReaderHelper builder_; | 534 ReaderHelper builder_; |
| 535 TokenPosition max_position_; | 535 TokenPosition max_position_; |
| 536 TokenPosition min_position_; | 536 TokenPosition min_position_; |
| 537 intptr_t current_script_id_; | 537 intptr_t current_script_id_; |
| 538 | 538 |
| 539 // The offset of the start of the string data is recorded to allow access to | 539 // The offset of the start of the string data is recorded to allow access to |
| 540 // the strings during deserialization. | 540 // the strings during deserialization. |
| 541 intptr_t string_data_offset_; | 541 intptr_t string_data_offset_; |
| 542 | 542 |
| 543 // The string offsets are decoded to support efficient access to string UTF-8 | 543 // The string offsets are decoded to support efficient access to string UTF-8 |
| 544 // encodings. | 544 // encodings. |
| 545 intptr_t* string_offsets_; | 545 intptr_t* string_offsets_; |
| 546 | 546 |
| 547 // The canonical names are decoded. | 547 // The canonical names are decoded. |
| 548 intptr_t* canonical_name_parents_; | 548 NameIndex* canonical_name_parents_; |
| 549 intptr_t* canonical_name_strings_; | 549 StringIndex* canonical_name_strings_; |
| 550 | 550 |
| 551 friend class PositionScope; | 551 friend class PositionScope; |
| 552 friend class Program; | 552 friend class Program; |
| 553 }; | 553 }; |
| 554 | 554 |
| 555 | 555 |
| 556 // A helper class that resets the readers min and max positions both upon | 556 // A helper class that resets the readers min and max positions both upon |
| 557 // initialization and upon destruction, i.e. when created the min an max | 557 // initialization and upon destruction, i.e. when created the min an max |
| 558 // positions will be reset to "noSource", when destructing the min and max will | 558 // positions will be reset to "noSource", when destructing the min and max will |
| 559 // be reset to have they value they would have had, if they hadn't been reset in | 559 // be reset to have they value they would have had, if they hadn't been reset in |
| (...skipping 20 matching lines...) Expand all Loading... |
| 580 Reader* reader_; | 580 Reader* reader_; |
| 581 TokenPosition min_; | 581 TokenPosition min_; |
| 582 TokenPosition max_; | 582 TokenPosition max_; |
| 583 }; | 583 }; |
| 584 | 584 |
| 585 } // namespace kernel | 585 } // namespace kernel |
| 586 } // namespace dart | 586 } // namespace dart |
| 587 | 587 |
| 588 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 588 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 589 #endif // RUNTIME_VM_KERNEL_BINARY_H_ | 589 #endif // RUNTIME_VM_KERNEL_BINARY_H_ |
| OLD | NEW |