Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: src/parsing/scanner.cc

Issue 1948403002: add UseCounters for NonOctalDecimalIntegerLiteral in strict mode (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix uninitialized field. guard against null Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/scanner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 void Utf16CharacterStream::ResetToBookmark() { UNREACHABLE(); } 33 void Utf16CharacterStream::ResetToBookmark() { UNREACHABLE(); }
34 34
35 35
36 // ---------------------------------------------------------------------------- 36 // ----------------------------------------------------------------------------
37 // Scanner 37 // Scanner
38 38
39 Scanner::Scanner(UnicodeCache* unicode_cache) 39 Scanner::Scanner(UnicodeCache* unicode_cache)
40 : unicode_cache_(unicode_cache), 40 : unicode_cache_(unicode_cache),
41 bookmark_c0_(kNoBookmark), 41 bookmark_c0_(kNoBookmark),
42 octal_pos_(Location::invalid()), 42 octal_pos_(Location::invalid()),
43 decimal_with_leading_zero_pos_(Location::invalid()),
43 found_html_comment_(false), 44 found_html_comment_(false),
44 allow_harmony_exponentiation_operator_(false) { 45 allow_harmony_exponentiation_operator_(false) {
45 bookmark_current_.literal_chars = &bookmark_current_literal_; 46 bookmark_current_.literal_chars = &bookmark_current_literal_;
46 bookmark_current_.raw_literal_chars = &bookmark_current_raw_literal_; 47 bookmark_current_.raw_literal_chars = &bookmark_current_raw_literal_;
47 bookmark_next_.literal_chars = &bookmark_next_literal_; 48 bookmark_next_.literal_chars = &bookmark_next_literal_;
48 bookmark_next_.raw_literal_chars = &bookmark_next_raw_literal_; 49 bookmark_next_.raw_literal_chars = &bookmark_next_raw_literal_;
49 } 50 }
50 51
51 52
52 void Scanner::Initialize(Utf16CharacterStream* source) { 53 void Scanner::Initialize(Utf16CharacterStream* source) {
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 969
969 void Scanner::ScanDecimalDigits() { 970 void Scanner::ScanDecimalDigits() {
970 while (IsDecimalDigit(c0_)) 971 while (IsDecimalDigit(c0_))
971 AddLiteralCharAdvance(); 972 AddLiteralCharAdvance();
972 } 973 }
973 974
974 975
975 Token::Value Scanner::ScanNumber(bool seen_period) { 976 Token::Value Scanner::ScanNumber(bool seen_period) {
976 DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction 977 DCHECK(IsDecimalDigit(c0_)); // the first digit of the number or the fraction
977 978
978 enum { DECIMAL, HEX, OCTAL, IMPLICIT_OCTAL, BINARY } kind = DECIMAL; 979 enum {
980 DECIMAL,
981 DECIMAL_WITH_LEADING_ZERO,
982 HEX,
983 OCTAL,
984 IMPLICIT_OCTAL,
985 BINARY
986 } kind = DECIMAL;
979 987
980 LiteralScope literal(this); 988 LiteralScope literal(this);
981 bool at_start = !seen_period; 989 bool at_start = !seen_period;
990 int start_pos; // For reporting octal positions.
caitp (gmail) 2016/05/13 12:58:31 Maybe rename this to `octal_start_pos` and initial
982 if (seen_period) { 991 if (seen_period) {
983 // we have already seen a decimal point of the float 992 // we have already seen a decimal point of the float
984 AddLiteralChar('.'); 993 AddLiteralChar('.');
985 ScanDecimalDigits(); // we know we have at least one digit 994 ScanDecimalDigits(); // we know we have at least one digit
986 995
987 } else { 996 } else {
988 // if the first character is '0' we must check for octals and hex 997 // if the first character is '0' we must check for octals and hex
989 if (c0_ == '0') { 998 if (c0_ == '0') {
990 int start_pos = source_pos(); // For reporting octal positions. 999 start_pos = source_pos();
991 AddLiteralCharAdvance(); 1000 AddLiteralCharAdvance();
992 1001
993 // either 0, 0exxx, 0Exxx, 0.xxx, a hex number, a binary number or 1002 // either 0, 0exxx, 0Exxx, 0.xxx, a hex number, a binary number or
994 // an octal number. 1003 // an octal number.
995 if (c0_ == 'x' || c0_ == 'X') { 1004 if (c0_ == 'x' || c0_ == 'X') {
996 // hex number 1005 // hex number
997 kind = HEX; 1006 kind = HEX;
998 AddLiteralCharAdvance(); 1007 AddLiteralCharAdvance();
999 if (!IsHexDigit(c0_)) { 1008 if (!IsHexDigit(c0_)) {
1000 // we must have at least one hex digit after 'x'/'X' 1009 // we must have at least one hex digit after 'x'/'X'
(...skipping 21 matching lines...) Expand all
1022 } 1031 }
1023 while (IsBinaryDigit(c0_)) { 1032 while (IsBinaryDigit(c0_)) {
1024 AddLiteralCharAdvance(); 1033 AddLiteralCharAdvance();
1025 } 1034 }
1026 } else if ('0' <= c0_ && c0_ <= '7') { 1035 } else if ('0' <= c0_ && c0_ <= '7') {
1027 // (possible) octal number 1036 // (possible) octal number
1028 kind = IMPLICIT_OCTAL; 1037 kind = IMPLICIT_OCTAL;
1029 while (true) { 1038 while (true) {
1030 if (c0_ == '8' || c0_ == '9') { 1039 if (c0_ == '8' || c0_ == '9') {
1031 at_start = false; 1040 at_start = false;
1032 kind = DECIMAL; 1041 kind = DECIMAL_WITH_LEADING_ZERO;
1033 break; 1042 break;
1034 } 1043 }
1035 if (c0_ < '0' || '7' < c0_) { 1044 if (c0_ < '0' || '7' < c0_) {
1036 // Octal literal finished. 1045 // Octal literal finished.
1037 octal_pos_ = Location(start_pos, source_pos()); 1046 octal_pos_ = Location(start_pos, source_pos());
1038 break; 1047 break;
1039 } 1048 }
1040 AddLiteralCharAdvance(); 1049 AddLiteralCharAdvance();
1041 } 1050 }
1051 } else if (c0_ == '8' || c0_ == '9') {
1052 kind = DECIMAL_WITH_LEADING_ZERO;
1042 } 1053 }
1043 } 1054 }
1044 1055
1045 // Parse decimal digits and allow trailing fractional part. 1056 // Parse decimal digits and allow trailing fractional part.
1046 if (kind == DECIMAL) { 1057 if (kind == DECIMAL || kind == DECIMAL_WITH_LEADING_ZERO) {
1047 if (at_start) { 1058 if (at_start) {
1048 uint64_t value = 0; 1059 uint64_t value = 0;
1049 while (IsDecimalDigit(c0_)) { 1060 while (IsDecimalDigit(c0_)) {
1050 value = 10 * value + (c0_ - '0'); 1061 value = 10 * value + (c0_ - '0');
1051 1062
1052 uc32 first_char = c0_; 1063 uc32 first_char = c0_;
1053 Advance<false, false>(); 1064 Advance<false, false>();
1054 AddLiteralChar(first_char); 1065 AddLiteralChar(first_char);
1055 } 1066 }
1056 1067
1057 if (next_.literal_chars->one_byte_literal().length() <= 10 && 1068 if (next_.literal_chars->one_byte_literal().length() <= 10 &&
1058 value <= Smi::kMaxValue && c0_ != '.' && c0_ != 'e' && c0_ != 'E') { 1069 value <= Smi::kMaxValue && c0_ != '.' && c0_ != 'e' && c0_ != 'E') {
1059 next_.smi_value_ = static_cast<int>(value); 1070 next_.smi_value_ = static_cast<int>(value);
1060 literal.Complete(); 1071 literal.Complete();
1061 HandleLeadSurrogate(); 1072 HandleLeadSurrogate();
1062 1073
1074 if (kind == DECIMAL_WITH_LEADING_ZERO)
1075 decimal_with_leading_zero_pos_ = Location(start_pos, source_pos());
1063 return Token::SMI; 1076 return Token::SMI;
1064 } 1077 }
1065 HandleLeadSurrogate(); 1078 HandleLeadSurrogate();
1066 } 1079 }
1067 1080
1068 ScanDecimalDigits(); // optional 1081 ScanDecimalDigits(); // optional
1069 if (c0_ == '.') { 1082 if (c0_ == '.') {
1070 AddLiteralCharAdvance(); 1083 AddLiteralCharAdvance();
1071 ScanDecimalDigits(); // optional 1084 ScanDecimalDigits(); // optional
1072 } 1085 }
1073 } 1086 }
1074 } 1087 }
1075 1088
1076 // scan exponent, if any 1089 // scan exponent, if any
1077 if (c0_ == 'e' || c0_ == 'E') { 1090 if (c0_ == 'e' || c0_ == 'E') {
1078 DCHECK(kind != HEX); // 'e'/'E' must be scanned as part of the hex number 1091 DCHECK(kind != HEX); // 'e'/'E' must be scanned as part of the hex number
1079 if (kind != DECIMAL) return Token::ILLEGAL; 1092 if (!(kind == DECIMAL || kind == DECIMAL_WITH_LEADING_ZERO))
1093 return Token::ILLEGAL;
1080 // scan exponent 1094 // scan exponent
1081 AddLiteralCharAdvance(); 1095 AddLiteralCharAdvance();
1082 if (c0_ == '+' || c0_ == '-') 1096 if (c0_ == '+' || c0_ == '-')
1083 AddLiteralCharAdvance(); 1097 AddLiteralCharAdvance();
1084 if (!IsDecimalDigit(c0_)) { 1098 if (!IsDecimalDigit(c0_)) {
1085 // we must have at least one decimal digit after 'e'/'E' 1099 // we must have at least one decimal digit after 'e'/'E'
1086 return Token::ILLEGAL; 1100 return Token::ILLEGAL;
1087 } 1101 }
1088 ScanDecimalDigits(); 1102 ScanDecimalDigits();
1089 } 1103 }
1090 1104
1091 // The source character immediately following a numeric literal must 1105 // The source character immediately following a numeric literal must
1092 // not be an identifier start or a decimal digit; see ECMA-262 1106 // not be an identifier start or a decimal digit; see ECMA-262
1093 // section 7.8.3, page 17 (note that we read only one decimal digit 1107 // section 7.8.3, page 17 (note that we read only one decimal digit
1094 // if the value is 0). 1108 // if the value is 0).
1095 if (IsDecimalDigit(c0_) || 1109 if (IsDecimalDigit(c0_) ||
1096 (c0_ >= 0 && unicode_cache_->IsIdentifierStart(c0_))) 1110 (c0_ >= 0 && unicode_cache_->IsIdentifierStart(c0_)))
1097 return Token::ILLEGAL; 1111 return Token::ILLEGAL;
1098 1112
1099 literal.Complete(); 1113 literal.Complete();
1100 1114
1115 if (kind == DECIMAL_WITH_LEADING_ZERO)
1116 decimal_with_leading_zero_pos_ = Location(start_pos, source_pos());
1101 return Token::NUMBER; 1117 return Token::NUMBER;
1102 } 1118 }
1103 1119
1104 1120
1105 uc32 Scanner::ScanIdentifierUnicodeEscape() { 1121 uc32 Scanner::ScanIdentifierUnicodeEscape() {
1106 Advance(); 1122 Advance();
1107 if (c0_ != 'u') return -1; 1123 if (c0_ != 'u') return -1;
1108 Advance(); 1124 Advance();
1109 return ScanUnicodeEscape<false>(); 1125 return ScanUnicodeEscape<false>();
1110 } 1126 }
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); 1703 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1688 } 1704 }
1689 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1705 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1690 1706
1691 backing_store_.AddBlock(bytes); 1707 backing_store_.AddBlock(bytes);
1692 return backing_store_.EndSequence().start(); 1708 return backing_store_.EndSequence().start();
1693 } 1709 }
1694 1710
1695 } // namespace internal 1711 } // namespace internal
1696 } // namespace v8 1712 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/scanner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698