| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 // can be reported later (in strict mode). | 781 // can be reported later (in strict mode). |
| 782 // We don't report the error immediately, because the octal escape can | 782 // We don't report the error immediately, because the octal escape can |
| 783 // occur before the "use strict" directive. | 783 // occur before the "use strict" directive. |
| 784 if (c != '0' || i > 0) { | 784 if (c != '0' || i > 0) { |
| 785 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); | 785 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); |
| 786 } | 786 } |
| 787 return x; | 787 return x; |
| 788 } | 788 } |
| 789 | 789 |
| 790 | 790 |
| 791 const int kMaxAscii = 127; |
| 792 |
| 793 |
| 791 Token::Value Scanner::ScanString() { | 794 Token::Value Scanner::ScanString() { |
| 792 uc32 quote = c0_; | 795 uc32 quote = c0_; |
| 793 Advance(); // consume quote | 796 Advance<false, false>(); // consume quote |
| 794 | 797 |
| 795 LiteralScope literal(this); | 798 LiteralScope literal(this); |
| 799 while (true) { |
| 800 if (c0_ > kMaxAscii) { |
| 801 HandleLeadSurrogate(); |
| 802 break; |
| 803 } |
| 804 if (c0_ < 0 || c0_ == '\n' || c0_ == '\r') return Token::ILLEGAL; |
| 805 if (c0_ == quote) { |
| 806 literal.Complete(); |
| 807 Advance<false, false>(); |
| 808 return Token::STRING; |
| 809 } |
| 810 uc32 c = c0_; |
| 811 if (c == '\\') break; |
| 812 Advance<false, false>(); |
| 813 AddLiteralChar(c); |
| 814 } |
| 815 |
| 796 while (c0_ != quote && c0_ >= 0 | 816 while (c0_ != quote && c0_ >= 0 |
| 797 && !unicode_cache_->IsLineTerminator(c0_)) { | 817 && !unicode_cache_->IsLineTerminator(c0_)) { |
| 798 uc32 c = c0_; | 818 uc32 c = c0_; |
| 799 Advance(); | 819 Advance(); |
| 800 if (c == '\\') { | 820 if (c == '\\') { |
| 801 if (c0_ < 0 || !ScanEscape<false, false>()) return Token::ILLEGAL; | 821 if (c0_ < 0 || !ScanEscape<false, false>()) return Token::ILLEGAL; |
| 802 } else { | 822 } else { |
| 803 AddLiteralChar(c); | 823 AddLiteralChar(c); |
| 804 } | 824 } |
| 805 } | 825 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 | 1006 |
| 987 uc32 first_char = c0_; | 1007 uc32 first_char = c0_; |
| 988 Advance<false, false>(); | 1008 Advance<false, false>(); |
| 989 AddLiteralChar(first_char); | 1009 AddLiteralChar(first_char); |
| 990 } | 1010 } |
| 991 | 1011 |
| 992 if (next_.literal_chars->one_byte_literal().length() < 10 && | 1012 if (next_.literal_chars->one_byte_literal().length() < 10 && |
| 993 c0_ != '.' && c0_ != 'e' && c0_ != 'E') { | 1013 c0_ != '.' && c0_ != 'e' && c0_ != 'E') { |
| 994 smi_value_ = value; | 1014 smi_value_ = value; |
| 995 literal.Complete(); | 1015 literal.Complete(); |
| 996 HandleLeadSurrugate(); | 1016 HandleLeadSurrogate(); |
| 997 | 1017 |
| 998 return Token::SMI; | 1018 return Token::SMI; |
| 999 } | 1019 } |
| 1000 HandleLeadSurrugate(); | 1020 HandleLeadSurrogate(); |
| 1001 } | 1021 } |
| 1002 | 1022 |
| 1003 ScanDecimalDigits(); // optional | 1023 ScanDecimalDigits(); // optional |
| 1004 if (c0_ == '.') { | 1024 if (c0_ == '.') { |
| 1005 AddLiteralCharAdvance(); | 1025 AddLiteralCharAdvance(); |
| 1006 ScanDecimalDigits(); // optional | 1026 ScanDecimalDigits(); // optional |
| 1007 } | 1027 } |
| 1008 } | 1028 } |
| 1009 } | 1029 } |
| 1010 | 1030 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 c0_ == '$') { | 1230 c0_ == '$') { |
| 1211 // Identifier starting with lowercase. | 1231 // Identifier starting with lowercase. |
| 1212 uc32 first_char = c0_; | 1232 uc32 first_char = c0_; |
| 1213 Advance<false, false>(); | 1233 Advance<false, false>(); |
| 1214 AddLiteralChar(first_char); | 1234 AddLiteralChar(first_char); |
| 1215 while (IsAsciiIdentifier(c0_)) { | 1235 while (IsAsciiIdentifier(c0_)) { |
| 1216 uc32 first_char = c0_; | 1236 uc32 first_char = c0_; |
| 1217 Advance<false, false>(); | 1237 Advance<false, false>(); |
| 1218 AddLiteralChar(first_char); | 1238 AddLiteralChar(first_char); |
| 1219 } | 1239 } |
| 1220 if (c0_ <= 127 && c0_ != '\\') { | 1240 if (c0_ <= kMaxAscii && c0_ != '\\') { |
| 1221 literal.Complete(); | 1241 literal.Complete(); |
| 1222 return Token::IDENTIFIER; | 1242 return Token::IDENTIFIER; |
| 1223 } | 1243 } |
| 1224 } else if (c0_ <= 127 && c0_ != '\\') { | 1244 } else if (c0_ <= kMaxAscii && c0_ != '\\') { |
| 1225 // Only a-z+: could be a keyword or identifier. | 1245 // Only a-z+: could be a keyword or identifier. |
| 1226 literal.Complete(); | 1246 literal.Complete(); |
| 1227 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); | 1247 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); |
| 1228 return KeywordOrIdentifierToken(chars.start(), chars.length(), | 1248 return KeywordOrIdentifierToken(chars.start(), chars.length(), |
| 1229 harmony_scoping_, harmony_modules_, | 1249 harmony_scoping_, harmony_modules_, |
| 1230 harmony_classes_); | 1250 harmony_classes_); |
| 1231 } | 1251 } |
| 1232 | 1252 |
| 1233 HandleLeadSurrugate(); | 1253 HandleLeadSurrogate(); |
| 1234 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { | 1254 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { |
| 1235 do { | 1255 do { |
| 1236 uc32 first_char = c0_; | 1256 uc32 first_char = c0_; |
| 1237 Advance<false, false>(); | 1257 Advance<false, false>(); |
| 1238 AddLiteralChar(first_char); | 1258 AddLiteralChar(first_char); |
| 1239 } while (IsAsciiIdentifier(c0_)); | 1259 } while (IsAsciiIdentifier(c0_)); |
| 1240 | 1260 |
| 1241 if (c0_ <= 127 && c0_ != '\\') { | 1261 if (c0_ <= kMaxAscii && c0_ != '\\') { |
| 1242 literal.Complete(); | 1262 literal.Complete(); |
| 1243 return Token::IDENTIFIER; | 1263 return Token::IDENTIFIER; |
| 1244 } | 1264 } |
| 1245 | 1265 |
| 1246 HandleLeadSurrugate(); | 1266 HandleLeadSurrogate(); |
| 1247 } else if (c0_ == '\\') { | 1267 } else if (c0_ == '\\') { |
| 1248 // Scan identifier start character. | 1268 // Scan identifier start character. |
| 1249 uc32 c = ScanIdentifierUnicodeEscape(); | 1269 uc32 c = ScanIdentifierUnicodeEscape(); |
| 1250 // Only allow legal identifier start characters. | 1270 // Only allow legal identifier start characters. |
| 1251 if (c < 0 || | 1271 if (c < 0 || |
| 1252 c == '\\' || // No recursive escapes. | 1272 c == '\\' || // No recursive escapes. |
| 1253 !unicode_cache_->IsIdentifierStart(c)) { | 1273 !unicode_cache_->IsIdentifierStart(c)) { |
| 1254 return Token::ILLEGAL; | 1274 return Token::ILLEGAL; |
| 1255 } | 1275 } |
| 1256 AddLiteralChar(c); | 1276 AddLiteralChar(c); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 } | 1574 } |
| 1555 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1575 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
| 1556 } | 1576 } |
| 1557 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1577 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
| 1558 | 1578 |
| 1559 backing_store_.AddBlock(bytes); | 1579 backing_store_.AddBlock(bytes); |
| 1560 return backing_store_.EndSequence().start(); | 1580 return backing_store_.EndSequence().start(); |
| 1561 } | 1581 } |
| 1562 | 1582 |
| 1563 } } // namespace v8::internal | 1583 } } // namespace v8::internal |
| OLD | NEW |