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 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); | 28 return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); |
29 } | 29 } |
30 | 30 |
31 | 31 |
32 // ---------------------------------------------------------------------------- | 32 // ---------------------------------------------------------------------------- |
33 // Scanner | 33 // Scanner |
34 | 34 |
35 Scanner::Scanner(UnicodeCache* unicode_cache) | 35 Scanner::Scanner(UnicodeCache* unicode_cache) |
36 : unicode_cache_(unicode_cache), | 36 : unicode_cache_(unicode_cache), |
| 37 capturing_raw_literal_(false), |
37 octal_pos_(Location::invalid()), | 38 octal_pos_(Location::invalid()), |
38 harmony_scoping_(false), | 39 harmony_scoping_(false), |
39 harmony_modules_(false), | 40 harmony_modules_(false), |
40 harmony_numeric_literals_(false), | 41 harmony_numeric_literals_(false), |
41 harmony_classes_(false), | 42 harmony_classes_(false), |
42 harmony_templates_(false) {} | 43 harmony_templates_(false) {} |
43 | 44 |
44 | 45 |
45 void Scanner::Initialize(Utf16CharacterStream* source) { | 46 void Scanner::Initialize(Utf16CharacterStream* source) { |
46 source_ = source; | 47 source_ = source; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 PushBack('-'); // undo Advance() | 397 PushBack('-'); // undo Advance() |
397 } | 398 } |
398 PushBack('!'); // undo Advance() | 399 PushBack('!'); // undo Advance() |
399 DCHECK(c0_ == '!'); | 400 DCHECK(c0_ == '!'); |
400 return Token::LT; | 401 return Token::LT; |
401 } | 402 } |
402 | 403 |
403 | 404 |
404 void Scanner::Scan() { | 405 void Scanner::Scan() { |
405 next_.literal_chars = NULL; | 406 next_.literal_chars = NULL; |
| 407 next_.raw_literal_chars = NULL; |
406 Token::Value token; | 408 Token::Value token; |
407 do { | 409 do { |
408 // Remember the position of the next token | 410 // Remember the position of the next token |
409 next_.location.beg_pos = source_pos(); | 411 next_.location.beg_pos = source_pos(); |
410 | 412 |
411 switch (c0_) { | 413 switch (c0_) { |
412 case ' ': | 414 case ' ': |
413 case '\t': | 415 case '\t': |
414 Advance(); | 416 Advance(); |
415 token = Token::WHITESPACE; | 417 token = Token::WHITESPACE; |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 // After parsing an Expression, the source position is incorrect due to | 797 // After parsing an Expression, the source position is incorrect due to |
796 // having scanned the brace. Push the RBRACE back into the stream. | 798 // having scanned the brace. Push the RBRACE back into the stream. |
797 PushBack('}'); | 799 PushBack('}'); |
798 } | 800 } |
799 | 801 |
800 next_.location.beg_pos = source_pos(); | 802 next_.location.beg_pos = source_pos(); |
801 Token::Value result = Token::TEMPLATE_SPAN; | 803 Token::Value result = Token::TEMPLATE_SPAN; |
802 DCHECK(c0_ == '`' || c0_ == '}'); | 804 DCHECK(c0_ == '`' || c0_ == '}'); |
803 Advance(); // Consume ` or } | 805 Advance(); // Consume ` or } |
804 | 806 |
805 LiteralScope literal(this); | 807 LiteralScope literal(this, true); |
| 808 |
806 while (true) { | 809 while (true) { |
807 uc32 c = c0_; | 810 uc32 c = c0_; |
808 Advance(); | 811 Advance(); |
809 if (c == '`') { | 812 if (c == '`') { |
810 result = Token::TEMPLATE_TAIL; | 813 result = Token::TEMPLATE_TAIL; |
| 814 ReduceRawLiteralLength(1); |
811 break; | 815 break; |
812 } else if (c == '$' && c0_ == '{') { | 816 } else if (c == '$' && c0_ == '{') { |
813 Advance(); // Consume '{' | 817 Advance(); // Consume '{' |
| 818 ReduceRawLiteralLength(2); |
814 break; | 819 break; |
815 } else if (c == '\\') { | 820 } else if (c == '\\') { |
816 if (unicode_cache_->IsLineTerminator(c0_)) { | 821 if (unicode_cache_->IsLineTerminator(c0_)) { |
817 // The TV of LineContinuation :: \ LineTerminatorSequence is the empty | 822 // The TV of LineContinuation :: \ LineTerminatorSequence is the empty |
818 // code unit sequence. | 823 // code unit sequence. |
819 uc32 lastChar = c0_; | 824 uc32 lastChar = c0_; |
820 Advance(); | 825 Advance(); |
821 if (lastChar == '\r' && c0_ == '\n') Advance(); | 826 if (lastChar == '\r') { |
| 827 ReduceRawLiteralLength(1); // Remove \r |
| 828 if (c0_ == '\n') { |
| 829 Advance(); // Adds \n |
| 830 } else { |
| 831 AddRawLiteralChar('\n'); |
| 832 } |
| 833 } |
822 } else if (c0_ == '0') { | 834 } else if (c0_ == '0') { |
823 Advance(); | 835 Advance(); |
824 AddLiteralChar('0'); | 836 AddLiteralChar('0'); |
825 } else { | 837 } else { |
826 ScanEscape(); | 838 ScanEscape(); |
827 } | 839 } |
828 } else if (c < 0) { | 840 } else if (c < 0) { |
829 // Unterminated template literal | 841 // Unterminated template literal |
830 PushBack(c); | 842 PushBack(c); |
831 break; | 843 break; |
832 } else { | 844 } else { |
833 // The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A. | 845 // The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A. |
834 // The TRV of LineTerminatorSequence :: <CR><LF> is the sequence | 846 // The TRV of LineTerminatorSequence :: <CR><LF> is the sequence |
835 // consisting of the CV 0x000A. | 847 // consisting of the CV 0x000A. |
836 if (c == '\r') { | 848 if (c == '\r') { |
837 if (c0_ == '\n') Advance(); | 849 ReduceRawLiteralLength(1); // Remove \r |
| 850 if (c0_ == '\n') { |
| 851 Advance(); // Adds \n |
| 852 } else { |
| 853 AddRawLiteralChar('\n'); |
| 854 } |
838 c = '\n'; | 855 c = '\n'; |
839 } | 856 } |
840 AddLiteralChar(c); | 857 AddLiteralChar(c); |
841 } | 858 } |
842 } | 859 } |
843 literal.Complete(); | 860 literal.Complete(); |
844 next_.location.end_pos = source_pos(); | 861 next_.location.end_pos = source_pos(); |
845 next_.token = result; | 862 next_.token = result; |
846 return result; | 863 return result; |
847 } | 864 } |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 | 1258 |
1242 | 1259 |
1243 const AstRawString* Scanner::NextSymbol(AstValueFactory* ast_value_factory) { | 1260 const AstRawString* Scanner::NextSymbol(AstValueFactory* ast_value_factory) { |
1244 if (is_next_literal_one_byte()) { | 1261 if (is_next_literal_one_byte()) { |
1245 return ast_value_factory->GetOneByteString(next_literal_one_byte_string()); | 1262 return ast_value_factory->GetOneByteString(next_literal_one_byte_string()); |
1246 } | 1263 } |
1247 return ast_value_factory->GetTwoByteString(next_literal_two_byte_string()); | 1264 return ast_value_factory->GetTwoByteString(next_literal_two_byte_string()); |
1248 } | 1265 } |
1249 | 1266 |
1250 | 1267 |
| 1268 const AstRawString* Scanner::CurrentRawSymbol( |
| 1269 AstValueFactory* ast_value_factory) { |
| 1270 if (is_raw_literal_one_byte()) { |
| 1271 return ast_value_factory->GetOneByteString(raw_literal_one_byte_string()); |
| 1272 } |
| 1273 return ast_value_factory->GetTwoByteString(raw_literal_two_byte_string()); |
| 1274 } |
| 1275 |
| 1276 |
1251 double Scanner::DoubleValue() { | 1277 double Scanner::DoubleValue() { |
1252 DCHECK(is_literal_one_byte()); | 1278 DCHECK(is_literal_one_byte()); |
1253 return StringToDouble( | 1279 return StringToDouble( |
1254 unicode_cache_, | 1280 unicode_cache_, |
1255 literal_one_byte_string(), | 1281 literal_one_byte_string(), |
1256 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); | 1282 ALLOW_HEX | ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); |
1257 } | 1283 } |
1258 | 1284 |
1259 | 1285 |
1260 int Scanner::FindNumber(DuplicateFinder* finder, int value) { | 1286 int Scanner::FindNumber(DuplicateFinder* finder, int value) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 } | 1429 } |
1404 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1430 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1405 } | 1431 } |
1406 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1432 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1407 | 1433 |
1408 backing_store_.AddBlock(bytes); | 1434 backing_store_.AddBlock(bytes); |
1409 return backing_store_.EndSequence().start(); | 1435 return backing_store_.EndSequence().start(); |
1410 } | 1436 } |
1411 | 1437 |
1412 } } // namespace v8::internal | 1438 } } // namespace v8::internal |
OLD | NEW |