Chromium Code Reviews| 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 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "src/scanner.h" | 9 #include "src/scanner.h" |
| 10 | 10 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 Token::RBRACE, // 0x7d | 202 Token::RBRACE, // 0x7d |
| 203 Token::BIT_NOT, // 0x7e | 203 Token::BIT_NOT, // 0x7e |
| 204 Token::ILLEGAL | 204 Token::ILLEGAL |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 | 207 |
| 208 Token::Value Scanner::Next() { | 208 Token::Value Scanner::Next() { |
| 209 current_ = next_; | 209 current_ = next_; |
| 210 has_line_terminator_before_next_ = false; | 210 has_line_terminator_before_next_ = false; |
| 211 has_multiline_comment_before_next_ = false; | 211 has_multiline_comment_before_next_ = false; |
| 212 has_source_map_comment_ = false; | |
| 212 if (static_cast<unsigned>(c0_) <= 0x7f) { | 213 if (static_cast<unsigned>(c0_) <= 0x7f) { |
| 213 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); | 214 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); |
| 214 if (token != Token::ILLEGAL) { | 215 if (token != Token::ILLEGAL) { |
| 215 int pos = source_pos(); | 216 int pos = source_pos(); |
| 216 next_.token = token; | 217 next_.token = token; |
| 217 next_.location.beg_pos = pos; | 218 next_.location.beg_pos = pos; |
| 218 next_.location.end_pos = pos + 1; | 219 next_.location.end_pos = pos + 1; |
| 219 Advance(); | 220 Advance(); |
| 220 return current_.token; | 221 return current_.token; |
| 221 } | 222 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 // stream of input elements for the syntactic grammar (see | 288 // stream of input elements for the syntactic grammar (see |
| 288 // ECMA-262, section 7.4). | 289 // ECMA-262, section 7.4). |
| 289 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { | 290 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { |
| 290 Advance(); | 291 Advance(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 return Token::WHITESPACE; | 294 return Token::WHITESPACE; |
| 294 } | 295 } |
| 295 | 296 |
| 296 | 297 |
| 298 Token::Value Scanner::SkipSourceMapComment() { | |
| 299 Advance(); | |
| 300 source_map_comment_.Reset(); | |
| 301 while (c0_ >= 0 && !unicode_cache_->IsLineTerminator(c0_)) { | |
| 302 source_map_comment_.AddChar(c0_); | |
| 303 Advance(); | |
| 304 } | |
| 305 has_source_map_comment_ = true; | |
| 306 return Token::WHITESPACE; | |
| 307 } | |
| 308 | |
| 309 | |
| 297 Token::Value Scanner::SkipMultiLineComment() { | 310 Token::Value Scanner::SkipMultiLineComment() { |
| 298 ASSERT(c0_ == '*'); | 311 ASSERT(c0_ == '*'); |
| 299 Advance(); | 312 Advance(); |
| 300 | 313 |
| 301 while (c0_ >= 0) { | 314 while (c0_ >= 0) { |
| 302 uc32 ch = c0_; | 315 uc32 ch = c0_; |
| 303 Advance(); | 316 Advance(); |
| 304 if (unicode_cache_->IsLineTerminator(ch)) { | 317 if (unicode_cache_->IsLineTerminator(ch)) { |
| 305 // Following ECMA-262, section 7.4, a comment containing | 318 // Following ECMA-262, section 7.4, a comment containing |
| 306 // a newline will make the comment count as a line-terminator. | 319 // a newline will make the comment count as a line-terminator. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 | 464 |
| 452 case '%': | 465 case '%': |
| 453 // % %= | 466 // % %= |
| 454 token = Select('=', Token::ASSIGN_MOD, Token::MOD); | 467 token = Select('=', Token::ASSIGN_MOD, Token::MOD); |
| 455 break; | 468 break; |
| 456 | 469 |
| 457 case '/': | 470 case '/': |
| 458 // / // /* /= | 471 // / // /* /= |
| 459 Advance(); | 472 Advance(); |
| 460 if (c0_ == '/') { | 473 if (c0_ == '/') { |
| 461 token = SkipSingleLineComment(); | 474 Advance(); |
| 475 if (c0_ == '@' || c0_ == '#') { | |
| 476 Advance(); | |
| 477 token = SkipSourceMapComment(); | |
|
yurys
2014/06/05 13:55:21
I believe we should consider only sourceURL that a
| |
| 478 } else { | |
| 479 PushBack(c0_); | |
| 480 token = SkipSingleLineComment(); | |
| 481 } | |
| 462 } else if (c0_ == '*') { | 482 } else if (c0_ == '*') { |
| 463 token = SkipMultiLineComment(); | 483 token = SkipMultiLineComment(); |
| 464 } else if (c0_ == '=') { | 484 } else if (c0_ == '=') { |
| 465 token = Select(Token::ASSIGN_DIV); | 485 token = Select(Token::ASSIGN_DIV); |
| 466 } else { | 486 } else { |
| 467 token = Token::DIV; | 487 token = Token::DIV; |
| 468 } | 488 } |
| 469 break; | 489 break; |
| 470 | 490 |
| 471 case '&': | 491 case '&': |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1086 Advance(); | 1106 Advance(); |
| 1087 } | 1107 } |
| 1088 } | 1108 } |
| 1089 literal.Complete(); | 1109 literal.Complete(); |
| 1090 | 1110 |
| 1091 next_.location.end_pos = source_pos() - 1; | 1111 next_.location.end_pos = source_pos() - 1; |
| 1092 return true; | 1112 return true; |
| 1093 } | 1113 } |
| 1094 | 1114 |
| 1095 | 1115 |
| 1116 Handle<String> Scanner::AllocateInternalizedSourceMapComment(Isolate* isolate) { | |
| 1117 if (source_map_comment_.is_one_byte()) { | |
| 1118 return isolate->factory()->InternalizeOneByteString( | |
| 1119 source_map_comment_.one_byte_literal()); | |
| 1120 } else { | |
| 1121 return isolate->factory()->InternalizeTwoByteString( | |
| 1122 source_map_comment_.two_byte_literal()); | |
| 1123 } | |
| 1124 } | |
| 1125 | |
| 1126 | |
| 1096 Handle<String> Scanner::AllocateNextLiteralString(Isolate* isolate, | 1127 Handle<String> Scanner::AllocateNextLiteralString(Isolate* isolate, |
| 1097 PretenureFlag tenured) { | 1128 PretenureFlag tenured) { |
| 1098 if (is_next_literal_one_byte()) { | 1129 if (is_next_literal_one_byte()) { |
| 1099 return isolate->factory()->NewStringFromOneByte( | 1130 return isolate->factory()->NewStringFromOneByte( |
| 1100 next_literal_one_byte_string(), tenured).ToHandleChecked(); | 1131 next_literal_one_byte_string(), tenured).ToHandleChecked(); |
| 1101 } else { | 1132 } else { |
| 1102 return isolate->factory()->NewStringFromTwoByte( | 1133 return isolate->factory()->NewStringFromTwoByte( |
| 1103 next_literal_two_byte_string(), tenured).ToHandleChecked(); | 1134 next_literal_two_byte_string(), tenured).ToHandleChecked(); |
| 1104 } | 1135 } |
| 1105 } | 1136 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 } | 1302 } |
| 1272 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1303 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
| 1273 } | 1304 } |
| 1274 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1305 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
| 1275 | 1306 |
| 1276 backing_store_.AddBlock(bytes); | 1307 backing_store_.AddBlock(bytes); |
| 1277 return backing_store_.EndSequence().start(); | 1308 return backing_store_.EndSequence().start(); |
| 1278 } | 1309 } |
| 1279 | 1310 |
| 1280 } } // namespace v8::internal | 1311 } } // namespace v8::internal |
| OLD | NEW |