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

Side by Side Diff: src/preparser.h

Issue 418143007: FYI Implementing 'super' keyword (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use private own symbol for [[HomeObject]] 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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 670 }
671 671
672 static PreParserExpression UseStrictStringLiteral() { 672 static PreParserExpression UseStrictStringLiteral() {
673 return PreParserExpression(kUseStrictString); 673 return PreParserExpression(kUseStrictString);
674 } 674 }
675 675
676 static PreParserExpression This() { 676 static PreParserExpression This() {
677 return PreParserExpression(kThisExpression); 677 return PreParserExpression(kThisExpression);
678 } 678 }
679 679
680 static PreParserExpression Super() {
681 return PreParserExpression(kSuperExpression);
682 }
683
680 static PreParserExpression ThisProperty() { 684 static PreParserExpression ThisProperty() {
681 return PreParserExpression(kThisPropertyExpression); 685 return PreParserExpression(kThisPropertyExpression);
682 } 686 }
683 687
684 static PreParserExpression Property() { 688 static PreParserExpression Property() {
685 return PreParserExpression(kPropertyExpression); 689 return PreParserExpression(kPropertyExpression);
686 } 690 }
687 691
688 static PreParserExpression Call() { 692 static PreParserExpression Call() {
689 return PreParserExpression(kCallExpression); 693 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 795 // duplicated identifier in parameter lists for arrow functions, because
792 // they are initially parsed as comma-separated expressions. 796 // they are initially parsed as comma-separated expressions.
793 kTypeBinaryOperation = 3, 797 kTypeBinaryOperation = 3,
794 kBinaryOperationArrowParamList = (1 << 4), 798 kBinaryOperationArrowParamList = (1 << 4),
795 799
796 // Below here applies if neither identifier nor string literal. Reserve the 800 // Below here applies if neither identifier nor string literal. Reserve the
797 // 2 least significant bits for flags. 801 // 2 least significant bits for flags.
798 kThisExpression = (1 << 4), 802 kThisExpression = (1 << 4),
799 kThisPropertyExpression = (2 << 4), 803 kThisPropertyExpression = (2 << 4),
800 kPropertyExpression = (3 << 4), 804 kPropertyExpression = (3 << 4),
801 kCallExpression = (4 << 4) 805 kCallExpression = (4 << 4),
806 kSuperExpression = (5 << 4)
802 }; 807 };
803 808
804 explicit PreParserExpression(int expression_code) : code_(expression_code) {} 809 explicit PreParserExpression(int expression_code) : code_(expression_code) {}
805 810
806 V8_INLINE int ArrowParamListBit() const { 811 V8_INLINE int ArrowParamListBit() const {
807 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList; 812 if (IsBinaryOperation()) return code_ & kBinaryOperationArrowParamList;
808 if (IsIdentifier()) { 813 if (IsIdentifier()) {
809 const PreParserIdentifier ident = AsIdentifier(); 814 const PreParserIdentifier ident = AsIdentifier();
810 // A valid identifier can be an arrow function parameter list 815 // A valid identifier can be an arrow function parameter list
811 // except for eval, arguments, yield, and reserved keywords. 816 // except for eval, arguments, yield, and reserved keywords.
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 1246
1242 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { 1247 static PreParserIdentifier GetNextSymbol(Scanner* scanner) {
1243 return PreParserIdentifier::Default(); 1248 return PreParserIdentifier::Default();
1244 } 1249 }
1245 1250
1246 static PreParserExpression ThisExpression(PreParserScope* scope, 1251 static PreParserExpression ThisExpression(PreParserScope* scope,
1247 PreParserFactory* factory) { 1252 PreParserFactory* factory) {
1248 return PreParserExpression::This(); 1253 return PreParserExpression::This();
1249 } 1254 }
1250 1255
1256 static PreParserExpression SuperReference(PreParserScope* scope,
1257 PreParserFactory* factory) {
1258 return PreParserExpression::Super();
1259 }
1260
1251 static PreParserExpression ExpressionFromLiteral( 1261 static PreParserExpression ExpressionFromLiteral(
1252 Token::Value token, int pos, Scanner* scanner, 1262 Token::Value token, int pos, Scanner* scanner,
1253 PreParserFactory* factory) { 1263 PreParserFactory* factory) {
1254 return PreParserExpression::Default(); 1264 return PreParserExpression::Default();
1255 } 1265 }
1256 1266
1257 static PreParserExpression ExpressionFromIdentifier( 1267 static PreParserExpression ExpressionFromIdentifier(
1258 PreParserIdentifier name, int pos, PreParserScope* scope, 1268 PreParserIdentifier name, int pos, PreParserScope* scope,
1259 PreParserFactory* factory) { 1269 PreParserFactory* factory) {
1260 return PreParserExpression::FromIdentifier(name); 1270 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 2386 // new foo.bar().baz means (new (foo.bar)()).baz
2377 // new foo()() means (new foo())() 2387 // new foo()() means (new foo())()
2378 // new new foo()() means (new (new foo())()) 2388 // new new foo()() means (new (new foo())())
2379 // new new foo means new (new foo) 2389 // new new foo means new (new foo)
2380 // new new foo() means new (new foo()) 2390 // new new foo() means new (new foo())
2381 // new new foo().bar().baz means (new (new foo()).bar()).baz 2391 // new new foo().bar().baz means (new (new foo()).bar()).baz
2382 2392
2383 if (peek() == Token::NEW) { 2393 if (peek() == Token::NEW) {
2384 Consume(Token::NEW); 2394 Consume(Token::NEW);
2385 int new_pos = position(); 2395 int new_pos = position();
2386 ExpressionT result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK); 2396 ExpressionT result = this->EmptyExpression();
2397 if (peek() == Token::SUPER) {
2398 Consume(Token::SUPER);
2399 result = this->SuperReference(scope_, factory());
2400 } else {
2401 result = this->ParseMemberWithNewPrefixesExpression(CHECK_OK);
2402 }
2387 if (peek() == Token::LPAREN) { 2403 if (peek() == Token::LPAREN) {
2388 // NewExpression with arguments. 2404 // NewExpression with arguments.
2389 typename Traits::Type::ExpressionList args = 2405 typename Traits::Type::ExpressionList args =
2390 this->ParseArguments(CHECK_OK); 2406 this->ParseArguments(CHECK_OK);
2391 result = factory()->NewCallNew(result, args, new_pos); 2407 result = factory()->NewCallNew(result, args, new_pos);
2392 // The expression can still continue with . or [ after the arguments. 2408 // The expression can still continue with . or [ after the arguments.
2393 result = this->ParseMemberExpressionContinuation(result, CHECK_OK); 2409 result = this->ParseMemberExpressionContinuation(result, CHECK_OK);
2394 return result; 2410 return result;
2395 } 2411 }
2396 // NewExpression without arguments. 2412 // NewExpression without arguments.
2397 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_), 2413 return factory()->NewCallNew(result, this->NewExpressionList(0, zone_),
2398 new_pos); 2414 new_pos);
2399 } 2415 }
2400 // No 'new' keyword. 2416 // No 'new' or 'super' keyword.
2401 return this->ParseMemberExpression(ok); 2417 return this->ParseMemberExpression(ok);
2402 } 2418 }
2403 2419
2404 2420
2405 template <class Traits> 2421 template <class Traits>
2406 typename ParserBase<Traits>::ExpressionT 2422 typename ParserBase<Traits>::ExpressionT
2407 ParserBase<Traits>::ParseMemberExpression(bool* ok) { 2423 ParserBase<Traits>::ParseMemberExpression(bool* ok) {
2408 // MemberExpression :: 2424 // MemberExpression ::
2409 // (PrimaryExpression | FunctionLiteral) 2425 // (PrimaryExpression | FunctionLiteral)
2410 // ('[' Expression ']' | '.' Identifier | Arguments)* 2426 // ('[' Expression ']' | '.' Identifier | Arguments)*
(...skipping 20 matching lines...) Expand all
2431 function_type = FunctionLiteral::NAMED_EXPRESSION; 2447 function_type = FunctionLiteral::NAMED_EXPRESSION;
2432 } 2448 }
2433 result = this->ParseFunctionLiteral(name, 2449 result = this->ParseFunctionLiteral(name,
2434 function_name_location, 2450 function_name_location,
2435 is_strict_reserved_name, 2451 is_strict_reserved_name,
2436 is_generator, 2452 is_generator,
2437 function_token_position, 2453 function_token_position,
2438 function_type, 2454 function_type,
2439 FunctionLiteral::NORMAL_ARITY, 2455 FunctionLiteral::NORMAL_ARITY,
2440 CHECK_OK); 2456 CHECK_OK);
2457 } else if (peek() == Token::SUPER) {
2458 int beg_pos = position();
2459 Consume(Token::SUPER);
2460 Token::Value next = peek();
2461 if (next == Token::PERIOD || next == Token::LBRACK ||
2462 next == Token::LPAREN) {
2463 result = this->SuperReference(scope_, factory());
2464 } else {
2465 ReportMessageAt(Scanner::Location(beg_pos, position()),
2466 "unexpected_super");
2467 *ok = false;
2468 return this->EmptyExpression();
2469 }
2441 } else { 2470 } else {
2442 result = ParsePrimaryExpression(CHECK_OK); 2471 result = ParsePrimaryExpression(CHECK_OK);
2443 } 2472 }
2444 2473
2445 result = ParseMemberExpressionContinuation(result, CHECK_OK); 2474 result = ParseMemberExpressionContinuation(result, CHECK_OK);
2446 return result; 2475 return result;
2447 } 2476 }
2448 2477
2449 2478
2450 template <class Traits> 2479 template <class Traits>
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 parser()->ReportMessage("accessor_get_set"); 2683 parser()->ReportMessage("accessor_get_set");
2655 } 2684 }
2656 *ok = false; 2685 *ok = false;
2657 } 2686 }
2658 } 2687 }
2659 2688
2660 2689
2661 } } // v8::internal 2690 } } // v8::internal
2662 2691
2663 #endif // V8_PREPARSER_H 2692 #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