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.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: Use a seperate 'hint' bit for "to be executed once" code aging. Created 5 years, 7 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
« no previous file with comments | « src/scanner.h ('k') | src/scanner-character-streams.h » ('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 #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_(kNoBookmark),
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 (c0_ != kNoBookmark && bookmark_c0_ == kNoBookmark &&
1442 source_->SetBookmark()) {
1443 bookmark_c0_ = c0_;
1444 CopyTokenDesc(&bookmark_current_, &current_);
1445 CopyTokenDesc(&bookmark_next_, &next_);
1446 return true;
1447 }
1448 return false;
1449 }
1450
1451
1452 void Scanner::ResetToBookmark() {
1453 DCHECK(BookmarkHasBeenSet()); // Caller hasn't called SetBookmark.
1454
1455 source_->ResetToBookmark();
1456 c0_ = bookmark_c0_;
1457 StartLiteral();
1458 StartRawLiteral();
1459 CopyTokenDesc(&next_, &bookmark_current_);
1460 current_ = next_;
1461 StartLiteral();
1462 StartRawLiteral();
1463 CopyTokenDesc(&next_, &bookmark_next_);
1464
1465 bookmark_c0_ = kBookmarkWasApplied;
1466 }
1467
1468
1469 bool Scanner::BookmarkHasBeenSet() { return bookmark_c0_ >= 0; }
1470
1471
1472 bool Scanner::BookmarkHasBeenReset() {
1473 return bookmark_c0_ == kBookmarkWasApplied;
1474 }
1475
1476
1477 void Scanner::DropBookmark() { bookmark_c0_ = kNoBookmark; }
1478
1479
1480 void Scanner::CopyTokenDesc(TokenDesc* to, TokenDesc* from) {
1481 DCHECK_NOT_NULL(to);
1482 DCHECK_NOT_NULL(from);
1483 to->token = from->token;
1484 to->location = from->location;
1485 to->literal_chars->CopyFrom(from->literal_chars);
1486 to->raw_literal_chars->CopyFrom(from->raw_literal_chars);
1487 }
1488
1489
1429 int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) { 1490 int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) {
1430 return AddSymbol(key, true, value); 1491 return AddSymbol(key, true, value);
1431 } 1492 }
1432 1493
1433 1494
1434 int DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key, int value) { 1495 int DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key, int value) {
1435 return AddSymbol(Vector<const uint8_t>::cast(key), false, value); 1496 return AddSymbol(Vector<const uint8_t>::cast(key), false, value);
1436 } 1497 }
1437 1498
1438 1499
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 } 1620 }
1560 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); 1621 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1561 } 1622 }
1562 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1623 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1563 1624
1564 backing_store_.AddBlock(bytes); 1625 backing_store_.AddBlock(bytes);
1565 return backing_store_.EndSequence().start(); 1626 return backing_store_.EndSequence().start();
1566 } 1627 }
1567 1628
1568 } } // namespace v8::internal 1629 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scanner.h ('k') | src/scanner-character-streams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698