OLD | NEW |
---|---|
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 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1422 return this->EmptyExpression(); | 1422 return this->EmptyExpression(); |
1423 } | 1423 } |
1424 | 1424 |
1425 | 1425 |
1426 template <class Traits> | 1426 template <class Traits> |
1427 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1427 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1428 bool accept_IN, bool* ok) { | 1428 bool accept_IN, bool* ok) { |
1429 ExpressionClassifier classifier; | 1429 ExpressionClassifier classifier; |
1430 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); | 1430 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); |
1431 ValidateExpression(&classifier, CHECK_OK); | 1431 ValidateExpression(&classifier, CHECK_OK); |
1432 result = Traits::RewriteExpression(result); | |
1432 return result; | 1433 return result; |
1433 } | 1434 } |
1434 | 1435 |
1435 | 1436 |
1436 template <class Traits> | 1437 template <class Traits> |
1437 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1438 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
1438 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 1439 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
1439 return ParseExpression(accept_IN, kIsLeftHandSide, classifier, ok); | 1440 return ParseExpression(accept_IN, kIsLeftHandSide, classifier, ok); |
1440 } | 1441 } |
1441 | 1442 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 Consume(Token::NUMBER); | 1588 Consume(Token::NUMBER); |
1588 *name = this->GetNumberAsSymbol(scanner()); | 1589 *name = this->GetNumberAsSymbol(scanner()); |
1589 break; | 1590 break; |
1590 | 1591 |
1591 case Token::LBRACK: { | 1592 case Token::LBRACK: { |
1592 *is_computed_name = true; | 1593 *is_computed_name = true; |
1593 Consume(Token::LBRACK); | 1594 Consume(Token::LBRACK); |
1594 ExpressionClassifier computed_name_classifier; | 1595 ExpressionClassifier computed_name_classifier; |
1595 ExpressionT expression = | 1596 ExpressionT expression = |
1596 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); | 1597 ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK); |
1598 expression = Traits::RewriteExpression(expression); | |
rossberg
2016/01/08 12:22:27
Do we actually need to do this here? My thinking w
nickie
2016/01/08 13:46:58
You can look at this as a "non-pattern rewriter".
| |
1597 classifier->Accumulate(computed_name_classifier, | 1599 classifier->Accumulate(computed_name_classifier, |
1598 ExpressionClassifier::ExpressionProductions); | 1600 ExpressionClassifier::ExpressionProductions); |
1599 Expect(Token::RBRACK, CHECK_OK); | 1601 Expect(Token::RBRACK, CHECK_OK); |
1600 return expression; | 1602 return expression; |
1601 } | 1603 } |
1602 | 1604 |
1603 case Token::ESCAPED_KEYWORD: | 1605 case Token::ESCAPED_KEYWORD: |
1604 *is_escaped_keyword = true; | 1606 *is_escaped_keyword = true; |
1605 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); | 1607 *name = ParseIdentifierNameOrGetOrSet(is_get, is_set, CHECK_OK); |
1606 break; | 1608 break; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1700 | 1702 |
1701 ExpressionT lhs = this->ExpressionFromIdentifier( | 1703 ExpressionT lhs = this->ExpressionFromIdentifier( |
1702 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1704 *name, next_beg_pos, next_end_pos, scope_, factory()); |
1703 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1705 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
1704 | 1706 |
1705 if (peek() == Token::ASSIGN) { | 1707 if (peek() == Token::ASSIGN) { |
1706 Consume(Token::ASSIGN); | 1708 Consume(Token::ASSIGN); |
1707 ExpressionClassifier rhs_classifier; | 1709 ExpressionClassifier rhs_classifier; |
1708 ExpressionT rhs = this->ParseAssignmentExpression( | 1710 ExpressionT rhs = this->ParseAssignmentExpression( |
1709 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1711 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1712 rhs = Traits::RewriteExpression(rhs); | |
1710 classifier->Accumulate(rhs_classifier, | 1713 classifier->Accumulate(rhs_classifier, |
1711 ExpressionClassifier::ExpressionProductions); | 1714 ExpressionClassifier::ExpressionProductions); |
1712 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, | 1715 value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs, |
1713 RelocInfo::kNoPosition); | 1716 RelocInfo::kNoPosition); |
1714 classifier->RecordCoverInitializedNameError( | 1717 classifier->RecordCoverInitializedNameError( |
1715 Scanner::Location(next_beg_pos, scanner()->location().end_pos), | 1718 Scanner::Location(next_beg_pos, scanner()->location().end_pos), |
1716 MessageTemplate::kInvalidCoverInitializedName); | 1719 MessageTemplate::kInvalidCoverInitializedName); |
1717 } else { | 1720 } else { |
1718 value = lhs; | 1721 value = lhs; |
1719 } | 1722 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1764 | 1767 |
1765 return factory()->NewObjectLiteralProperty(name_expression, value, | 1768 return factory()->NewObjectLiteralProperty(name_expression, value, |
1766 ObjectLiteralProperty::COMPUTED, | 1769 ObjectLiteralProperty::COMPUTED, |
1767 is_static, *is_computed_name); | 1770 is_static, *is_computed_name); |
1768 } | 1771 } |
1769 | 1772 |
1770 if (in_class && name_is_static && !is_static) { | 1773 if (in_class && name_is_static && !is_static) { |
1771 // ClassElement (static) | 1774 // ClassElement (static) |
1772 // 'static' MethodDefinition | 1775 // 'static' MethodDefinition |
1773 *name = this->EmptyIdentifier(); | 1776 *name = this->EmptyIdentifier(); |
1774 return ParsePropertyDefinition(checker, true, has_extends, true, | 1777 ObjectLiteralPropertyT property = ParsePropertyDefinition( |
1775 is_computed_name, nullptr, classifier, name, | 1778 checker, true, has_extends, true, is_computed_name, nullptr, classifier, |
1776 ok); | 1779 name, ok); |
1780 property = Traits::RewriteObjectLiteralProperty(property); | |
1781 return property; | |
1777 } | 1782 } |
1778 | 1783 |
1779 if (is_get || is_set) { | 1784 if (is_get || is_set) { |
1780 // MethodDefinition (Accessors) | 1785 // MethodDefinition (Accessors) |
1781 // get PropertyName '(' ')' '{' FunctionBody '}' | 1786 // get PropertyName '(' ')' '{' FunctionBody '}' |
1782 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' | 1787 // set PropertyName '(' PropertySetParameterList ')' '{' FunctionBody '}' |
1783 *name = this->EmptyIdentifier(); | 1788 *name = this->EmptyIdentifier(); |
1784 bool dont_care = false; | 1789 bool dont_care = false; |
1785 name_token = peek(); | 1790 name_token = peek(); |
1786 | 1791 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1905 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 1910 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
1906 bool done = (peek() == Token::RPAREN); | 1911 bool done = (peek() == Token::RPAREN); |
1907 bool was_unspread = false; | 1912 bool was_unspread = false; |
1908 int unspread_sequences_count = 0; | 1913 int unspread_sequences_count = 0; |
1909 while (!done) { | 1914 while (!done) { |
1910 int start_pos = peek_position(); | 1915 int start_pos = peek_position(); |
1911 bool is_spread = Check(Token::ELLIPSIS); | 1916 bool is_spread = Check(Token::ELLIPSIS); |
1912 | 1917 |
1913 ExpressionT argument = this->ParseAssignmentExpression( | 1918 ExpressionT argument = this->ParseAssignmentExpression( |
1914 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); | 1919 true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
1920 argument = Traits::RewriteExpression(argument); | |
1915 if (is_spread) { | 1921 if (is_spread) { |
1916 if (!spread_arg.IsValid()) { | 1922 if (!spread_arg.IsValid()) { |
1917 spread_arg.beg_pos = start_pos; | 1923 spread_arg.beg_pos = start_pos; |
1918 spread_arg.end_pos = peek_position(); | 1924 spread_arg.end_pos = peek_position(); |
1919 } | 1925 } |
1920 argument = factory()->NewSpread(argument, start_pos); | 1926 argument = factory()->NewSpread(argument, start_pos); |
1921 } | 1927 } |
1922 result->Add(argument, zone_); | 1928 result->Add(argument, zone_); |
1923 | 1929 |
1924 // unspread_sequences_count is the number of sequences of parameters which | 1930 // unspread_sequences_count is the number of sequences of parameters which |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2089 } | 2095 } |
2090 int pos = position(); | 2096 int pos = position(); |
2091 | 2097 |
2092 ExpressionClassifier rhs_classifier; | 2098 ExpressionClassifier rhs_classifier; |
2093 | 2099 |
2094 int rhs_flags = flags; | 2100 int rhs_flags = flags; |
2095 rhs_flags &= ~(kIsPatternElement | kIsPossibleArrowFormals); | 2101 rhs_flags &= ~(kIsPatternElement | kIsPossibleArrowFormals); |
2096 rhs_flags |= kIsRightHandSide; | 2102 rhs_flags |= kIsRightHandSide; |
2097 ExpressionT right = this->ParseAssignmentExpression( | 2103 ExpressionT right = this->ParseAssignmentExpression( |
2098 accept_IN, rhs_flags, &rhs_classifier, CHECK_OK); | 2104 accept_IN, rhs_flags, &rhs_classifier, CHECK_OK); |
2105 right = Traits::RewriteExpression(right); | |
2099 classifier->Accumulate( | 2106 classifier->Accumulate( |
2100 rhs_classifier, ExpressionClassifier::ExpressionProductions | | 2107 rhs_classifier, ExpressionClassifier::ExpressionProductions | |
2101 ExpressionClassifier::CoverInitializedNameProduction); | 2108 ExpressionClassifier::CoverInitializedNameProduction); |
2102 | 2109 |
2103 // TODO(1231235): We try to estimate the set of properties set by | 2110 // TODO(1231235): We try to estimate the set of properties set by |
2104 // constructors. We define a new property whenever there is an | 2111 // constructors. We define a new property whenever there is an |
2105 // assignment to a property of 'this'. We should probably only add | 2112 // assignment to a property of 'this'. We should probably only add |
2106 // properties if we haven't seen them before. Otherwise we'll | 2113 // properties if we haven't seen them before. Otherwise we'll |
2107 // probably overestimate the number of properties. | 2114 // probably overestimate the number of properties. |
2108 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { | 2115 if (op == Token::ASSIGN && this->IsThisProperty(expression)) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2160 // The above set of tokens is the complete set of tokens that can appear | 2167 // The above set of tokens is the complete set of tokens that can appear |
2161 // after an AssignmentExpression, and none of them can start an | 2168 // after an AssignmentExpression, and none of them can start an |
2162 // AssignmentExpression. This allows us to avoid looking for an RHS for | 2169 // AssignmentExpression. This allows us to avoid looking for an RHS for |
2163 // a Yield::kSuspend operation, given only one look-ahead token. | 2170 // a Yield::kSuspend operation, given only one look-ahead token. |
2164 if (kind == Yield::kSuspend) | 2171 if (kind == Yield::kSuspend) |
2165 break; | 2172 break; |
2166 DCHECK_EQ(Yield::kDelegating, kind); | 2173 DCHECK_EQ(Yield::kDelegating, kind); |
2167 // Delegating yields require an RHS; fall through. | 2174 // Delegating yields require an RHS; fall through. |
2168 default: | 2175 default: |
2169 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); | 2176 expression = ParseAssignmentExpression(false, classifier, CHECK_OK); |
2177 expression = Traits::RewriteExpression(expression); | |
2170 break; | 2178 break; |
2171 } | 2179 } |
2172 } | 2180 } |
2173 if (kind == Yield::kDelegating) { | 2181 if (kind == Yield::kDelegating) { |
2174 // var iterator = subject[Symbol.iterator](); | 2182 // var iterator = subject[Symbol.iterator](); |
2175 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2183 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
2176 // TODO(verwaest): Come up with a better solution. | 2184 // TODO(verwaest): Come up with a better solution. |
2177 expression = this->GetIterator(expression, factory(), pos + 1); | 2185 expression = this->GetIterator(expression, factory(), pos + 1); |
2178 } | 2186 } |
2179 // Hackily disambiguate o from o.next and o [Symbol.iterator](). | 2187 // Hackily disambiguate o from o.next and o [Symbol.iterator](). |
(...skipping 12 matching lines...) Expand all Loading... | |
2192 bool* ok) { | 2200 bool* ok) { |
2193 // ConditionalExpression :: | 2201 // ConditionalExpression :: |
2194 // LogicalOrExpression | 2202 // LogicalOrExpression |
2195 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | 2203 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression |
2196 | 2204 |
2197 int pos = peek_position(); | 2205 int pos = peek_position(); |
2198 // We start using the binary expression parser for prec >= 4 only! | 2206 // We start using the binary expression parser for prec >= 4 only! |
2199 ExpressionT expression = | 2207 ExpressionT expression = |
2200 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); | 2208 this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK); |
2201 if (peek() != Token::CONDITIONAL) return expression; | 2209 if (peek() != Token::CONDITIONAL) return expression; |
2210 expression = Traits::RewriteExpression(expression); | |
2202 ArrowFormalParametersUnexpectedToken(classifier); | 2211 ArrowFormalParametersUnexpectedToken(classifier); |
2203 BindingPatternUnexpectedToken(classifier); | 2212 BindingPatternUnexpectedToken(classifier); |
2204 Consume(Token::CONDITIONAL); | 2213 Consume(Token::CONDITIONAL); |
2205 // In parsing the first assignment expression in conditional | 2214 // In parsing the first assignment expression in conditional |
2206 // expressions we always accept the 'in' keyword; see ECMA-262, | 2215 // expressions we always accept the 'in' keyword; see ECMA-262, |
2207 // section 11.12, page 58. | 2216 // section 11.12, page 58. |
2208 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); | 2217 ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK); |
2218 left = Traits::RewriteExpression(left); | |
2209 Expect(Token::COLON, CHECK_OK); | 2219 Expect(Token::COLON, CHECK_OK); |
2210 ExpressionT right = | 2220 ExpressionT right = |
2211 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); | 2221 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK); |
2222 right = Traits::RewriteExpression(right); | |
2212 return factory()->NewConditional(expression, left, right, pos); | 2223 return factory()->NewConditional(expression, left, right, pos); |
2213 } | 2224 } |
2214 | 2225 |
2215 | 2226 |
2216 // Precedence >= 4 | 2227 // Precedence >= 4 |
2217 template <class Traits> | 2228 template <class Traits> |
2218 typename ParserBase<Traits>::ExpressionT | 2229 typename ParserBase<Traits>::ExpressionT |
2219 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, | 2230 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, |
2220 ExpressionClassifier* classifier, | 2231 ExpressionClassifier* classifier, |
2221 bool* ok) { | 2232 bool* ok) { |
2222 DCHECK(prec >= 4); | 2233 DCHECK(prec >= 4); |
2223 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 2234 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
2224 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2235 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
2225 // prec1 >= 4 | 2236 // prec1 >= 4 |
2226 while (Precedence(peek(), accept_IN) == prec1) { | 2237 while (Precedence(peek(), accept_IN) == prec1) { |
2238 x = Traits::RewriteExpression(x); | |
2227 BindingPatternUnexpectedToken(classifier); | 2239 BindingPatternUnexpectedToken(classifier); |
2228 ArrowFormalParametersUnexpectedToken(classifier); | 2240 ArrowFormalParametersUnexpectedToken(classifier); |
2229 Token::Value op = Next(); | 2241 Token::Value op = Next(); |
2230 Scanner::Location op_location = scanner()->location(); | 2242 Scanner::Location op_location = scanner()->location(); |
2231 int pos = position(); | 2243 int pos = position(); |
2232 ExpressionT y = | 2244 ExpressionT y = |
2233 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); | 2245 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); |
2246 y = Traits::RewriteExpression(y); | |
2234 | 2247 |
2235 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 2248 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
2236 factory())) { | 2249 factory())) { |
2237 continue; | 2250 continue; |
2238 } | 2251 } |
2239 | 2252 |
2240 // For now we distinguish between comparisons and other binary | 2253 // For now we distinguish between comparisons and other binary |
2241 // operations. (We could combine the two and get rid of this | 2254 // operations. (We could combine the two and get rid of this |
2242 // code and AST node eventually.) | 2255 // code and AST node eventually.) |
2243 if (Token::IsCompareOp(op)) { | 2256 if (Token::IsCompareOp(op)) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2286 // '!' UnaryExpression | 2299 // '!' UnaryExpression |
2287 | 2300 |
2288 Token::Value op = peek(); | 2301 Token::Value op = peek(); |
2289 if (Token::IsUnaryOp(op)) { | 2302 if (Token::IsUnaryOp(op)) { |
2290 BindingPatternUnexpectedToken(classifier); | 2303 BindingPatternUnexpectedToken(classifier); |
2291 ArrowFormalParametersUnexpectedToken(classifier); | 2304 ArrowFormalParametersUnexpectedToken(classifier); |
2292 | 2305 |
2293 op = Next(); | 2306 op = Next(); |
2294 int pos = position(); | 2307 int pos = position(); |
2295 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); | 2308 ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK); |
2309 expression = Traits::RewriteExpression(expression); | |
2296 | 2310 |
2297 if (op == Token::DELETE && is_strict(language_mode())) { | 2311 if (op == Token::DELETE && is_strict(language_mode())) { |
2298 if (is_strong(language_mode())) { | 2312 if (is_strong(language_mode())) { |
2299 ReportMessage(MessageTemplate::kStrongDelete); | 2313 ReportMessage(MessageTemplate::kStrongDelete); |
2300 *ok = false; | 2314 *ok = false; |
2301 return this->EmptyExpression(); | 2315 return this->EmptyExpression(); |
2302 } else if (this->IsIdentifier(expression)) { | 2316 } else if (this->IsIdentifier(expression)) { |
2303 // "delete identifier" is a syntax error in strict mode. | 2317 // "delete identifier" is a syntax error in strict mode. |
2304 ReportMessage(MessageTemplate::kStrictDelete); | 2318 ReportMessage(MessageTemplate::kStrictDelete); |
2305 *ok = false; | 2319 *ok = false; |
2306 return this->EmptyExpression(); | 2320 return this->EmptyExpression(); |
2307 } | 2321 } |
2308 } | 2322 } |
2309 | 2323 |
2310 // Allow Traits do rewrite the expression. | 2324 // Allow Traits do rewrite the expression. |
2311 return this->BuildUnaryExpression(expression, op, pos, factory()); | 2325 return this->BuildUnaryExpression(expression, op, pos, factory()); |
2312 } else if (Token::IsCountOp(op)) { | 2326 } else if (Token::IsCountOp(op)) { |
2313 BindingPatternUnexpectedToken(classifier); | 2327 BindingPatternUnexpectedToken(classifier); |
2314 ArrowFormalParametersUnexpectedToken(classifier); | 2328 ArrowFormalParametersUnexpectedToken(classifier); |
2315 op = Next(); | 2329 op = Next(); |
2316 int beg_pos = peek_position(); | 2330 int beg_pos = peek_position(); |
2317 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 2331 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
2318 expression = this->CheckAndRewriteReferenceExpression( | 2332 expression = this->CheckAndRewriteReferenceExpression( |
2319 expression, beg_pos, scanner()->location().end_pos, | 2333 expression, beg_pos, scanner()->location().end_pos, |
2320 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2334 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
2321 this->MarkExpressionAsAssigned(expression); | 2335 this->MarkExpressionAsAssigned(expression); |
2336 expression = Traits::RewriteExpression(expression); | |
2322 | 2337 |
2323 return factory()->NewCountOperation(op, | 2338 return factory()->NewCountOperation(op, |
2324 true /* prefix */, | 2339 true /* prefix */, |
2325 expression, | 2340 expression, |
2326 position()); | 2341 position()); |
2327 | 2342 |
2328 } else { | 2343 } else { |
2329 return this->ParsePostfixExpression(classifier, ok); | 2344 return this->ParsePostfixExpression(classifier, ok); |
2330 } | 2345 } |
2331 } | 2346 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2373 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2388 this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
2374 | 2389 |
2375 while (true) { | 2390 while (true) { |
2376 switch (peek()) { | 2391 switch (peek()) { |
2377 case Token::LBRACK: { | 2392 case Token::LBRACK: { |
2378 BindingPatternUnexpectedToken(classifier); | 2393 BindingPatternUnexpectedToken(classifier); |
2379 ArrowFormalParametersUnexpectedToken(classifier); | 2394 ArrowFormalParametersUnexpectedToken(classifier); |
2380 Consume(Token::LBRACK); | 2395 Consume(Token::LBRACK); |
2381 int pos = position(); | 2396 int pos = position(); |
2382 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); | 2397 ExpressionT index = ParseExpression(true, classifier, CHECK_OK); |
2398 index = Traits::RewriteExpression(index); | |
2383 result = factory()->NewProperty(result, index, pos); | 2399 result = factory()->NewProperty(result, index, pos); |
2384 Expect(Token::RBRACK, CHECK_OK); | 2400 Expect(Token::RBRACK, CHECK_OK); |
2385 break; | 2401 break; |
2386 } | 2402 } |
2387 | 2403 |
2388 case Token::LPAREN: { | 2404 case Token::LPAREN: { |
2405 result = Traits::RewriteExpression(result); | |
2389 BindingPatternUnexpectedToken(classifier); | 2406 BindingPatternUnexpectedToken(classifier); |
2390 ArrowFormalParametersUnexpectedToken(classifier); | 2407 ArrowFormalParametersUnexpectedToken(classifier); |
2391 | 2408 |
2392 if (is_strong(language_mode()) && this->IsIdentifier(result) && | 2409 if (is_strong(language_mode()) && this->IsIdentifier(result) && |
2393 this->IsEval(this->AsIdentifier(result))) { | 2410 this->IsEval(this->AsIdentifier(result))) { |
2394 ReportMessage(MessageTemplate::kStrongDirectEval); | 2411 ReportMessage(MessageTemplate::kStrongDirectEval); |
2395 *ok = false; | 2412 *ok = false; |
2396 return this->EmptyExpression(); | 2413 return this->EmptyExpression(); |
2397 } | 2414 } |
2398 int pos; | 2415 int pos; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2506 int new_pos = position(); | 2523 int new_pos = position(); |
2507 ExpressionT result = this->EmptyExpression(); | 2524 ExpressionT result = this->EmptyExpression(); |
2508 if (peek() == Token::SUPER) { | 2525 if (peek() == Token::SUPER) { |
2509 const bool is_new = true; | 2526 const bool is_new = true; |
2510 result = ParseSuperExpression(is_new, classifier, CHECK_OK); | 2527 result = ParseSuperExpression(is_new, classifier, CHECK_OK); |
2511 } else if (peek() == Token::PERIOD) { | 2528 } else if (peek() == Token::PERIOD) { |
2512 return ParseNewTargetExpression(CHECK_OK); | 2529 return ParseNewTargetExpression(CHECK_OK); |
2513 } else { | 2530 } else { |
2514 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); | 2531 result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK); |
2515 } | 2532 } |
2533 result = Traits::RewriteExpression(result); | |
2516 if (peek() == Token::LPAREN) { | 2534 if (peek() == Token::LPAREN) { |
2517 // NewExpression with arguments. | 2535 // NewExpression with arguments. |
2518 Scanner::Location spread_pos; | 2536 Scanner::Location spread_pos; |
2519 typename Traits::Type::ExpressionList args = | 2537 typename Traits::Type::ExpressionList args = |
2520 this->ParseArguments(&spread_pos, classifier, CHECK_OK); | 2538 this->ParseArguments(&spread_pos, classifier, CHECK_OK); |
2521 | 2539 |
2522 if (spread_pos.IsValid()) { | 2540 if (spread_pos.IsValid()) { |
2523 args = Traits::PrepareSpreadArguments(args); | 2541 args = Traits::PrepareSpreadArguments(args); |
2524 result = Traits::SpreadCallNew(result, args, new_pos); | 2542 result = Traits::SpreadCallNew(result, args, new_pos); |
2525 } else { | 2543 } else { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2605 int pos = position(); | 2623 int pos = position(); |
2606 function_state_->set_this_location(scanner()->location()); | 2624 function_state_->set_this_location(scanner()->location()); |
2607 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 2625 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); |
2608 | 2626 |
2609 ExpressionT left = this->EmptyExpression(); | 2627 ExpressionT left = this->EmptyExpression(); |
2610 switch (peek()) { | 2628 switch (peek()) { |
2611 case Token::LBRACK: { | 2629 case Token::LBRACK: { |
2612 Consume(Token::LBRACK); | 2630 Consume(Token::LBRACK); |
2613 int pos = position(); | 2631 int pos = position(); |
2614 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2632 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
2633 index = Traits::RewriteExpression(index); | |
2615 left = factory()->NewProperty(this_expr, index, pos); | 2634 left = factory()->NewProperty(this_expr, index, pos); |
2616 if (fni_ != NULL) { | 2635 if (fni_ != NULL) { |
2617 this->PushPropertyName(fni_, index); | 2636 this->PushPropertyName(fni_, index); |
2618 } | 2637 } |
2619 Expect(Token::RBRACK, CHECK_OK); | 2638 Expect(Token::RBRACK, CHECK_OK); |
2620 break; | 2639 break; |
2621 } | 2640 } |
2622 case Token::PERIOD: { | 2641 case Token::PERIOD: { |
2623 Consume(Token::PERIOD); | 2642 Consume(Token::PERIOD); |
2624 int pos = position(); | 2643 int pos = position(); |
(...skipping 15 matching lines...) Expand all Loading... | |
2640 ReportMessageAt(function_state_->this_location(), | 2659 ReportMessageAt(function_state_->this_location(), |
2641 MessageTemplate::kStrongConstructorThis); | 2660 MessageTemplate::kStrongConstructorThis); |
2642 *ok = false; | 2661 *ok = false; |
2643 return this->EmptyExpression(); | 2662 return this->EmptyExpression(); |
2644 } | 2663 } |
2645 Consume(Token::ASSIGN); | 2664 Consume(Token::ASSIGN); |
2646 left = this->MarkExpressionAsAssigned(left); | 2665 left = this->MarkExpressionAsAssigned(left); |
2647 | 2666 |
2648 ExpressionT right = | 2667 ExpressionT right = |
2649 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 2668 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
2669 right = Traits::RewriteExpression(right); | |
2650 this->CheckAssigningFunctionLiteralToProperty(left, right); | 2670 this->CheckAssigningFunctionLiteralToProperty(left, right); |
2651 function_state_->AddProperty(); | 2671 function_state_->AddProperty(); |
2652 if (fni_ != NULL) { | 2672 if (fni_ != NULL) { |
2653 // Check if the right hand side is a call to avoid inferring a | 2673 // Check if the right hand side is a call to avoid inferring a |
2654 // name if we're dealing with "this.a = function(){...}();"-like | 2674 // name if we're dealing with "this.a = function(){...}();"-like |
2655 // expression. | 2675 // expression. |
2656 if (!right->IsCall() && !right->IsCallNew()) { | 2676 if (!right->IsCall() && !right->IsCallNew()) { |
2657 fni_->Infer(); | 2677 fni_->Infer(); |
2658 } else { | 2678 } else { |
2659 fni_->RemoveLastFunction(); | 2679 fni_->RemoveLastFunction(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2796 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 2816 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
2797 while (true) { | 2817 while (true) { |
2798 switch (peek()) { | 2818 switch (peek()) { |
2799 case Token::LBRACK: { | 2819 case Token::LBRACK: { |
2800 BindingPatternUnexpectedToken(classifier); | 2820 BindingPatternUnexpectedToken(classifier); |
2801 ArrowFormalParametersUnexpectedToken(classifier); | 2821 ArrowFormalParametersUnexpectedToken(classifier); |
2802 | 2822 |
2803 Consume(Token::LBRACK); | 2823 Consume(Token::LBRACK); |
2804 int pos = position(); | 2824 int pos = position(); |
2805 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); | 2825 ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK); |
2826 index = Traits::RewriteExpression(index); | |
2806 expression = factory()->NewProperty(expression, index, pos); | 2827 expression = factory()->NewProperty(expression, index, pos); |
2807 if (fni_ != NULL) { | 2828 if (fni_ != NULL) { |
2808 this->PushPropertyName(fni_, index); | 2829 this->PushPropertyName(fni_, index); |
2809 } | 2830 } |
2810 Expect(Token::RBRACK, CHECK_OK); | 2831 Expect(Token::RBRACK, CHECK_OK); |
2811 break; | 2832 break; |
2812 } | 2833 } |
2813 case Token::PERIOD: { | 2834 case Token::PERIOD: { |
2814 BindingPatternUnexpectedToken(classifier); | 2835 BindingPatternUnexpectedToken(classifier); |
2815 ArrowFormalParametersUnexpectedToken(classifier); | 2836 ArrowFormalParametersUnexpectedToken(classifier); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2879 } | 2900 } |
2880 | 2901 |
2881 ExpressionT initializer = Traits::EmptyExpression(); | 2902 ExpressionT initializer = Traits::EmptyExpression(); |
2882 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { | 2903 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { |
2883 ExpressionClassifier init_classifier; | 2904 ExpressionClassifier init_classifier; |
2884 initializer = ParseAssignmentExpression(true, &init_classifier, ok); | 2905 initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
2885 if (!*ok) return; | 2906 if (!*ok) return; |
2886 ValidateExpression(&init_classifier, ok); | 2907 ValidateExpression(&init_classifier, ok); |
2887 ValidateFormalParameterInitializer(&init_classifier, ok); | 2908 ValidateFormalParameterInitializer(&init_classifier, ok); |
2888 if (!*ok) return; | 2909 if (!*ok) return; |
2910 initializer = Traits::RewriteExpression(initializer); | |
2889 parameters->is_simple = false; | 2911 parameters->is_simple = false; |
2890 classifier->RecordNonSimpleParameter(); | 2912 classifier->RecordNonSimpleParameter(); |
2891 } | 2913 } |
2892 | 2914 |
2893 Traits::AddFormalParameter(parameters, pattern, initializer, | 2915 Traits::AddFormalParameter(parameters, pattern, initializer, |
2894 scanner()->location().end_pos, is_rest); | 2916 scanner()->location().end_pos, is_rest); |
2895 } | 2917 } |
2896 | 2918 |
2897 | 2919 |
2898 template <class Traits> | 2920 template <class Traits> |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3051 expected_property_count = function_state.expected_property_count(); | 3073 expected_property_count = function_state.expected_property_count(); |
3052 } | 3074 } |
3053 } else { | 3075 } else { |
3054 // Single-expression body | 3076 // Single-expression body |
3055 int pos = position(); | 3077 int pos = position(); |
3056 parenthesized_function_ = false; | 3078 parenthesized_function_ = false; |
3057 ExpressionClassifier classifier; | 3079 ExpressionClassifier classifier; |
3058 ExpressionT expression = | 3080 ExpressionT expression = |
3059 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); | 3081 ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK); |
3060 ValidateExpression(&classifier, CHECK_OK); | 3082 ValidateExpression(&classifier, CHECK_OK); |
3083 expression = Traits::RewriteExpression(expression); | |
3061 body = this->NewStatementList(1, zone()); | 3084 body = this->NewStatementList(1, zone()); |
3062 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); | 3085 this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK); |
3063 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 3086 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
3064 materialized_literal_count = function_state.materialized_literal_count(); | 3087 materialized_literal_count = function_state.materialized_literal_count(); |
3065 expected_property_count = function_state.expected_property_count(); | 3088 expected_property_count = function_state.expected_property_count(); |
3066 } | 3089 } |
3067 super_loc = function_state.super_location(); | 3090 super_loc = function_state.super_location(); |
3068 | 3091 |
3069 formal_parameters.scope->set_end_position(scanner()->location().end_pos); | 3092 formal_parameters.scope->set_end_position(scanner()->location().end_pos); |
3070 | 3093 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3157 } else if (next == Token::ILLEGAL) { | 3180 } else if (next == Token::ILLEGAL) { |
3158 Traits::ReportMessageAt( | 3181 Traits::ReportMessageAt( |
3159 Scanner::Location(position() + 1, peek_position()), | 3182 Scanner::Location(position() + 1, peek_position()), |
3160 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); | 3183 MessageTemplate::kUnexpectedToken, "ILLEGAL", kSyntaxError); |
3161 *ok = false; | 3184 *ok = false; |
3162 return Traits::EmptyExpression(); | 3185 return Traits::EmptyExpression(); |
3163 } | 3186 } |
3164 | 3187 |
3165 int expr_pos = peek_position(); | 3188 int expr_pos = peek_position(); |
3166 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); | 3189 ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK); |
3190 expression = Traits::RewriteExpression(expression); | |
3167 Traits::AddTemplateExpression(&ts, expression); | 3191 Traits::AddTemplateExpression(&ts, expression); |
3168 | 3192 |
3169 if (peek() != Token::RBRACE) { | 3193 if (peek() != Token::RBRACE) { |
3170 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), | 3194 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), |
3171 MessageTemplate::kUnterminatedTemplateExpr); | 3195 MessageTemplate::kUnterminatedTemplateExpr); |
3172 *ok = false; | 3196 *ok = false; |
3173 return Traits::EmptyExpression(); | 3197 return Traits::EmptyExpression(); |
3174 } | 3198 } |
3175 | 3199 |
3176 // If we didn't die parsing that expression, our next token should be a | 3200 // If we didn't die parsing that expression, our next token should be a |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3339 return; | 3363 return; |
3340 } | 3364 } |
3341 has_seen_constructor_ = true; | 3365 has_seen_constructor_ = true; |
3342 return; | 3366 return; |
3343 } | 3367 } |
3344 } | 3368 } |
3345 } // namespace internal | 3369 } // namespace internal |
3346 } // namespace v8 | 3370 } // namespace v8 |
3347 | 3371 |
3348 #endif // V8_PARSING_PARSER_BASE_H | 3372 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |