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 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 } | 976 } |
977 } | 977 } |
978 } | 978 } |
979 | 979 |
980 // Parse decimal digits and allow trailing fractional part. | 980 // Parse decimal digits and allow trailing fractional part. |
981 if (kind == DECIMAL) { | 981 if (kind == DECIMAL) { |
982 if (at_start) { | 982 if (at_start) { |
983 int value = 0; | 983 int value = 0; |
984 while (IsDecimalDigit(c0_)) { | 984 while (IsDecimalDigit(c0_)) { |
985 value = 10 * value + (c0_ - '0'); | 985 value = 10 * value + (c0_ - '0'); |
986 AddLiteralCharAdvance(); | 986 |
| 987 uc32 first_char = c0_; |
| 988 Advance<false, false>(); |
| 989 AddLiteralChar(first_char); |
987 } | 990 } |
988 | 991 |
989 if (next_.literal_chars->one_byte_literal().length() < 10 && | 992 if (next_.literal_chars->one_byte_literal().length() < 10 && |
990 c0_ != '.' && c0_ != 'e' && c0_ != 'E') { | 993 c0_ != '.' && c0_ != 'e' && c0_ != 'E') { |
991 smi_value_ = value; | 994 smi_value_ = value; |
992 literal.Complete(); | 995 literal.Complete(); |
| 996 HandleLeadSurrugate(); |
| 997 |
993 return Token::SMI; | 998 return Token::SMI; |
994 } | 999 } |
| 1000 HandleLeadSurrugate(); |
995 } | 1001 } |
996 | 1002 |
997 ScanDecimalDigits(); // optional | 1003 ScanDecimalDigits(); // optional |
998 if (c0_ == '.') { | 1004 if (c0_ == '.') { |
999 AddLiteralCharAdvance(); | 1005 AddLiteralCharAdvance(); |
1000 ScanDecimalDigits(); // optional | 1006 ScanDecimalDigits(); // optional |
1001 } | 1007 } |
1002 } | 1008 } |
1003 } | 1009 } |
1004 | 1010 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 return Token::FUTURE_STRICT_RESERVED_WORD == | 1192 return Token::FUTURE_STRICT_RESERVED_WORD == |
1187 KeywordOrIdentifierToken(string->raw_data(), string->length(), | 1193 KeywordOrIdentifierToken(string->raw_data(), string->length(), |
1188 harmony_scoping_, harmony_modules_, | 1194 harmony_scoping_, harmony_modules_, |
1189 harmony_classes_); | 1195 harmony_classes_); |
1190 } | 1196 } |
1191 | 1197 |
1192 | 1198 |
1193 Token::Value Scanner::ScanIdentifierOrKeyword() { | 1199 Token::Value Scanner::ScanIdentifierOrKeyword() { |
1194 DCHECK(unicode_cache_->IsIdentifierStart(c0_)); | 1200 DCHECK(unicode_cache_->IsIdentifierStart(c0_)); |
1195 LiteralScope literal(this); | 1201 LiteralScope literal(this); |
1196 // Scan identifier start character. | 1202 if (IsInRange(c0_, 'a', 'z')) { |
1197 if (c0_ == '\\') { | 1203 do { |
| 1204 uc32 first_char = c0_; |
| 1205 Advance<false, false>(); |
| 1206 AddLiteralChar(first_char); |
| 1207 } while (IsInRange(c0_, 'a', 'z')); |
| 1208 |
| 1209 if (IsDecimalDigit(c0_) || IsInRange(c0_, 'A', 'Z') || c0_ == '_' || |
| 1210 c0_ == '$') { |
| 1211 // Identifier starting with lowercase. |
| 1212 uc32 first_char = c0_; |
| 1213 Advance<false, false>(); |
| 1214 AddLiteralChar(first_char); |
| 1215 while (IsAsciiIdentifier(c0_)) { |
| 1216 uc32 first_char = c0_; |
| 1217 Advance<false, false>(); |
| 1218 AddLiteralChar(first_char); |
| 1219 } |
| 1220 if (c0_ <= 127 && c0_ != '\\') { |
| 1221 literal.Complete(); |
| 1222 return Token::IDENTIFIER; |
| 1223 } |
| 1224 } else if (c0_ <= 127 && c0_ != '\\') { |
| 1225 // Only a-z+: could be a keyword or identifier. |
| 1226 literal.Complete(); |
| 1227 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); |
| 1228 return KeywordOrIdentifierToken(chars.start(), chars.length(), |
| 1229 harmony_scoping_, harmony_modules_, |
| 1230 harmony_classes_); |
| 1231 } |
| 1232 |
| 1233 HandleLeadSurrugate(); |
| 1234 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { |
| 1235 do { |
| 1236 uc32 first_char = c0_; |
| 1237 Advance<false, false>(); |
| 1238 AddLiteralChar(first_char); |
| 1239 } while (IsAsciiIdentifier(c0_)); |
| 1240 |
| 1241 if (c0_ <= 127 && c0_ != '\\') { |
| 1242 literal.Complete(); |
| 1243 return Token::IDENTIFIER; |
| 1244 } |
| 1245 |
| 1246 HandleLeadSurrugate(); |
| 1247 } else if (c0_ == '\\') { |
| 1248 // Scan identifier start character. |
1198 uc32 c = ScanIdentifierUnicodeEscape(); | 1249 uc32 c = ScanIdentifierUnicodeEscape(); |
1199 // Only allow legal identifier start characters. | 1250 // Only allow legal identifier start characters. |
1200 if (c < 0 || | 1251 if (c < 0 || |
1201 c == '\\' || // No recursive escapes. | 1252 c == '\\' || // No recursive escapes. |
1202 !unicode_cache_->IsIdentifierStart(c)) { | 1253 !unicode_cache_->IsIdentifierStart(c)) { |
1203 return Token::ILLEGAL; | 1254 return Token::ILLEGAL; |
1204 } | 1255 } |
1205 AddLiteralChar(c); | 1256 AddLiteralChar(c); |
1206 return ScanIdentifierSuffix(&literal); | 1257 return ScanIdentifierSuffix(&literal); |
| 1258 } else { |
| 1259 uc32 first_char = c0_; |
| 1260 Advance(); |
| 1261 AddLiteralChar(first_char); |
1207 } | 1262 } |
1208 | 1263 |
1209 uc32 first_char = c0_; | |
1210 Advance(); | |
1211 AddLiteralChar(first_char); | |
1212 | |
1213 // Scan the rest of the identifier characters. | 1264 // Scan the rest of the identifier characters. |
1214 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { | 1265 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { |
1215 if (c0_ != '\\') { | 1266 if (c0_ != '\\') { |
1216 uc32 next_char = c0_; | 1267 uc32 next_char = c0_; |
1217 Advance(); | 1268 Advance(); |
1218 AddLiteralChar(next_char); | 1269 AddLiteralChar(next_char); |
1219 continue; | 1270 continue; |
1220 } | 1271 } |
1221 // Fallthrough if no longer able to complete keyword. | 1272 // Fallthrough if no longer able to complete keyword. |
1222 return ScanIdentifierSuffix(&literal); | 1273 return ScanIdentifierSuffix(&literal); |
1223 } | 1274 } |
1224 | 1275 |
1225 literal.Complete(); | 1276 literal.Complete(); |
1226 | 1277 |
1227 if (next_.literal_chars->is_one_byte()) { | 1278 if (next_.literal_chars->is_one_byte()) { |
1228 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); | 1279 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); |
1229 return KeywordOrIdentifierToken(chars.start(), | 1280 return KeywordOrIdentifierToken(chars.start(), |
1230 chars.length(), | 1281 chars.length(), |
1231 harmony_scoping_, | 1282 harmony_scoping_, |
1232 harmony_modules_, | 1283 harmony_modules_, |
1233 harmony_classes_); | 1284 harmony_classes_); |
1234 } | 1285 } |
1235 | |
1236 return Token::IDENTIFIER; | 1286 return Token::IDENTIFIER; |
1237 } | 1287 } |
1238 | 1288 |
1239 | 1289 |
1240 Token::Value Scanner::ScanIdentifierSuffix(LiteralScope* literal) { | 1290 Token::Value Scanner::ScanIdentifierSuffix(LiteralScope* literal) { |
1241 // Scan the rest of the identifier characters. | 1291 // Scan the rest of the identifier characters. |
1242 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { | 1292 while (c0_ >= 0 && unicode_cache_->IsIdentifierPart(c0_)) { |
1243 if (c0_ == '\\') { | 1293 if (c0_ == '\\') { |
1244 uc32 c = ScanIdentifierUnicodeEscape(); | 1294 uc32 c = ScanIdentifierUnicodeEscape(); |
1245 // Only allow legal identifier part characters. | 1295 // Only allow legal identifier part characters. |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 } | 1554 } |
1505 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1555 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1506 } | 1556 } |
1507 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1557 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1508 | 1558 |
1509 backing_store_.AddBlock(bytes); | 1559 backing_store_.AddBlock(bytes); |
1510 return backing_store_.EndSequence().start(); | 1560 return backing_store_.EndSequence().start(); |
1511 } | 1561 } |
1512 | 1562 |
1513 } } // namespace v8::internal | 1563 } } // namespace v8::internal |
OLD | NEW |