Chromium Code Reviews| Index: src/scanner-base.cc |
| diff --git a/src/scanner-base.cc b/src/scanner-base.cc |
| index 2066b5a1e6553d4da67ebc3eb646e7c71dc2af34..9ef6db46031413e455680b1fe2b3055ddd4bda25 100644 |
| --- a/src/scanner-base.cc |
| +++ b/src/scanner-base.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright 2010 the V8 project authors. All rights reserved. |
| +// Copyright 2011 the V8 project authors. All rights reserved. |
| // Redistribution and use in source and binary forms, with or without |
| // modification, are permitted provided that the following conditions are |
| // met: |
| @@ -35,27 +35,10 @@ namespace v8 { |
| namespace internal { |
| // ---------------------------------------------------------------------------- |
| -// Compound predicates. |
| - |
| -bool ScannerConstants::IsIdentifier(unibrow::CharacterStream* buffer) { |
| - // Checks whether the buffer contains an identifier (no escape). |
| - if (!buffer->has_more()) return false; |
| - if (!kIsIdentifierStart.get(buffer->GetNext())) { |
| - return false; |
| - } |
| - while (buffer->has_more()) { |
| - if (!kIsIdentifierPart.get(buffer->GetNext())) { |
| - return false; |
| - } |
| - } |
| - return true; |
| -} |
| - |
| -// ---------------------------------------------------------------------------- |
| // Scanner |
| -Scanner::Scanner(ScannerConstants* scanner_constants) |
| - : scanner_constants_(scanner_constants), |
| +Scanner::Scanner(UnicodeCache* unicode_cache) |
| + : unicode_cache_(unicode_cache), |
| octal_pos_(kNoOctalLocation) { |
|
Karl Klose
2011/04/12 07:55:40
I think this newline should be removed.
Lasse Reichstein
2011/04/12 08:18:47
Done.
|
| } |
| @@ -114,7 +97,7 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) { |
| // ---------------------------------------------------------------------------- |
| // JavaScriptScanner |
| -JavaScriptScanner::JavaScriptScanner(ScannerConstants* scanner_contants) |
| +JavaScriptScanner::JavaScriptScanner(UnicodeCache* scanner_contants) |
| : Scanner(scanner_contants) { } |
| @@ -144,9 +127,9 @@ bool JavaScriptScanner::SkipWhiteSpace() { |
| while (true) { |
| // We treat byte-order marks (BOMs) as whitespace for better |
| // compatibility with Spidermonkey and other JavaScript engines. |
| - while (scanner_constants_->IsWhiteSpace(c0_) || IsByteOrderMark(c0_)) { |
| + while (unicode_cache_->IsWhiteSpace(c0_) || IsByteOrderMark(c0_)) { |
| // IsWhiteSpace() includes line terminators! |
| - if (scanner_constants_->IsLineTerminator(c0_)) { |
| + if (unicode_cache_->IsLineTerminator(c0_)) { |
| // Ignore line terminators, but remember them. This is necessary |
| // for automatic semicolon insertion. |
| has_line_terminator_before_next_ = true; |
| @@ -186,7 +169,7 @@ Token::Value JavaScriptScanner::SkipSingleLineComment() { |
| // separately by the lexical grammar and becomes part of the |
| // stream of input elements for the syntactic grammar (see |
| // ECMA-262, section 7.4, page 12). |
| - while (c0_ >= 0 && !scanner_constants_->IsLineTerminator(c0_)) { |
| + while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { |
| Advance(); |
| } |
| @@ -451,7 +434,7 @@ void JavaScriptScanner::Scan() { |
| break; |
| default: |
| - if (scanner_constants_->IsIdentifierStart(c0_)) { |
| + if (unicode_cache_->IsIdentifierStart(c0_)) { |
| token = ScanIdentifierOrKeyword(); |
| } else if (IsDecimalDigit(c0_)) { |
| token = ScanNumber(false); |
| @@ -499,7 +482,7 @@ void JavaScriptScanner::ScanEscape() { |
| Advance(); |
| // Skip escaped newlines. |
| - if (scanner_constants_->IsLineTerminator(c)) { |
| + if (unicode_cache_->IsLineTerminator(c)) { |
| // Allow CR+LF newlines in multiline string literals. |
| if (IsCarriageReturn(c) && IsLineFeed(c0_)) Advance(); |
| // Allow LF+CR newlines in multiline string literals. |
| @@ -542,7 +525,7 @@ Token::Value JavaScriptScanner::ScanString() { |
| LiteralScope literal(this); |
| while (c0_ != quote && c0_ >= 0 |
| - && !scanner_constants_->IsLineTerminator(c0_)) { |
| + && !unicode_cache_->IsLineTerminator(c0_)) { |
| uc32 c = c0_; |
| Advance(); |
| if (c == '\\') { |
| @@ -641,7 +624,7 @@ Token::Value JavaScriptScanner::ScanNumber(bool seen_period) { |
| // not be an identifier start or a decimal digit; see ECMA-262 |
| // section 7.8.3, page 17 (note that we read only one decimal digit |
| // if the value is 0). |
| - if (IsDecimalDigit(c0_) || scanner_constants_->IsIdentifierStart(c0_)) |
| + if (IsDecimalDigit(c0_) || unicode_cache_->IsIdentifierStart(c0_)) |
| return Token::ILLEGAL; |
| literal.Complete(); |
| @@ -663,14 +646,14 @@ uc32 JavaScriptScanner::ScanIdentifierUnicodeEscape() { |
| Token::Value JavaScriptScanner::ScanIdentifierOrKeyword() { |
| - ASSERT(scanner_constants_->IsIdentifierStart(c0_)); |
| + ASSERT(unicode_cache_->IsIdentifierStart(c0_)); |
| LiteralScope literal(this); |
| KeywordMatcher keyword_match; |
| // Scan identifier start character. |
| if (c0_ == '\\') { |
| uc32 c = ScanIdentifierUnicodeEscape(); |
| // Only allow legal identifier start characters. |
| - if (!scanner_constants_->IsIdentifierStart(c)) return Token::ILLEGAL; |
| + if (!unicode_cache_->IsIdentifierStart(c)) return Token::ILLEGAL; |
| AddLiteralChar(c); |
| return ScanIdentifierSuffix(&literal); |
| } |
| @@ -683,7 +666,7 @@ Token::Value JavaScriptScanner::ScanIdentifierOrKeyword() { |
| } |
| // Scan the rest of the identifier characters. |
| - while (scanner_constants_->IsIdentifierPart(c0_)) { |
| + while (unicode_cache_->IsIdentifierPart(c0_)) { |
| if (c0_ != '\\') { |
| uc32 next_char = c0_; |
| Advance(); |
| @@ -701,11 +684,11 @@ Token::Value JavaScriptScanner::ScanIdentifierOrKeyword() { |
| Token::Value JavaScriptScanner::ScanIdentifierSuffix(LiteralScope* literal) { |
| // Scan the rest of the identifier characters. |
| - while (scanner_constants_->IsIdentifierPart(c0_)) { |
| + while (unicode_cache_->IsIdentifierPart(c0_)) { |
| if (c0_ == '\\') { |
| uc32 c = ScanIdentifierUnicodeEscape(); |
| // Only allow legal identifier part characters. |
| - if (!scanner_constants_->IsIdentifierPart(c)) return Token::ILLEGAL; |
| + if (!unicode_cache_->IsIdentifierPart(c)) return Token::ILLEGAL; |
| AddLiteralChar(c); |
| } else { |
| AddLiteralChar(c0_); |
| @@ -735,10 +718,10 @@ bool JavaScriptScanner::ScanRegExpPattern(bool seen_equal) { |
| AddLiteralChar('='); |
| while (c0_ != '/' || in_character_class) { |
| - if (scanner_constants_->IsLineTerminator(c0_) || c0_ < 0) return false; |
| + if (unicode_cache_->IsLineTerminator(c0_) || c0_ < 0) return false; |
| if (c0_ == '\\') { // Escape sequence. |
| AddLiteralCharAdvance(); |
| - if (scanner_constants_->IsLineTerminator(c0_) || c0_ < 0) return false; |
| + if (unicode_cache_->IsLineTerminator(c0_) || c0_ < 0) return false; |
| AddLiteralCharAdvance(); |
| // If the escape allows more characters, i.e., \x??, \u????, or \c?, |
| // only "safe" characters are allowed (letters, digits, underscore), |
| @@ -764,7 +747,7 @@ bool JavaScriptScanner::ScanRegExpPattern(bool seen_equal) { |
| bool JavaScriptScanner::ScanRegExpFlags() { |
| // Scan regular expression flags. |
| LiteralScope literal(this); |
| - while (scanner_constants_->IsIdentifierPart(c0_)) { |
| + while (unicode_cache_->IsIdentifierPart(c0_)) { |
| if (c0_ == '\\') { |
| uc32 c = ScanIdentifierUnicodeEscape(); |
| if (c != static_cast<uc32>(unibrow::Utf8::kBadChar)) { |