OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_PARSING_SCANNER_CHARACTER_STREAMS_H_ | 5 #ifndef V8_PARSING_SCANNER_CHARACTER_STREAMS_H_ |
6 #define V8_PARSING_SCANNER_CHARACTER_STREAMS_H_ | 6 #define V8_PARSING_SCANNER_CHARACTER_STREAMS_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/parsing/scanner.h" | 9 #include "src/parsing/scanner.h" |
10 #include "src/vector.h" | 10 #include "src/vector.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 // Forward declarations. | 15 // Forward declarations. |
16 class ExternalTwoByteString; | 16 class ExternalTwoByteString; |
| 17 class ExternalOneByteString; |
17 | 18 |
18 // A buffered character stream based on a random access character | 19 // A buffered character stream based on a random access character |
19 // source (ReadBlock can be called with pos_ pointing to any position, | 20 // source (ReadBlock can be called with pos_ pointing to any position, |
20 // even positions before the current). | 21 // even positions before the current). |
21 class BufferedUtf16CharacterStream: public Utf16CharacterStream { | 22 class BufferedUtf16CharacterStream: public Utf16CharacterStream { |
22 public: | 23 public: |
23 BufferedUtf16CharacterStream(); | 24 BufferedUtf16CharacterStream(); |
24 ~BufferedUtf16CharacterStream() override; | 25 ~BufferedUtf16CharacterStream() override; |
25 | 26 |
26 void PushBack(uc32 character) override; | 27 void PushBack(uc32 character) override; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 DCHECK(buffer_cursor_ > raw_data_); | 161 DCHECK(buffer_cursor_ > raw_data_); |
161 pos_--; | 162 pos_--; |
162 if (character != kEndOfInput) { | 163 if (character != kEndOfInput) { |
163 buffer_cursor_--; | 164 buffer_cursor_--; |
164 } | 165 } |
165 } | 166 } |
166 | 167 |
167 bool SetBookmark() override; | 168 bool SetBookmark() override; |
168 void ResetToBookmark() override; | 169 void ResetToBookmark() override; |
169 | 170 |
170 protected: | 171 private: |
171 size_t SlowSeekForward(size_t delta) override { | 172 size_t SlowSeekForward(size_t delta) override { |
172 // Fast case always handles seeking. | 173 // Fast case always handles seeking. |
173 return 0; | 174 return 0; |
174 } | 175 } |
175 bool ReadBlock() override { | 176 bool ReadBlock() override { |
176 // Entire string is read at start. | 177 // Entire string is read at start. |
177 return false; | 178 return false; |
178 } | 179 } |
179 Handle<ExternalTwoByteString> source_; | |
180 const uc16* raw_data_; // Pointer to the actual array of characters. | 180 const uc16* raw_data_; // Pointer to the actual array of characters. |
181 | 181 |
182 private: | |
183 static const size_t kNoBookmark = -1; | 182 static const size_t kNoBookmark = -1; |
184 | 183 |
185 size_t bookmark_; | 184 size_t bookmark_; |
186 }; | 185 }; |
187 | 186 |
| 187 // UTF16 buffer to read characters from an external latin1 string. |
| 188 class ExternalOneByteStringUtf16CharacterStream |
| 189 : public BufferedUtf16CharacterStream { |
| 190 public: |
| 191 ExternalOneByteStringUtf16CharacterStream(Handle<ExternalOneByteString> data, |
| 192 int start_position, |
| 193 int end_position); |
| 194 ~ExternalOneByteStringUtf16CharacterStream() override; |
| 195 |
| 196 bool SetBookmark() override; |
| 197 void ResetToBookmark() override; |
| 198 |
| 199 private: |
| 200 static const size_t kNoBookmark = -1; |
| 201 |
| 202 size_t BufferSeekForward(size_t delta) override; |
| 203 size_t FillBuffer(size_t position) override; |
| 204 |
| 205 const uint8_t* raw_data_; // Pointer to the actual array of characters. |
| 206 size_t length_; |
| 207 size_t bookmark_; |
| 208 }; |
| 209 |
188 } // namespace internal | 210 } // namespace internal |
189 } // namespace v8 | 211 } // namespace v8 |
190 | 212 |
191 #endif // V8_PARSING_SCANNER_CHARACTER_STREAMS_H_ | 213 #endif // V8_PARSING_SCANNER_CHARACTER_STREAMS_H_ |
OLD | NEW |