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

Unified Diff: src/scanner-base.cc

Issue 6824071: Cleanup of ScannerConstants, now named UnicodeCache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed review comments. Created 9 years, 8 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
« no previous file with comments | « src/scanner-base.h ('k') | test/cctest/test-conversions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scanner-base.cc
diff --git a/src/scanner-base.cc b/src/scanner-base.cc
index 2066b5a1e6553d4da67ebc3eb646e7c71dc2af34..9715ca995c65c784c5a0959396ec9de8bf965536 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,29 +35,11 @@ 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),
- octal_pos_(kNoOctalLocation) {
-}
+Scanner::Scanner(UnicodeCache* unicode_cache)
+ : unicode_cache_(unicode_cache),
+ octal_pos_(kNoOctalLocation) { }
uc32 Scanner::ScanHexEscape(uc32 c, int length) {
@@ -114,7 +96,7 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
// ----------------------------------------------------------------------------
// JavaScriptScanner
-JavaScriptScanner::JavaScriptScanner(ScannerConstants* scanner_contants)
+JavaScriptScanner::JavaScriptScanner(UnicodeCache* scanner_contants)
: Scanner(scanner_contants) { }
@@ -144,9 +126,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 +168,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 +433,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 +481,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 +524,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 +623,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 +645,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 +665,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 +683,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 +717,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 +746,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)) {
« no previous file with comments | « src/scanner-base.h ('k') | test/cctest/test-conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698