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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 size_t BufferSeekForward(size_t delta) override; | 58 size_t BufferSeekForward(size_t delta) override; |
59 size_t FillBuffer(size_t position) override; | 59 size_t FillBuffer(size_t position) override; |
60 | 60 |
61 Handle<String> string_; | 61 Handle<String> string_; |
62 size_t length_; | 62 size_t length_; |
63 size_t bookmark_; | 63 size_t bookmark_; |
64 }; | 64 }; |
65 | 65 |
66 | 66 |
67 // Utf16 stream based on a literal UTF-8 string. | |
68 class Utf8ToUtf16CharacterStream: public BufferedUtf16CharacterStream { | |
69 public: | |
70 Utf8ToUtf16CharacterStream(const byte* data, size_t length); | |
71 ~Utf8ToUtf16CharacterStream() override; | |
72 | |
73 static size_t CopyChars(uint16_t* dest, size_t length, const byte* src, | |
74 size_t* src_pos, size_t src_length); | |
75 | |
76 protected: | |
77 size_t BufferSeekForward(size_t delta) override; | |
78 size_t FillBuffer(size_t char_position) override; | |
79 void SetRawPosition(size_t char_position); | |
80 | |
81 const byte* raw_data_; | |
82 size_t raw_data_length_; // Measured in bytes, not characters. | |
83 size_t raw_data_pos_; | |
84 // The character position of the character at raw_data[raw_data_pos_]. | |
85 // Not necessarily the same as pos_. | |
86 size_t raw_character_position_; | |
87 }; | |
88 | |
89 | |
90 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see | 67 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see |
91 // include/v8.h) subclass implemented by the embedder. | 68 // include/v8.h) subclass implemented by the embedder. |
92 class ExternalStreamingStream : public BufferedUtf16CharacterStream { | 69 class ExternalStreamingStream : public BufferedUtf16CharacterStream { |
93 public: | 70 public: |
94 ExternalStreamingStream(ScriptCompiler::ExternalSourceStream* source_stream, | 71 ExternalStreamingStream(ScriptCompiler::ExternalSourceStream* source_stream, |
95 v8::ScriptCompiler::StreamedSource::Encoding encoding) | 72 v8::ScriptCompiler::StreamedSource::Encoding encoding) |
96 : source_stream_(source_stream), | 73 : source_stream_(source_stream), |
97 encoding_(encoding), | 74 encoding_(encoding), |
98 current_data_(NULL), | 75 current_data_(NULL), |
99 current_data_offset_(0), | 76 current_data_offset_(0), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 163 |
187 // UTF16 buffer to read characters from an external latin1 string. | 164 // UTF16 buffer to read characters from an external latin1 string. |
188 class ExternalOneByteStringUtf16CharacterStream | 165 class ExternalOneByteStringUtf16CharacterStream |
189 : public BufferedUtf16CharacterStream { | 166 : public BufferedUtf16CharacterStream { |
190 public: | 167 public: |
191 ExternalOneByteStringUtf16CharacterStream(Handle<ExternalOneByteString> data, | 168 ExternalOneByteStringUtf16CharacterStream(Handle<ExternalOneByteString> data, |
192 int start_position, | 169 int start_position, |
193 int end_position); | 170 int end_position); |
194 ~ExternalOneByteStringUtf16CharacterStream() override; | 171 ~ExternalOneByteStringUtf16CharacterStream() override; |
195 | 172 |
| 173 // For testing: |
| 174 explicit ExternalOneByteStringUtf16CharacterStream(const char* data); |
| 175 ExternalOneByteStringUtf16CharacterStream(const char* data, size_t length); |
| 176 |
196 bool SetBookmark() override; | 177 bool SetBookmark() override; |
197 void ResetToBookmark() override; | 178 void ResetToBookmark() override; |
198 | 179 |
199 private: | 180 private: |
200 static const size_t kNoBookmark = -1; | 181 static const size_t kNoBookmark = -1; |
201 | 182 |
202 size_t BufferSeekForward(size_t delta) override; | 183 size_t BufferSeekForward(size_t delta) override; |
203 size_t FillBuffer(size_t position) override; | 184 size_t FillBuffer(size_t position) override; |
204 | 185 |
205 const uint8_t* raw_data_; // Pointer to the actual array of characters. | 186 const uint8_t* raw_data_; // Pointer to the actual array of characters. |
206 size_t length_; | 187 size_t length_; |
207 size_t bookmark_; | 188 size_t bookmark_; |
208 }; | 189 }; |
209 | 190 |
210 } // namespace internal | 191 } // namespace internal |
211 } // namespace v8 | 192 } // namespace v8 |
212 | 193 |
213 #endif // V8_PARSING_SCANNER_CHARACTER_STREAMS_H_ | 194 #endif // V8_PARSING_SCANNER_CHARACTER_STREAMS_H_ |
OLD | NEW |