Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: src/scanner-character-streams.h

Issue 1412223018: [presubmit] Enabling readability/inheritance linter checking. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressing comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/rewriter.cc ('k') | src/snapshot/serialize.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/handles.h" 8 #include "src/handles.h"
9 #include "src/scanner.h" 9 #include "src/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 17
18 // A buffered character stream based on a random access character 18 // A buffered character stream based on a random access character
19 // source (ReadBlock can be called with pos_ pointing to any position, 19 // source (ReadBlock can be called with pos_ pointing to any position,
20 // even positions before the current). 20 // even positions before the current).
21 class BufferedUtf16CharacterStream: public Utf16CharacterStream { 21 class BufferedUtf16CharacterStream: public Utf16CharacterStream {
22 public: 22 public:
23 BufferedUtf16CharacterStream(); 23 BufferedUtf16CharacterStream();
24 virtual ~BufferedUtf16CharacterStream(); 24 ~BufferedUtf16CharacterStream() override;
25 25
26 virtual void PushBack(uc32 character); 26 void PushBack(uc32 character) override;
27 27
28 protected: 28 protected:
29 static const size_t kBufferSize = 512; 29 static const size_t kBufferSize = 512;
30 static const size_t kPushBackStepSize = 16; 30 static const size_t kPushBackStepSize = 16;
31 31
32 virtual size_t SlowSeekForward(size_t delta); 32 size_t SlowSeekForward(size_t delta) override;
33 virtual bool ReadBlock(); 33 bool ReadBlock() override;
34 virtual void SlowPushBack(uc16 character); 34 virtual void SlowPushBack(uc16 character);
35 35
36 virtual size_t BufferSeekForward(size_t delta) = 0; 36 virtual size_t BufferSeekForward(size_t delta) = 0;
37 virtual size_t FillBuffer(size_t position) = 0; 37 virtual size_t FillBuffer(size_t position) = 0;
38 38
39 const uc16* pushback_limit_; 39 const uc16* pushback_limit_;
40 uc16 buffer_[kBufferSize]; 40 uc16 buffer_[kBufferSize];
41 }; 41 };
42 42
43 43
44 // Generic string stream. 44 // Generic string stream.
45 class GenericStringUtf16CharacterStream: public BufferedUtf16CharacterStream { 45 class GenericStringUtf16CharacterStream: public BufferedUtf16CharacterStream {
46 public: 46 public:
47 GenericStringUtf16CharacterStream(Handle<String> data, size_t start_position, 47 GenericStringUtf16CharacterStream(Handle<String> data, size_t start_position,
48 size_t end_position); 48 size_t end_position);
49 virtual ~GenericStringUtf16CharacterStream(); 49 ~GenericStringUtf16CharacterStream() override;
50 50
51 virtual bool SetBookmark(); 51 bool SetBookmark() override;
52 virtual void ResetToBookmark(); 52 void ResetToBookmark() override;
53 53
54 protected: 54 protected:
55 static const size_t kNoBookmark = -1; 55 static const size_t kNoBookmark = -1;
56 56
57 virtual size_t BufferSeekForward(size_t delta); 57 size_t BufferSeekForward(size_t delta) override;
58 virtual size_t FillBuffer(size_t position); 58 size_t FillBuffer(size_t position) override;
59 59
60 Handle<String> string_; 60 Handle<String> string_;
61 size_t length_; 61 size_t length_;
62 size_t bookmark_; 62 size_t bookmark_;
63 }; 63 };
64 64
65 65
66 // Utf16 stream based on a literal UTF-8 string. 66 // Utf16 stream based on a literal UTF-8 string.
67 class Utf8ToUtf16CharacterStream: public BufferedUtf16CharacterStream { 67 class Utf8ToUtf16CharacterStream: public BufferedUtf16CharacterStream {
68 public: 68 public:
69 Utf8ToUtf16CharacterStream(const byte* data, size_t length); 69 Utf8ToUtf16CharacterStream(const byte* data, size_t length);
70 virtual ~Utf8ToUtf16CharacterStream(); 70 ~Utf8ToUtf16CharacterStream() override;
71 71
72 static size_t CopyChars(uint16_t* dest, size_t length, const byte* src, 72 static size_t CopyChars(uint16_t* dest, size_t length, const byte* src,
73 size_t* src_pos, size_t src_length); 73 size_t* src_pos, size_t src_length);
74 74
75 protected: 75 protected:
76 virtual size_t BufferSeekForward(size_t delta); 76 size_t BufferSeekForward(size_t delta) override;
77 virtual size_t FillBuffer(size_t char_position); 77 size_t FillBuffer(size_t char_position) override;
78 void SetRawPosition(size_t char_position); 78 void SetRawPosition(size_t char_position);
79 79
80 const byte* raw_data_; 80 const byte* raw_data_;
81 size_t raw_data_length_; // Measured in bytes, not characters. 81 size_t raw_data_length_; // Measured in bytes, not characters.
82 size_t raw_data_pos_; 82 size_t raw_data_pos_;
83 // The character position of the character at raw_data[raw_data_pos_]. 83 // The character position of the character at raw_data[raw_data_pos_].
84 // Not necessarily the same as pos_. 84 // Not necessarily the same as pos_.
85 size_t raw_character_position_; 85 size_t raw_character_position_;
86 }; 86 };
87 87
88 88
89 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see 89 // ExternalStreamingStream is a wrapper around an ExternalSourceStream (see
90 // include/v8.h) subclass implemented by the embedder. 90 // include/v8.h) subclass implemented by the embedder.
91 class ExternalStreamingStream : public BufferedUtf16CharacterStream { 91 class ExternalStreamingStream : public BufferedUtf16CharacterStream {
92 public: 92 public:
93 ExternalStreamingStream(ScriptCompiler::ExternalSourceStream* source_stream, 93 ExternalStreamingStream(ScriptCompiler::ExternalSourceStream* source_stream,
94 v8::ScriptCompiler::StreamedSource::Encoding encoding) 94 v8::ScriptCompiler::StreamedSource::Encoding encoding)
95 : source_stream_(source_stream), 95 : source_stream_(source_stream),
96 encoding_(encoding), 96 encoding_(encoding),
97 current_data_(NULL), 97 current_data_(NULL),
98 current_data_offset_(0), 98 current_data_offset_(0),
99 current_data_length_(0), 99 current_data_length_(0),
100 utf8_split_char_buffer_length_(0), 100 utf8_split_char_buffer_length_(0),
101 bookmark_(0), 101 bookmark_(0),
102 bookmark_data_is_from_current_data_(false), 102 bookmark_data_is_from_current_data_(false),
103 bookmark_data_offset_(0), 103 bookmark_data_offset_(0),
104 bookmark_utf8_split_char_buffer_length_(0) {} 104 bookmark_utf8_split_char_buffer_length_(0) {}
105 105
106 virtual ~ExternalStreamingStream() { 106 ~ExternalStreamingStream() override {
107 delete[] current_data_; 107 delete[] current_data_;
108 bookmark_buffer_.Dispose(); 108 bookmark_buffer_.Dispose();
109 bookmark_data_.Dispose(); 109 bookmark_data_.Dispose();
110 } 110 }
111 111
112 size_t BufferSeekForward(size_t delta) override { 112 size_t BufferSeekForward(size_t delta) override {
113 // We never need to seek forward when streaming scripts. We only seek 113 // We never need to seek forward when streaming scripts. We only seek
114 // forward when we want to parse a function whose location we already know, 114 // forward when we want to parse a function whose location we already know,
115 // and when streaming, we don't know the locations of anything we haven't 115 // and when streaming, we don't know the locations of anything we haven't
116 // seen yet. 116 // seen yet.
117 UNREACHABLE(); 117 UNREACHABLE();
118 return 0; 118 return 0;
119 } 119 }
120 120
121 size_t FillBuffer(size_t position) override; 121 size_t FillBuffer(size_t position) override;
122 122
123 virtual bool SetBookmark() override; 123 bool SetBookmark() override;
124 virtual void ResetToBookmark() override; 124 void ResetToBookmark() override;
125 125
126 private: 126 private:
127 void HandleUtf8SplitCharacters(size_t* data_in_buffer); 127 void HandleUtf8SplitCharacters(size_t* data_in_buffer);
128 void FlushCurrent(); 128 void FlushCurrent();
129 129
130 ScriptCompiler::ExternalSourceStream* source_stream_; 130 ScriptCompiler::ExternalSourceStream* source_stream_;
131 v8::ScriptCompiler::StreamedSource::Encoding encoding_; 131 v8::ScriptCompiler::StreamedSource::Encoding encoding_;
132 const uint8_t* current_data_; 132 const uint8_t* current_data_;
133 size_t current_data_offset_; 133 size_t current_data_offset_;
134 size_t current_data_length_; 134 size_t current_data_length_;
(...skipping 12 matching lines...) Expand all
147 size_t bookmark_utf8_split_char_buffer_length_; 147 size_t bookmark_utf8_split_char_buffer_length_;
148 }; 148 };
149 149
150 150
151 // UTF16 buffer to read characters from an external string. 151 // UTF16 buffer to read characters from an external string.
152 class ExternalTwoByteStringUtf16CharacterStream: public Utf16CharacterStream { 152 class ExternalTwoByteStringUtf16CharacterStream: public Utf16CharacterStream {
153 public: 153 public:
154 ExternalTwoByteStringUtf16CharacterStream(Handle<ExternalTwoByteString> data, 154 ExternalTwoByteStringUtf16CharacterStream(Handle<ExternalTwoByteString> data,
155 int start_position, 155 int start_position,
156 int end_position); 156 int end_position);
157 virtual ~ExternalTwoByteStringUtf16CharacterStream(); 157 ~ExternalTwoByteStringUtf16CharacterStream() override;
158 158
159 virtual void PushBack(uc32 character) { 159 void PushBack(uc32 character) override {
160 DCHECK(buffer_cursor_ > raw_data_); 160 DCHECK(buffer_cursor_ > raw_data_);
161 buffer_cursor_--; 161 buffer_cursor_--;
162 pos_--; 162 pos_--;
163 } 163 }
164 164
165 virtual bool SetBookmark(); 165 bool SetBookmark() override;
166 virtual void ResetToBookmark(); 166 void ResetToBookmark() override;
167 167
168 protected: 168 protected:
169 virtual size_t SlowSeekForward(size_t delta) { 169 size_t SlowSeekForward(size_t delta) override {
170 // Fast case always handles seeking. 170 // Fast case always handles seeking.
171 return 0; 171 return 0;
172 } 172 }
173 virtual bool ReadBlock() { 173 bool ReadBlock() override {
174 // Entire string is read at start. 174 // Entire string is read at start.
175 return false; 175 return false;
176 } 176 }
177 Handle<ExternalTwoByteString> source_; 177 Handle<ExternalTwoByteString> source_;
178 const uc16* raw_data_; // Pointer to the actual array of characters. 178 const uc16* raw_data_; // Pointer to the actual array of characters.
179 179
180 private: 180 private:
181 static const size_t kNoBookmark = -1; 181 static const size_t kNoBookmark = -1;
182 182
183 size_t bookmark_; 183 size_t bookmark_;
184 }; 184 };
185 185
186 } // namespace internal 186 } // namespace internal
187 } // namespace v8 187 } // namespace v8
188 188
189 #endif // V8_SCANNER_CHARACTER_STREAMS_H_ 189 #endif // V8_SCANNER_CHARACTER_STREAMS_H_
OLDNEW
« no previous file with comments | « src/rewriter.cc ('k') | src/snapshot/serialize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698