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

Side by Side Diff: src/parsing/preparser.cc

Issue 1663773003: Remove redundant/unnecessary variables and checks in ParseForStatement (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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/parsing/parser.cc ('k') | no next file » | 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) || 917 if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) ||
918 (peek() == Token::LET && IsNextLetKeyword())) { 918 (peek() == Token::LET && IsNextLetKeyword())) {
919 int decl_count; 919 int decl_count;
920 bool is_lexical; 920 bool is_lexical;
921 bool is_binding_pattern; 921 bool is_binding_pattern;
922 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); 922 Scanner::Location first_initializer_loc = Scanner::Location::invalid();
923 Scanner::Location bindings_loc = Scanner::Location::invalid(); 923 Scanner::Location bindings_loc = Scanner::Location::invalid();
924 ParseVariableDeclarations(kForStatement, &decl_count, &is_lexical, 924 ParseVariableDeclarations(kForStatement, &decl_count, &is_lexical,
925 &is_binding_pattern, &first_initializer_loc, 925 &is_binding_pattern, &first_initializer_loc,
926 &bindings_loc, CHECK_OK); 926 &bindings_loc, CHECK_OK);
927 bool accept_IN = decl_count >= 1; 927 if (CheckInOrOf(&mode, ok)) {
928 if (accept_IN && CheckInOrOf(&mode, ok)) {
929 if (!*ok) return Statement::Default(); 928 if (!*ok) return Statement::Default();
930 if (decl_count != 1) { 929 if (decl_count != 1) {
931 const char* loop_type =
932 mode == ForEachStatement::ITERATE ? "for-of" : "for-in";
933 PreParserTraits::ReportMessageAt( 930 PreParserTraits::ReportMessageAt(
934 bindings_loc, MessageTemplate::kForInOfLoopMultiBindings, 931 bindings_loc, MessageTemplate::kForInOfLoopMultiBindings,
935 loop_type); 932 ForEachStatement::VisitModeString(mode));
936 *ok = false; 933 *ok = false;
937 return Statement::Default(); 934 return Statement::Default();
938 } 935 }
939 if (first_initializer_loc.IsValid() && 936 if (first_initializer_loc.IsValid() &&
940 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE || 937 (is_strict(language_mode()) || mode == ForEachStatement::ITERATE ||
941 is_lexical || is_binding_pattern)) { 938 is_lexical || is_binding_pattern)) {
942 if (mode == ForEachStatement::ITERATE) { 939 PreParserTraits::ReportMessageAt(
943 ReportMessageAt(first_initializer_loc, 940 first_initializer_loc, MessageTemplate::kForInOfLoopInitializer,
944 MessageTemplate::kForOfLoopInitializer); 941 ForEachStatement::VisitModeString(mode));
945 } else {
946 // TODO(caitp): This should be an error in sloppy mode, too.
947 ReportMessageAt(first_initializer_loc,
948 MessageTemplate::kForInLoopInitializer);
949 }
950 *ok = false; 942 *ok = false;
951 return Statement::Default(); 943 return Statement::Default();
952 } 944 }
953 945
954 if (mode == ForEachStatement::ITERATE) { 946 if (mode == ForEachStatement::ITERATE) {
955 ExpressionClassifier classifier; 947 ExpressionClassifier classifier;
956 Expression enumerable = 948 Expression enumerable =
957 ParseAssignmentExpression(true, &classifier, CHECK_OK); 949 ParseAssignmentExpression(true, &classifier, CHECK_OK);
958 PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK); 950 PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK);
959 } else { 951 } else {
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 Expect(Token::RBRACE, CHECK_OK); 1293 Expect(Token::RBRACE, CHECK_OK);
1302 return PreParserExpression::Default(); 1294 return PreParserExpression::Default();
1303 } 1295 }
1304 } 1296 }
1305 1297
1306 #undef CHECK_OK 1298 #undef CHECK_OK
1307 1299
1308 1300
1309 } // namespace internal 1301 } // namespace internal
1310 } // namespace v8 1302 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698