diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-12-13 22:03:33 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-12-13 22:12:14 -0800 |
commit | 1d78159e8f8ad7f41167a38ebfa973ed055bc7b6 (patch) | |
tree | bb05356b1eee2278149dfb3d52c34272ef30f149 /deps/v8/src/scanner-base.h | |
parent | 3d0627dc6aae4937c7542243535cade959ced2ee (diff) | |
download | node-new-1d78159e8f8ad7f41167a38ebfa973ed055bc7b6.tar.gz |
Upgrade V8 to 3.0.1
Diffstat (limited to 'deps/v8/src/scanner-base.h')
-rw-r--r-- | deps/v8/src/scanner-base.h | 80 |
1 files changed, 62 insertions, 18 deletions
diff --git a/deps/v8/src/scanner-base.h b/deps/v8/src/scanner-base.h index 3d344f306c..c50b8f3ef6 100644 --- a/deps/v8/src/scanner-base.h +++ b/deps/v8/src/scanner-base.h @@ -52,31 +52,75 @@ inline int HexValue(uc32 c) { return -1; } -// ---------------------------------------------------------------------------- -// UTF16Buffer - scanner input source with pushback. -class UTF16Buffer { +// --------------------------------------------------------------------- +// Buffered stream of characters, using an internal UC16 buffer. + +class UC16CharacterStream { public: - UTF16Buffer(); - virtual ~UTF16Buffer() {} + UC16CharacterStream() : pos_(0) { } + virtual ~UC16CharacterStream() { } + + // Returns and advances past the next UC16 character in the input + // stream. If there are no more characters, it returns a negative + // value. + inline int32_t Advance() { + if (buffer_cursor_ < buffer_end_ || ReadBlock()) { + pos_++; + return *(buffer_cursor_++); + } + // Note: currently the following increment is necessary to avoid a + // parser problem! The scanner treats the final kEndOfInput as + // a character with a position, and does math relative to that + // position. + pos_++; - virtual void PushBack(uc32 ch) = 0; - // Returns a value < 0 when the buffer end is reached. - virtual uc32 Advance() = 0; - virtual void SeekForward(int pos) = 0; + return kEndOfInput; + } - int pos() const { return pos_; } + // Return the current position in the character stream. + // Starts at zero. + inline unsigned pos() const { return pos_; } + + // Skips forward past the next character_count UC16 characters + // in the input, or until the end of input if that comes sooner. + // Returns the number of characters actually skipped. If less + // than character_count, + inline unsigned SeekForward(unsigned character_count) { + unsigned buffered_chars = + static_cast<unsigned>(buffer_end_ - buffer_cursor_); + if (character_count <= buffered_chars) { + buffer_cursor_ += character_count; + pos_ += character_count; + return character_count; + } + return SlowSeekForward(character_count); + } - static const int kNoEndPosition = 1; + // Pushes back the most recently read UC16 character, i.e., + // the value returned by the most recent call to Advance. + // Must not be used right after calling SeekForward. + virtual void PushBack(uc16 character) = 0; protected: - // Initial value of end_ before the input stream is initialized. - - int pos_; // Current position in the buffer. - int end_; // Position where scanning should stop (EOF). + static const int32_t kEndOfInput = -1; + + // Ensures that the buffer_cursor_ points to the character at + // position pos_ of the input, if possible. If the position + // is at or after the end of the input, return false. If there + // are more characters available, return true. + virtual bool ReadBlock() = 0; + virtual unsigned SlowSeekForward(unsigned character_count) = 0; + + const uc16* buffer_cursor_; + const uc16* buffer_end_; + unsigned pos_; }; +// --------------------------------------------------------------------- +// Constants used by scanners. + class ScannerConstants : AllStatic { public: typedef unibrow::Utf8InputBuffer<1024> Utf8Decoder; @@ -277,7 +321,7 @@ class Scanner { // Low-level scanning support. void Advance() { c0_ = source_->Advance(); } void PushBack(uc32 ch) { - source_->PushBack(ch); + source_->PushBack(c0_); c0_ = ch; } @@ -307,8 +351,8 @@ class Scanner { TokenDesc current_; // desc for current token (as returned by Next()) TokenDesc next_; // desc for next token (one token look-ahead) - // Input stream. Must be initialized to an UTF16Buffer. - UTF16Buffer* source_; + // Input stream. Must be initialized to an UC16CharacterStream. + UC16CharacterStream* source_; // Buffer to hold literal values (identifiers, strings, numbers) // using '\x00'-terminated UTF-8 encoding. Handles allocation internally. |