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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()), | 81 decimal_with_leading_zero_pos_(Location::invalid()), |
82 found_html_comment_(false) { | 82 octal_message_(MessageTemplate::kNone), |
83 } | 83 found_html_comment_(false) {} |
84 | |
85 | 84 |
86 void Scanner::Initialize(Utf16CharacterStream* source) { | 85 void Scanner::Initialize(Utf16CharacterStream* source) { |
87 source_ = source; | 86 source_ = source; |
88 // Need to capture identifiers in order to recognize "get" and "set" | 87 // Need to capture identifiers in order to recognize "get" and "set" |
89 // in object literals. | 88 // in object literals. |
90 Init(); | 89 Init(); |
91 // Skip initial whitespace allowing HTML comment ends just like | 90 // Skip initial whitespace allowing HTML comment ends just like |
92 // after a newline and scan first token. | 91 // after a newline and scan first token. |
93 has_line_terminator_before_next_ = true; | 92 has_line_terminator_before_next_ = true; |
94 SkipWhiteSpace(); | 93 SkipWhiteSpace(); |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 x = nx; | 909 x = nx; |
911 Advance<capture_raw>(); | 910 Advance<capture_raw>(); |
912 } | 911 } |
913 // Anything except '\0' is an octal escape sequence, illegal in strict mode. | 912 // Anything except '\0' is an octal escape sequence, illegal in strict mode. |
914 // Remember the position of octal escape sequences so that an error | 913 // Remember the position of octal escape sequences so that an error |
915 // can be reported later (in strict mode). | 914 // can be reported later (in strict mode). |
916 // We don't report the error immediately, because the octal escape can | 915 // We don't report the error immediately, because the octal escape can |
917 // occur before the "use strict" directive. | 916 // occur before the "use strict" directive. |
918 if (c != '0' || i > 0) { | 917 if (c != '0' || i > 0) { |
919 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); | 918 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); |
| 919 octal_message_ = MessageTemplate::kStrictOctalEscape; |
920 } | 920 } |
921 return x; | 921 return x; |
922 } | 922 } |
923 | 923 |
924 | 924 |
925 Token::Value Scanner::ScanString() { | 925 Token::Value Scanner::ScanString() { |
926 uc32 quote = c0_; | 926 uc32 quote = c0_; |
927 Advance<false, false>(); // consume quote | 927 Advance<false, false>(); // consume quote |
928 | 928 |
929 LiteralScope literal(this); | 929 LiteralScope literal(this); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 kind = IMPLICIT_OCTAL; | 1123 kind = IMPLICIT_OCTAL; |
1124 while (true) { | 1124 while (true) { |
1125 if (c0_ == '8' || c0_ == '9') { | 1125 if (c0_ == '8' || c0_ == '9') { |
1126 at_start = false; | 1126 at_start = false; |
1127 kind = DECIMAL_WITH_LEADING_ZERO; | 1127 kind = DECIMAL_WITH_LEADING_ZERO; |
1128 break; | 1128 break; |
1129 } | 1129 } |
1130 if (c0_ < '0' || '7' < c0_) { | 1130 if (c0_ < '0' || '7' < c0_) { |
1131 // Octal literal finished. | 1131 // Octal literal finished. |
1132 octal_pos_ = Location(start_pos, source_pos()); | 1132 octal_pos_ = Location(start_pos, source_pos()); |
| 1133 octal_message_ = MessageTemplate::kStrictOctalLiteral; |
1133 break; | 1134 break; |
1134 } | 1135 } |
1135 AddLiteralCharAdvance(); | 1136 AddLiteralCharAdvance(); |
1136 } | 1137 } |
1137 } else if (c0_ == '8' || c0_ == '9') { | 1138 } else if (c0_ == '8' || c0_ == '9') { |
1138 kind = DECIMAL_WITH_LEADING_ZERO; | 1139 kind = DECIMAL_WITH_LEADING_ZERO; |
1139 } | 1140 } |
1140 } | 1141 } |
1141 | 1142 |
1142 // Parse decimal digits and allow trailing fractional part. | 1143 // Parse decimal digits and allow trailing fractional part. |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 // 2, reset the source to the desired position, | 1624 // 2, reset the source to the desired position, |
1624 source_->Seek(position); | 1625 source_->Seek(position); |
1625 // 3, re-scan, by scanning the look-ahead char + 1 token (next_). | 1626 // 3, re-scan, by scanning the look-ahead char + 1 token (next_). |
1626 c0_ = source_->Advance(); | 1627 c0_ = source_->Advance(); |
1627 Next(); | 1628 Next(); |
1628 DCHECK_EQ(next_.location.beg_pos, static_cast<int>(position)); | 1629 DCHECK_EQ(next_.location.beg_pos, static_cast<int>(position)); |
1629 } | 1630 } |
1630 | 1631 |
1631 } // namespace internal | 1632 } // namespace internal |
1632 } // namespace v8 | 1633 } // namespace v8 |
OLD | NEW |