Commit 2a237ed4 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[scanner] Use more range checks and const

Bug: v8:7926
Change-Id: I62e05240fd2bb165ddf8965b77763ec11a40a609
Reviewed-on: https://chromium-review.googlesource.com/1202543
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55636}
parent d3d37157
...@@ -18,17 +18,14 @@ inline int AsciiAlphaToLower(uc32 c) { ...@@ -18,17 +18,14 @@ inline int AsciiAlphaToLower(uc32 c) {
return c | 0x20; return c | 0x20;
} }
inline bool IsCarriageReturn(uc32 c) { inline bool IsCarriageReturn(uc32 c) {
return c == 0x000D; return c == 0x000D;
} }
inline bool IsLineFeed(uc32 c) { inline bool IsLineFeed(uc32 c) {
return c == 0x000A; return c == 0x000A;
} }
inline bool IsAsciiIdentifier(uc32 c) { inline bool IsAsciiIdentifier(uc32 c) {
return IsAlphaNumeric(c) || c == '$' || c == '_'; return IsAlphaNumeric(c) || c == '$' || c == '_';
} }
...@@ -52,6 +49,8 @@ inline bool IsOctalDigit(uc32 c) { ...@@ -52,6 +49,8 @@ inline bool IsOctalDigit(uc32 c) {
return IsInRange(c, '0', '7'); return IsInRange(c, '0', '7');
} }
inline bool IsNonOctalDecimalDigit(uc32 c) { return IsInRange(c, '8', '9'); }
inline bool IsBinaryDigit(uc32 c) { inline bool IsBinaryDigit(uc32 c) {
// ECMA-262, 6th, 7.8.3 // ECMA-262, 6th, 7.8.3
return c == '0' || c == '1'; return c == '0' || c == '1';
......
...@@ -158,11 +158,11 @@ void Scanner::BookmarkScope::Apply() { ...@@ -158,11 +158,11 @@ void Scanner::BookmarkScope::Apply() {
bookmark_ = kBookmarkWasApplied; bookmark_ = kBookmarkWasApplied;
} }
bool Scanner::BookmarkScope::HasBeenSet() { bool Scanner::BookmarkScope::HasBeenSet() const {
return bookmark_ != kNoBookmark && bookmark_ != kBookmarkWasApplied; return bookmark_ != kNoBookmark && bookmark_ != kBookmarkWasApplied;
} }
bool Scanner::BookmarkScope::HasBeenApplied() { bool Scanner::BookmarkScope::HasBeenApplied() const {
return bookmark_ == kBookmarkWasApplied; return bookmark_ == kBookmarkWasApplied;
} }
...@@ -530,7 +530,7 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) { ...@@ -530,7 +530,7 @@ uc32 Scanner::ScanOctalEscape(uc32 c, int length) {
// can be reported later (in strict mode). // can be reported later (in strict mode).
// We don't report the error immediately, because the octal escape can // We don't report the error immediately, because the octal escape can
// occur before the "use strict" directive. // occur before the "use strict" directive.
if (c != '0' || i > 0 || c0_ == '8' || c0_ == '9') { if (c != '0' || i > 0 || IsNonOctalDecimalDigit(c0_)) {
octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1);
octal_message_ = capture_raw ? MessageTemplate::kTemplateOctalLiteral octal_message_ = capture_raw ? MessageTemplate::kTemplateOctalLiteral
: MessageTemplate::kStrictOctalEscape; : MessageTemplate::kStrictOctalEscape;
...@@ -806,11 +806,11 @@ bool Scanner::ScanImplicitOctalDigits(int start_pos, ...@@ -806,11 +806,11 @@ bool Scanner::ScanImplicitOctalDigits(int start_pos,
while (true) { while (true) {
// (possible) octal number // (possible) octal number
if (c0_ == '8' || c0_ == '9') { if (IsNonOctalDecimalDigit(c0_)) {
*kind = DECIMAL_WITH_LEADING_ZERO; *kind = DECIMAL_WITH_LEADING_ZERO;
return true; return true;
} }
if (c0_ < '0' || '7' < c0_) { if (!IsOctalDigit(c0_)) {
// Octal literal finished. // Octal literal finished.
octal_pos_ = Location(start_pos, source_pos()); octal_pos_ = Location(start_pos, source_pos());
octal_message_ = MessageTemplate::kStrictOctalLiteral; octal_message_ = MessageTemplate::kStrictOctalLiteral;
...@@ -878,7 +878,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -878,7 +878,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
AddLiteralCharAdvance(); AddLiteralCharAdvance();
kind = BINARY; kind = BINARY;
if (!ScanBinaryDigits()) return Token::ILLEGAL; if (!ScanBinaryDigits()) return Token::ILLEGAL;
} else if ('0' <= c0_ && c0_ <= '7') { } else if (IsOctalDigit(c0_)) {
kind = IMPLICIT_OCTAL; kind = IMPLICIT_OCTAL;
if (!ScanImplicitOctalDigits(start_pos, &kind)) { if (!ScanImplicitOctalDigits(start_pos, &kind)) {
return Token::ILLEGAL; return Token::ILLEGAL;
...@@ -886,7 +886,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) { ...@@ -886,7 +886,7 @@ Token::Value Scanner::ScanNumber(bool seen_period) {
if (kind == DECIMAL_WITH_LEADING_ZERO) { if (kind == DECIMAL_WITH_LEADING_ZERO) {
at_start = false; at_start = false;
} }
} else if (c0_ == '8' || c0_ == '9') { } else if (IsNonOctalDecimalDigit(c0_)) {
kind = DECIMAL_WITH_LEADING_ZERO; kind = DECIMAL_WITH_LEADING_ZERO;
} else if (allow_harmony_numeric_separator() && c0_ == '_') { } else if (allow_harmony_numeric_separator() && c0_ == '_') {
ReportScannerError(Location(source_pos(), source_pos() + 1), ReportScannerError(Location(source_pos(), source_pos() + 1),
......
...@@ -198,8 +198,8 @@ class Scanner { ...@@ -198,8 +198,8 @@ class Scanner {
void Set(); void Set();
void Apply(); void Apply();
bool HasBeenSet(); bool HasBeenSet() const;
bool HasBeenApplied(); bool HasBeenApplied() const;
private: private:
static const size_t kNoBookmark; static const size_t kNoBookmark;
...@@ -241,10 +241,12 @@ class Scanner { ...@@ -241,10 +241,12 @@ class Scanner {
// Returns the token following peek() // Returns the token following peek()
Token::Value PeekAhead(); Token::Value PeekAhead();
// Returns the current token again. // Returns the current token again.
Token::Value current_token() { return current().token; } Token::Value current_token() const { return current().token; }
Token::Value current_contextual_token() { return current().contextual_token; } Token::Value current_contextual_token() const {
Token::Value next_contextual_token() { return next().contextual_token; } return current().contextual_token;
}
Token::Value next_contextual_token() const { return next().contextual_token; }
// Returns the location information for the current token // Returns the location information for the current token
// (the token last returned by Next()). // (the token last returned by Next()).
...@@ -317,11 +319,13 @@ class Scanner { ...@@ -317,11 +319,13 @@ class Scanner {
current().literal_chars.Equals( current().literal_chars.Equals(
Vector<const char>("use strict", strlen("use strict"))); Vector<const char>("use strict", strlen("use strict")));
} }
bool IsGetOrSet(bool* is_get, bool* is_set) const { bool IsGetOrSet(bool* is_get, bool* is_set) const {
*is_get = CurrentMatchesContextual(Token::GET); *is_get = CurrentMatchesContextual(Token::GET);
*is_set = CurrentMatchesContextual(Token::SET); *is_set = CurrentMatchesContextual(Token::SET);
return *is_get || *is_set; return *is_get || *is_set;
} }
bool IsLet() const { bool IsLet() const {
return CurrentMatches(Token::LET) || return CurrentMatches(Token::LET) ||
CurrentMatchesContextualEscaped(Token::LET); CurrentMatchesContextualEscaped(Token::LET);
...@@ -333,7 +337,7 @@ class Scanner { ...@@ -333,7 +337,7 @@ class Scanner {
bool IsDuplicateSymbol(DuplicateFinder* duplicate_finder, bool IsDuplicateSymbol(DuplicateFinder* duplicate_finder,
AstValueFactory* ast_value_factory) const; AstValueFactory* ast_value_factory) const;
UnicodeCache* unicode_cache() { return unicode_cache_; } UnicodeCache* unicode_cache() const { return unicode_cache_; }
// Returns the location of the last seen octal literal. // Returns the location of the last seen octal literal.
Location octal_position() const { return octal_pos_; } Location octal_position() const { return octal_pos_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment