Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: vm/object.h

Issue 10697055: Represent tokens as a compressed stream instead of an array. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/datastream.h ('k') | vm/object.cc » ('j') | vm/object.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "vm/bitmap.h" 11 #include "vm/bitmap.h"
12 #include "vm/dart.h" 12 #include "vm/dart.h"
13 #include "vm/datastream.h"
13 #include "vm/globals.h" 14 #include "vm/globals.h"
14 #include "vm/handles.h" 15 #include "vm/handles.h"
15 #include "vm/heap.h" 16 #include "vm/heap.h"
16 #include "vm/isolate.h" 17 #include "vm/isolate.h"
17 #include "vm/os.h" 18 #include "vm/os.h"
18 #include "vm/raw_object.h" 19 #include "vm/raw_object.h"
19 #include "vm/scanner.h" 20 #include "vm/scanner.h"
20 21
21 namespace dart { 22 namespace dart {
22 23
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 1678
1678 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); 1679 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object);
1679 friend class Class; 1680 friend class Class;
1680 }; 1681 };
1681 1682
1682 1683
1683 class TokenStream : public Object { 1684 class TokenStream : public Object {
1684 public: 1685 public:
1685 inline intptr_t Length() const; 1686 inline intptr_t Length() const;
1686 1687
1687 inline Token::Kind KindAt(intptr_t index) const; 1688 RawArray* TokenObjects() const;
1689 void SetTokenObjects(const Array& value) const;
1688 1690
1689 void SetTokenAt(intptr_t index, Token::Kind kind, const String& literal);
1690 void SetTokenAt(intptr_t index, const Object& token);
1691
1692 RawObject* TokenAt(intptr_t index) const;
1693 RawString* LiteralAt(intptr_t index) const;
1694 RawString* GenerateSource() const; 1691 RawString* GenerateSource() const;
1692 intptr_t ComputeSourcePosition(intptr_t tok_pos) const;
1695 1693
1696 static intptr_t InstanceSize() { 1694 static intptr_t InstanceSize() {
1697 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); 1695 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_));
1698 return 0; 1696 return 0;
1699 } 1697 }
1700 static intptr_t InstanceSize(intptr_t len) { 1698 static intptr_t InstanceSize(intptr_t len) {
1701 return RoundedAllocationSize(sizeof(RawTokenStream) + (len * kWordSize)); 1699 return RoundedAllocationSize(sizeof(RawTokenStream) + len);
1702 } 1700 }
1703 static intptr_t StreamLength(intptr_t len) { 1701 static intptr_t StreamLength(intptr_t len) {
1704 return len; 1702 return len;
1705 } 1703 }
1706 1704
1707 static RawTokenStream* New(intptr_t length); 1705 static RawTokenStream* New(intptr_t length);
1708 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); 1706 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens);
1709 1707
1710 private: 1708 private:
1711 void SetLength(intptr_t value) const; 1709 void SetLength(intptr_t value) const;
1712 1710
1713 RawObject** EntryAddr(intptr_t index) const { 1711 uint8_t* EntryAddr(intptr_t token_pos) const {
1714 ASSERT((index >=0) && (index < Length())); 1712 ASSERT((token_pos >=0) && (token_pos < Length()));
1715 return &raw_ptr()->data_[index]; 1713 return &raw_ptr()->data_[token_pos];
1716 }
1717
1718 RawSmi** SmiAddr(intptr_t index) const {
1719 return reinterpret_cast<RawSmi**>(EntryAddr(index));
1720 } 1714 }
1721 1715
1722 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); 1716 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object);
1723 friend class Class; 1717 friend class Class;
1718 friend class TokenStreamIterator;
1719 };
1720
1721
1722 // The class TokenStreamIterator encapsulates iteration over the tokens
1723 // in a TokenStream object.
1724 class TokenStreamIterator : ValueObject {
1725 public:
1726 TokenStreamIterator(const TokenStream& tokens, intptr_t token_pos);
1727
1728 bool IsValid() const;
1729
1730 inline Token::Kind CurrentTokenKind() const {
1731 return cur_token_kind_;
1732 }
1733
1734 Token::Kind LookaheadTokenKind(intptr_t num_tokens);
1735
1736 intptr_t CurrentPosition() const;
1737 void SetCurrentPosition(intptr_t value);
1738
1739 void Advance();
1740
1741 RawObject* CurrentToken() const;
1742 RawString* CurrentLiteral() const;
1743 RawString* MakeLiteralToken(const Object& obj) const;
1744
1745 private:
1746 // Read token from the token stream (could be a simple token or an index
1747 // into the token objects array for IDENT or literal tokens).
1748 intptr_t ReadToken() {
1749 int64_t value = stream_.ReadUnsigned();
1750 ASSERT((value >= 0) && (value <= kIntptrMax));
1751 return value;
1752 }
1753
1754 const TokenStream& tokens_;
1755 ReadStream stream_;
1756 Array& token_objects_;
1757 Object& obj_;
1758 intptr_t cur_token_pos_;
1759 Token::Kind cur_token_kind_;
1760 intptr_t cur_token_obj_index_;
1724 }; 1761 };
1725 1762
1726 1763
1727 class Script : public Object { 1764 class Script : public Object {
1728 public: 1765 public:
1729 RawString* url() const { return raw_ptr()->url_; } 1766 RawString* url() const { return raw_ptr()->url_; }
1730 RawString* source() const; 1767 RawString* source() const;
1731 RawScript::Kind kind() const { return raw_ptr()->kind_; } 1768 RawScript::Kind kind() const { return raw_ptr()->kind_; }
1732 1769
1733 RawTokenStream* tokens() const { return raw_ptr()->tokens_; } 1770 RawTokenStream* tokens() const { return raw_ptr()->tokens_; }
(...skipping 3326 matching lines...) Expand 10 before | Expand all | Expand 10 after
5060 } 5097 }
5061 5098
5062 5099
5063 void Field::SetOffset(intptr_t value) const { 5100 void Field::SetOffset(intptr_t value) const {
5064 ASSERT(!is_static()); // SetOffset is valid only for instance fields. 5101 ASSERT(!is_static()); // SetOffset is valid only for instance fields.
5065 raw_ptr()->value_ = Smi::New(value); 5102 raw_ptr()->value_ = Smi::New(value);
5066 } 5103 }
5067 5104
5068 5105
5069 intptr_t TokenStream::Length() const { 5106 intptr_t TokenStream::Length() const {
5070 return Smi::Value(raw_ptr()->length_); 5107 return raw_ptr()->length_;
5071 }
5072
5073
5074 Token::Kind TokenStream::KindAt(intptr_t index) const {
5075 const Object& obj = Object::Handle(TokenAt(index));
5076 if (obj.IsSmi()) {
5077 return static_cast<Token::Kind>(
5078 Smi::Value(reinterpret_cast<RawSmi*>(obj.raw())));
5079 } else if (obj.IsLiteralToken()) {
5080 LiteralToken& token = LiteralToken::Handle();
5081 token ^= obj.raw();
5082 return token.kind();
5083 }
5084 ASSERT(obj.IsString()); // Must be an identifier.
5085 return Token::kIDENT;
5086 } 5108 }
5087 5109
5088 5110
5089 void Context::SetAt(intptr_t index, const Instance& value) const { 5111 void Context::SetAt(intptr_t index, const Instance& value) const {
5090 StorePointer(InstanceAddr(index), value.raw()); 5112 StorePointer(InstanceAddr(index), value.raw());
5091 } 5113 }
5092 5114
5093 5115
5094 intptr_t Stackmap::SizeInBits() const { 5116 intptr_t Stackmap::SizeInBits() const {
5095 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); 5117 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte);
5096 } 5118 }
5097 5119
5098 } // namespace dart 5120 } // namespace dart
5099 5121
5100 #endif // VM_OBJECT_H_ 5122 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « vm/datastream.h ('k') | vm/object.cc » ('j') | vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698