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

Unified Diff: src/parsing/scanner.h

Issue 2341323002: Simplify Scanner bookmarking. (Closed)
Patch Set: 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
Index: src/parsing/scanner.h
diff --git a/src/parsing/scanner.h b/src/parsing/scanner.h
index d43bb65cd493885c9a916eca67cafc68eaca6648..9a4aac1253036799f7621ad206fc70a5e30b6236 100644
--- a/src/parsing/scanner.h
+++ b/src/parsing/scanner.h
@@ -110,26 +110,15 @@ class Utf16CharacterStream {
Back2();
#endif // DEBUG
}
- bool SetBookmark() {
- bookmark_ = pos();
- return true;
- }
- void ResetToBookmark() {
- DCHECK_NE(bookmark_, kNoBookmark);
- Seek(bookmark_);
- }
protected:
- static const size_t kNoBookmark;
-
Utf16CharacterStream(const uint16_t* buffer_start,
const uint16_t* buffer_cursor,
const uint16_t* buffer_end, size_t buffer_pos)
: buffer_start_(buffer_start),
buffer_cursor_(buffer_cursor),
buffer_end_(buffer_end),
- buffer_pos_(buffer_pos),
- bookmark_(kNoBookmark) {}
+ buffer_pos_(buffer_pos) {}
Utf16CharacterStream() : Utf16CharacterStream(nullptr, nullptr, nullptr, 0) {}
void ReadBlockAt(size_t new_pos) {
@@ -173,7 +162,6 @@ class Utf16CharacterStream {
const uint16_t* buffer_cursor_;
const uint16_t* buffer_end_;
size_t buffer_pos_;
- size_t bookmark_;
};
@@ -185,18 +173,23 @@ class Scanner {
// Scoped helper for a re-settable bookmark.
class BookmarkScope {
public:
- explicit BookmarkScope(Scanner* scanner) : scanner_(scanner) {
+ explicit BookmarkScope(Scanner* scanner)
+ : scanner_(scanner), bookmark_(kNoBookmark) {
DCHECK_NOT_NULL(scanner_);
}
- ~BookmarkScope() { scanner_->DropBookmark(); }
+ ~BookmarkScope() {}
- bool Set() { return scanner_->SetBookmark(); }
- void Reset() { scanner_->ResetToBookmark(); }
- bool HasBeenSet() { return scanner_->BookmarkHasBeenSet(); }
- bool HasBeenReset() { return scanner_->BookmarkHasBeenReset(); }
+ void Set();
+ void Reset();
+ bool HasBeenSet();
+ bool HasBeenReset();
private:
+ static const size_t kNoBookmark;
+ static const size_t kBookmarkWasApplied;
+
Scanner* scanner_;
+ size_t bookmark_;
DISALLOW_COPY_AND_ASSIGN(BookmarkScope);
};
@@ -449,23 +442,6 @@ class Scanner {
Handle<String> Internalize(Isolate* isolate) const;
- void CopyFrom(const LiteralBuffer* other) {
- if (other == nullptr) {
- Reset();
- } else {
- is_one_byte_ = other->is_one_byte_;
- position_ = other->position_;
- if (position_ < backing_store_.length()) {
- std::copy(other->backing_store_.begin(),
- other->backing_store_.begin() + position_,
- backing_store_.begin());
- } else {
- backing_store_.Dispose();
- backing_store_ = other->backing_store_.Clone();
- }
- }
- }
-
private:
static const int kInitialCapacity = 16;
static const int kGrowthFactory = 4;
@@ -559,15 +535,6 @@ class Scanner {
scanner_error_ = MessageTemplate::kNone;
}
- // Support BookmarkScope functionality.
- bool SetBookmark();
- void ResetToBookmark();
- bool BookmarkHasBeenSet();
- bool BookmarkHasBeenReset();
- void DropBookmark();
- void CopyToNextTokenDesc(TokenDesc* from);
- static void CopyTokenDesc(TokenDesc* to, TokenDesc* from);
-
void ReportScannerError(const Location& location,
MessageTemplate::Template error) {
if (has_error()) return;
@@ -581,6 +548,8 @@ class Scanner {
scanner_error_location_ = Location(pos, pos + 1);
}
+ void Seek(size_t position);
+
// Literal buffer support
inline void StartLiteral() {
LiteralBuffer* free_buffer =
@@ -821,37 +790,6 @@ class Scanner {
TokenDesc next_; // desc for next token (one token look-ahead)
TokenDesc next_next_; // desc for the token after next (after PeakAhead())
- // Variables for Scanner::BookmarkScope and the *Bookmark implementation.
- // These variables contain the scanner state when a bookmark is set.
- //
- // We will use bookmark_c0_ as a 'control' variable, where:
- // - bookmark_c0_ >= 0: A bookmark has been set and this contains c0_.
- // - bookmark_c0_ == -1: No bookmark has been set.
- // - bookmark_c0_ == -2: The bookmark has been applied (ResetToBookmark).
- //
- // Which state is being bookmarked? The parser state is distributed over
- // several variables, roughly like this:
- // ... 1234 + 5678 ..... [character stream]
- // [current_] [next_] c0_ | [scanner state]
- // So when the scanner is logically at the beginning of an expression
- // like "1234 + 4567", then:
- // - current_ contains "1234"
- // - next_ contains "+"
- // - c0_ contains ' ' (the space between "+" and "5678",
- // - the source_ character stream points to the beginning of "5678".
- // To be able to restore this state, we will keep copies of current_, next_,
- // and c0_; we'll ask the stream to bookmark itself, and we'll copy the
- // contents of current_'s and next_'s literal buffers to bookmark_*_literal_.
- static const uc32 kNoBookmark = -1;
- static const uc32 kBookmarkWasApplied = -2;
- uc32 bookmark_c0_;
- TokenDesc bookmark_current_;
- TokenDesc bookmark_next_;
- LiteralBuffer bookmark_current_literal_;
- LiteralBuffer bookmark_current_raw_literal_;
- LiteralBuffer bookmark_next_literal_;
- LiteralBuffer bookmark_next_raw_literal_;
-
// Input stream. Must be initialized to an Utf16CharacterStream.
Utf16CharacterStream* source_;
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/scanner.cc » ('j') | src/parsing/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698