| 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 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 | 1682 |
| 1683 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); | 1683 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); |
| 1684 friend class Class; | 1684 friend class Class; |
| 1685 }; | 1685 }; |
| 1686 | 1686 |
| 1687 | 1687 |
| 1688 class TokenStream : public Object { | 1688 class TokenStream : public Object { |
| 1689 public: | 1689 public: |
| 1690 inline intptr_t Length() const; | 1690 inline intptr_t Length() const; |
| 1691 | 1691 |
| 1692 inline Token::Kind KindAt(intptr_t index) const; | 1692 RawArray* TokenObjects() const; |
| 1693 void SetTokenObjects(const Array& value) const; |
| 1693 | 1694 |
| 1694 void SetTokenAt(intptr_t index, Token::Kind kind, const String& literal); | |
| 1695 void SetTokenAt(intptr_t index, const Object& token); | |
| 1696 | |
| 1697 RawObject* TokenAt(intptr_t index) const; | |
| 1698 RawString* LiteralAt(intptr_t index) const; | |
| 1699 RawString* GenerateSource() const; | 1695 RawString* GenerateSource() const; |
| 1696 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; |
| 1697 intptr_t ComputeTokenPosition(intptr_t src_pos) const; |
| 1700 | 1698 |
| 1701 static intptr_t InstanceSize() { | 1699 static intptr_t InstanceSize() { |
| 1702 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); | 1700 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); |
| 1703 return 0; | 1701 return 0; |
| 1704 } | 1702 } |
| 1705 static intptr_t InstanceSize(intptr_t len) { | 1703 static intptr_t InstanceSize(intptr_t len) { |
| 1706 return RoundedAllocationSize(sizeof(RawTokenStream) + (len * kWordSize)); | 1704 return RoundedAllocationSize(sizeof(RawTokenStream) + len); |
| 1707 } | |
| 1708 static intptr_t StreamLength(intptr_t len) { | |
| 1709 return len; | |
| 1710 } | 1705 } |
| 1711 | 1706 |
| 1712 static RawTokenStream* New(intptr_t length); | 1707 static RawTokenStream* New(intptr_t length); |
| 1713 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); | 1708 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); |
| 1714 | 1709 |
| 1710 // The class Iterator encapsulates iteration over the tokens |
| 1711 // in a TokenStream object. |
| 1712 class Iterator : ValueObject { |
| 1713 public: |
| 1714 Iterator(const TokenStream& tokens, intptr_t token_pos); |
| 1715 |
| 1716 bool IsValid() const; |
| 1717 |
| 1718 inline Token::Kind CurrentTokenKind() const { |
| 1719 return cur_token_kind_; |
| 1720 } |
| 1721 |
| 1722 Token::Kind LookaheadTokenKind(intptr_t num_tokens); |
| 1723 |
| 1724 intptr_t CurrentPosition() const; |
| 1725 void SetCurrentPosition(intptr_t value); |
| 1726 |
| 1727 void Advance(); |
| 1728 |
| 1729 RawObject* CurrentToken() const; |
| 1730 RawString* CurrentLiteral() const; |
| 1731 RawString* MakeLiteralToken(const Object& obj) const; |
| 1732 |
| 1733 private: |
| 1734 // Read token from the token stream (could be a simple token or an index |
| 1735 // into the token objects array for IDENT or literal tokens). |
| 1736 intptr_t ReadToken(); |
| 1737 uint8_t ReadByte(); |
| 1738 |
| 1739 const TokenStream& tokens_; |
| 1740 Array& token_objects_; |
| 1741 Object& obj_; |
| 1742 intptr_t cur_token_pos_; |
| 1743 intptr_t stream_token_pos_; |
| 1744 Token::Kind cur_token_kind_; |
| 1745 intptr_t cur_token_obj_index_; |
| 1746 }; |
| 1747 |
| 1715 private: | 1748 private: |
| 1716 void SetLength(intptr_t value) const; | 1749 void SetLength(intptr_t value) const; |
| 1717 | 1750 |
| 1718 RawObject** EntryAddr(intptr_t index) const { | 1751 uint8_t* EntryAddr(intptr_t token_pos) const { |
| 1719 ASSERT((index >=0) && (index < Length())); | 1752 ASSERT((token_pos >=0) && (token_pos < Length())); |
| 1720 return &raw_ptr()->data_[index]; | 1753 return &raw_ptr()->data_[token_pos]; |
| 1721 } | |
| 1722 | |
| 1723 RawSmi** SmiAddr(intptr_t index) const { | |
| 1724 return reinterpret_cast<RawSmi**>(EntryAddr(index)); | |
| 1725 } | 1754 } |
| 1726 | 1755 |
| 1727 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); | 1756 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); |
| 1728 friend class Class; | 1757 friend class Class; |
| 1729 }; | 1758 }; |
| 1730 | 1759 |
| 1731 | 1760 |
| 1732 class Script : public Object { | 1761 class Script : public Object { |
| 1733 public: | 1762 public: |
| 1734 RawString* url() const { return raw_ptr()->url_; } | 1763 RawString* url() const { return raw_ptr()->url_; } |
| (...skipping 3343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5078 ASSERT(!is_static()); // SetOffset is valid only for instance fields. | 5107 ASSERT(!is_static()); // SetOffset is valid only for instance fields. |
| 5079 raw_ptr()->value_ = Smi::New(value); | 5108 raw_ptr()->value_ = Smi::New(value); |
| 5080 } | 5109 } |
| 5081 | 5110 |
| 5082 | 5111 |
| 5083 intptr_t TokenStream::Length() const { | 5112 intptr_t TokenStream::Length() const { |
| 5084 return Smi::Value(raw_ptr()->length_); | 5113 return Smi::Value(raw_ptr()->length_); |
| 5085 } | 5114 } |
| 5086 | 5115 |
| 5087 | 5116 |
| 5088 Token::Kind TokenStream::KindAt(intptr_t index) const { | |
| 5089 const Object& obj = Object::Handle(TokenAt(index)); | |
| 5090 if (obj.IsSmi()) { | |
| 5091 return static_cast<Token::Kind>(Smi::Cast(obj).Value()); | |
| 5092 } else if (obj.IsLiteralToken()) { | |
| 5093 return LiteralToken::Cast(obj).kind(); | |
| 5094 } | |
| 5095 ASSERT(obj.IsString()); // Must be an identifier. | |
| 5096 return Token::kIDENT; | |
| 5097 } | |
| 5098 | |
| 5099 | |
| 5100 void Context::SetAt(intptr_t index, const Instance& value) const { | 5117 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 5101 StorePointer(InstanceAddr(index), value.raw()); | 5118 StorePointer(InstanceAddr(index), value.raw()); |
| 5102 } | 5119 } |
| 5103 | 5120 |
| 5104 | 5121 |
| 5105 intptr_t Stackmap::SizeInBits() const { | 5122 intptr_t Stackmap::SizeInBits() const { |
| 5106 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); | 5123 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); |
| 5107 } | 5124 } |
| 5108 | 5125 |
| 5109 } // namespace dart | 5126 } // namespace dart |
| 5110 | 5127 |
| 5111 #endif // VM_OBJECT_H_ | 5128 #endif // VM_OBJECT_H_ |
| OLD | NEW |