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

Unified Diff: src/parsing/scanner-character-streams.h

Issue 2314663002: Rework scanner-character-streams. (Closed)
Patch Set: Marja's feedback. Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/scanner.cc ('k') | src/parsing/scanner-character-streams.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/scanner-character-streams.h
diff --git a/src/parsing/scanner-character-streams.h b/src/parsing/scanner-character-streams.h
index 94d8284f14052beb2c3a2e3aaa08fdc1a96e3550..ac81613ab7d49a349f34de712aa0ca76e164243c 100644
--- a/src/parsing/scanner-character-streams.h
+++ b/src/parsing/scanner-character-streams.h
@@ -5,187 +5,27 @@
#ifndef V8_PARSING_SCANNER_CHARACTER_STREAMS_H_
#define V8_PARSING_SCANNER_CHARACTER_STREAMS_H_
+#include "include/v8.h" // for v8::ScriptCompiler
#include "src/handles.h"
-#include "src/parsing/scanner.h"
-#include "src/vector.h"
namespace v8 {
namespace internal {
-// Forward declarations.
-class ExternalTwoByteString;
-class ExternalOneByteString;
+class Utf16CharacterStream;
-// A buffered character stream based on a random access character
-// source (ReadBlock can be called with pos_ pointing to any position,
-// even positions before the current).
-class BufferedUtf16CharacterStream: public Utf16CharacterStream {
+class ScannerStream {
public:
- BufferedUtf16CharacterStream();
- ~BufferedUtf16CharacterStream() override;
-
- void PushBack(uc32 character) override;
-
- protected:
- static const size_t kBufferSize = 512;
- static const size_t kPushBackStepSize = 16;
-
- size_t SlowSeekForward(size_t delta) override;
- bool ReadBlock() override;
- virtual void SlowPushBack(uc16 character);
-
- virtual size_t BufferSeekForward(size_t delta) = 0;
- virtual size_t FillBuffer(size_t position) = 0;
-
- const uc16* pushback_limit_;
- uc16 buffer_[kBufferSize];
-};
-
-
-// Generic string stream.
-class GenericStringUtf16CharacterStream: public BufferedUtf16CharacterStream {
- public:
- GenericStringUtf16CharacterStream(Handle<String> data, size_t start_position,
- size_t end_position);
- ~GenericStringUtf16CharacterStream() override;
-
- bool SetBookmark() override;
- void ResetToBookmark() override;
-
- protected:
- static const size_t kNoBookmark = -1;
-
- size_t BufferSeekForward(size_t delta) override;
- size_t FillBuffer(size_t position) override;
-
- Handle<String> string_;
- size_t length_;
- size_t bookmark_;
-};
-
-
-// ExternalStreamingStream is a wrapper around an ExternalSourceStream (see
-// include/v8.h) subclass implemented by the embedder.
-class ExternalStreamingStream : public BufferedUtf16CharacterStream {
- public:
- ExternalStreamingStream(ScriptCompiler::ExternalSourceStream* source_stream,
- v8::ScriptCompiler::StreamedSource::Encoding encoding)
- : source_stream_(source_stream),
- encoding_(encoding),
- current_data_(NULL),
- current_data_offset_(0),
- current_data_length_(0),
- utf8_split_char_buffer_length_(0),
- bookmark_(0),
- bookmark_data_is_from_current_data_(false),
- bookmark_data_offset_(0),
- bookmark_utf8_split_char_buffer_length_(0) {}
-
- ~ExternalStreamingStream() override {
- delete[] current_data_;
- bookmark_buffer_.Dispose();
- bookmark_data_.Dispose();
- }
-
- size_t BufferSeekForward(size_t delta) override {
- // We never need to seek forward when streaming scripts. We only seek
- // forward when we want to parse a function whose location we already know,
- // and when streaming, we don't know the locations of anything we haven't
- // seen yet.
- UNREACHABLE();
- return 0;
- }
-
- size_t FillBuffer(size_t position) override;
-
- bool SetBookmark() override;
- void ResetToBookmark() override;
-
- private:
- void HandleUtf8SplitCharacters(size_t* data_in_buffer);
- void FlushCurrent();
-
- ScriptCompiler::ExternalSourceStream* source_stream_;
- v8::ScriptCompiler::StreamedSource::Encoding encoding_;
- const uint8_t* current_data_;
- size_t current_data_offset_;
- size_t current_data_length_;
- // For converting UTF-8 characters which are split across two data chunks.
- uint8_t utf8_split_char_buffer_[4];
- size_t utf8_split_char_buffer_length_;
-
- // Bookmark support. See comments in ExternalStreamingStream::SetBookmark
- // for additional details.
- size_t bookmark_;
- Vector<uint16_t> bookmark_buffer_;
- Vector<uint8_t> bookmark_data_;
- bool bookmark_data_is_from_current_data_;
- size_t bookmark_data_offset_;
- uint8_t bookmark_utf8_split_char_buffer_[4];
- size_t bookmark_utf8_split_char_buffer_length_;
-};
-
-
-// UTF16 buffer to read characters from an external string.
-class ExternalTwoByteStringUtf16CharacterStream: public Utf16CharacterStream {
- public:
- ExternalTwoByteStringUtf16CharacterStream(Handle<ExternalTwoByteString> data,
- int start_position,
- int end_position);
- ~ExternalTwoByteStringUtf16CharacterStream() override;
-
- void PushBack(uc32 character) override {
- DCHECK(buffer_cursor_ > raw_data_);
- pos_--;
- if (character != kEndOfInput) {
- buffer_cursor_--;
- }
- }
-
- bool SetBookmark() override;
- void ResetToBookmark() override;
-
- private:
- size_t SlowSeekForward(size_t delta) override {
- // Fast case always handles seeking.
- return 0;
- }
- bool ReadBlock() override {
- // Entire string is read at start.
- return false;
- }
- const uc16* raw_data_; // Pointer to the actual array of characters.
-
- static const size_t kNoBookmark = -1;
-
- size_t bookmark_;
-};
-
-// UTF16 buffer to read characters from an external latin1 string.
-class ExternalOneByteStringUtf16CharacterStream
- : public BufferedUtf16CharacterStream {
- public:
- ExternalOneByteStringUtf16CharacterStream(Handle<ExternalOneByteString> data,
- int start_position,
- int end_position);
- ~ExternalOneByteStringUtf16CharacterStream() override;
+ static Utf16CharacterStream* For(Handle<String> data);
+ static Utf16CharacterStream* For(Handle<String> data, int start_pos,
+ int end_pos);
+ static Utf16CharacterStream* For(
+ ScriptCompiler::ExternalSourceStream* source_stream,
+ ScriptCompiler::StreamedSource::Encoding encoding);
// For testing:
- explicit ExternalOneByteStringUtf16CharacterStream(const char* data);
- ExternalOneByteStringUtf16CharacterStream(const char* data, size_t length);
-
- bool SetBookmark() override;
- void ResetToBookmark() override;
-
- private:
- static const size_t kNoBookmark = -1;
-
- size_t BufferSeekForward(size_t delta) override;
- size_t FillBuffer(size_t position) override;
-
- const uint8_t* raw_data_; // Pointer to the actual array of characters.
- size_t length_;
- size_t bookmark_;
+ static std::unique_ptr<Utf16CharacterStream> ForTesting(const char* data);
+ static std::unique_ptr<Utf16CharacterStream> ForTesting(const char* data,
+ size_t length);
};
} // namespace internal
« no previous file with comments | « src/parsing/scanner.cc ('k') | src/parsing/scanner-character-streams.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698