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

Side by Side Diff: src/parsing/parser-base.h

Issue 1606193003: [parser cleanup] Small cleanups to ParsePropertyName (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #ifndef V8_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 IdentifierT ParseIdentifierOrStrictReservedWord(bool is_generator, 708 IdentifierT ParseIdentifierOrStrictReservedWord(bool is_generator,
709 bool* is_strict_reserved, 709 bool* is_strict_reserved,
710 bool* ok); 710 bool* ok);
711 IdentifierT ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved, 711 IdentifierT ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved,
712 bool* ok) { 712 bool* ok) {
713 return ParseIdentifierOrStrictReservedWord(this->is_generator(), 713 return ParseIdentifierOrStrictReservedWord(this->is_generator(),
714 is_strict_reserved, ok); 714 is_strict_reserved, ok);
715 } 715 }
716 716
717 IdentifierT ParseIdentifierName(bool* ok); 717 IdentifierT ParseIdentifierName(bool* ok);
718 // Parses an identifier and determines whether or not it is 'get' or 'set'.
719 IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get, bool* is_set,
720 bool* ok);
721
722 718
723 ExpressionT ParseRegExpLiteral(bool seen_equal, 719 ExpressionT ParseRegExpLiteral(bool seen_equal,
724 ExpressionClassifier* classifier, bool* ok); 720 ExpressionClassifier* classifier, bool* ok);
725 721
726 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, 722 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier,
727 bool* ok); 723 bool* ok);
728 ExpressionT ParseExpression(bool accept_IN, bool* ok); 724 ExpressionT ParseExpression(bool accept_IN, bool* ok);
729 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, 725 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier,
730 bool* ok); 726 bool* ok);
731 ExpressionT ParseExpression(bool accept_IN, int flags, 727 ExpressionT ParseExpression(bool accept_IN, int flags,
732 ExpressionClassifier* classifier, bool* ok); 728 ExpressionClassifier* classifier, bool* ok);
733 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); 729 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok);
734 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, 730 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set,
735 bool* is_static, bool* is_computed_name, 731 bool* is_computed_name,
736 ExpressionClassifier* classifier, bool* ok); 732 ExpressionClassifier* classifier, bool* ok);
737 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); 733 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok);
738 ObjectLiteralPropertyT ParsePropertyDefinition( 734 ObjectLiteralPropertyT ParsePropertyDefinition(
739 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, 735 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends,
740 bool is_static, bool* is_computed_name, bool* has_seen_constructor, 736 bool is_static, bool* is_computed_name, bool* has_seen_constructor,
741 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); 737 ExpressionClassifier* classifier, IdentifierT* name, bool* ok);
742 typename Traits::Type::ExpressionList ParseArguments( 738 typename Traits::Type::ExpressionList ParseArguments(
743 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, 739 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier,
744 bool* ok); 740 bool* ok);
745 741
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 return Traits::EmptyIdentifier(); 1162 return Traits::EmptyIdentifier();
1167 } 1163 }
1168 1164
1169 IdentifierT name = this->GetSymbol(scanner()); 1165 IdentifierT name = this->GetSymbol(scanner());
1170 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); 1166 if (this->IsArguments(name)) scope_->RecordArgumentsUsage();
1171 return name; 1167 return name;
1172 } 1168 }
1173 1169
1174 1170
1175 template <class Traits> 1171 template <class Traits>
1176 typename ParserBase<Traits>::IdentifierT
1177 ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get,
1178 bool* is_set,
1179 bool* ok) {
1180 IdentifierT result = ParseIdentifierName(ok);
1181 if (!*ok) return Traits::EmptyIdentifier();
1182 scanner()->IsGetOrSet(is_get, is_set);
1183 return result;
1184 }
1185
1186
1187 template <class Traits>
1188 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( 1172 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral(
1189 bool seen_equal, ExpressionClassifier* classifier, bool* ok) { 1173 bool seen_equal, ExpressionClassifier* classifier, bool* ok) {
1190 int pos = peek_position(); 1174 int pos = peek_position();
1191 if (!scanner()->ScanRegExpPattern(seen_equal)) { 1175 if (!scanner()->ScanRegExpPattern(seen_equal)) {
1192 Next(); 1176 Next();
1193 ReportMessage(MessageTemplate::kUnterminatedRegExp); 1177 ReportMessage(MessageTemplate::kUnterminatedRegExp);
1194 *ok = false; 1178 *ok = false;
1195 return Traits::EmptyExpression(); 1179 return Traits::EmptyExpression();
1196 } 1180 }
1197 1181
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 // Update the scope information before the pre-parsing bailout. 1534 // Update the scope information before the pre-parsing bailout.
1551 int literal_index = function_state_->NextMaterializedLiteralIndex(); 1535 int literal_index = function_state_->NextMaterializedLiteralIndex();
1552 1536
1553 return factory()->NewArrayLiteral(values, first_spread_index, literal_index, 1537 return factory()->NewArrayLiteral(values, first_spread_index, literal_index,
1554 is_strong(language_mode()), pos); 1538 is_strong(language_mode()), pos);
1555 } 1539 }
1556 1540
1557 1541
1558 template <class Traits> 1542 template <class Traits>
1559 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName( 1543 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
1560 IdentifierT* name, bool* is_get, bool* is_set, bool* is_static, 1544 IdentifierT* name, bool* is_get, bool* is_set, bool* is_computed_name,
1561 bool* is_computed_name, ExpressionClassifier* classifier, bool* ok) { 1545 ExpressionClassifier* classifier, bool* ok) {
1562 Token::Value token = peek(); 1546 Token::Value token = peek();
1563 int pos = peek_position(); 1547 int pos = peek_position();
1564 1548
1565 // For non computed property names we normalize the name a bit: 1549 // For non computed property names we normalize the name a bit:
1566 // 1550 //
1567 // "12" -> 12 1551 // "12" -> 12
1568 // 12.3 -> "12.3" 1552 // 12.3 -> "12.3"
1569 // 12.30 -> "12.3" 1553 // 12.30 -> "12.3"
1570 // identifier -> "identifier" 1554 // identifier -> "identifier"
1571 // 1555 //
(...skipping 22 matching lines...) Expand all
1594 ExpressionT expression = 1578 ExpressionT expression =
1595 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); 1579 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK);
1596 expression = Traits::RewriteNonPattern( 1580 expression = Traits::RewriteNonPattern(
1597 expression, &computed_name_classifier, CHECK_OK); 1581 expression, &computed_name_classifier, CHECK_OK);
1598 classifier->Accumulate(computed_name_classifier, 1582 classifier->Accumulate(computed_name_classifier,
1599 ExpressionClassifier::ExpressionProductions); 1583 ExpressionClassifier::ExpressionProductions);
1600 Expect(Token::RBRACK, CHECK_OK); 1584 Expect(Token::RBRACK, CHECK_OK);
1601 return expression; 1585 return expression;
1602 } 1586 }
1603 1587
1604 case Token::STATIC:
1605 *is_static = true;
1606
1607 // Fall through.
1608 default: 1588 default:
1609 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); 1589 *name = ParseIdentifierName(CHECK_OK);
1590 scanner()->IsGetOrSet(is_get, is_set);
1610 break; 1591 break;
1611 } 1592 }
1612 1593
1613 uint32_t index; 1594 uint32_t index;
1614 return this->IsArrayIndex(*name, &index) 1595 return this->IsArrayIndex(*name, &index)
1615 ? factory()->NewNumberLiteral(index, pos) 1596 ? factory()->NewNumberLiteral(index, pos)
1616 : factory()->NewStringLiteral(*name, pos); 1597 : factory()->NewStringLiteral(*name, pos);
1617 } 1598 }
1618 1599
1619 1600
1620 template <class Traits> 1601 template <class Traits>
1621 typename ParserBase<Traits>::ObjectLiteralPropertyT 1602 typename ParserBase<Traits>::ObjectLiteralPropertyT
1622 ParserBase<Traits>::ParsePropertyDefinition( 1603 ParserBase<Traits>::ParsePropertyDefinition(
1623 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, 1604 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends,
1624 bool is_static, bool* is_computed_name, bool* has_seen_constructor, 1605 bool is_static, bool* is_computed_name, bool* has_seen_constructor,
1625 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) { 1606 ExpressionClassifier* classifier, IdentifierT* name, bool* ok) {
1626 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); 1607 DCHECK(!in_class || is_static || has_seen_constructor != nullptr);
1627 ExpressionT value = this->EmptyExpression(); 1608 ExpressionT value = this->EmptyExpression();
1628 bool is_get = false; 1609 bool is_get = false;
1629 bool is_set = false; 1610 bool is_set = false;
1630 bool name_is_static = false;
1631 bool is_generator = Check(Token::MUL); 1611 bool is_generator = Check(Token::MUL);
1632 1612
1633 Token::Value name_token = peek(); 1613 Token::Value name_token = peek();
1634 int next_beg_pos = scanner()->peek_location().beg_pos; 1614 int next_beg_pos = scanner()->peek_location().beg_pos;
1635 int next_end_pos = scanner()->peek_location().end_pos; 1615 int next_end_pos = scanner()->peek_location().end_pos;
1636 ExpressionT name_expression = ParsePropertyName( 1616 ExpressionT name_expression =
1637 name, &is_get, &is_set, &name_is_static, is_computed_name, classifier, 1617 ParsePropertyName(name, &is_get, &is_set, is_computed_name, classifier,
1638 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1618 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1639 1619
1640 if (fni_ != nullptr && !*is_computed_name) { 1620 if (fni_ != nullptr && !*is_computed_name) {
1641 this->PushLiteralName(fni_, *name); 1621 this->PushLiteralName(fni_, *name);
1642 } 1622 }
1643 1623
1644 if (!in_class && !is_generator) { 1624 if (!in_class && !is_generator) {
1645 DCHECK(!is_static); 1625 DCHECK(!is_static);
1646 1626
1647 if (peek() == Token::COLON) { 1627 if (peek() == Token::COLON) {
1648 // PropertyDefinition 1628 // PropertyDefinition
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 *name, scanner()->location(), kSkipFunctionNameCheck, kind, 1717 *name, scanner()->location(), kSkipFunctionNameCheck, kind,
1738 RelocInfo::kNoPosition, FunctionLiteral::kAnonymousExpression, 1718 RelocInfo::kNoPosition, FunctionLiteral::kAnonymousExpression,
1739 FunctionLiteral::kNormalArity, language_mode(), 1719 FunctionLiteral::kNormalArity, language_mode(),
1740 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1720 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1741 1721
1742 return factory()->NewObjectLiteralProperty(name_expression, value, 1722 return factory()->NewObjectLiteralProperty(name_expression, value,
1743 ObjectLiteralProperty::COMPUTED, 1723 ObjectLiteralProperty::COMPUTED,
1744 is_static, *is_computed_name); 1724 is_static, *is_computed_name);
1745 } 1725 }
1746 1726
1747 if (in_class && name_is_static && !is_static) { 1727 if (in_class && name_token == Token::STATIC && !is_static) {
1748 // ClassElement (static) 1728 // ClassElement (static)
1749 // 'static' MethodDefinition 1729 // 'static' MethodDefinition
1750 *name = this->EmptyIdentifier(); 1730 *name = this->EmptyIdentifier();
1751 ObjectLiteralPropertyT property = ParsePropertyDefinition( 1731 ObjectLiteralPropertyT property = ParsePropertyDefinition(
1752 checker, true, has_extends, true, is_computed_name, nullptr, classifier, 1732 checker, true, has_extends, true, is_computed_name, nullptr, classifier,
1753 name, ok); 1733 name, ok);
1754 property = Traits::RewriteNonPatternObjectLiteralProperty(property, 1734 property = Traits::RewriteNonPatternObjectLiteralProperty(property,
1755 classifier, ok); 1735 classifier, ok);
1756 return property; 1736 return property;
1757 } 1737 }
1758 1738
1759 if (is_get || is_set) { 1739 if (is_get || is_set) {
1760 // MethodDefinition (Accessors) 1740 // MethodDefinition (Accessors)
1761 // get PropertyName '(' ')' '{' FunctionBody '}' 1741 // get PropertyName '(' ')' '{' FunctionBody '}'
1762 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' 1742 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}'
1763 *name = this->EmptyIdentifier(); 1743 *name = this->EmptyIdentifier();
1764 bool dont_care = false; 1744 bool dont_care = false;
1765 name_token = peek(); 1745 name_token = peek();
1766 1746
1767 name_expression = ParsePropertyName( 1747 name_expression = ParsePropertyName(
1768 name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, 1748 name, &dont_care, &dont_care, is_computed_name, classifier,
1769 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1749 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1770 1750
1771 if (!*is_computed_name) { 1751 if (!*is_computed_name) {
1772 checker->CheckProperty(name_token, kAccessorProperty, is_static, 1752 checker->CheckProperty(name_token, kAccessorProperty, is_static,
1773 is_generator, 1753 is_generator,
1774 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); 1754 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
1775 } 1755 }
1776 1756
1777 FunctionKind kind = FunctionKind::kAccessorFunction; 1757 FunctionKind kind = FunctionKind::kAccessorFunction;
1778 if (!in_class) kind = WithObjectLiteralBit(kind); 1758 if (!in_class) kind = WithObjectLiteralBit(kind);
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after
3348 return; 3328 return;
3349 } 3329 }
3350 has_seen_constructor_ = true; 3330 has_seen_constructor_ = true;
3351 return; 3331 return;
3352 } 3332 }
3353 } 3333 }
3354 } // namespace internal 3334 } // namespace internal
3355 } // namespace v8 3335 } // namespace v8
3356 3336
3357 #endif // V8_PARSING_PARSER_BASE_H 3337 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698