| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
| 6 | 6 |
| 7 #include "src/parsing/scanner.h" | 7 #include "src/parsing/scanner.h" |
| 8 | 8 |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 bool Scanner::BookmarkScope::HasBeenApplied() { | 71 bool Scanner::BookmarkScope::HasBeenApplied() { |
| 72 return bookmark_ == kBookmarkWasApplied; | 72 return bookmark_ == kBookmarkWasApplied; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // ---------------------------------------------------------------------------- | 75 // ---------------------------------------------------------------------------- |
| 76 // Scanner | 76 // Scanner |
| 77 | 77 |
| 78 Scanner::Scanner(UnicodeCache* unicode_cache) | 78 Scanner::Scanner(UnicodeCache* unicode_cache) |
| 79 : unicode_cache_(unicode_cache), | 79 : unicode_cache_(unicode_cache), |
| 80 octal_pos_(Location::invalid()), | 80 octal_pos_(Location::invalid()), |
| 81 decimal_with_leading_zero_pos_(Location::invalid()), | |
| 82 octal_message_(MessageTemplate::kNone), | 81 octal_message_(MessageTemplate::kNone), |
| 83 found_html_comment_(false) {} | 82 found_html_comment_(false) {} |
| 84 | 83 |
| 85 void Scanner::Initialize(Utf16CharacterStream* source) { | 84 void Scanner::Initialize(Utf16CharacterStream* source) { |
| 86 source_ = source; | 85 source_ = source; |
| 87 // Need to capture identifiers in order to recognize "get" and "set" | 86 // Need to capture identifiers in order to recognize "get" and "set" |
| 88 // in object literals. | 87 // in object literals. |
| 89 Init(); | 88 Init(); |
| 90 // Skip initial whitespace allowing HTML comment ends just like | 89 // Skip initial whitespace allowing HTML comment ends just like |
| 91 // after a newline and scan first token. | 90 // after a newline and scan first token. |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 AddLiteralChar(first_char); | 1151 AddLiteralChar(first_char); |
| 1153 } | 1152 } |
| 1154 | 1153 |
| 1155 if (next_.literal_chars->one_byte_literal().length() <= 10 && | 1154 if (next_.literal_chars->one_byte_literal().length() <= 10 && |
| 1156 value <= Smi::kMaxValue && c0_ != '.' && | 1155 value <= Smi::kMaxValue && c0_ != '.' && |
| 1157 (c0_ == kEndOfInput || !unicode_cache_->IsIdentifierStart(c0_))) { | 1156 (c0_ == kEndOfInput || !unicode_cache_->IsIdentifierStart(c0_))) { |
| 1158 next_.smi_value_ = static_cast<uint32_t>(value); | 1157 next_.smi_value_ = static_cast<uint32_t>(value); |
| 1159 literal.Complete(); | 1158 literal.Complete(); |
| 1160 HandleLeadSurrogate(); | 1159 HandleLeadSurrogate(); |
| 1161 | 1160 |
| 1162 if (kind == DECIMAL_WITH_LEADING_ZERO) | 1161 if (kind == DECIMAL_WITH_LEADING_ZERO) { |
| 1163 decimal_with_leading_zero_pos_ = Location(start_pos, source_pos()); | 1162 octal_pos_ = Location(start_pos, source_pos()); |
| 1163 octal_message_ = MessageTemplate::kStrictDecimalWithLeadingZero; |
| 1164 } |
| 1164 return Token::SMI; | 1165 return Token::SMI; |
| 1165 } | 1166 } |
| 1166 HandleLeadSurrogate(); | 1167 HandleLeadSurrogate(); |
| 1167 } | 1168 } |
| 1168 | 1169 |
| 1169 ScanDecimalDigits(); // optional | 1170 ScanDecimalDigits(); // optional |
| 1170 if (c0_ == '.') { | 1171 if (c0_ == '.') { |
| 1171 AddLiteralCharAdvance(); | 1172 AddLiteralCharAdvance(); |
| 1172 ScanDecimalDigits(); // optional | 1173 ScanDecimalDigits(); // optional |
| 1173 } | 1174 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1193 // The source character immediately following a numeric literal must | 1194 // The source character immediately following a numeric literal must |
| 1194 // not be an identifier start or a decimal digit; see ECMA-262 | 1195 // not be an identifier start or a decimal digit; see ECMA-262 |
| 1195 // section 7.8.3, page 17 (note that we read only one decimal digit | 1196 // section 7.8.3, page 17 (note that we read only one decimal digit |
| 1196 // if the value is 0). | 1197 // if the value is 0). |
| 1197 if (IsDecimalDigit(c0_) || | 1198 if (IsDecimalDigit(c0_) || |
| 1198 (c0_ != kEndOfInput && unicode_cache_->IsIdentifierStart(c0_))) | 1199 (c0_ != kEndOfInput && unicode_cache_->IsIdentifierStart(c0_))) |
| 1199 return Token::ILLEGAL; | 1200 return Token::ILLEGAL; |
| 1200 | 1201 |
| 1201 literal.Complete(); | 1202 literal.Complete(); |
| 1202 | 1203 |
| 1203 if (kind == DECIMAL_WITH_LEADING_ZERO) | 1204 if (kind == DECIMAL_WITH_LEADING_ZERO) { |
| 1204 decimal_with_leading_zero_pos_ = Location(start_pos, source_pos()); | 1205 octal_pos_ = Location(start_pos, source_pos()); |
| 1206 octal_message_ = MessageTemplate::kStrictDecimalWithLeadingZero; |
| 1207 } |
| 1205 return Token::NUMBER; | 1208 return Token::NUMBER; |
| 1206 } | 1209 } |
| 1207 | 1210 |
| 1208 | 1211 |
| 1209 uc32 Scanner::ScanIdentifierUnicodeEscape() { | 1212 uc32 Scanner::ScanIdentifierUnicodeEscape() { |
| 1210 Advance(); | 1213 Advance(); |
| 1211 if (c0_ != 'u') return -1; | 1214 if (c0_ != 'u') return -1; |
| 1212 Advance(); | 1215 Advance(); |
| 1213 return ScanUnicodeEscape<false>(); | 1216 return ScanUnicodeEscape<false>(); |
| 1214 } | 1217 } |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 // 2, reset the source to the desired position, | 1627 // 2, reset the source to the desired position, |
| 1625 source_->Seek(position); | 1628 source_->Seek(position); |
| 1626 // 3, re-scan, by scanning the look-ahead char + 1 token (next_). | 1629 // 3, re-scan, by scanning the look-ahead char + 1 token (next_). |
| 1627 c0_ = source_->Advance(); | 1630 c0_ = source_->Advance(); |
| 1628 Next(); | 1631 Next(); |
| 1629 DCHECK_EQ(next_.location.beg_pos, static_cast<int>(position)); | 1632 DCHECK_EQ(next_.location.beg_pos, static_cast<int>(position)); |
| 1630 } | 1633 } |
| 1631 | 1634 |
| 1632 } // namespace internal | 1635 } // namespace internal |
| 1633 } // namespace v8 | 1636 } // namespace v8 |
| OLD | NEW |