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

Side by Side Diff: src/preparser.h

Issue 1226123010: Represent implicit 'this' binding by 'super' in AST. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. Created 5 years, 5 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
« no previous file with comments | « src/ppc/full-codegen-ppc.cc ('k') | src/x64/full-codegen-x64.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/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 return PreParserExpression( 940 return PreParserExpression(
941 TypeField::encode(kExpression) | 941 TypeField::encode(kExpression) |
942 ExpressionTypeField::encode(kPropertyExpression)); 942 ExpressionTypeField::encode(kPropertyExpression));
943 } 943 }
944 944
945 static PreParserExpression Call() { 945 static PreParserExpression Call() {
946 return PreParserExpression(TypeField::encode(kExpression) | 946 return PreParserExpression(TypeField::encode(kExpression) |
947 ExpressionTypeField::encode(kCallExpression)); 947 ExpressionTypeField::encode(kCallExpression));
948 } 948 }
949 949
950 static PreParserExpression SuperCallReference() {
951 return PreParserExpression(
952 TypeField::encode(kExpression) |
953 ExpressionTypeField::encode(kSuperCallReference));
954 }
955
950 static PreParserExpression NoTemplateTag() { 956 static PreParserExpression NoTemplateTag() {
951 return PreParserExpression(TypeField::encode(kExpression) | 957 return PreParserExpression(
952 ExpressionTypeField::encode( 958 TypeField::encode(kExpression) |
953 kNoTemplateTagExpression)); 959 ExpressionTypeField::encode(kNoTemplateTagExpression));
954 } 960 }
955 961
956 bool IsIdentifier() const { 962 bool IsIdentifier() const {
957 return TypeField::decode(code_) == kIdentifierExpression; 963 return TypeField::decode(code_) == kIdentifierExpression;
958 } 964 }
959 965
960 PreParserIdentifier AsIdentifier() const { 966 PreParserIdentifier AsIdentifier() const {
961 DCHECK(IsIdentifier()); 967 DCHECK(IsIdentifier());
962 return PreParserIdentifier(IdentifierTypeField::decode(code_)); 968 return PreParserIdentifier(IdentifierTypeField::decode(code_));
963 } 969 }
(...skipping 26 matching lines...) Expand all
990 return TypeField::decode(code_) == kExpression && 996 return TypeField::decode(code_) == kExpression &&
991 (ExpressionTypeField::decode(code_) == kPropertyExpression || 997 (ExpressionTypeField::decode(code_) == kPropertyExpression ||
992 ExpressionTypeField::decode(code_) == kThisPropertyExpression); 998 ExpressionTypeField::decode(code_) == kThisPropertyExpression);
993 } 999 }
994 1000
995 bool IsCall() const { 1001 bool IsCall() const {
996 return TypeField::decode(code_) == kExpression && 1002 return TypeField::decode(code_) == kExpression &&
997 ExpressionTypeField::decode(code_) == kCallExpression; 1003 ExpressionTypeField::decode(code_) == kCallExpression;
998 } 1004 }
999 1005
1006 bool IsSuperCallReference() const {
1007 return TypeField::decode(code_) == kExpression &&
1008 ExpressionTypeField::decode(code_) == kSuperCallReference;
1009 }
1010
1000 bool IsValidReferenceExpression() const { 1011 bool IsValidReferenceExpression() const {
1001 return IsIdentifier() || IsProperty(); 1012 return IsIdentifier() || IsProperty();
1002 } 1013 }
1003 1014
1004 // At the moment PreParser doesn't track these expression types. 1015 // At the moment PreParser doesn't track these expression types.
1005 bool IsFunctionLiteral() const { return false; } 1016 bool IsFunctionLiteral() const { return false; }
1006 bool IsCallNew() const { return false; } 1017 bool IsCallNew() const { return false; }
1007 1018
1008 bool IsNoTemplateTag() const { 1019 bool IsNoTemplateTag() const {
1009 return TypeField::decode(code_) == kExpression && 1020 return TypeField::decode(code_) == kExpression &&
(...skipping 28 matching lines...) Expand all
1038 kStringLiteralExpression, 1049 kStringLiteralExpression,
1039 kBinaryOperationExpression, 1050 kBinaryOperationExpression,
1040 kSpreadExpression 1051 kSpreadExpression
1041 }; 1052 };
1042 1053
1043 enum ExpressionType { 1054 enum ExpressionType {
1044 kThisExpression, 1055 kThisExpression,
1045 kThisPropertyExpression, 1056 kThisPropertyExpression,
1046 kPropertyExpression, 1057 kPropertyExpression,
1047 kCallExpression, 1058 kCallExpression,
1059 kSuperCallReference,
1048 kNoTemplateTagExpression 1060 kNoTemplateTagExpression
1049 }; 1061 };
1050 1062
1051 explicit PreParserExpression(uint32_t expression_code) 1063 explicit PreParserExpression(uint32_t expression_code)
1052 : code_(expression_code) {} 1064 : code_(expression_code) {}
1053 1065
1054 // The first three bits are for the Type. 1066 // The first three bits are for the Type.
1055 typedef BitField<Type, 0, 3> TypeField; 1067 typedef BitField<Type, 0, 3> TypeField;
1056 1068
1057 // The rest of the bits are interpreted depending on the value 1069 // The rest of the bits are interpreted depending on the value
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 1533
1522 static PreParserExpression SuperPropertyReference(Scope* scope, 1534 static PreParserExpression SuperPropertyReference(Scope* scope,
1523 PreParserFactory* factory, 1535 PreParserFactory* factory,
1524 int pos) { 1536 int pos) {
1525 return PreParserExpression::Default(); 1537 return PreParserExpression::Default();
1526 } 1538 }
1527 1539
1528 static PreParserExpression SuperCallReference(Scope* scope, 1540 static PreParserExpression SuperCallReference(Scope* scope,
1529 PreParserFactory* factory, 1541 PreParserFactory* factory,
1530 int pos) { 1542 int pos) {
1531 return PreParserExpression::Default(); 1543 return PreParserExpression::SuperCallReference();
1532 } 1544 }
1533 1545
1534 static PreParserExpression NewTargetExpression(Scope* scope, 1546 static PreParserExpression NewTargetExpression(Scope* scope,
1535 PreParserFactory* factory, 1547 PreParserFactory* factory,
1536 int pos) { 1548 int pos) {
1537 return PreParserExpression::Default(); 1549 return PreParserExpression::Default();
1538 } 1550 }
1539 1551
1540 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope, 1552 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope,
1541 int pos, int end_pos) { 1553 int pos, int end_pos) {
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
3177 3189
3178 // Keep track of eval() calls since they disable all local variable 3190 // Keep track of eval() calls since they disable all local variable
3179 // optimizations. 3191 // optimizations.
3180 // The calls that need special treatment are the 3192 // The calls that need special treatment are the
3181 // direct eval calls. These calls are all of the form eval(...), with 3193 // direct eval calls. These calls are all of the form eval(...), with
3182 // no explicit receiver. 3194 // no explicit receiver.
3183 // These calls are marked as potentially direct eval calls. Whether 3195 // These calls are marked as potentially direct eval calls. Whether
3184 // they are actually direct calls to eval is determined at run time. 3196 // they are actually direct calls to eval is determined at run time.
3185 this->CheckPossibleEvalCall(result, scope_); 3197 this->CheckPossibleEvalCall(result, scope_);
3186 3198
3199 bool is_super_call = result->IsSuperCallReference();
3187 if (spread_pos.IsValid()) { 3200 if (spread_pos.IsValid()) {
3188 args = Traits::PrepareSpreadArguments(args); 3201 args = Traits::PrepareSpreadArguments(args);
3189 result = Traits::SpreadCall(result, args, pos); 3202 result = Traits::SpreadCall(result, args, pos);
3190 } else { 3203 } else {
3191 result = factory()->NewCall(result, args, pos); 3204 result = factory()->NewCall(result, args, pos);
3192 } 3205 }
3206
3207 // Explicit calls to the super constructor using super() perform an
3208 // implicit binding assignment to the 'this' variable.
3209 if (is_super_call) {
3210 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos);
3211 result = factory()->NewAssignment(Token::INIT_CONST, this_expr,
3212 result, pos);
3213 }
3214
3193 if (fni_ != NULL) fni_->RemoveLastFunction(); 3215 if (fni_ != NULL) fni_->RemoveLastFunction();
3194 break; 3216 break;
3195 } 3217 }
3196 3218
3197 case Token::PERIOD: { 3219 case Token::PERIOD: {
3198 BindingPatternUnexpectedToken(classifier); 3220 BindingPatternUnexpectedToken(classifier);
3199 Consume(Token::PERIOD); 3221 Consume(Token::PERIOD);
3200 int pos = position(); 3222 int pos = position();
3201 IdentifierT name = ParseIdentifierName(CHECK_OK); 3223 IdentifierT name = ParseIdentifierName(CHECK_OK);
3202 result = factory()->NewProperty( 3224 result = factory()->NewProperty(
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
3455 } else if (function_state_->return_location().IsValid()) { 3477 } else if (function_state_->return_location().IsValid()) {
3456 ReportMessageAt(function_state_->return_location(), 3478 ReportMessageAt(function_state_->return_location(),
3457 MessageTemplate::kStrongConstructorReturnMisplaced); 3479 MessageTemplate::kStrongConstructorReturnMisplaced);
3458 *ok = false; 3480 *ok = false;
3459 return this->EmptyExpression(); 3481 return this->EmptyExpression();
3460 } 3482 }
3461 3483
3462 function_state_->set_super_location(super_loc); 3484 function_state_->set_super_location(super_loc);
3463 if (spread_pos.IsValid()) { 3485 if (spread_pos.IsValid()) {
3464 args = Traits::PrepareSpreadArguments(args); 3486 args = Traits::PrepareSpreadArguments(args);
3465 return Traits::SpreadCall(expr, args, pos); 3487 expr = Traits::SpreadCall(expr, args, pos);
3466 } else { 3488 } else {
3467 return factory()->NewCall(expr, args, pos); 3489 expr = factory()->NewCall(expr, args, pos);
3468 } 3490 }
3491
3492 // Explicit calls to the super constructor using super() perform an implicit
3493 // binding assignment to the 'this' variable.
3494 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos);
3495 return factory()->NewAssignment(Token::INIT_CONST, this_expr, expr, pos);
3469 } 3496 }
3470 3497
3471 3498
3472 template <class Traits> 3499 template <class Traits>
3473 typename ParserBase<Traits>::ExpressionT 3500 typename ParserBase<Traits>::ExpressionT
3474 ParserBase<Traits>::ParseSuperExpression(bool is_new, 3501 ParserBase<Traits>::ParseSuperExpression(bool is_new,
3475 ExpressionClassifier* classifier, 3502 ExpressionClassifier* classifier,
3476 bool* ok) { 3503 bool* ok) {
3477 int pos = position(); 3504 int pos = position();
3478 Expect(Token::SUPER, CHECK_OK); 3505 Expect(Token::SUPER, CHECK_OK);
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
3998 *ok = false; 4025 *ok = false;
3999 return; 4026 return;
4000 } 4027 }
4001 has_seen_constructor_ = true; 4028 has_seen_constructor_ = true;
4002 return; 4029 return;
4003 } 4030 }
4004 } 4031 }
4005 } } // v8::internal 4032 } } // v8::internal
4006 4033
4007 #endif // V8_PREPARSER_H 4034 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/ppc/full-codegen-ppc.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698