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_SCANNER_CHARACTER_STREAMS_H_ | 5 #ifndef V8_SCANNER_CHARACTER_STREAMS_H_ |
6 #define V8_SCANNER_CHARACTER_STREAMS_H_ | 6 #define V8_SCANNER_CHARACTER_STREAMS_H_ |
7 | 7 |
8 #include "src/scanner.h" | 8 #include "src/scanner.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 25 matching lines...) Expand all Loading... | |
36 }; | 36 }; |
37 | 37 |
38 | 38 |
39 // Generic string stream. | 39 // Generic string stream. |
40 class GenericStringUtf16CharacterStream: public BufferedUtf16CharacterStream { | 40 class GenericStringUtf16CharacterStream: public BufferedUtf16CharacterStream { |
41 public: | 41 public: |
42 GenericStringUtf16CharacterStream(Handle<String> data, size_t start_position, | 42 GenericStringUtf16CharacterStream(Handle<String> data, size_t start_position, |
43 size_t end_position); | 43 size_t end_position); |
44 virtual ~GenericStringUtf16CharacterStream(); | 44 virtual ~GenericStringUtf16CharacterStream(); |
45 | 45 |
46 virtual bool SetBookmark(); | |
47 virtual bool CanResetToBookmark(); | |
48 virtual bool ResetToBookmark(); | |
49 | |
46 protected: | 50 protected: |
47 virtual size_t BufferSeekForward(size_t delta); | 51 virtual size_t BufferSeekForward(size_t delta); |
48 virtual size_t FillBuffer(size_t position); | 52 virtual size_t FillBuffer(size_t position); |
49 | 53 |
50 Handle<String> string_; | 54 Handle<String> string_; |
51 size_t length_; | 55 size_t length_; |
56 size_t bookmark_; | |
52 }; | 57 }; |
53 | 58 |
54 | 59 |
55 // Utf16 stream based on a literal UTF-8 string. | 60 // Utf16 stream based on a literal UTF-8 string. |
56 class Utf8ToUtf16CharacterStream: public BufferedUtf16CharacterStream { | 61 class Utf8ToUtf16CharacterStream: public BufferedUtf16CharacterStream { |
57 public: | 62 public: |
58 Utf8ToUtf16CharacterStream(const byte* data, size_t length); | 63 Utf8ToUtf16CharacterStream(const byte* data, size_t length); |
59 virtual ~Utf8ToUtf16CharacterStream(); | 64 virtual ~Utf8ToUtf16CharacterStream(); |
60 | 65 |
61 static size_t CopyChars(uint16_t* dest, size_t length, const byte* src, | 66 static size_t CopyChars(uint16_t* dest, size_t length, const byte* src, |
62 size_t* src_pos, size_t src_length); | 67 size_t* src_pos, size_t src_length); |
63 | 68 |
64 protected: | 69 protected: |
65 virtual size_t BufferSeekForward(size_t delta); | 70 virtual size_t BufferSeekForward(size_t delta); |
66 virtual size_t FillBuffer(size_t char_position); | 71 virtual size_t FillBuffer(size_t char_position); |
67 void SetRawPosition(size_t char_position); | 72 void SetRawPosition(size_t char_position); |
68 | 73 |
69 const byte* raw_data_; | 74 const byte* raw_data_; |
70 size_t raw_data_length_; // Measured in bytes, not characters. | 75 size_t raw_data_length_; // Measured in bytes, not characters. |
71 size_t raw_data_pos_; | 76 size_t raw_data_pos_; |
72 // The character position of the character at raw_data[raw_data_pos_]. | 77 // The character position of the character at raw_data[raw_data_pos_]. |
73 // Not necessarily the same as pos_. | 78 // Not necessarily the same as pos_. |
74 size_t raw_character_position_; | 79 size_t raw_character_position_; |
75 }; | 80 }; |
76 | 81 |
77 | 82 |
78 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see | 83 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see |
79 // include/v8.h) subclass implemented by the embedder. | 84 // include/v8.h) subclass implemented by the embedder. |
80 class ExternalStreamingStream : public BufferedUtf16CharacterStream { | 85 class ExternalStreamingStream : public BufferedUtf16CharacterStream { |
marja
2015/04/22 16:40:55
Pls add a todo here to implement bookmarking for t
| |
81 public: | 86 public: |
82 ExternalStreamingStream(ScriptCompiler::ExternalSourceStream* source_stream, | 87 ExternalStreamingStream(ScriptCompiler::ExternalSourceStream* source_stream, |
83 v8::ScriptCompiler::StreamedSource::Encoding encoding) | 88 v8::ScriptCompiler::StreamedSource::Encoding encoding) |
84 : source_stream_(source_stream), | 89 : source_stream_(source_stream), |
85 encoding_(encoding), | 90 encoding_(encoding), |
86 current_data_(NULL), | 91 current_data_(NULL), |
87 current_data_offset_(0), | 92 current_data_offset_(0), |
88 current_data_length_(0), | 93 current_data_length_(0), |
89 utf8_split_char_buffer_length_(0) {} | 94 utf8_split_char_buffer_length_(0) {} |
90 | 95 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 int start_position, | 127 int start_position, |
123 int end_position); | 128 int end_position); |
124 virtual ~ExternalTwoByteStringUtf16CharacterStream(); | 129 virtual ~ExternalTwoByteStringUtf16CharacterStream(); |
125 | 130 |
126 virtual void PushBack(uc32 character) { | 131 virtual void PushBack(uc32 character) { |
127 DCHECK(buffer_cursor_ > raw_data_); | 132 DCHECK(buffer_cursor_ > raw_data_); |
128 buffer_cursor_--; | 133 buffer_cursor_--; |
129 pos_--; | 134 pos_--; |
130 } | 135 } |
131 | 136 |
137 virtual bool SetBookmark(); | |
138 virtual bool CanResetToBookmark(); | |
139 virtual bool ResetToBookmark(); | |
140 | |
132 protected: | 141 protected: |
133 virtual size_t SlowSeekForward(size_t delta) { | 142 virtual size_t SlowSeekForward(size_t delta) { |
134 // Fast case always handles seeking. | 143 // Fast case always handles seeking. |
135 return 0; | 144 return 0; |
136 } | 145 } |
137 virtual bool ReadBlock() { | 146 virtual bool ReadBlock() { |
138 // Entire string is read at start. | 147 // Entire string is read at start. |
139 return false; | 148 return false; |
140 } | 149 } |
141 Handle<ExternalTwoByteString> source_; | 150 Handle<ExternalTwoByteString> source_; |
142 const uc16* raw_data_; // Pointer to the actual array of characters. | 151 const uc16* raw_data_; // Pointer to the actual array of characters. |
152 | |
153 private: | |
154 int bookmark_; | |
143 }; | 155 }; |
144 | 156 |
145 } } // namespace v8::internal | 157 } } // namespace v8::internal |
146 | 158 |
147 #endif // V8_SCANNER_CHARACTER_STREAMS_H_ | 159 #endif // V8_SCANNER_CHARACTER_STREAMS_H_ |
OLD | NEW |