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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 unsigned length_; | 52 unsigned length_; |
53 }; | 53 }; |
54 | 54 |
55 | 55 |
56 // Utf16 stream based on a literal UTF-8 string. | 56 // Utf16 stream based on a literal UTF-8 string. |
57 class Utf8ToUtf16CharacterStream: public BufferedUtf16CharacterStream { | 57 class Utf8ToUtf16CharacterStream: public BufferedUtf16CharacterStream { |
58 public: | 58 public: |
59 Utf8ToUtf16CharacterStream(const byte* data, unsigned length); | 59 Utf8ToUtf16CharacterStream(const byte* data, unsigned length); |
60 virtual ~Utf8ToUtf16CharacterStream(); | 60 virtual ~Utf8ToUtf16CharacterStream(); |
61 | 61 |
| 62 static unsigned CopyChars(uint16_t* dest, unsigned length, const byte* src, |
| 63 unsigned* src_pos, unsigned src_length); |
| 64 |
62 protected: | 65 protected: |
63 virtual unsigned BufferSeekForward(unsigned delta); | 66 virtual unsigned BufferSeekForward(unsigned delta); |
64 virtual unsigned FillBuffer(unsigned char_position); | 67 virtual unsigned FillBuffer(unsigned char_position); |
65 void SetRawPosition(unsigned char_position); | 68 void SetRawPosition(unsigned char_position); |
66 | 69 |
67 const byte* raw_data_; | 70 const byte* raw_data_; |
68 unsigned raw_data_length_; // Measured in bytes, not characters. | 71 unsigned raw_data_length_; // Measured in bytes, not characters. |
69 unsigned raw_data_pos_; | 72 unsigned raw_data_pos_; |
70 // The character position of the character at raw_data[raw_data_pos_]. | 73 // The character position of the character at raw_data[raw_data_pos_]. |
71 // Not necessarily the same as pos_. | 74 // Not necessarily the same as pos_. |
72 unsigned raw_character_position_; | 75 unsigned raw_character_position_; |
73 }; | 76 }; |
74 | 77 |
75 | 78 |
| 79 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see |
| 80 // include/v8.h) subclass implemented by the embedder. |
| 81 class ExternalStreamingStream : public BufferedUtf16CharacterStream { |
| 82 public: |
| 83 explicit ExternalStreamingStream(ExternalSourceStream* source_stream) |
| 84 : source_stream_(source_stream), |
| 85 current_data_(NULL), |
| 86 current_data_offset_(0), |
| 87 current_data_length_(0), |
| 88 raw_position_(0) {} |
| 89 |
| 90 virtual ~ExternalStreamingStream() { delete[] current_data_; } |
| 91 |
| 92 virtual unsigned BufferSeekForward(unsigned delta) V8_OVERRIDE { |
| 93 // We never need to seek forward when streaming scripts. We only seek |
| 94 // forward when we want to parse a function whose location we already know, |
| 95 // and when streaming, we don't know the locations of anything we haven't |
| 96 // seen yet. |
| 97 UNREACHABLE(); |
| 98 return 0; |
| 99 } |
| 100 |
| 101 virtual unsigned FillBuffer(unsigned position); |
| 102 |
| 103 private: |
| 104 ExternalSourceStream* source_stream_; |
| 105 const char* current_data_; |
| 106 unsigned current_data_offset_; |
| 107 unsigned current_data_length_; |
| 108 unsigned raw_position_; |
| 109 }; |
| 110 |
| 111 |
76 // UTF16 buffer to read characters from an external string. | 112 // UTF16 buffer to read characters from an external string. |
77 class ExternalTwoByteStringUtf16CharacterStream: public Utf16CharacterStream { | 113 class ExternalTwoByteStringUtf16CharacterStream: public Utf16CharacterStream { |
78 public: | 114 public: |
79 ExternalTwoByteStringUtf16CharacterStream(Handle<ExternalTwoByteString> data, | 115 ExternalTwoByteStringUtf16CharacterStream(Handle<ExternalTwoByteString> data, |
80 int start_position, | 116 int start_position, |
81 int end_position); | 117 int end_position); |
82 virtual ~ExternalTwoByteStringUtf16CharacterStream(); | 118 virtual ~ExternalTwoByteStringUtf16CharacterStream(); |
83 | 119 |
84 virtual void PushBack(uc32 character) { | 120 virtual void PushBack(uc32 character) { |
85 DCHECK(buffer_cursor_ > raw_data_); | 121 DCHECK(buffer_cursor_ > raw_data_); |
(...skipping 10 matching lines...) Expand all Loading... |
96 // Entire string is read at start. | 132 // Entire string is read at start. |
97 return false; | 133 return false; |
98 } | 134 } |
99 Handle<ExternalTwoByteString> source_; | 135 Handle<ExternalTwoByteString> source_; |
100 const uc16* raw_data_; // Pointer to the actual array of characters. | 136 const uc16* raw_data_; // Pointer to the actual array of characters. |
101 }; | 137 }; |
102 | 138 |
103 } } // namespace v8::internal | 139 } } // namespace v8::internal |
104 | 140 |
105 #endif // V8_SCANNER_CHARACTER_STREAMS_H_ | 141 #endif // V8_SCANNER_CHARACTER_STREAMS_H_ |
OLD | NEW |