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

Side by Side Diff: src/preparser.cc

Issue 12646003: Add parser support for generators. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Created 7 years, 9 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/preparser.h ('k') | src/scanner.cc » ('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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 1112
1113 case i::Token::FUTURE_RESERVED_WORD: { 1113 case i::Token::FUTURE_RESERVED_WORD: {
1114 Next(); 1114 Next();
1115 i::Scanner::Location location = scanner_->location(); 1115 i::Scanner::Location location = scanner_->location();
1116 ReportMessageAt(location.beg_pos, location.end_pos, 1116 ReportMessageAt(location.beg_pos, location.end_pos,
1117 "reserved_word", NULL); 1117 "reserved_word", NULL);
1118 *ok = false; 1118 *ok = false;
1119 return Expression::Default(); 1119 return Expression::Default();
1120 } 1120 }
1121 1121
1122 // FIXME!!!!
1123 case i::Token::YIELD:
wingo 2013/03/11 12:10:53 This FIXME is to mark that this case and the FUTUR
1124 if (scope_->is_generator()) {
1125 // 'yield' in a generator is only valid as part of a YieldExpression.
1126 i::Scanner::Location location = scanner_->location();
1127 ReportMessageAt(location, "unexpected_token", NULL);
1128 *ok = false;
1129 return Expression::Default();
1130 }
1131 // FALLTHROUGH
1122 case i::Token::FUTURE_STRICT_RESERVED_WORD: 1132 case i::Token::FUTURE_STRICT_RESERVED_WORD:
1123 if (!is_classic_mode()) { 1133 if (!is_classic_mode()) {
1124 Next(); 1134 Next();
1125 i::Scanner::Location location = scanner_->location(); 1135 i::Scanner::Location location = scanner_->location();
1126 ReportMessageAt(location, "strict_reserved_word", NULL); 1136 ReportMessageAt(location, "strict_reserved_word", NULL);
1127 *ok = false; 1137 *ok = false;
1128 return Expression::Default(); 1138 return Expression::Default();
1129 } 1139 }
1130 // FALLTHROUGH 1140 // FALLTHROUGH
1131 case i::Token::IDENTIFIER: { 1141 case i::Token::IDENTIFIER: {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 } 1516 }
1507 1517
1508 1518
1509 PreParser::Identifier PreParser::GetIdentifierSymbol() { 1519 PreParser::Identifier PreParser::GetIdentifierSymbol() {
1510 LogSymbol(); 1520 LogSymbol();
1511 if (scanner_->current_token() == i::Token::FUTURE_RESERVED_WORD) { 1521 if (scanner_->current_token() == i::Token::FUTURE_RESERVED_WORD) {
1512 return Identifier::FutureReserved(); 1522 return Identifier::FutureReserved();
1513 } else if (scanner_->current_token() == 1523 } else if (scanner_->current_token() ==
1514 i::Token::FUTURE_STRICT_RESERVED_WORD) { 1524 i::Token::FUTURE_STRICT_RESERVED_WORD) {
1515 return Identifier::FutureStrictReserved(); 1525 return Identifier::FutureStrictReserved();
1526 } else if (scanner_->current_token() == i::Token::YIELD) {
1527 return Identifier::Yield();
1516 } 1528 }
1517 if (scanner_->is_literal_ascii()) { 1529 if (scanner_->is_literal_ascii()) {
1518 // Detect strict-mode poison words. 1530 // Detect strict-mode poison words.
1519 if (scanner_->literal_length() == 4 && 1531 if (scanner_->literal_length() == 4 &&
1520 !strncmp(scanner_->literal_ascii_string().start(), "eval", 4)) { 1532 !strncmp(scanner_->literal_ascii_string().start(), "eval", 4)) {
1521 return Identifier::Eval(); 1533 return Identifier::Eval();
1522 } 1534 }
1523 if (scanner_->literal_length() == 9 && 1535 if (scanner_->literal_length() == 9 &&
1524 !strncmp(scanner_->literal_ascii_string().start(), "arguments", 9)) { 1536 !strncmp(scanner_->literal_ascii_string().start(), "arguments", 9)) {
1525 return Identifier::Arguments(); 1537 return Identifier::Arguments();
1526 } 1538 }
1527 } 1539 }
1528 return Identifier::Default(); 1540 return Identifier::Default();
1529 } 1541 }
1530 1542
1531 1543
1532 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { 1544 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) {
1533 i::Token::Value next = Next(); 1545 i::Token::Value next = Next();
1534 switch (next) { 1546 switch (next) {
1535 case i::Token::FUTURE_RESERVED_WORD: { 1547 case i::Token::FUTURE_RESERVED_WORD: {
1536 i::Scanner::Location location = scanner_->location(); 1548 i::Scanner::Location location = scanner_->location();
1537 ReportMessageAt(location.beg_pos, location.end_pos, 1549 ReportMessageAt(location.beg_pos, location.end_pos,
1538 "reserved_word", NULL); 1550 "reserved_word", NULL);
1539 *ok = false; 1551 *ok = false;
1540 return GetIdentifierSymbol(); 1552 return GetIdentifierSymbol();
1541 } 1553 }
1554 case i::Token::YIELD:
1555 if (scope_->is_generator()) {
1556 // 'yield' in a generator is only valid as part of a YieldExpression.
1557 i::Scanner::Location location = scanner_->location();
1558 ReportMessageAt(location.beg_pos, location.end_pos,
1559 "unexpected_token", NULL);
1560 *ok = false;
1561 return Identifier::Default();
1562 }
1563 // FALLTHROUGH
1542 case i::Token::FUTURE_STRICT_RESERVED_WORD: 1564 case i::Token::FUTURE_STRICT_RESERVED_WORD:
1543 if (!is_classic_mode()) { 1565 if (!is_classic_mode()) {
1544 i::Scanner::Location location = scanner_->location(); 1566 i::Scanner::Location location = scanner_->location();
1545 ReportMessageAt(location.beg_pos, location.end_pos, 1567 ReportMessageAt(location.beg_pos, location.end_pos,
1546 "strict_reserved_word", NULL); 1568 "strict_reserved_word", NULL);
1547 *ok = false; 1569 *ok = false;
1548 } 1570 }
1549 // FALLTHROUGH 1571 // FALLTHROUGH
1550 case i::Token::IDENTIFIER: 1572 case i::Token::IDENTIFIER:
1551 return GetIdentifierSymbol(); 1573 return GetIdentifierSymbol();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 } 1611 }
1590 1612
1591 1613
1592 void PreParser::StrictModeIdentifierViolation(i::Scanner::Location location, 1614 void PreParser::StrictModeIdentifierViolation(i::Scanner::Location location,
1593 const char* eval_args_type, 1615 const char* eval_args_type,
1594 Identifier identifier, 1616 Identifier identifier,
1595 bool* ok) { 1617 bool* ok) {
1596 const char* type = eval_args_type; 1618 const char* type = eval_args_type;
1597 if (identifier.IsFutureReserved()) { 1619 if (identifier.IsFutureReserved()) {
1598 type = "reserved_word"; 1620 type = "reserved_word";
1599 } else if (identifier.IsFutureStrictReserved()) { 1621 } else if (identifier.IsFutureStrictReserved() || identifier.IsYield()) {
1600 type = "strict_reserved_word"; 1622 type = "strict_reserved_word";
1601 } 1623 }
1602 if (!is_classic_mode()) { 1624 if (!is_classic_mode()) {
1603 ReportMessageAt(location, type, NULL); 1625 ReportMessageAt(location, type, NULL);
1604 *ok = false; 1626 *ok = false;
1605 return; 1627 return;
1606 } 1628 }
1607 strict_mode_violation_location_ = location; 1629 strict_mode_violation_location_ = location;
1608 strict_mode_violation_type_ = type; 1630 strict_mode_violation_type_ = type;
1609 } 1631 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); 1802 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u));
1781 } 1803 }
1782 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); 1804 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u));
1783 } 1805 }
1784 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); 1806 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f));
1785 1807
1786 backing_store_.AddBlock(bytes); 1808 backing_store_.AddBlock(bytes);
1787 return backing_store_.EndSequence().start(); 1809 return backing_store_.EndSequence().start();
1788 } 1810 }
1789 } } // v8::preparser 1811 } } // v8::preparser
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698