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

Side by Side Diff: src/scanner.cc

Issue 1102523003: Implement a 'trial parse' step, that will abort pre-parsing excessively (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: The Great Rebase Adventure. Created 5 years, 8 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 11 matching lines...) Expand all
22 22
23 23
24 Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const { 24 Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const {
25 if (is_one_byte()) { 25 if (is_one_byte()) {
26 return isolate->factory()->InternalizeOneByteString(one_byte_literal()); 26 return isolate->factory()->InternalizeOneByteString(one_byte_literal());
27 } 27 }
28 return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); 28 return isolate->factory()->InternalizeTwoByteString(two_byte_literal());
29 } 29 }
30 30
31 31
32 // Default implementation for streams that do not support bookmarks.
33 bool Utf16CharacterStream::SetBookmark() { return false; }
34 void Utf16CharacterStream::ResetToBookmark() { UNREACHABLE(); }
35
36
32 // ---------------------------------------------------------------------------- 37 // ----------------------------------------------------------------------------
33 // Scanner 38 // Scanner
34 39
35 Scanner::Scanner(UnicodeCache* unicode_cache) 40 Scanner::Scanner(UnicodeCache* unicode_cache)
36 : unicode_cache_(unicode_cache), 41 : unicode_cache_(unicode_cache),
42 bookmark_c0_(-1),
37 octal_pos_(Location::invalid()), 43 octal_pos_(Location::invalid()),
38 harmony_modules_(false), 44 harmony_modules_(false),
39 harmony_classes_(false), 45 harmony_classes_(false),
40 harmony_unicode_(false) {} 46 harmony_unicode_(false) {
47 bookmark_current_.literal_chars = &bookmark_current_literal_;
48 bookmark_current_.raw_literal_chars = &bookmark_current_raw_literal_;
49 bookmark_next_.literal_chars = &bookmark_next_literal_;
50 bookmark_next_.raw_literal_chars = &bookmark_next_raw_literal_;
51 }
41 52
42 53
43 void Scanner::Initialize(Utf16CharacterStream* source) { 54 void Scanner::Initialize(Utf16CharacterStream* source) {
44 source_ = source; 55 source_ = source;
45 // Need to capture identifiers in order to recognize "get" and "set" 56 // Need to capture identifiers in order to recognize "get" and "set"
46 // in object literals. 57 // in object literals.
47 Init(); 58 Init();
48 // Skip initial whitespace allowing HTML comment ends just like 59 // Skip initial whitespace allowing HTML comment ends just like
49 // after a newline and scan first token. 60 // after a newline and scan first token.
50 has_line_terminator_before_next_ = true; 61 has_line_terminator_before_next_ = true;
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 1430
1420 1431
1421 int Scanner::FindSymbol(DuplicateFinder* finder, int value) { 1432 int Scanner::FindSymbol(DuplicateFinder* finder, int value) {
1422 if (is_literal_one_byte()) { 1433 if (is_literal_one_byte()) {
1423 return finder->AddOneByteSymbol(literal_one_byte_string(), value); 1434 return finder->AddOneByteSymbol(literal_one_byte_string(), value);
1424 } 1435 }
1425 return finder->AddTwoByteSymbol(literal_two_byte_string(), value); 1436 return finder->AddTwoByteSymbol(literal_two_byte_string(), value);
1426 } 1437 }
1427 1438
1428 1439
1440 bool Scanner::SetBookmark() {
1441 if (bookmark_c0_ == -1 && source_->SetBookmark()) {
1442 bookmark_c0_ = c0_;
1443 CopyTokenDesc(&bookmark_current_, &current_);
1444 CopyTokenDesc(&bookmark_next_, &next_);
1445 return true;
1446 }
1447 return false;
1448 }
1449
1450
1451 void Scanner::ResetToBookmark() {
1452 DCHECK(bookmark_c0_ >= 0); // Caller hasn't called SetBookmark.
1453
1454 source_->ResetToBookmark();
1455 c0_ = bookmark_c0_;
1456 StartLiteral();
1457 StartRawLiteral();
1458 CopyTokenDesc(&next_, &bookmark_current_);
1459 current_ = next_;
1460 StartLiteral();
1461 StartRawLiteral();
1462 CopyTokenDesc(&next_, &bookmark_next_);
1463
1464 bookmark_c0_ = -2;
1465 }
1466
1467
1468 bool Scanner::BookmarkHasBeenSet() { return bookmark_c0_ >= 0; }
1469
1470
1471 bool Scanner::BookmarkHasBeenReset() { return bookmark_c0_ == -2; }
1472
1473
1474 void Scanner::DropBookmark() { bookmark_c0_ = -1; }
1475
1476
1477 void Scanner::CopyTokenDesc(TokenDesc* to, TokenDesc* from) {
1478 DCHECK_NOT_NULL(to);
1479 DCHECK_NOT_NULL(from);
1480 to->token = from->token;
1481 to->location = from->location;
1482 to->literal_chars->CopyFrom(from->literal_chars);
1483 to->raw_literal_chars->CopyFrom(from->raw_literal_chars);
1484 }
1485
1486
1429 int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) { 1487 int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) {
1430 return AddSymbol(key, true, value); 1488 return AddSymbol(key, true, value);
1431 } 1489 }
1432 1490
1433 1491
1434 int DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key, int value) { 1492 int DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key, int value) {
1435 return AddSymbol(Vector<const uint8_t>::cast(key), false, value); 1493 return AddSymbol(Vector<const uint8_t>::cast(key), false, value);
1436 } 1494 }
1437 1495
1438 1496
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 } 1617 }
1560 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); 1618 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1561 } 1619 }
1562 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1620 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1563 1621
1564 backing_store_.AddBlock(bytes); 1622 backing_store_.AddBlock(bytes);
1565 return backing_store_.EndSequence().start(); 1623 return backing_store_.EndSequence().start();
1566 } 1624 }
1567 1625
1568 } } // namespace v8::internal 1626 } } // namespace v8::internal
OLDNEW
« src/scanner.h ('K') | « src/scanner.h ('k') | src/scanner-character-streams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698