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

Side by Side Diff: src/scanner.h

Issue 1429983002: [es6] early error when Identifier is an escaped reserved word (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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
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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 Location location() const { return current_.location; } 366 Location location() const { return current_.location; }
367 367
368 // Similar functions for the upcoming token. 368 // Similar functions for the upcoming token.
369 369
370 // One token look-ahead (past the token returned by Next()). 370 // One token look-ahead (past the token returned by Next()).
371 Token::Value peek() const { return next_.token; } 371 Token::Value peek() const { return next_.token; }
372 372
373 Location peek_location() const { return next_.location; } 373 Location peek_location() const { return next_.location; }
374 374
375 bool literal_contains_escapes() const { 375 bool literal_contains_escapes() const {
376 Location location = current_.location; 376 return literal_contains_escapes(current_);
377 int source_length = (location.end_pos - location.beg_pos); 377 }
378 if (current_.token == Token::STRING) { 378 bool next_literal_contains_escapes() const {
379 // Subtract delimiters. 379 return literal_contains_escapes(next_);
380 source_length -= 2;
381 }
382 return current_.literal_chars->length() != source_length;
383 } 380 }
384 bool is_literal_contextual_keyword(Vector<const char> keyword) { 381 bool is_literal_contextual_keyword(Vector<const char> keyword) {
385 DCHECK_NOT_NULL(current_.literal_chars); 382 DCHECK_NOT_NULL(current_.literal_chars);
386 return current_.literal_chars->is_contextual_keyword(keyword); 383 return current_.literal_chars->is_contextual_keyword(keyword);
387 } 384 }
388 bool is_next_contextual_keyword(Vector<const char> keyword) { 385 bool is_next_contextual_keyword(Vector<const char> keyword) {
389 DCHECK_NOT_NULL(next_.literal_chars); 386 DCHECK_NOT_NULL(next_.literal_chars);
390 return next_.literal_chars->is_contextual_keyword(keyword); 387 return next_.literal_chars->is_contextual_keyword(keyword);
391 } 388 }
392 389
393 const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory); 390 const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory);
394 const AstRawString* NextSymbol(AstValueFactory* ast_value_factory); 391 const AstRawString* NextSymbol(AstValueFactory* ast_value_factory);
395 const AstRawString* CurrentRawSymbol(AstValueFactory* ast_value_factory); 392 const AstRawString* CurrentRawSymbol(AstValueFactory* ast_value_factory);
396 393
394 bool IsNextEscapedReservedWord(LanguageMode language_mode, bool is_generator,
395 bool allow_sloppy_let);
396
397 double DoubleValue(); 397 double DoubleValue();
398 bool ContainsDot(); 398 bool ContainsDot();
399 bool LiteralMatches(const char* data, int length, bool allow_escapes = true) { 399 bool LiteralMatches(const char* data, int length, bool allow_escapes = true) {
400 if (is_literal_one_byte() && 400 if (is_literal_one_byte() &&
401 literal_length() == length && 401 literal_length() == length &&
402 (allow_escapes || !literal_contains_escapes())) { 402 (allow_escapes || !literal_contains_escapes())) {
403 const char* token = 403 const char* token =
404 reinterpret_cast<const char*>(literal_one_byte_string().start()); 404 reinterpret_cast<const char*>(literal_one_byte_string().start());
405 return !strncmp(token, data, length); 405 return !strncmp(token, data, length);
406 } 406 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 template <bool capture_raw> 682 template <bool capture_raw>
683 uc32 ScanUnicodeEscape(); 683 uc32 ScanUnicodeEscape();
684 684
685 Token::Value ScanTemplateSpan(); 685 Token::Value ScanTemplateSpan();
686 686
687 // Return the current source position. 687 // Return the current source position.
688 int source_pos() { 688 int source_pos() {
689 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize; 689 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize;
690 } 690 }
691 691
692 bool literal_contains_escapes(const TokenDesc& token) const {
adamk 2015/11/03 23:00:57 This could be static (and thus not const). And Cam
caitp (gmail) 2015/11/04 04:49:24 Done.
693 Location location = token.location;
694 int source_length = (location.end_pos - location.beg_pos);
695 if (token.token == Token::STRING) {
696 // Subtract delimiters.
697 source_length -= 2;
698 }
699 return token.literal_chars->length() != source_length;
700 }
701
692 UnicodeCache* unicode_cache_; 702 UnicodeCache* unicode_cache_;
693 703
694 // Buffers collecting literal strings, numbers, etc. 704 // Buffers collecting literal strings, numbers, etc.
695 LiteralBuffer literal_buffer0_; 705 LiteralBuffer literal_buffer0_;
696 LiteralBuffer literal_buffer1_; 706 LiteralBuffer literal_buffer1_;
697 LiteralBuffer literal_buffer2_; 707 LiteralBuffer literal_buffer2_;
698 708
699 // Values parsed from magic comments. 709 // Values parsed from magic comments.
700 LiteralBuffer source_url_; 710 LiteralBuffer source_url_;
701 LiteralBuffer source_mapping_url_; 711 LiteralBuffer source_mapping_url_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 bool has_line_terminator_before_next_; 766 bool has_line_terminator_before_next_;
757 // Whether there is a multi-line comment that contains a 767 // Whether there is a multi-line comment that contains a
758 // line-terminator after the current token, and before the next. 768 // line-terminator after the current token, and before the next.
759 bool has_multiline_comment_before_next_; 769 bool has_multiline_comment_before_next_;
760 }; 770 };
761 771
762 } // namespace internal 772 } // namespace internal
763 } // namespace v8 773 } // namespace v8
764 774
765 #endif // V8_SCANNER_H_ 775 #endif // V8_SCANNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698