| 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 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 void set_literal(const String& literal) const; | 1815 void set_literal(const String& literal) const; |
| 1816 void set_value(const Object& value) const; | 1816 void set_value(const Object& value) const; |
| 1817 | 1817 |
| 1818 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); | 1818 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); |
| 1819 friend class Class; | 1819 friend class Class; |
| 1820 }; | 1820 }; |
| 1821 | 1821 |
| 1822 | 1822 |
| 1823 class TokenStream : public Object { | 1823 class TokenStream : public Object { |
| 1824 public: | 1824 public: |
| 1825 inline intptr_t Length() const; | |
| 1826 | |
| 1827 RawArray* TokenObjects() const; | 1825 RawArray* TokenObjects() const; |
| 1828 void SetTokenObjects(const Array& value) const; | 1826 void SetTokenObjects(const Array& value) const; |
| 1829 | 1827 |
| 1828 RawExternalUint8Array* GetStream() const; |
| 1829 void SetStream(const ExternalUint8Array& stream) const; |
| 1830 |
| 1830 RawString* GenerateSource() const; | 1831 RawString* GenerateSource() const; |
| 1831 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; | 1832 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; |
| 1832 intptr_t ComputeTokenPosition(intptr_t src_pos) const; | 1833 intptr_t ComputeTokenPosition(intptr_t src_pos) const; |
| 1833 | 1834 |
| 1834 static const intptr_t kBytesPerElement = 1; | 1835 static const intptr_t kBytesPerElement = 1; |
| 1835 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | 1836 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 1836 | 1837 |
| 1837 static intptr_t InstanceSize() { | 1838 static intptr_t InstanceSize() { |
| 1838 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); | 1839 return RoundedAllocationSize(sizeof(RawTokenStream)); |
| 1839 return 0; | |
| 1840 } | |
| 1841 static intptr_t InstanceSize(intptr_t len) { | |
| 1842 ASSERT(0 <= len && len <= kMaxElements); | |
| 1843 return RoundedAllocationSize( | |
| 1844 sizeof(RawTokenStream) + (len * kBytesPerElement)); | |
| 1845 } | 1840 } |
| 1846 | 1841 |
| 1847 static RawTokenStream* New(intptr_t length); | 1842 static RawTokenStream* New(intptr_t length); |
| 1848 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens, | 1843 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens, |
| 1849 const String& private_key); | 1844 const String& private_key); |
| 1850 | 1845 |
| 1851 // The class Iterator encapsulates iteration over the tokens | 1846 // The class Iterator encapsulates iteration over the tokens |
| 1852 // in a TokenStream object. | 1847 // in a TokenStream object. |
| 1853 class Iterator : ValueObject { | 1848 class Iterator : ValueObject { |
| 1854 public: | 1849 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1867 | 1862 |
| 1868 void Advance(); | 1863 void Advance(); |
| 1869 | 1864 |
| 1870 RawObject* CurrentToken() const; | 1865 RawObject* CurrentToken() const; |
| 1871 RawString* CurrentLiteral() const; | 1866 RawString* CurrentLiteral() const; |
| 1872 RawString* MakeLiteralToken(const Object& obj) const; | 1867 RawString* MakeLiteralToken(const Object& obj) const; |
| 1873 | 1868 |
| 1874 private: | 1869 private: |
| 1875 // Read token from the token stream (could be a simple token or an index | 1870 // Read token from the token stream (could be a simple token or an index |
| 1876 // into the token objects array for IDENT or literal tokens). | 1871 // into the token objects array for IDENT or literal tokens). |
| 1877 intptr_t ReadToken(); | 1872 intptr_t ReadToken() { |
| 1878 uint8_t ReadByte(); | 1873 int64_t value = stream_.ReadUnsigned(); |
| 1874 ASSERT((value >= 0) && (value <= kIntptrMax)); |
| 1875 return value; |
| 1876 } |
| 1879 | 1877 |
| 1880 const TokenStream& tokens_; | 1878 const TokenStream& tokens_; |
| 1879 const ExternalUint8Array& data_; |
| 1880 ReadStream stream_; |
| 1881 Array& token_objects_; | 1881 Array& token_objects_; |
| 1882 Object& obj_; | 1882 Object& obj_; |
| 1883 intptr_t cur_token_pos_; | 1883 intptr_t cur_token_pos_; |
| 1884 intptr_t stream_token_pos_; | |
| 1885 Token::Kind cur_token_kind_; | 1884 Token::Kind cur_token_kind_; |
| 1886 intptr_t cur_token_obj_index_; | 1885 intptr_t cur_token_obj_index_; |
| 1887 }; | 1886 }; |
| 1888 | 1887 |
| 1889 private: | 1888 private: |
| 1890 void SetLength(intptr_t value) const; | |
| 1891 | |
| 1892 RawString* PrivateKey() const; | 1889 RawString* PrivateKey() const; |
| 1893 void SetPrivateKey(const String& value) const; | 1890 void SetPrivateKey(const String& value) const; |
| 1894 | 1891 |
| 1895 uint8_t* EntryAddr(intptr_t token_pos) const { | 1892 static RawTokenStream* New(); |
| 1896 ASSERT((token_pos >=0) && (token_pos < Length())); | 1893 static void DataFinalizer(void *peer); |
| 1897 return &raw_ptr()->data_[token_pos]; | |
| 1898 } | |
| 1899 | 1894 |
| 1900 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); | 1895 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); |
| 1901 friend class Class; | 1896 friend class Class; |
| 1902 }; | 1897 }; |
| 1903 | 1898 |
| 1904 | 1899 |
| 1905 class Script : public Object { | 1900 class Script : public Object { |
| 1906 public: | 1901 public: |
| 1907 RawString* url() const { return raw_ptr()->url_; } | 1902 RawString* url() const { return raw_ptr()->url_; } |
| 1908 bool HasSource() const; | 1903 bool HasSource() const; |
| (...skipping 2918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4827 return data + byte_offset; | 4822 return data + byte_offset; |
| 4828 } | 4823 } |
| 4829 | 4824 |
| 4830 void SetExternalData(ExternalByteArrayData<uint8_t>* data) { | 4825 void SetExternalData(ExternalByteArrayData<uint8_t>* data) { |
| 4831 raw_ptr()->external_data_ = data; | 4826 raw_ptr()->external_data_ = data; |
| 4832 } | 4827 } |
| 4833 | 4828 |
| 4834 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray); | 4829 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray); |
| 4835 friend class ByteArray; | 4830 friend class ByteArray; |
| 4836 friend class Class; | 4831 friend class Class; |
| 4832 friend class TokenStream; |
| 4837 }; | 4833 }; |
| 4838 | 4834 |
| 4839 | 4835 |
| 4840 class ExternalInt16Array : public ByteArray { | 4836 class ExternalInt16Array : public ByteArray { |
| 4841 public: | 4837 public: |
| 4842 intptr_t ByteLength() const { | 4838 intptr_t ByteLength() const { |
| 4843 return Length() * kBytesPerElement; | 4839 return Length() * kBytesPerElement; |
| 4844 } | 4840 } |
| 4845 | 4841 |
| 4846 int16_t At(intptr_t index) const { | 4842 int16_t At(intptr_t index) const { |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5527 return Smi::Value(reinterpret_cast<RawSmi*>(raw_ptr()->value_)); | 5523 return Smi::Value(reinterpret_cast<RawSmi*>(raw_ptr()->value_)); |
| 5528 } | 5524 } |
| 5529 | 5525 |
| 5530 | 5526 |
| 5531 void Field::SetOffset(intptr_t value) const { | 5527 void Field::SetOffset(intptr_t value) const { |
| 5532 ASSERT(!is_static()); // SetOffset is valid only for instance fields. | 5528 ASSERT(!is_static()); // SetOffset is valid only for instance fields. |
| 5533 raw_ptr()->value_ = Smi::New(value); | 5529 raw_ptr()->value_ = Smi::New(value); |
| 5534 } | 5530 } |
| 5535 | 5531 |
| 5536 | 5532 |
| 5537 intptr_t TokenStream::Length() const { | |
| 5538 return Smi::Value(raw_ptr()->length_); | |
| 5539 } | |
| 5540 | |
| 5541 | |
| 5542 void Context::SetAt(intptr_t index, const Instance& value) const { | 5533 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 5543 StorePointer(InstanceAddr(index), value.raw()); | 5534 StorePointer(InstanceAddr(index), value.raw()); |
| 5544 } | 5535 } |
| 5545 | 5536 |
| 5546 | 5537 |
| 5547 bool String::Equals(const String& str) const { | 5538 bool String::Equals(const String& str) const { |
| 5548 if (raw() == str.raw()) { | 5539 if (raw() == str.raw()) { |
| 5549 return true; // Both handles point to the same raw instance. | 5540 return true; // Both handles point to the same raw instance. |
| 5550 } | 5541 } |
| 5551 if (str.IsNull()) { | 5542 if (str.IsNull()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5569 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5560 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5570 return false; | 5561 return false; |
| 5571 } | 5562 } |
| 5572 } | 5563 } |
| 5573 return true; | 5564 return true; |
| 5574 } | 5565 } |
| 5575 | 5566 |
| 5576 } // namespace dart | 5567 } // namespace dart |
| 5577 | 5568 |
| 5578 #endif // VM_OBJECT_H_ | 5569 #endif // VM_OBJECT_H_ |
| OLD | NEW |