| 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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 } | 645 } |
| 646 | 646 |
| 647 static PreParserExpression UseStrictStringLiteral() { | 647 static PreParserExpression UseStrictStringLiteral() { |
| 648 return PreParserExpression(kUseStrictString); | 648 return PreParserExpression(kUseStrictString); |
| 649 } | 649 } |
| 650 | 650 |
| 651 static PreParserExpression This() { | 651 static PreParserExpression This() { |
| 652 return PreParserExpression(kThisExpression); | 652 return PreParserExpression(kThisExpression); |
| 653 } | 653 } |
| 654 | 654 |
| 655 static PreParserExpression Super() { |
| 656 return PreParserExpression(kSuperExpression); |
| 657 } |
| 658 |
| 655 static PreParserExpression ThisProperty() { | 659 static PreParserExpression ThisProperty() { |
| 656 return PreParserExpression(kThisPropertyExpression); | 660 return PreParserExpression(kThisPropertyExpression); |
| 657 } | 661 } |
| 658 | 662 |
| 659 static PreParserExpression Property() { | 663 static PreParserExpression Property() { |
| 660 return PreParserExpression(kPropertyExpression); | 664 return PreParserExpression(kPropertyExpression); |
| 661 } | 665 } |
| 662 | 666 |
| 663 static PreParserExpression Call() { | 667 static PreParserExpression Call() { |
| 664 return PreParserExpression(kCallExpression); | 668 return PreParserExpression(kCallExpression); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 // duplicated identifier in parameter lists for arrow functions, because | 770 // duplicated identifier in parameter lists for arrow functions, because |
| 767 // they are initially parsed as comma-separated expressions. | 771 // they are initially parsed as comma-separated expressions. |
| 768 kTypeBinaryOperation = 3, | 772 kTypeBinaryOperation = 3, |
| 769 kBinaryOperationArrowParamList = (1 << 4), | 773 kBinaryOperationArrowParamList = (1 << 4), |
| 770 | 774 |
| 771 // Below here applies if neither identifier nor string literal. Reserve the | 775 // Below here applies if neither identifier nor string literal. Reserve the |
| 772 // 2 least significant bits for flags. | 776 // 2 least significant bits for flags. |
| 773 kThisExpression = (1 << 4), | 777 kThisExpression = (1 << 4), |
| 774 kThisPropertyExpression = (2 << 4), | 778 kThisPropertyExpression = (2 << 4), |
| 775 kPropertyExpression = (3 << 4), | 779 kPropertyExpression = (3 << 4), |
| 776 kCallExpression = (4 << 4) | 780 kCallExpression = (4 << 4), |
| 781 kSuperExpression = (5 << 4) |
| 777 }; | 782 }; |
| 778 | 783 |
| 779 explicit PreParserExpression(int expression_code) : code_(expression_code) {} | 784 explicit PreParserExpression(int expression_code) : code_(expression_code) {} |
| 780 | 785 |
| 781 V8_INLINE int ArrowParamListBit() const { | 786 V8_INLINE int ArrowParamListBit() const { |
| 782 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList; | 787 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList; |
| 783 if (IsIdentifier()) { | 788 if (IsIdentifier()) { |
| 784 const PreParserIdentifier ident = AsIdentifier(); | 789 const PreParserIdentifier ident = AsIdentifier(); |
| 785 // A valid identifier can be an arrow function parameter list | 790 // A valid identifier can be an arrow function parameter list |
| 786 // except for eval, arguments, yield, and reserved keywords. | 791 // except for eval, arguments, yield, and reserved keywords. |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 | 1214 |
| 1210 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { | 1215 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { |
| 1211 return PreParserIdentifier::Default(); | 1216 return PreParserIdentifier::Default(); |
| 1212 } | 1217 } |
| 1213 | 1218 |
| 1214 static PreParserExpression ThisExpression(PreParserScope* scope, | 1219 static PreParserExpression ThisExpression(PreParserScope* scope, |
| 1215 PreParserFactory* factory) { | 1220 PreParserFactory* factory) { |
| 1216 return PreParserExpression::This(); | 1221 return PreParserExpression::This(); |
| 1217 } | 1222 } |
| 1218 | 1223 |
| 1224 static PreParserExpression SuperReference(PreParserScope* scope, |
| 1225 PreParserFactory* factory) { |
| 1226 return PreParserExpression::Super(); |
| 1227 } |
| 1228 |
| 1219 static PreParserExpression ExpressionFromLiteral( | 1229 static PreParserExpression ExpressionFromLiteral( |
| 1220 Token::Value token, int pos, Scanner* scanner, | 1230 Token::Value token, int pos, Scanner* scanner, |
| 1221 PreParserFactory* factory) { | 1231 PreParserFactory* factory) { |
| 1222 return PreParserExpression::Default(); | 1232 return PreParserExpression::Default(); |
| 1223 } | 1233 } |
| 1224 | 1234 |
| 1225 static PreParserExpression ExpressionFromIdentifier( | 1235 static PreParserExpression ExpressionFromIdentifier( |
| 1226 PreParserIdentifier name, int pos, PreParserScope* scope, | 1236 PreParserIdentifier name, int pos, PreParserScope* scope, |
| 1227 PreParserFactory* factory) { | 1237 PreParserFactory* factory) { |
| 1228 return PreParserExpression::FromIdentifier(name); | 1238 return PreParserExpression::FromIdentifier(name); |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2333 // new foo.bar().baz means (new (foo.bar)()).baz | 2343 // new foo.bar().baz means (new (foo.bar)()).baz |
| 2334 // new foo()() means (new foo())() | 2344 // new foo()() means (new foo())() |
| 2335 // new new foo()() means (new (new foo())()) | 2345 // new new foo()() means (new (new foo())()) |
| 2336 // new new foo means new (new foo) | 2346 // new new foo means new (new foo) |
| 2337 // new new foo() means new (new foo()) | 2347 // new new foo() means new (new foo()) |
| 2338 // new new foo().bar().baz means (new (new foo()).bar()).baz | 2348 // new new foo().bar().baz means (new (new foo()).bar()).baz |
| 2339 | 2349 |
| 2340 if (peek() == Token::NEW) { | 2350 if (peek() == Token::NEW) { |
| 2341 Consume(Token::NEW); | 2351 Consume(Token::NEW); |
| 2342 int new_pos = position(); | 2352 int new_pos = position(); |
| 2343 ExpressionT result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); | 2353 ExpressionT result = this->EmptyExpression(); |
| 2354 if (peek() == Token::SUPER) { |
| 2355 Consume(Token::SUPER); |
| 2356 result = this->SuperReference(scope_, factory()); |
| 2357 } else { |
| 2358 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); |
| 2359 } |
| 2344 if (peek() == Token::LPAREN) { | 2360 if (peek() == Token::LPAREN) { |
| 2345 // NewExpression with arguments. | 2361 // NewExpression with arguments. |
| 2346 typename Traits::Type::ExpressionList args = | 2362 typename Traits::Type::ExpressionList args = |
| 2347 this->ParseArguments(CHECK_OK); | 2363 this->ParseArguments(CHECK_OK); |
| 2348 result = factory()->NewCallNew(result, args, new_pos); | 2364 result = factory()->NewCallNew(result, args, new_pos); |
| 2349 // The expression can still continue with . or [ after the arguments. | 2365 // The expression can still continue with . or [ after the arguments. |
| 2350 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); | 2366 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); |
| 2351 return result; | 2367 return result; |
| 2352 } | 2368 } |
| 2353 // NewExpression without arguments. | 2369 // NewExpression without arguments. |
| 2354 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), | 2370 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), |
| 2355 new_pos); | 2371 new_pos); |
| 2356 } | 2372 } |
| 2357 // No 'new' keyword. | 2373 // No 'new' or 'super' keyword. |
| 2358 return this->ParseMemberExpression(ok); | 2374 return this->ParseMemberExpression(ok); |
| 2359 } | 2375 } |
| 2360 | 2376 |
| 2361 | 2377 |
| 2362 template <class Traits> | 2378 template <class Traits> |
| 2363 typename ParserBase<Traits>::ExpressionT | 2379 typename ParserBase<Traits>::ExpressionT |
| 2364 ParserBase<Traits>::ParseMemberExpression(bool* ok) { | 2380 ParserBase<Traits>::ParseMemberExpression(bool* ok) { |
| 2365 // MemberExpression :: | 2381 // MemberExpression :: |
| 2366 // (PrimaryExpression | FunctionLiteral) | 2382 // (PrimaryExpression | FunctionLiteral) |
| 2367 // ('[' Expression ']' | '.' Identifier | Arguments)* | 2383 // ('[' Expression ']' | '.' Identifier | Arguments)* |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2388 function_type = FunctionLiteral::NAMED_EXPRESSION; | 2404 function_type = FunctionLiteral::NAMED_EXPRESSION; |
| 2389 } | 2405 } |
| 2390 result = this->ParseFunctionLiteral(name, | 2406 result = this->ParseFunctionLiteral(name, |
| 2391 function_name_location, | 2407 function_name_location, |
| 2392 is_strict_reserved_name, | 2408 is_strict_reserved_name, |
| 2393 is_generator, | 2409 is_generator, |
| 2394 function_token_position, | 2410 function_token_position, |
| 2395 function_type, | 2411 function_type, |
| 2396 FunctionLiteral::NORMAL_ARITY, | 2412 FunctionLiteral::NORMAL_ARITY, |
| 2397 CHECK_OK); | 2413 CHECK_OK); |
| 2414 } else if (peek() == Token::SUPER) { |
| 2415 int beg_pos = position(); |
| 2416 Consume(Token::SUPER); |
| 2417 Token::Value next = peek(); |
| 2418 if (next == Token::PERIOD || next == Token::LBRACK || |
| 2419 next == Token::LPAREN) { |
| 2420 result = this->SuperReference(scope_, factory()); |
| 2421 } else { |
| 2422 ReportMessageAt(Scanner::Location(beg_pos, position()), |
| 2423 "unexpected_super"); |
| 2424 *ok = false; |
| 2425 return this->EmptyExpression(); |
| 2426 } |
| 2398 } else { | 2427 } else { |
| 2399 result = ParsePrimaryExpression(CHECK_OK); | 2428 result = ParsePrimaryExpression(CHECK_OK); |
| 2400 } | 2429 } |
| 2401 | 2430 |
| 2402 result = ParseMemberExpressionContinuation(result, CHECK_OK); | 2431 result = ParseMemberExpressionContinuation(result, CHECK_OK); |
| 2403 return result; | 2432 return result; |
| 2404 } | 2433 } |
| 2405 | 2434 |
| 2406 | 2435 |
| 2407 template <class Traits> | 2436 template <class Traits> |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2619 parser()->ReportMessage("accessor_get_set"); | 2648 parser()->ReportMessage("accessor_get_set"); |
| 2620 } | 2649 } |
| 2621 *ok = false; | 2650 *ok = false; |
| 2622 } | 2651 } |
| 2623 } | 2652 } |
| 2624 | 2653 |
| 2625 | 2654 |
| 2626 } } // v8::internal | 2655 } } // v8::internal |
| 2627 | 2656 |
| 2628 #endif // V8_PREPARSER_H | 2657 #endif // V8_PREPARSER_H |
| OLD | NEW |