OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_STRING_STREAM_H_ | 5 #ifndef V8_STRING_STREAM_H_ |
6 #define V8_STRING_STREAM_H_ | 6 #define V8_STRING_STREAM_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 17 matching lines...) Expand all Loading... | |
28 public: | 28 public: |
29 ~HeapStringAllocator() { DeleteArray(space_); } | 29 ~HeapStringAllocator() { DeleteArray(space_); } |
30 char* allocate(unsigned bytes) override; | 30 char* allocate(unsigned bytes) override; |
31 char* grow(unsigned* bytes) override; | 31 char* grow(unsigned* bytes) override; |
32 | 32 |
33 private: | 33 private: |
34 char* space_; | 34 char* space_; |
35 }; | 35 }; |
36 | 36 |
37 | 37 |
38 class FixedStringAllocator final : public StringAllocator { | |
39 public: | |
40 FixedStringAllocator(char* buffer, unsigned length) | |
41 : buffer_(buffer), length_(length) {} | |
42 ~FixedStringAllocator() {} | |
jochen (gone - plz use gerrit)
2015/06/05 16:03:43
override
| |
43 char* allocate(unsigned bytes) override; | |
44 char* grow(unsigned* bytes) override; | |
45 | |
46 private: | |
47 char* buffer_; | |
48 unsigned length_; | |
49 }; | |
jochen (gone - plz use gerrit)
2015/06/05 16:03:43
disallow copy/assign
| |
50 | |
51 | |
38 class FmtElm final { | 52 class FmtElm final { |
39 public: | 53 public: |
40 FmtElm(int value) : type_(INT) { // NOLINT | 54 FmtElm(int value) : type_(INT) { // NOLINT |
41 data_.u_int_ = value; | 55 data_.u_int_ = value; |
42 } | 56 } |
43 explicit FmtElm(double value) : type_(DOUBLE) { | 57 explicit FmtElm(double value) : type_(DOUBLE) { |
44 data_.u_double_ = value; | 58 data_.u_double_ = value; |
45 } | 59 } |
46 FmtElm(const char* value) : type_(C_STR) { // NOLINT | 60 FmtElm(const char* value) : type_(C_STR) { // NOLINT |
47 data_.u_c_str_ = value; | 61 data_.u_c_str_ = value; |
(...skipping 22 matching lines...) Expand all Loading... | |
70 const Vector<const uc16>* u_lc_str_; | 84 const Vector<const uc16>* u_lc_str_; |
71 Object* u_obj_; | 85 Object* u_obj_; |
72 Object** u_handle_; | 86 Object** u_handle_; |
73 void* u_pointer_; | 87 void* u_pointer_; |
74 } data_; | 88 } data_; |
75 }; | 89 }; |
76 | 90 |
77 | 91 |
78 class StringStream final { | 92 class StringStream final { |
79 public: | 93 public: |
80 explicit StringStream(StringAllocator* allocator): | 94 enum ObjectPrintMode { kPrintObjectConcise, kPrintObjectVerbose }; |
81 allocator_(allocator), | 95 explicit StringStream(StringAllocator* allocator, |
jochen (gone - plz use gerrit)
2015/06/05 16:03:43
no explicit
| |
82 capacity_(kInitialCapacity), | 96 ObjectPrintMode object_print_mode = kPrintObjectConcise) |
83 length_(0), | 97 : allocator_(allocator), |
84 buffer_(allocator_->allocate(kInitialCapacity)) { | 98 object_print_mode_(object_print_mode), |
99 capacity_(kInitialCapacity), | |
100 length_(0), | |
101 buffer_(allocator_->allocate(kInitialCapacity)) { | |
85 buffer_[0] = 0; | 102 buffer_[0] = 0; |
86 } | 103 } |
87 | 104 |
88 bool Put(char c); | 105 bool Put(char c); |
89 bool Put(String* str); | 106 bool Put(String* str); |
90 bool Put(String* str, int start, int end); | 107 bool Put(String* str, int start, int end); |
91 void Add(Vector<const char> format, Vector<FmtElm> elms); | 108 void Add(Vector<const char> format, Vector<FmtElm> elms); |
92 void Add(const char* format); | 109 void Add(const char* format); |
93 void Add(Vector<const char> format); | 110 void Add(Vector<const char> format); |
94 void Add(const char* format, FmtElm arg0); | 111 void Add(const char* format, FmtElm arg0); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 // Reset the stream. | 144 // Reset the stream. |
128 void Reset() { | 145 void Reset() { |
129 length_ = 0; | 146 length_ = 0; |
130 buffer_[0] = 0; | 147 buffer_[0] = 0; |
131 } | 148 } |
132 | 149 |
133 // Mentioned object cache support. | 150 // Mentioned object cache support. |
134 void PrintMentionedObjectCache(Isolate* isolate); | 151 void PrintMentionedObjectCache(Isolate* isolate); |
135 static void ClearMentionedObjectCache(Isolate* isolate); | 152 static void ClearMentionedObjectCache(Isolate* isolate); |
136 #ifdef DEBUG | 153 #ifdef DEBUG |
137 static bool IsMentionedObjectCacheClear(Isolate* isolate); | 154 bool IsMentionedObjectCacheClear(Isolate* isolate); |
138 #endif | 155 #endif |
139 | 156 |
140 static const int kInitialCapacity = 16; | 157 static const int kInitialCapacity = 16; |
141 | 158 |
142 private: | 159 private: |
143 void PrintObject(Object* obj); | 160 void PrintObject(Object* obj); |
144 | 161 |
145 StringAllocator* allocator_; | 162 StringAllocator* allocator_; |
163 ObjectPrintMode object_print_mode_; | |
146 unsigned capacity_; | 164 unsigned capacity_; |
147 unsigned length_; // does not include terminating 0-character | 165 unsigned length_; // does not include terminating 0-character |
148 char* buffer_; | 166 char* buffer_; |
149 | 167 |
150 bool full() const { return (capacity_ - length_) == 1; } | 168 bool full() const { return (capacity_ - length_) == 1; } |
151 int space() const { return capacity_ - length_; } | 169 int space() const { return capacity_ - length_; } |
152 | 170 |
153 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); | 171 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); |
154 }; | 172 }; |
155 | 173 |
156 } } // namespace v8::internal | 174 } } // namespace v8::internal |
157 | 175 |
158 #endif // V8_STRING_STREAM_H_ | 176 #endif // V8_STRING_STREAM_H_ |
OLD | NEW |