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

Side by Side Diff: src/scanner.h

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

Powered by Google App Engine
This is Rietveld 408576698