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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 AddLiteralCharAdvance(); | 906 AddLiteralCharAdvance(); |
907 } | 907 } |
908 | 908 |
909 | 909 |
910 Token::Value Scanner::ScanNumber(bool seen_period) { | 910 Token::Value Scanner::ScanNumber(bool seen_period) { |
911 DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction | 911 DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction |
912 | 912 |
913 enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL; | 913 enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL; |
914 | 914 |
915 LiteralScope literal(this); | 915 LiteralScope literal(this); |
| 916 bool at_start = !seen_period; |
916 if (seen_period) { | 917 if (seen_period) { |
917 // we have already seen a decimal point of the float | 918 // we have already seen a decimal point of the float |
918 AddLiteralChar('.'); | 919 AddLiteralChar('.'); |
919 ScanDecimalDigits(); // we know we have at least one digit | 920 ScanDecimalDigits(); // we know we have at least one digit |
920 | 921 |
921 } else { | 922 } else { |
922 // if the first character is '0' we must check for octals and hex | 923 // if the first character is '0' we must check for octals and hex |
923 if (c0_ == '0') { | 924 if (c0_ == '0') { |
924 int start_pos = source_pos(); // For reporting octal positions. | 925 int start_pos = source_pos(); // For reporting octal positions. |
925 AddLiteralCharAdvance(); | 926 AddLiteralCharAdvance(); |
(...skipping 29 matching lines...) Expand all Loading... |
955 return Token::ILLEGAL; | 956 return Token::ILLEGAL; |
956 } | 957 } |
957 while (IsBinaryDigit(c0_)) { | 958 while (IsBinaryDigit(c0_)) { |
958 AddLiteralCharAdvance(); | 959 AddLiteralCharAdvance(); |
959 } | 960 } |
960 } else if ('0' <= c0_ && c0_ <= '7') { | 961 } else if ('0' <= c0_ && c0_ <= '7') { |
961 // (possible) octal number | 962 // (possible) octal number |
962 kind = IMPLICIT_OCTAL; | 963 kind = IMPLICIT_OCTAL; |
963 while (true) { | 964 while (true) { |
964 if (c0_ == '8' || c0_ == '9') { | 965 if (c0_ == '8' || c0_ == '9') { |
| 966 at_start = false; |
965 kind = DECIMAL; | 967 kind = DECIMAL; |
966 break; | 968 break; |
967 } | 969 } |
968 if (c0_ < '0' || '7' < c0_) { | 970 if (c0_ < '0' || '7' < c0_) { |
969 // Octal literal finished. | 971 // Octal literal finished. |
970 octal_pos_ = Location(start_pos, source_pos()); | 972 octal_pos_ = Location(start_pos, source_pos()); |
971 break; | 973 break; |
972 } | 974 } |
973 AddLiteralCharAdvance(); | 975 AddLiteralCharAdvance(); |
974 } | 976 } |
975 } | 977 } |
976 } | 978 } |
977 | 979 |
978 // Parse decimal digits and allow trailing fractional part. | 980 // Parse decimal digits and allow trailing fractional part. |
979 if (kind == DECIMAL) { | 981 if (kind == DECIMAL) { |
| 982 if (at_start) { |
| 983 int value = 0; |
| 984 while (IsDecimalDigit(c0_)) { |
| 985 value = 10 * value + (c0_ - '0'); |
| 986 AddLiteralCharAdvance(); |
| 987 } |
| 988 |
| 989 if (next_.literal_chars->one_byte_literal().length() < 10 && |
| 990 c0_ != '.' && c0_ != 'e' && c0_ != 'E') { |
| 991 smi_value_ = value; |
| 992 literal.Complete(); |
| 993 return Token::SMI; |
| 994 } |
| 995 } |
| 996 |
980 ScanDecimalDigits(); // optional | 997 ScanDecimalDigits(); // optional |
981 if (c0_ == '.') { | 998 if (c0_ == '.') { |
982 AddLiteralCharAdvance(); | 999 AddLiteralCharAdvance(); |
983 ScanDecimalDigits(); // optional | 1000 ScanDecimalDigits(); // optional |
984 } | 1001 } |
985 } | 1002 } |
986 } | 1003 } |
987 | 1004 |
988 // scan exponent, if any | 1005 // scan exponent, if any |
989 if (c0_ == 'e' || c0_ == 'E') { | 1006 if (c0_ == 'e' || c0_ == 'E') { |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 } | 1504 } |
1488 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1505 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1489 } | 1506 } |
1490 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1507 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1491 | 1508 |
1492 backing_store_.AddBlock(bytes); | 1509 backing_store_.AddBlock(bytes); |
1493 return backing_store_.EndSequence().start(); | 1510 return backing_store_.EndSequence().start(); |
1494 } | 1511 } |
1495 | 1512 |
1496 } } // namespace v8::internal | 1513 } } // namespace v8::internal |
OLD | NEW |