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 77 matching lines...) Loading... | |
88 // allowed to be parsed by this instance of the parser. | 88 // allowed to be parsed by this instance of the parser. |
89 bool allow_lazy() const { return allow_lazy_; } | 89 bool allow_lazy() const { return allow_lazy_; } |
90 bool allow_natives_syntax() const { return allow_natives_syntax_; } | 90 bool allow_natives_syntax() const { return allow_natives_syntax_; } |
91 bool allow_generators() const { return allow_generators_; } | 91 bool allow_generators() const { return allow_generators_; } |
92 bool allow_arrow_functions() const { return allow_arrow_functions_; } | 92 bool allow_arrow_functions() const { return allow_arrow_functions_; } |
93 bool allow_modules() const { return scanner()->HarmonyModules(); } | 93 bool allow_modules() const { return scanner()->HarmonyModules(); } |
94 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 94 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
95 bool allow_harmony_numeric_literals() const { | 95 bool allow_harmony_numeric_literals() const { |
96 return scanner()->HarmonyNumericLiterals(); | 96 return scanner()->HarmonyNumericLiterals(); |
97 } | 97 } |
98 bool allow_classes() const { return scanner()->HarmonyClasses(); } | |
98 | 99 |
99 // Setters that determine whether certain syntactical constructs are | 100 // Setters that determine whether certain syntactical constructs are |
100 // allowed to be parsed by this instance of the parser. | 101 // allowed to be parsed by this instance of the parser. |
101 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } | 102 void set_allow_lazy(bool allow) { allow_lazy_ = allow; } |
102 void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; } | 103 void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; } |
103 void set_allow_generators(bool allow) { allow_generators_ = allow; } | 104 void set_allow_generators(bool allow) { allow_generators_ = allow; } |
104 void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; } | 105 void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; } |
105 void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); } | 106 void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); } |
106 void set_allow_harmony_scoping(bool allow) { | 107 void set_allow_harmony_scoping(bool allow) { |
107 scanner()->SetHarmonyScoping(allow); | 108 scanner()->SetHarmonyScoping(allow); |
108 } | 109 } |
109 void set_allow_harmony_numeric_literals(bool allow) { | 110 void set_allow_harmony_numeric_literals(bool allow) { |
110 scanner()->SetHarmonyNumericLiterals(allow); | 111 scanner()->SetHarmonyNumericLiterals(allow); |
111 } | 112 } |
113 void set_allow_classes(bool allow) { | |
114 scanner()->SetHarmonyClasses(allow); | |
115 } | |
112 | 116 |
113 protected: | 117 protected: |
114 friend class Traits::Type::Checkpoint; | 118 friend class Traits::Type::Checkpoint; |
115 | 119 |
116 enum AllowEvalOrArgumentsAsIdentifier { | 120 enum AllowEvalOrArgumentsAsIdentifier { |
117 kAllowEvalOrArguments, | 121 kAllowEvalOrArguments, |
118 kDontAllowEvalOrArguments | 122 kDontAllowEvalOrArguments |
119 }; | 123 }; |
120 | 124 |
121 enum Mode { | 125 enum Mode { |
(...skipping 548 matching lines...) Loading... | |
670 } | 674 } |
671 | 675 |
672 static PreParserExpression UseStrictStringLiteral() { | 676 static PreParserExpression UseStrictStringLiteral() { |
673 return PreParserExpression(kUseStrictString); | 677 return PreParserExpression(kUseStrictString); |
674 } | 678 } |
675 | 679 |
676 static PreParserExpression This() { | 680 static PreParserExpression This() { |
677 return PreParserExpression(kThisExpression); | 681 return PreParserExpression(kThisExpression); |
678 } | 682 } |
679 | 683 |
684 static PreParserExpression Super() { | |
685 return PreParserExpression(kSuperExpression); | |
686 } | |
687 | |
680 static PreParserExpression ThisProperty() { | 688 static PreParserExpression ThisProperty() { |
681 return PreParserExpression(kThisPropertyExpression); | 689 return PreParserExpression(kThisPropertyExpression); |
682 } | 690 } |
683 | 691 |
684 static PreParserExpression Property() { | 692 static PreParserExpression Property() { |
685 return PreParserExpression(kPropertyExpression); | 693 return PreParserExpression(kPropertyExpression); |
686 } | 694 } |
687 | 695 |
688 static PreParserExpression Call() { | 696 static PreParserExpression Call() { |
689 return PreParserExpression(kCallExpression); | 697 return PreParserExpression(kCallExpression); |
(...skipping 101 matching lines...) Loading... | |
791 // duplicated identifier in parameter lists for arrow functions, because | 799 // duplicated identifier in parameter lists for arrow functions, because |
792 // they are initially parsed as comma-separated expressions. | 800 // they are initially parsed as comma-separated expressions. |
793 kTypeBinaryOperation = 3, | 801 kTypeBinaryOperation = 3, |
794 kBinaryOperationArrowParamList = (1 << 4), | 802 kBinaryOperationArrowParamList = (1 << 4), |
795 | 803 |
796 // Below here applies if neither identifier nor string literal. Reserve the | 804 // Below here applies if neither identifier nor string literal. Reserve the |
797 // 2 least significant bits for flags. | 805 // 2 least significant bits for flags. |
798 kThisExpression = (1 << 4), | 806 kThisExpression = (1 << 4), |
799 kThisPropertyExpression = (2 << 4), | 807 kThisPropertyExpression = (2 << 4), |
800 kPropertyExpression = (3 << 4), | 808 kPropertyExpression = (3 << 4), |
801 kCallExpression = (4 << 4) | 809 kCallExpression = (4 << 4), |
810 kSuperExpression = (5 << 4) | |
802 }; | 811 }; |
803 | 812 |
804 explicit PreParserExpression(int expression_code) : code_(expression_code) {} | 813 explicit PreParserExpression(int expression_code) : code_(expression_code) {} |
805 | 814 |
806 V8_INLINE int ArrowParamListBit() const { | 815 V8_INLINE int ArrowParamListBit() const { |
807 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList; | 816 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList; |
808 if (IsIdentifier()) { | 817 if (IsIdentifier()) { |
809 const PreParserIdentifier ident = AsIdentifier(); | 818 const PreParserIdentifier ident = AsIdentifier(); |
810 // A valid identifier can be an arrow function parameter list | 819 // A valid identifier can be an arrow function parameter list |
811 // except for eval, arguments, yield, and reserved keywords. | 820 // except for eval, arguments, yield, and reserved keywords. |
(...skipping 429 matching lines...) Loading... | |
1241 | 1250 |
1242 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { | 1251 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { |
1243 return PreParserIdentifier::Default(); | 1252 return PreParserIdentifier::Default(); |
1244 } | 1253 } |
1245 | 1254 |
1246 static PreParserExpression ThisExpression(PreParserScope* scope, | 1255 static PreParserExpression ThisExpression(PreParserScope* scope, |
1247 PreParserFactory* factory) { | 1256 PreParserFactory* factory) { |
1248 return PreParserExpression::This(); | 1257 return PreParserExpression::This(); |
1249 } | 1258 } |
1250 | 1259 |
1260 static PreParserExpression SuperReference(PreParserScope* scope, | |
1261 PreParserFactory* factory) { | |
1262 return PreParserExpression::Super(); | |
1263 } | |
1264 | |
1251 static PreParserExpression ExpressionFromLiteral( | 1265 static PreParserExpression ExpressionFromLiteral( |
1252 Token::Value token, int pos, Scanner* scanner, | 1266 Token::Value token, int pos, Scanner* scanner, |
1253 PreParserFactory* factory) { | 1267 PreParserFactory* factory) { |
1254 return PreParserExpression::Default(); | 1268 return PreParserExpression::Default(); |
1255 } | 1269 } |
1256 | 1270 |
1257 static PreParserExpression ExpressionFromIdentifier( | 1271 static PreParserExpression ExpressionFromIdentifier( |
1258 PreParserIdentifier name, int pos, PreParserScope* scope, | 1272 PreParserIdentifier name, int pos, PreParserScope* scope, |
1259 PreParserFactory* factory) { | 1273 PreParserFactory* factory) { |
1260 return PreParserExpression::FromIdentifier(name); | 1274 return PreParserExpression::FromIdentifier(name); |
(...skipping 1115 matching lines...) Loading... | |
2376 // new foo.bar().baz means (new (foo.bar)()).baz | 2390 // new foo.bar().baz means (new (foo.bar)()).baz |
2377 // new foo()() means (new foo())() | 2391 // new foo()() means (new foo())() |
2378 // new new foo()() means (new (new foo())()) | 2392 // new new foo()() means (new (new foo())()) |
2379 // new new foo means new (new foo) | 2393 // new new foo means new (new foo) |
2380 // new new foo() means new (new foo()) | 2394 // new new foo() means new (new foo()) |
2381 // new new foo().bar().baz means (new (new foo()).bar()).baz | 2395 // new new foo().bar().baz means (new (new foo()).bar()).baz |
2382 | 2396 |
2383 if (peek() == Token::NEW) { | 2397 if (peek() == Token::NEW) { |
2384 Consume(Token::NEW); | 2398 Consume(Token::NEW); |
2385 int new_pos = position(); | 2399 int new_pos = position(); |
2386 ExpressionT result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); | 2400 ExpressionT result = this->EmptyExpression(); |
2401 if (peek() == Token::SUPER) { | |
arv (Not doing code reviews)
2014/08/15 19:41:07
You can use Check here instead.
if (Check(Token::
Dmitry Lomov (no reviews)
2014/08/15 22:11:41
Done.
| |
2402 Consume(Token::SUPER); | |
2403 result = this->SuperReference(scope_, factory()); | |
2404 } else { | |
2405 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); | |
2406 } | |
2387 if (peek() == Token::LPAREN) { | 2407 if (peek() == Token::LPAREN) { |
2388 // NewExpression with arguments. | 2408 // NewExpression with arguments. |
2389 typename Traits::Type::ExpressionList args = | 2409 typename Traits::Type::ExpressionList args = |
2390 this->ParseArguments(CHECK_OK); | 2410 this->ParseArguments(CHECK_OK); |
2391 result = factory()->NewCallNew(result, args, new_pos); | 2411 result = factory()->NewCallNew(result, args, new_pos); |
2392 // The expression can still continue with . or [ after the arguments. | 2412 // The expression can still continue with . or [ after the arguments. |
2393 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); | 2413 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); |
2394 return result; | 2414 return result; |
2395 } | 2415 } |
2396 // NewExpression without arguments. | 2416 // NewExpression without arguments. |
2397 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), | 2417 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), |
2398 new_pos); | 2418 new_pos); |
2399 } | 2419 } |
2400 // No 'new' keyword. | 2420 // No 'new' or 'super' keyword. |
2401 return this->ParseMemberExpression(ok); | 2421 return this->ParseMemberExpression(ok); |
2402 } | 2422 } |
2403 | 2423 |
2404 | 2424 |
2405 template <class Traits> | 2425 template <class Traits> |
2406 typename ParserBase<Traits>::ExpressionT | 2426 typename ParserBase<Traits>::ExpressionT |
2407 ParserBase<Traits>::ParseMemberExpression(bool* ok) { | 2427 ParserBase<Traits>::ParseMemberExpression(bool* ok) { |
2408 // MemberExpression :: | 2428 // MemberExpression :: |
2409 // (PrimaryExpression | FunctionLiteral) | 2429 // (PrimaryExpression | FunctionLiteral) |
2410 // ('[' Expression ']' | '.' Identifier | Arguments)* | 2430 // ('[' Expression ']' | '.' Identifier | Arguments)* |
(...skipping 20 matching lines...) Loading... | |
2431 function_type = FunctionLiteral::NAMED_EXPRESSION; | 2451 function_type = FunctionLiteral::NAMED_EXPRESSION; |
2432 } | 2452 } |
2433 result = this->ParseFunctionLiteral(name, | 2453 result = this->ParseFunctionLiteral(name, |
2434 function_name_location, | 2454 function_name_location, |
2435 is_strict_reserved_name, | 2455 is_strict_reserved_name, |
2436 is_generator, | 2456 is_generator, |
2437 function_token_position, | 2457 function_token_position, |
2438 function_type, | 2458 function_type, |
2439 FunctionLiteral::NORMAL_ARITY, | 2459 FunctionLiteral::NORMAL_ARITY, |
2440 CHECK_OK); | 2460 CHECK_OK); |
2461 } else if (peek() == Token::SUPER) { | |
2462 int beg_pos = position(); | |
2463 Consume(Token::SUPER); | |
2464 Token::Value next = peek(); | |
2465 if (next == Token::PERIOD || next == Token::LBRACK || | |
2466 next == Token::LPAREN) { | |
2467 result = this->SuperReference(scope_, factory()); | |
2468 } else { | |
2469 ReportMessageAt(Scanner::Location(beg_pos, position()), | |
2470 "unexpected_super"); | |
2471 *ok = false; | |
2472 return this->EmptyExpression(); | |
2473 } | |
2441 } else { | 2474 } else { |
2442 result = ParsePrimaryExpression(CHECK_OK); | 2475 result = ParsePrimaryExpression(CHECK_OK); |
2443 } | 2476 } |
2444 | 2477 |
2445 result = ParseMemberExpressionContinuation(result, CHECK_OK); | 2478 result = ParseMemberExpressionContinuation(result, CHECK_OK); |
2446 return result; | 2479 return result; |
2447 } | 2480 } |
2448 | 2481 |
2449 | 2482 |
2450 template <class Traits> | 2483 template <class Traits> |
(...skipping 203 matching lines...) Loading... | |
2654 parser()->ReportMessage("accessor_get_set"); | 2687 parser()->ReportMessage("accessor_get_set"); |
2655 } | 2688 } |
2656 *ok = false; | 2689 *ok = false; |
2657 } | 2690 } |
2658 } | 2691 } |
2659 | 2692 |
2660 | 2693 |
2661 } } // v8::internal | 2694 } } // v8::internal |
2662 | 2695 |
2663 #endif // V8_PREPARSER_H | 2696 #endif // V8_PREPARSER_H |
OLD | NEW |