Index: src/scanner.cc |
diff --git a/src/scanner.cc b/src/scanner.cc |
index 1dae1e42cd4c8f726cf95916205066782dc35fcd..30a97fc8e02a6d28e81fd2db33642901cbbd8f6f 100644 |
--- a/src/scanner.cc |
+++ b/src/scanner.cc |
@@ -29,11 +29,18 @@ Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const { |
} |
+// 'Safe' default implementation for streams that do not support bookmarks. |
+bool Utf16CharacterStream::SetBookmark() { return false; } |
+bool Utf16CharacterStream::CanResetToBookmark() { return false; } |
marja
2015/04/22 16:40:56
I don't get why we need CanResetToBookmark; if Set
|
+bool Utf16CharacterStream::ResetToBookmark() { return false; } |
marja
2015/04/22 16:40:56
Also here, if we successfully set a bookmark, I'd
|
+ |
+ |
marja
2015/04/22 16:40:56
... or is there some logic here like "this bookmar
vogelheim
2015/04/22 17:08:35
(answered elsewhere:) The idea is to support a str
|
// ---------------------------------------------------------------------------- |
// Scanner |
Scanner::Scanner(UnicodeCache* unicode_cache) |
: unicode_cache_(unicode_cache), |
+ bookmark_c0_(-1), |
octal_pos_(Location::invalid()), |
harmony_modules_(false), |
harmony_classes_(false), |
@@ -1426,6 +1433,58 @@ int Scanner::FindSymbol(DuplicateFinder* finder, int value) { |
} |
+bool Scanner::SetBookmark() { |
+ bool can_bookmark = (bookmark_c0_ == -1) && source_->SetBookmark(); |
+ if (can_bookmark) { |
+ bookmark_c0_ = c0_; |
+ bookmark_current_ = current_; |
+ bookmark_current_.literal_chars = nullptr; |
+ bookmark_current_.raw_literal_chars = nullptr; |
+ bookmark_next_ = next_; |
+ bookmark_next_.literal_chars = nullptr; |
+ bookmark_next_.raw_literal_chars = nullptr; |
+ bookmark_literal_.CopyFrom(next_.literal_chars); |
+ bookmark_raw_literal_.CopyFrom(next_.raw_literal_chars); |
+ } |
+ return can_bookmark; |
+} |
+ |
+ |
+bool Scanner::ResetToBookmark() { |
+ DCHECK(bookmark_c0_ >= 0); // Caller hasn't called SetBookmark. |
+ bool can_reset = CanResetBookmark(); |
+ if (can_reset) { |
+ source_->ResetToBookmark(); |
+ next_ = bookmark_next_; |
+ current_ = bookmark_current_; |
+ c0_ = bookmark_c0_; |
+ |
+ next_.literal_chars = &literal_buffer1_; |
+ next_.literal_chars->CopyFrom(&bookmark_literal_); |
+ next_.raw_literal_chars = &raw_literal_buffer1_; |
+ next_.raw_literal_chars->CopyFrom(&bookmark_raw_literal_); |
+ |
+ bookmark_c0_ = -2; |
+ } |
+ |
+ return can_reset; |
+} |
+ |
+ |
+bool Scanner::CanResetBookmark() { |
+ return source_->CanResetToBookmark() && BookmarkHasBeenSet(); |
+} |
+ |
+ |
+bool Scanner::BookmarkHasBeenSet() { return bookmark_c0_ >= 0; } |
+ |
+ |
+bool Scanner::BookmarkHasBeenReset() { return bookmark_c0_ == -2; } |
+ |
+ |
+void Scanner::DropBookmark() { bookmark_c0_ = -1; } |
+ |
+ |
int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) { |
return AddSymbol(key, true, value); |
} |