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

Side by Side Diff: src/preparser.h

Issue 480543002: Parse 'super' keyword. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Patch for landing (minor fix for tests in release mode) Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.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 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...) Expand 10 before | Expand all | Expand 10 after
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...) Expand 10 before | Expand all | Expand 10 after
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...) Expand 10 before | Expand all | Expand 10 after
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...) Expand 10 before | Expand all | Expand 10 after
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...) Expand 10 before | Expand all | Expand 10 after
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 (Check(Token::SUPER)) {
2402 result = this->SuperReference(scope_, factory());
2403 } else {
2404 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK);
2405 }
2387 if (peek() == Token::LPAREN) { 2406 if (peek() == Token::LPAREN) {
2388 // NewExpression with arguments. 2407 // NewExpression with arguments.
2389 typename Traits::Type::ExpressionList args = 2408 typename Traits::Type::ExpressionList args =
2390 this->ParseArguments(CHECK_OK); 2409 this->ParseArguments(CHECK_OK);
2391 result = factory()->NewCallNew(result, args, new_pos); 2410 result = factory()->NewCallNew(result, args, new_pos);
2392 // The expression can still continue with . or [ after the arguments. 2411 // The expression can still continue with . or [ after the arguments.
2393 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); 2412 result = this->ParseMemberExpressionContinuation(result, CHECK_OK);
2394 return result; 2413 return result;
2395 } 2414 }
2396 // NewExpression without arguments. 2415 // NewExpression without arguments.
2397 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), 2416 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_),
2398 new_pos); 2417 new_pos);
2399 } 2418 }
2400 // No 'new' keyword. 2419 // No 'new' or 'super' keyword.
2401 return this->ParseMemberExpression(ok); 2420 return this->ParseMemberExpression(ok);
2402 } 2421 }
2403 2422
2404 2423
2405 template <class Traits> 2424 template <class Traits>
2406 typename ParserBase<Traits>::ExpressionT 2425 typename ParserBase<Traits>::ExpressionT
2407 ParserBase<Traits>::ParseMemberExpression(bool* ok) { 2426 ParserBase<Traits>::ParseMemberExpression(bool* ok) {
2408 // MemberExpression :: 2427 // MemberExpression ::
2409 // (PrimaryExpression | FunctionLiteral) 2428 // (PrimaryExpression | FunctionLiteral)
2410 // ('[' Expression ']' | '.' Identifier | Arguments)* 2429 // ('[' Expression ']' | '.' Identifier | Arguments)*
(...skipping 20 matching lines...) Expand all
2431 function_type = FunctionLiteral::NAMED_EXPRESSION; 2450 function_type = FunctionLiteral::NAMED_EXPRESSION;
2432 } 2451 }
2433 result = this->ParseFunctionLiteral(name, 2452 result = this->ParseFunctionLiteral(name,
2434 function_name_location, 2453 function_name_location,
2435 is_strict_reserved_name, 2454 is_strict_reserved_name,
2436 is_generator, 2455 is_generator,
2437 function_token_position, 2456 function_token_position,
2438 function_type, 2457 function_type,
2439 FunctionLiteral::NORMAL_ARITY, 2458 FunctionLiteral::NORMAL_ARITY,
2440 CHECK_OK); 2459 CHECK_OK);
2460 } else if (peek() == Token::SUPER) {
2461 int beg_pos = position();
2462 Consume(Token::SUPER);
2463 Token::Value next = peek();
2464 if (next == Token::PERIOD || next == Token::LBRACK ||
2465 next == Token::LPAREN) {
2466 result = this->SuperReference(scope_, factory());
2467 } else {
2468 ReportMessageAt(Scanner::Location(beg_pos, position()),
2469 "unexpected_super");
2470 *ok = false;
2471 return this->EmptyExpression();
2472 }
2441 } else { 2473 } else {
2442 result = ParsePrimaryExpression(CHECK_OK); 2474 result = ParsePrimaryExpression(CHECK_OK);
2443 } 2475 }
2444 2476
2445 result = ParseMemberExpressionContinuation(result, CHECK_OK); 2477 result = ParseMemberExpressionContinuation(result, CHECK_OK);
2446 return result; 2478 return result;
2447 } 2479 }
2448 2480
2449 2481
2450 template <class Traits> 2482 template <class Traits>
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 parser()->ReportMessage("accessor_get_set"); 2686 parser()->ReportMessage("accessor_get_set");
2655 } 2687 }
2656 *ok = false; 2688 *ok = false;
2657 } 2689 }
2658 } 2690 }
2659 2691
2660 2692
2661 } } // v8::internal 2693 } } // v8::internal
2662 2694
2663 #endif // V8_PREPARSER_H 2695 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698