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

Side by Side Diff: src/scanner.cc

Issue 160073006: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Version with parsing code only, tests into test-parsing.cc Created 6 years, 6 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
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 #include <cmath> 7 #include <cmath>
8 8
9 #include "src/scanner.h" 9 #include "src/scanner.h"
10 10
11 #include "include/v8stdint.h" 11 #include "include/v8stdint.h"
12 #include "src/ast-value-factory.h" 12 #include "src/ast-value-factory.h"
13 #include "src/char-predicates-inl.h" 13 #include "src/char-predicates-inl.h"
14 #include "src/conversions-inl.h" 14 #include "src/conversions-inl.h"
15 #include "src/list-inl.h" 15 #include "src/list-inl.h"
16 #include "src/v8.h" 16 #include "src/v8.h"
17 #include "src/parser.h" 17 #include "src/parser.h"
18 18
19 namespace v8 { 19 namespace v8 {
20 namespace internal { 20 namespace internal {
21 21
22 // ---------------------------------------------------------------------------- 22 // ----------------------------------------------------------------------------
23 // Scanner 23 // Scanner
24 24
25 Scanner::Scanner(UnicodeCache* unicode_cache) 25 Scanner::Scanner(UnicodeCache* unicode_cache)
26 : unicode_cache_(unicode_cache), 26 : unicode_cache_(unicode_cache),
27 param_list_finder_(unicode_cache_),
27 octal_pos_(Location::invalid()), 28 octal_pos_(Location::invalid()),
28 harmony_scoping_(false), 29 harmony_scoping_(false),
29 harmony_modules_(false), 30 harmony_modules_(false),
30 harmony_numeric_literals_(false) { } 31 harmony_numeric_literals_(false) { }
31 32
32 33
33 void Scanner::Initialize(Utf16CharacterStream* source) { 34 void Scanner::Initialize(Utf16CharacterStream* source) {
34 source_ = source; 35 source_ = source;
35 // Need to capture identifiers in order to recognize "get" and "set" 36 // Need to capture identifiers in order to recognize "get" and "set"
36 // in object literals. 37 // in object literals.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 Token::RBRACE, // 0x7d 204 Token::RBRACE, // 0x7d
204 Token::BIT_NOT, // 0x7e 205 Token::BIT_NOT, // 0x7e
205 Token::ILLEGAL 206 Token::ILLEGAL
206 }; 207 };
207 208
208 209
209 Token::Value Scanner::Next() { 210 Token::Value Scanner::Next() {
210 current_ = next_; 211 current_ = next_;
211 has_line_terminator_before_next_ = false; 212 has_line_terminator_before_next_ = false;
212 has_multiline_comment_before_next_ = false; 213 has_multiline_comment_before_next_ = false;
214 param_list_finder_.Update(this);
213 if (static_cast<unsigned>(c0_) <= 0x7f) { 215 if (static_cast<unsigned>(c0_) <= 0x7f) {
214 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); 216 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]);
215 if (token != Token::ILLEGAL) { 217 if (token != Token::ILLEGAL) {
216 int pos = source_pos(); 218 int pos = source_pos();
217 next_.token = token; 219 next_.token = token;
218 next_.location.beg_pos = pos; 220 next_.location.beg_pos = pos;
219 next_.location.end_pos = pos + 1; 221 next_.location.end_pos = pos + 1;
220 Advance(); 222 Advance();
221 return current_.token; 223 return current_.token;
222 } 224 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 token = Select('=', Token::ASSIGN_SHR, Token::SHR); 390 token = Select('=', Token::ASSIGN_SHR, Token::SHR);
389 } else { 391 } else {
390 token = Token::SAR; 392 token = Token::SAR;
391 } 393 }
392 } else { 394 } else {
393 token = Token::GT; 395 token = Token::GT;
394 } 396 }
395 break; 397 break;
396 398
397 case '=': 399 case '=':
398 // = == === 400 // = == === =>
399 Advance(); 401 Advance();
400 if (c0_ == '=') { 402 if (c0_ == '=') {
401 token = Select('=', Token::EQ_STRICT, Token::EQ); 403 token = Select('=', Token::EQ_STRICT, Token::EQ);
404 } else if (c0_ == '>') {
405 token = Select(Token::ARROW);
402 } else { 406 } else {
403 token = Token::ASSIGN; 407 token = Token::ASSIGN;
404 } 408 }
405 break; 409 break;
406 410
407 case '!': 411 case '!':
408 // ! != !== 412 // ! != !==
409 Advance(); 413 Advance();
410 if (c0_ == '=') { 414 if (c0_ == '=') {
411 token = Select('=', Token::NE_STRICT, Token::NE); 415 token = Select('=', Token::NE_STRICT, Token::NE);
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 (keyword_length <= 9 || input[9] == keyword[9])) { \ 925 (keyword_length <= 9 || input[9] == keyword[9])) { \
922 return token; \ 926 return token; \
923 } \ 927 } \
924 } 928 }
925 KEYWORDS(KEYWORD_GROUP_CASE, KEYWORD) 929 KEYWORDS(KEYWORD_GROUP_CASE, KEYWORD)
926 } 930 }
927 return Token::IDENTIFIER; 931 return Token::IDENTIFIER;
928 } 932 }
929 933
930 934
935 bool Scanner::IdentifierIsFutureStrictReserved(const AstString* string) const {
marja 2014/06/17 11:47:38 This sounds wrong, since we have a separate token
936 if (string->is_one_byte()) {
937 return Token::FUTURE_STRICT_RESERVED_WORD == KeywordOrIdentifierToken(
938 string->raw_data(), string->length(),
939 harmony_scoping_, harmony_modules_);
940 }
941
942 // Language keywords are always ASCII-only, so we can just pick the
943 // lower bytes to have a one-byte representation of the keyword.
944 const unsigned len = string->length();
945 Vector<unsigned char> chars = Vector<unsigned char>::New(len);
946 const uint16_t* uchars = reinterpret_cast<const uint16_t*>(string->raw_data()) ;
947
948 for (unsigned i = 0; i < len; i++)
949 (chars.start())[i] = 0xFF & uchars[i];
950
951 bool result = Token::FUTURE_STRICT_RESERVED_WORD == KeywordOrIdentifierToken(
952 chars.start(), len, harmony_scoping_, harmony_modules_);
953 chars.Dispose();
954 return result;
955 }
956
957
931 Token::Value Scanner::ScanIdentifierOrKeyword() { 958 Token::Value Scanner::ScanIdentifierOrKeyword() {
932 ASSERT(unicode_cache_->IsIdentifierStart(c0_)); 959 ASSERT(unicode_cache_->IsIdentifierStart(c0_));
933 LiteralScope literal(this); 960 LiteralScope literal(this);
934 // Scan identifier start character. 961 // Scan identifier start character.
935 if (c0_ == '\\') { 962 if (c0_ == '\\') {
936 uc32 c = ScanIdentifierUnicodeEscape(); 963 uc32 c = ScanIdentifierUnicodeEscape();
937 // Only allow legal identifier start characters. 964 // Only allow legal identifier start characters.
938 if (c < 0 || 965 if (c < 0 ||
939 c == '\\' || // No recursive escapes. 966 c == '\\' || // No recursive escapes.
940 !unicode_cache_->IsIdentifierStart(c)) { 967 !unicode_cache_->IsIdentifierStart(c)) {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 } 1292 }
1266 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); 1293 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1267 } 1294 }
1268 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1295 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1269 1296
1270 backing_store_.AddBlock(bytes); 1297 backing_store_.AddBlock(bytes);
1271 return backing_store_.EndSequence().start(); 1298 return backing_store_.EndSequence().start();
1272 } 1299 }
1273 1300
1274 } } // namespace v8::internal 1301 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698