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

Side by Side Diff: src/preparser.cc

Issue 1066933005: Use ExpressionClassifier for bindings. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebasre + feedback = patch for landing Created 5 years, 8 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/preparser.h ('k') | src/scanner.h » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 #include <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 506
507 // The scope of a var/const declared variable anywhere inside a function 507 // The scope of a var/const declared variable anywhere inside a function
508 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope 508 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope
509 // of a let declared variable is the scope of the immediately enclosing 509 // of a let declared variable is the scope of the immediately enclosing
510 // block. 510 // block.
511 int nvars = 0; // the number of variables declared 511 int nvars = 0; // the number of variables declared
512 int bindings_start = peek_position(); 512 int bindings_start = peek_position();
513 do { 513 do {
514 // Parse variable name. 514 // Parse variable name.
515 if (nvars > 0) Consume(Token::COMMA); 515 if (nvars > 0) Consume(Token::COMMA);
516 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 516 {
517 ExpressionClassifier pattern_classifier;
518 Token::Value next = peek();
519 PreParserExpression pattern =
520 ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
521 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
522
523 if (!pattern.IsIdentifier()) {
524 ReportUnexpectedToken(next);
525 *ok = false;
526 return Statement::Default();
527 }
528 }
517 Scanner::Location variable_loc = scanner()->location(); 529 Scanner::Location variable_loc = scanner()->location();
518 nvars++; 530 nvars++;
519 if (peek() == Token::ASSIGN || require_initializer || 531 if (peek() == Token::ASSIGN || require_initializer ||
520 // require initializers for multiple consts. 532 // require initializers for multiple consts.
521 (is_strict_const && peek() == Token::COMMA)) { 533 (is_strict_const && peek() == Token::COMMA)) {
522 Expect(Token::ASSIGN, CHECK_OK); 534 Expect(Token::ASSIGN, CHECK_OK);
523 ExpressionClassifier classifier; 535 ExpressionClassifier classifier;
524 ParseAssignmentExpression(var_context != kForStatement, &classifier, 536 ParseAssignmentExpression(var_context != kForStatement, &classifier,
525 CHECK_OK); 537 CHECK_OK);
526 // TODO(dslomov): report error if not valid expression. 538 ValidateExpression(&classifier, CHECK_OK);
527 539
528 variable_loc.end_pos = scanner()->location().end_pos; 540 variable_loc.end_pos = scanner()->location().end_pos;
529 if (first_initializer_loc && !first_initializer_loc->IsValid()) { 541 if (first_initializer_loc && !first_initializer_loc->IsValid()) {
530 *first_initializer_loc = variable_loc; 542 *first_initializer_loc = variable_loc;
531 } 543 }
532 } 544 }
533 } while (peek() == Token::COMMA); 545 } while (peek() == Token::COMMA);
534 546
535 if (bindings_loc) { 547 if (bindings_loc) {
536 *bindings_loc = 548 *bindings_loc =
(...skipping 24 matching lines...) Expand all
561 if (is_strong(language_mode()) && 573 if (is_strong(language_mode()) &&
562 i::IsConstructor(function_state_->kind())) { 574 i::IsConstructor(function_state_->kind())) {
563 bool is_this = peek() == Token::THIS; 575 bool is_this = peek() == Token::THIS;
564 Expression expr = Expression::Default(); 576 Expression expr = Expression::Default();
565 ExpressionClassifier classifier; 577 ExpressionClassifier classifier;
566 if (is_this) { 578 if (is_this) {
567 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK); 579 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK);
568 } else { 580 } else {
569 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); 581 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK);
570 } 582 }
571 // TODO(dslomov): report error if not a valid expression. 583 ValidateExpression(&classifier, CHECK_OK);
572 switch (peek()) { 584 switch (peek()) {
573 case Token::SEMICOLON: 585 case Token::SEMICOLON:
574 Consume(Token::SEMICOLON); 586 Consume(Token::SEMICOLON);
575 break; 587 break;
576 case Token::RBRACE: 588 case Token::RBRACE:
577 case Token::EOS: 589 case Token::EOS:
578 break; 590 break;
579 default: 591 default:
580 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { 592 if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
581 ReportMessageAt(function_state_->this_location(), 593 ReportMessageAt(function_state_->this_location(),
(...skipping 10 matching lines...) Expand all
592 // TODO(arv): Handle `let [` 604 // TODO(arv): Handle `let [`
593 // https://code.google.com/p/v8/issues/detail?id=3847 605 // https://code.google.com/p/v8/issues/detail?id=3847
594 606
595 default: 607 default:
596 break; 608 break;
597 } 609 }
598 610
599 bool starts_with_identifier = peek_any_identifier(); 611 bool starts_with_identifier = peek_any_identifier();
600 ExpressionClassifier classifier; 612 ExpressionClassifier classifier;
601 Expression expr = ParseExpression(true, &classifier, CHECK_OK); 613 Expression expr = ParseExpression(true, &classifier, CHECK_OK);
602 // TODO(dslomov): report error if not a valid expression. 614 ValidateExpression(&classifier, CHECK_OK);
603 615
604 // Even if the expression starts with an identifier, it is not necessarily an 616 // Even if the expression starts with an identifier, it is not necessarily an
605 // identifier. For example, "foo + bar" starts with an identifier but is not 617 // identifier. For example, "foo + bar" starts with an identifier but is not
606 // an identifier. 618 // an identifier.
607 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { 619 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) {
608 // Expression is a single identifier, and not, e.g., a parenthesized 620 // Expression is a single identifier, and not, e.g., a parenthesized
609 // identifier. 621 // identifier.
610 DCHECK(!expr.AsIdentifier().IsFutureReserved()); 622 DCHECK(!expr.AsIdentifier().IsFutureReserved());
611 DCHECK(is_sloppy(language_mode()) || 623 DCHECK(is_sloppy(language_mode()) ||
612 !IsFutureStrictReserved(expr.AsIdentifier())); 624 !IsFutureStrictReserved(expr.AsIdentifier()));
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 BlockState block_state(&scope_, scope); 1096 BlockState block_state(&scope_, scope);
1085 scope_->SetLanguageMode( 1097 scope_->SetLanguageMode(
1086 static_cast<LanguageMode>(class_language_mode | STRICT_BIT)); 1098 static_cast<LanguageMode>(class_language_mode | STRICT_BIT));
1087 // TODO(marja): Make PreParser use scope names too. 1099 // TODO(marja): Make PreParser use scope names too.
1088 // scope_->SetScopeName(name); 1100 // scope_->SetScopeName(name);
1089 1101
1090 bool has_extends = Check(Token::EXTENDS); 1102 bool has_extends = Check(Token::EXTENDS);
1091 if (has_extends) { 1103 if (has_extends) {
1092 ExpressionClassifier classifier; 1104 ExpressionClassifier classifier;
1093 ParseLeftHandSideExpression(&classifier, CHECK_OK); 1105 ParseLeftHandSideExpression(&classifier, CHECK_OK);
1094 // TODO(dslomov): report error if not a valid expression. 1106 ValidateExpression(&classifier, CHECK_OK);
1095 } 1107 }
1096 1108
1097 ClassLiteralChecker checker(this); 1109 ClassLiteralChecker checker(this);
1098 bool has_seen_constructor = false; 1110 bool has_seen_constructor = false;
1099 1111
1100 Expect(Token::LBRACE, CHECK_OK); 1112 Expect(Token::LBRACE, CHECK_OK);
1101 while (peek() != Token::RBRACE) { 1113 while (peek() != Token::RBRACE) {
1102 if (Check(Token::SEMICOLON)) continue; 1114 if (Check(Token::SEMICOLON)) continue;
1103 const bool in_class = true; 1115 const bool in_class = true;
1104 const bool is_static = false; 1116 const bool is_static = false;
1105 bool is_computed_name = false; // Classes do not care about computed 1117 bool is_computed_name = false; // Classes do not care about computed
1106 // property names here. 1118 // property names here.
1107 ExpressionClassifier classifier; 1119 ExpressionClassifier classifier;
1108 ParsePropertyDefinition(&checker, in_class, has_extends, is_static, 1120 ParsePropertyDefinition(&checker, in_class, has_extends, is_static,
1109 &is_computed_name, &has_seen_constructor, 1121 &is_computed_name, &has_seen_constructor,
1110 &classifier, CHECK_OK); 1122 &classifier, CHECK_OK);
1111 // TODO(dslomov): report error if not a valid expression. 1123 ValidateExpression(&classifier, CHECK_OK);
1112 } 1124 }
1113 1125
1114 Expect(Token::RBRACE, CHECK_OK); 1126 Expect(Token::RBRACE, CHECK_OK);
1115 1127
1116 return Expression::Default(); 1128 return Expression::Default();
1117 } 1129 }
1118 1130
1119 1131
1120 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { 1132 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) {
1121 // CallRuntime :: 1133 // CallRuntime ::
1122 // '%' Identifier Arguments 1134 // '%' Identifier Arguments
1123 Expect(Token::MOD, CHECK_OK); 1135 Expect(Token::MOD, CHECK_OK);
1124 if (!allow_natives()) { 1136 if (!allow_natives()) {
1125 *ok = false; 1137 *ok = false;
1126 return Expression::Default(); 1138 return Expression::Default();
1127 } 1139 }
1128 // Allow "eval" or "arguments" for backward compatibility. 1140 // Allow "eval" or "arguments" for backward compatibility.
1129 ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK); 1141 ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
1130 Scanner::Location spread_pos; 1142 Scanner::Location spread_pos;
1131 ExpressionClassifier classifier; 1143 ExpressionClassifier classifier;
1132 ParseArguments(&spread_pos, &classifier, ok); 1144 ParseArguments(&spread_pos, &classifier, ok);
1133 // TODO(dslomov): report error if not a valid expression. 1145 ValidateExpression(&classifier, CHECK_OK);
1134 1146
1135 DCHECK(!spread_pos.IsValid()); 1147 DCHECK(!spread_pos.IsValid());
1136 1148
1137 return Expression::Default(); 1149 return Expression::Default();
1138 } 1150 }
1139 1151
1140 #undef CHECK_OK 1152 #undef CHECK_OK
1141 1153
1142 1154
1143 } } // v8::internal 1155 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698