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 #ifndef V8_SCANNER_H_ | 7 #ifndef V8_SCANNER_H_ |
8 #define V8_SCANNER_H_ | 8 #define V8_SCANNER_H_ |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 position_ += kOneByteSize; | 207 position_ += kOneByteSize; |
208 return; | 208 return; |
209 } | 209 } |
210 ConvertToTwoByte(); | 210 ConvertToTwoByte(); |
211 } | 211 } |
212 ASSERT(code_unit < 0x10000u); | 212 ASSERT(code_unit < 0x10000u); |
213 *reinterpret_cast<uint16_t*>(&backing_store_[position_]) = code_unit; | 213 *reinterpret_cast<uint16_t*>(&backing_store_[position_]) = code_unit; |
214 position_ += kUC16Size; | 214 position_ += kUC16Size; |
215 } | 215 } |
216 | 216 |
217 bool is_one_byte() { return is_one_byte_; } | 217 bool is_one_byte() const { return is_one_byte_; } |
218 | 218 |
219 bool is_contextual_keyword(Vector<const char> keyword) { | 219 bool is_contextual_keyword(Vector<const char> keyword) const { |
220 return is_one_byte() && keyword.length() == position_ && | 220 return is_one_byte() && keyword.length() == position_ && |
221 (memcmp(keyword.start(), backing_store_.start(), position_) == 0); | 221 (memcmp(keyword.start(), backing_store_.start(), position_) == 0); |
222 } | 222 } |
223 | 223 |
224 Vector<const uint16_t> two_byte_literal() { | 224 Vector<const uint16_t> two_byte_literal() const { |
225 ASSERT(!is_one_byte_); | 225 ASSERT(!is_one_byte_); |
226 ASSERT((position_ & 0x1) == 0); | 226 ASSERT((position_ & 0x1) == 0); |
227 return Vector<const uint16_t>( | 227 return Vector<const uint16_t>( |
228 reinterpret_cast<const uint16_t*>(backing_store_.start()), | 228 reinterpret_cast<const uint16_t*>(backing_store_.start()), |
229 position_ >> 1); | 229 position_ >> 1); |
230 } | 230 } |
231 | 231 |
232 Vector<const uint8_t> one_byte_literal() { | 232 Vector<const uint8_t> one_byte_literal() const { |
233 ASSERT(is_one_byte_); | 233 ASSERT(is_one_byte_); |
234 return Vector<const uint8_t>( | 234 return Vector<const uint8_t>( |
235 reinterpret_cast<const uint8_t*>(backing_store_.start()), | 235 reinterpret_cast<const uint8_t*>(backing_store_.start()), |
236 position_); | 236 position_); |
237 } | 237 } |
238 | 238 |
239 int length() { | 239 int length() const { |
240 return is_one_byte_ ? position_ : (position_ >> 1); | 240 return is_one_byte_ ? position_ : (position_ >> 1); |
241 } | 241 } |
242 | 242 |
243 void Reset() { | 243 void Reset() { |
244 position_ = 0; | 244 position_ = 0; |
245 is_one_byte_ = true; | 245 is_one_byte_ = true; |
246 } | 246 } |
247 | 247 |
| 248 Handle<String> Internalize(Isolate* isolate) const; |
| 249 |
248 private: | 250 private: |
249 static const int kInitialCapacity = 16; | 251 static const int kInitialCapacity = 16; |
250 static const int kGrowthFactory = 4; | 252 static const int kGrowthFactory = 4; |
251 static const int kMinConversionSlack = 256; | 253 static const int kMinConversionSlack = 256; |
252 static const int kMaxGrowth = 1 * MB; | 254 static const int kMaxGrowth = 1 * MB; |
253 inline int NewCapacity(int min_capacity) { | 255 inline int NewCapacity(int min_capacity) { |
254 int capacity = Max(min_capacity, backing_store_.length()); | 256 int capacity = Max(min_capacity, backing_store_.length()); |
255 int new_capacity = Min(capacity * kGrowthFactory, capacity + kMaxGrowth); | 257 int new_capacity = Min(capacity * kGrowthFactory, capacity + kMaxGrowth); |
256 return new_capacity; | 258 return new_capacity; |
257 } | 259 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 has_multiline_comment_before_next_; | 445 has_multiline_comment_before_next_; |
444 } | 446 } |
445 | 447 |
446 // Scans the input as a regular expression pattern, previous | 448 // Scans the input as a regular expression pattern, previous |
447 // character(s) must be /(=). Returns true if a pattern is scanned. | 449 // character(s) must be /(=). Returns true if a pattern is scanned. |
448 bool ScanRegExpPattern(bool seen_equal); | 450 bool ScanRegExpPattern(bool seen_equal); |
449 // Returns true if regexp flags are scanned (always since flags can | 451 // Returns true if regexp flags are scanned (always since flags can |
450 // be empty). | 452 // be empty). |
451 bool ScanRegExpFlags(); | 453 bool ScanRegExpFlags(); |
452 | 454 |
| 455 const LiteralBuffer* source_url() const { return &source_url_; } |
| 456 const LiteralBuffer* source_mapping_url() const { |
| 457 return &source_mapping_url_; |
| 458 } |
| 459 |
453 private: | 460 private: |
454 // The current and look-ahead token. | 461 // The current and look-ahead token. |
455 struct TokenDesc { | 462 struct TokenDesc { |
456 Token::Value token; | 463 Token::Value token; |
457 Location location; | 464 Location location; |
458 LiteralBuffer* literal_chars; | 465 LiteralBuffer* literal_chars; |
459 }; | 466 }; |
460 | 467 |
461 static const int kCharacterLookaheadBufferSize = 1; | 468 static const int kCharacterLookaheadBufferSize = 1; |
462 | 469 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 return next_.literal_chars->length(); | 571 return next_.literal_chars->length(); |
565 } | 572 } |
566 | 573 |
567 uc32 ScanHexNumber(int expected_length); | 574 uc32 ScanHexNumber(int expected_length); |
568 | 575 |
569 // Scans a single JavaScript token. | 576 // Scans a single JavaScript token. |
570 void Scan(); | 577 void Scan(); |
571 | 578 |
572 bool SkipWhiteSpace(); | 579 bool SkipWhiteSpace(); |
573 Token::Value SkipSingleLineComment(); | 580 Token::Value SkipSingleLineComment(); |
| 581 Token::Value SkipMagicComment(); |
| 582 void TryToParseMagicComment(); |
574 Token::Value SkipMultiLineComment(); | 583 Token::Value SkipMultiLineComment(); |
575 // Scans a possible HTML comment -- begins with '<!'. | 584 // Scans a possible HTML comment -- begins with '<!'. |
576 Token::Value ScanHtmlComment(); | 585 Token::Value ScanHtmlComment(); |
577 | 586 |
578 void ScanDecimalDigits(); | 587 void ScanDecimalDigits(); |
579 Token::Value ScanNumber(bool seen_period); | 588 Token::Value ScanNumber(bool seen_period); |
580 Token::Value ScanIdentifierOrKeyword(); | 589 Token::Value ScanIdentifierOrKeyword(); |
581 Token::Value ScanIdentifierSuffix(LiteralScope* literal); | 590 Token::Value ScanIdentifierSuffix(LiteralScope* literal); |
582 | 591 |
583 Token::Value ScanString(); | 592 Token::Value ScanString(); |
(...skipping 14 matching lines...) Expand all Loading... |
598 int source_pos() { | 607 int source_pos() { |
599 return source_->pos() - kCharacterLookaheadBufferSize; | 608 return source_->pos() - kCharacterLookaheadBufferSize; |
600 } | 609 } |
601 | 610 |
602 UnicodeCache* unicode_cache_; | 611 UnicodeCache* unicode_cache_; |
603 | 612 |
604 // Buffers collecting literal strings, numbers, etc. | 613 // Buffers collecting literal strings, numbers, etc. |
605 LiteralBuffer literal_buffer1_; | 614 LiteralBuffer literal_buffer1_; |
606 LiteralBuffer literal_buffer2_; | 615 LiteralBuffer literal_buffer2_; |
607 | 616 |
| 617 // Values parsed from magic comments. |
| 618 LiteralBuffer source_url_; |
| 619 LiteralBuffer source_mapping_url_; |
| 620 |
608 TokenDesc current_; // desc for current token (as returned by Next()) | 621 TokenDesc current_; // desc for current token (as returned by Next()) |
609 TokenDesc next_; // desc for next token (one token look-ahead) | 622 TokenDesc next_; // desc for next token (one token look-ahead) |
610 | 623 |
611 // Input stream. Must be initialized to an Utf16CharacterStream. | 624 // Input stream. Must be initialized to an Utf16CharacterStream. |
612 Utf16CharacterStream* source_; | 625 Utf16CharacterStream* source_; |
613 | 626 |
614 | 627 |
615 // Start position of the octal literal last scanned. | 628 // Start position of the octal literal last scanned. |
616 Location octal_pos_; | 629 Location octal_pos_; |
617 | 630 |
(...skipping 11 matching lines...) Expand all Loading... |
629 bool harmony_scoping_; | 642 bool harmony_scoping_; |
630 // Whether we scan 'module', 'import', 'export' as keywords. | 643 // Whether we scan 'module', 'import', 'export' as keywords. |
631 bool harmony_modules_; | 644 bool harmony_modules_; |
632 // Whether we scan 0o777 and 0b111 as numbers. | 645 // Whether we scan 0o777 and 0b111 as numbers. |
633 bool harmony_numeric_literals_; | 646 bool harmony_numeric_literals_; |
634 }; | 647 }; |
635 | 648 |
636 } } // namespace v8::internal | 649 } } // namespace v8::internal |
637 | 650 |
638 #endif // V8_SCANNER_H_ | 651 #endif // V8_SCANNER_H_ |
OLD | NEW |