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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2004223002: Revert "If an if or do statement always exits, following statements are dead." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | pkg/analyzer/test/generated/hint_code_test.dart » ('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 (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 } 2072 }
2073 if (element == null) { 2073 if (element == null) {
2074 _errorReporter 2074 _errorReporter
2075 .reportErrorForNode(hintCode, name, [library.identifier, nameStr]); 2075 .reportErrorForNode(hintCode, name, [library.identifier, nameStr]);
2076 } 2076 }
2077 } 2077 }
2078 } 2078 }
2079 2079
2080 /** 2080 /**
2081 * Given some [NodeList] of [Statement]s, from either a [Block] or 2081 * Given some [NodeList] of [Statement]s, from either a [Block] or
2082 * [SwitchMember], this loops through the list searching for dead statements. 2082 * [SwitchMember], this loops through the list in reverse order searching for statements
2083 * after a return, unlabeled break or unlabeled continue statement to mark the m as dead code.
2083 * 2084 *
2084 * @param statements some ordered list of statements in a [Block] or [SwitchMe mber] 2085 * @param statements some ordered list of statements in a [Block] or [SwitchMe mber]
2085 */ 2086 */
2086 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) { 2087 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) {
2087 bool statementExits(Statement statement) {
2088 if (statement is BreakStatement) {
2089 return statement.label == null;
2090 } else if (statement is ContinueStatement) {
2091 return statement.label == null;
2092 }
2093 return ExitDetector.exits(statement);
2094 }
2095
2096 int size = statements.length; 2088 int size = statements.length;
2097 for (int i = 0; i < size; i++) { 2089 for (int i = 0; i < size; i++) {
2098 Statement currentStatement = statements[i]; 2090 Statement currentStatement = statements[i];
2099 currentStatement?.accept(this); 2091 currentStatement?.accept(this);
2100 if (statementExits(currentStatement) && i != size - 1) { 2092 bool returnOrBreakingStatement = currentStatement is ReturnStatement ||
2093 (currentStatement is BreakStatement &&
2094 currentStatement.label == null) ||
2095 (currentStatement is ContinueStatement &&
2096 currentStatement.label == null);
2097 if (returnOrBreakingStatement && i != size - 1) {
2101 Statement nextStatement = statements[i + 1]; 2098 Statement nextStatement = statements[i + 1];
2102 Statement lastStatement = statements[size - 1]; 2099 Statement lastStatement = statements[size - 1];
2103 int offset = nextStatement.offset; 2100 int offset = nextStatement.offset;
2104 int length = lastStatement.end - offset; 2101 int length = lastStatement.end - offset;
2105 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length); 2102 _errorReporter.reportErrorForOffset(HintCode.DEAD_CODE, offset, length);
2106 return; 2103 return;
2107 } 2104 }
2108 } 2105 }
2109 } 2106 }
2110 2107
(...skipping 8871 matching lines...) Expand 10 before | Expand all | Expand 10 after
10982 return null; 10979 return null;
10983 } 10980 }
10984 if (identical(node.staticElement, variable)) { 10981 if (identical(node.staticElement, variable)) {
10985 if (node.inSetterContext()) { 10982 if (node.inSetterContext()) {
10986 result = true; 10983 result = true;
10987 } 10984 }
10988 } 10985 }
10989 return null; 10986 return null;
10990 } 10987 }
10991 } 10988 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698