Index: src/scanner.h |
diff --git a/src/scanner.h b/src/scanner.h |
index 4d7411f54fdfde593d4b553874d7c78e98de4a2f..05160575b33c5a945f26345d428d9085027b4280 100644 |
--- a/src/scanner.h |
+++ b/src/scanner.h |
@@ -89,6 +89,9 @@ class Utf16CharacterStream { |
// Must not be used right after calling SeekForward. |
virtual void PushBack(int32_t code_unit) = 0; |
+ virtual bool SetBookmark(); |
+ virtual void ResetToBookmark(); |
+ |
protected: |
static const uc32 kEndOfInput = -1; |
@@ -268,6 +271,17 @@ class LiteralBuffer { |
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_; |
+ backing_store_.Dispose(); |
+ backing_store_ = other->backing_store_.Clone(); |
+ } |
+ } |
+ |
private: |
static const int kInitialCapacity = 16; |
static const int kGrowthFactory = 4; |
@@ -342,6 +356,23 @@ class Scanner { |
bool complete_; |
}; |
+ // Scoped helper for a re-settable bookmark. |
+ class BookmarkScope { |
+ public: |
+ explicit BookmarkScope(Scanner* scanner) : scanner_(scanner) { |
+ DCHECK_NOT_NULL(scanner_); |
+ } |
+ ~BookmarkScope() { scanner_->DropBookmark(); } |
+ |
+ bool Set() { return scanner_->SetBookmark(); } |
+ void Reset() { scanner_->ResetToBookmark(); } |
+ bool HasBeenSet() { return scanner_->BookmarkHasBeenSet(); } |
+ bool HasBeenReset() { return scanner_->BookmarkHasBeenReset(); } |
+ |
+ private: |
+ Scanner* scanner_; |
+ }; |
+ |
// Representation of an interval of source positions. |
struct Location { |
Location(int b, int e) : beg_pos(b), end_pos(e) { } |
@@ -517,6 +548,14 @@ class Scanner { |
current_.raw_literal_chars = NULL; |
} |
+ // Support BookmarkScope functionality. |
+ bool SetBookmark(); |
+ void ResetToBookmark(); |
+ bool BookmarkHasBeenSet(); |
+ bool BookmarkHasBeenReset(); |
+ void DropBookmark(); |
+ static void CopyTokenDesc(TokenDesc* to, TokenDesc* from); |
+ |
// Literal buffer support |
inline void StartLiteral() { |
LiteralBuffer* free_buffer = (current_.literal_chars == &literal_buffer1_) ? |
@@ -719,6 +758,20 @@ class Scanner { |
TokenDesc current_; // desc for current token (as returned by Next()) |
TokenDesc next_; // desc for next token (one token look-ahead) |
+ // 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). |
+ TokenDesc bookmark_current_; |
+ TokenDesc bookmark_next_; |
+ uc32 bookmark_c0_; |
marja
2015/04/24 12:08:13
Pls add a comment here about why we need to store
|
+ 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_; |