OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 17 matching lines...) Expand all Loading... |
28 // Features shared by parsing and pre-parsing scanners. | 28 // Features shared by parsing and pre-parsing scanners. |
29 | 29 |
30 #include "../include/v8stdint.h" | 30 #include "../include/v8stdint.h" |
31 #include "scanner-base.h" | 31 #include "scanner-base.h" |
32 #include "char-predicates-inl.h" | 32 #include "char-predicates-inl.h" |
33 | 33 |
34 namespace v8 { | 34 namespace v8 { |
35 namespace internal { | 35 namespace internal { |
36 | 36 |
37 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
| 38 // UTF16Buffer |
| 39 |
| 40 UTF16Buffer::UTF16Buffer() |
| 41 : pos_(0), end_(kNoEndPosition) { } |
| 42 |
| 43 // ---------------------------------------------------------------------------- |
38 // LiteralCollector | 44 // LiteralCollector |
39 | 45 |
40 LiteralCollector::LiteralCollector() | 46 LiteralCollector::LiteralCollector() |
41 : buffer_(kInitialCapacity), recording_(false) { } | 47 : buffer_(kInitialCapacity), recording_(false) { } |
42 | 48 |
43 | 49 |
44 LiteralCollector::~LiteralCollector() {} | 50 LiteralCollector::~LiteralCollector() {} |
45 | 51 |
46 | 52 |
47 void LiteralCollector::AddCharSlow(uc32 c) { | 53 void LiteralCollector::AddCharSlow(uc32 c) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (!kIsIdentifierPart.get(buffer->GetNext())) { | 85 if (!kIsIdentifierPart.get(buffer->GetNext())) { |
80 return false; | 86 return false; |
81 } | 87 } |
82 } | 88 } |
83 return true; | 89 return true; |
84 } | 90 } |
85 | 91 |
86 // ---------------------------------------------------------------------------- | 92 // ---------------------------------------------------------------------------- |
87 // Scanner | 93 // Scanner |
88 | 94 |
89 Scanner::Scanner() { } | 95 Scanner::Scanner() : source_(NULL) {} |
90 | 96 |
91 | 97 |
92 uc32 Scanner::ScanHexEscape(uc32 c, int length) { | 98 uc32 Scanner::ScanHexEscape(uc32 c, int length) { |
93 ASSERT(length <= 4); // prevent overflow | 99 ASSERT(length <= 4); // prevent overflow |
94 | 100 |
95 uc32 digits[4]; | 101 uc32 digits[4]; |
96 uc32 x = 0; | 102 uc32 x = 0; |
97 for (int i = 0; i < length; i++) { | 103 for (int i = 0; i < length; i++) { |
98 digits[i] = c0_; | 104 digits[i] = c0_; |
99 int d = HexValue(c0_); | 105 int d = HexValue(c0_); |
(...skipping 29 matching lines...) Expand all Loading... |
129 x = nx; | 135 x = nx; |
130 Advance(); | 136 Advance(); |
131 } | 137 } |
132 return x; | 138 return x; |
133 } | 139 } |
134 | 140 |
135 | 141 |
136 // ---------------------------------------------------------------------------- | 142 // ---------------------------------------------------------------------------- |
137 // JavaScriptScanner | 143 // JavaScriptScanner |
138 | 144 |
139 JavaScriptScanner::JavaScriptScanner() : Scanner() {} | 145 JavaScriptScanner::JavaScriptScanner() |
| 146 : has_line_terminator_before_next_(false) {} |
140 | 147 |
141 | 148 |
142 Token::Value JavaScriptScanner::Next() { | 149 Token::Value JavaScriptScanner::Next() { |
143 current_ = next_; | 150 current_ = next_; |
144 has_line_terminator_before_next_ = false; | 151 has_line_terminator_before_next_ = false; |
145 Scan(); | 152 Scan(); |
146 return current_.token; | 153 return current_.token; |
147 } | 154 } |
148 | 155 |
149 | 156 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // Continue scanning for tokens as long as we're just skipping | 496 // Continue scanning for tokens as long as we're just skipping |
490 // whitespace. | 497 // whitespace. |
491 } while (token == Token::WHITESPACE); | 498 } while (token == Token::WHITESPACE); |
492 | 499 |
493 next_.location.end_pos = source_pos(); | 500 next_.location.end_pos = source_pos(); |
494 next_.token = token; | 501 next_.token = token; |
495 } | 502 } |
496 | 503 |
497 | 504 |
498 void JavaScriptScanner::SeekForward(int pos) { | 505 void JavaScriptScanner::SeekForward(int pos) { |
499 // After this call, we will have the token at the given position as | 506 source_->SeekForward(pos - 1); |
500 // the "next" token. The "current" token will be invalid. | 507 Advance(); |
501 if (pos == next_.location.beg_pos) return; | 508 // This function is only called to seek to the location |
502 int current_pos = source_pos(); | 509 // of the end of a function (at the "}" token). It doesn't matter |
503 ASSERT_EQ(next_.location.end_pos, current_pos); | 510 // whether there was a line terminator in the part we skip. |
504 // Positions inside the lookahead token aren't supported. | 511 has_line_terminator_before_next_ = false; |
505 ASSERT(pos >= current_pos); | |
506 if (pos != current_pos) { | |
507 source_->SeekForward(pos - source_->pos()); | |
508 Advance(); | |
509 // This function is only called to seek to the location | |
510 // of the end of a function (at the "}" token). It doesn't matter | |
511 // whether there was a line terminator in the part we skip. | |
512 has_line_terminator_before_next_ = false; | |
513 } | |
514 Scan(); | 512 Scan(); |
515 } | 513 } |
516 | 514 |
517 | 515 |
518 void JavaScriptScanner::ScanEscape() { | 516 void JavaScriptScanner::ScanEscape() { |
519 uc32 c = c0_; | 517 uc32 c = c0_; |
520 Advance(); | 518 Advance(); |
521 | 519 |
522 // Skip escaped newlines. | 520 // Skip escaped newlines. |
523 if (ScannerConstants::kIsLineTerminator.get(c)) { | 521 if (ScannerConstants::kIsLineTerminator.get(c)) { |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | 914 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; |
917 break; | 915 break; |
918 case UNMATCHABLE: | 916 case UNMATCHABLE: |
919 break; | 917 break; |
920 } | 918 } |
921 // On fallthrough, it's a failure. | 919 // On fallthrough, it's a failure. |
922 state_ = UNMATCHABLE; | 920 state_ = UNMATCHABLE; |
923 } | 921 } |
924 | 922 |
925 } } // namespace v8::internal | 923 } } // namespace v8::internal |
OLD | NEW |