OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 void set_literal(const String& literal) const; | 1808 void set_literal(const String& literal) const; |
1809 void set_value(const Object& value) const; | 1809 void set_value(const Object& value) const; |
1810 | 1810 |
1811 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); | 1811 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); |
1812 friend class Class; | 1812 friend class Class; |
1813 }; | 1813 }; |
1814 | 1814 |
1815 | 1815 |
1816 class TokenStream : public Object { | 1816 class TokenStream : public Object { |
1817 public: | 1817 public: |
1818 inline intptr_t Length() const; | |
1819 | |
1820 RawArray* TokenObjects() const; | 1818 RawArray* TokenObjects() const; |
1821 void SetTokenObjects(const Array& value) const; | 1819 void SetTokenObjects(const Array& value) const; |
1822 | 1820 |
| 1821 RawExternalUint8Array* GetStream() const; |
| 1822 void SetStream(const ExternalUint8Array& stream) const; |
| 1823 |
1823 RawString* GenerateSource() const; | 1824 RawString* GenerateSource() const; |
1824 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; | 1825 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; |
1825 intptr_t ComputeTokenPosition(intptr_t src_pos) const; | 1826 intptr_t ComputeTokenPosition(intptr_t src_pos) const; |
1826 | 1827 |
1827 static const intptr_t kBytesPerElement = 1; | 1828 static const intptr_t kBytesPerElement = 1; |
1828 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 1829 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
1829 | 1830 |
1830 static intptr_t InstanceSize() { | 1831 static intptr_t InstanceSize() { |
1831 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); | 1832 return RoundedAllocationSize(sizeof(RawTokenStream)); |
1832 return 0; | |
1833 } | |
1834 static intptr_t InstanceSize(intptr_t len) { | |
1835 ASSERT(0 <= len && len <= kMaxElements); | |
1836 return RoundedAllocationSize( | |
1837 sizeof(RawTokenStream) + (len * kBytesPerElement)); | |
1838 } | 1833 } |
1839 | 1834 |
1840 static RawTokenStream* New(intptr_t length); | 1835 static RawTokenStream* New(intptr_t length); |
1841 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens, | 1836 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens, |
1842 const String& private_key); | 1837 const String& private_key); |
1843 | 1838 |
1844 // The class Iterator encapsulates iteration over the tokens | 1839 // The class Iterator encapsulates iteration over the tokens |
1845 // in a TokenStream object. | 1840 // in a TokenStream object. |
1846 class Iterator : ValueObject { | 1841 class Iterator : ValueObject { |
1847 public: | 1842 public: |
(...skipping 12 matching lines...) Expand all Loading... |
1860 | 1855 |
1861 void Advance(); | 1856 void Advance(); |
1862 | 1857 |
1863 RawObject* CurrentToken() const; | 1858 RawObject* CurrentToken() const; |
1864 RawString* CurrentLiteral() const; | 1859 RawString* CurrentLiteral() const; |
1865 RawString* MakeLiteralToken(const Object& obj) const; | 1860 RawString* MakeLiteralToken(const Object& obj) const; |
1866 | 1861 |
1867 private: | 1862 private: |
1868 // Read token from the token stream (could be a simple token or an index | 1863 // Read token from the token stream (could be a simple token or an index |
1869 // into the token objects array for IDENT or literal tokens). | 1864 // into the token objects array for IDENT or literal tokens). |
1870 intptr_t ReadToken(); | 1865 intptr_t ReadToken() { |
1871 uint8_t ReadByte(); | 1866 int64_t value = stream_.ReadUnsigned(); |
| 1867 ASSERT((value >= 0) && (value <= kIntptrMax)); |
| 1868 return value; |
| 1869 } |
1872 | 1870 |
1873 const TokenStream& tokens_; | 1871 const TokenStream& tokens_; |
| 1872 const ExternalUint8Array& data_; |
| 1873 ReadStream stream_; |
1874 Array& token_objects_; | 1874 Array& token_objects_; |
1875 Object& obj_; | 1875 Object& obj_; |
1876 intptr_t cur_token_pos_; | 1876 intptr_t cur_token_pos_; |
1877 intptr_t stream_token_pos_; | |
1878 Token::Kind cur_token_kind_; | 1877 Token::Kind cur_token_kind_; |
1879 intptr_t cur_token_obj_index_; | 1878 intptr_t cur_token_obj_index_; |
1880 }; | 1879 }; |
1881 | 1880 |
1882 private: | 1881 private: |
1883 void SetLength(intptr_t value) const; | |
1884 | |
1885 RawString* PrivateKey() const; | 1882 RawString* PrivateKey() const; |
1886 void SetPrivateKey(const String& value) const; | 1883 void SetPrivateKey(const String& value) const; |
1887 | 1884 |
1888 uint8_t* EntryAddr(intptr_t token_pos) const { | 1885 static RawTokenStream* New(); |
1889 ASSERT((token_pos >=0) && (token_pos < Length())); | 1886 static void DataFinalizer(void *peer); |
1890 return &raw_ptr()->data_[token_pos]; | |
1891 } | |
1892 | 1887 |
1893 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); | 1888 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); |
1894 friend class Class; | 1889 friend class Class; |
1895 }; | 1890 }; |
1896 | 1891 |
1897 | 1892 |
1898 class Script : public Object { | 1893 class Script : public Object { |
1899 public: | 1894 public: |
1900 RawString* url() const { return raw_ptr()->url_; } | 1895 RawString* url() const { return raw_ptr()->url_; } |
1901 bool HasSource() const; | 1896 bool HasSource() const; |
(...skipping 3611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5513 return Smi::Value(reinterpret_cast<RawSmi*>(raw_ptr()->value_)); | 5508 return Smi::Value(reinterpret_cast<RawSmi*>(raw_ptr()->value_)); |
5514 } | 5509 } |
5515 | 5510 |
5516 | 5511 |
5517 void Field::SetOffset(intptr_t value) const { | 5512 void Field::SetOffset(intptr_t value) const { |
5518 ASSERT(!is_static()); // SetOffset is valid only for instance fields. | 5513 ASSERT(!is_static()); // SetOffset is valid only for instance fields. |
5519 raw_ptr()->value_ = Smi::New(value); | 5514 raw_ptr()->value_ = Smi::New(value); |
5520 } | 5515 } |
5521 | 5516 |
5522 | 5517 |
5523 intptr_t TokenStream::Length() const { | |
5524 return Smi::Value(raw_ptr()->length_); | |
5525 } | |
5526 | |
5527 | |
5528 void Context::SetAt(intptr_t index, const Instance& value) const { | 5518 void Context::SetAt(intptr_t index, const Instance& value) const { |
5529 StorePointer(InstanceAddr(index), value.raw()); | 5519 StorePointer(InstanceAddr(index), value.raw()); |
5530 } | 5520 } |
5531 | 5521 |
5532 | 5522 |
5533 bool String::Equals(const String& str) const { | 5523 bool String::Equals(const String& str) const { |
5534 if (raw() == str.raw()) { | 5524 if (raw() == str.raw()) { |
5535 return true; // Both handles point to the same raw instance. | 5525 return true; // Both handles point to the same raw instance. |
5536 } | 5526 } |
5537 if (str.IsNull()) { | 5527 if (str.IsNull()) { |
(...skipping 17 matching lines...) Expand all Loading... |
5555 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5545 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5556 return false; | 5546 return false; |
5557 } | 5547 } |
5558 } | 5548 } |
5559 return true; | 5549 return true; |
5560 } | 5550 } |
5561 | 5551 |
5562 } // namespace dart | 5552 } // namespace dart |
5563 | 5553 |
5564 #endif // VM_OBJECT_H_ | 5554 #endif // VM_OBJECT_H_ |
OLD | NEW |