Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1925 HintCode.DEAD_CODE, node.thenExpression); | 1925 HintCode.DEAD_CODE, node.thenExpression); |
| 1926 node.elseExpression?.accept(this); | 1926 node.elseExpression?.accept(this); |
| 1927 return null; | 1927 return null; |
| 1928 } | 1928 } |
| 1929 } | 1929 } |
| 1930 } | 1930 } |
| 1931 return super.visitConditionalExpression(node); | 1931 return super.visitConditionalExpression(node); |
| 1932 } | 1932 } |
| 1933 | 1933 |
| 1934 @override | 1934 @override |
| 1935 Object visitExportDirective(ExportDirective node) { | |
| 1936 ExportElement exportElement = node.element; | |
| 1937 if (exportElement != null) { | |
| 1938 // The element is null when the URI is invalid | |
| 1939 LibraryElement library = exportElement.exportedLibrary; | |
| 1940 if (library != null) { | |
| 1941 for (Combinator combinator in node.combinators) { | |
| 1942 _checkCombinator(exportElement.exportedLibrary, combinator); | |
| 1943 } | |
| 1944 } | |
| 1945 } | |
| 1946 return super.visitExportDirective(node); | |
| 1947 } | |
| 1948 | |
| 1949 @override | |
| 1935 Object visitIfStatement(IfStatement node) { | 1950 Object visitIfStatement(IfStatement node) { |
| 1936 Expression conditionExpression = node.condition; | 1951 Expression conditionExpression = node.condition; |
| 1937 conditionExpression?.accept(this); | 1952 conditionExpression?.accept(this); |
| 1938 if (!_isDebugConstant(conditionExpression)) { | 1953 if (!_isDebugConstant(conditionExpression)) { |
| 1939 EvaluationResultImpl result = | 1954 EvaluationResultImpl result = |
| 1940 _getConstantBooleanValue(conditionExpression); | 1955 _getConstantBooleanValue(conditionExpression); |
| 1941 if (result != null) { | 1956 if (result != null) { |
| 1942 if (result.value.toBoolValue() == true) { | 1957 if (result.value.toBoolValue() == true) { |
| 1943 // report error on else block: if(true) {} else {!} | 1958 // report error on else block: if(true) {} else {!} |
| 1944 Statement elseStatement = node.elseStatement; | 1959 Statement elseStatement = node.elseStatement; |
| 1945 if (elseStatement != null) { | 1960 if (elseStatement != null) { |
| 1946 _errorReporter.reportErrorForNode( | 1961 _errorReporter.reportErrorForNode( |
| 1947 HintCode.DEAD_CODE, elseStatement); | 1962 HintCode.DEAD_CODE, elseStatement); |
| 1948 node.thenStatement?.accept(this); | 1963 node.thenStatement?.accept(this); |
| 1949 return null; | 1964 return null; |
| 1950 } | 1965 } |
| 1951 } else { | 1966 } else { |
| 1952 // report error on if block: if (false) {!} else {} | 1967 // report error on if block: if (false) {!} else {} |
| 1953 _errorReporter.reportErrorForNode( | 1968 _errorReporter.reportErrorForNode( |
| 1954 HintCode.DEAD_CODE, node.thenStatement); | 1969 HintCode.DEAD_CODE, node.thenStatement); |
| 1955 node.elseStatement?.accept(this); | 1970 node.elseStatement?.accept(this); |
| 1956 return null; | 1971 return null; |
| 1957 } | 1972 } |
| 1958 } | 1973 } |
| 1959 } | 1974 } |
| 1960 return super.visitIfStatement(node); | 1975 return super.visitIfStatement(node); |
| 1961 } | 1976 } |
| 1962 | 1977 |
| 1963 @override | 1978 @override |
| 1979 Object visitImportDirective(ImportDirective node) { | |
| 1980 ImportElement importElement = node.element; | |
| 1981 if (importElement != null) { | |
| 1982 // The element is null when the URI is invalid | |
| 1983 LibraryElement library = importElement.importedLibrary; | |
| 1984 if (library != null) { | |
| 1985 for (Combinator combinator in node.combinators) { | |
| 1986 _checkCombinator(library, combinator); | |
| 1987 } | |
| 1988 } | |
| 1989 } | |
| 1990 return super.visitImportDirective(node); | |
| 1991 } | |
| 1992 | |
| 1993 @override | |
| 1964 Object visitSwitchCase(SwitchCase node) { | 1994 Object visitSwitchCase(SwitchCase node) { |
| 1965 _checkForDeadStatementsInNodeList(node.statements); | 1995 _checkForDeadStatementsInNodeList(node.statements); |
| 1966 return super.visitSwitchCase(node); | 1996 return super.visitSwitchCase(node); |
| 1967 } | 1997 } |
| 1968 | 1998 |
| 1969 @override | 1999 @override |
| 1970 Object visitSwitchDefault(SwitchDefault node) { | 2000 Object visitSwitchDefault(SwitchDefault node) { |
| 1971 _checkForDeadStatementsInNodeList(node.statements); | 2001 _checkForDeadStatementsInNodeList(node.statements); |
| 1972 return super.visitSwitchDefault(node); | 2002 return super.visitSwitchDefault(node); |
| 1973 } | 2003 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2053 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.body); | 2083 _errorReporter.reportErrorForNode(HintCode.DEAD_CODE, node.body); |
| 2054 return null; | 2084 return null; |
| 2055 } | 2085 } |
| 2056 } | 2086 } |
| 2057 } | 2087 } |
| 2058 node.body?.accept(this); | 2088 node.body?.accept(this); |
| 2059 return null; | 2089 return null; |
| 2060 } | 2090 } |
| 2061 | 2091 |
| 2062 /** | 2092 /** |
| 2093 * Resolve the names in the given [combinator] in the scope of the given | |
| 2094 * [library]. | |
| 2095 */ | |
| 2096 void _checkCombinator(LibraryElement library, Combinator combinator) { | |
| 2097 Namespace namespace = | |
| 2098 new NamespaceBuilder().createExportNamespaceForLibrary(library); | |
| 2099 NodeList<SimpleIdentifier> names; | |
| 2100 if (combinator is HideCombinator) { | |
|
Brian Wilkerson
2016/04/20 21:34:25
Can we pass in the list of names (and the hint cod
srawlins
2016/04/20 21:52:39
I've uploaded another patch. Is this what you want
Brian Wilkerson
2016/04/20 22:49:32
Close enough. I was thinking of
void _checkCombin
| |
| 2101 names = combinator.hiddenNames; | |
| 2102 } else { | |
| 2103 names = (combinator as ShowCombinator).shownNames; | |
| 2104 } | |
| 2105 for (SimpleIdentifier name in names) { | |
| 2106 String nameStr = name.name; | |
| 2107 Element element = namespace.get(nameStr); | |
| 2108 if (element == null) { | |
| 2109 element = namespace.get("$nameStr="); | |
| 2110 } | |
| 2111 if (element == null) { | |
| 2112 ErrorCode hintCode; | |
| 2113 if (combinator is HideCombinator) { | |
| 2114 hintCode = HintCode.UNDEFINED_HIDDEN_NAME; | |
| 2115 } else { | |
| 2116 hintCode = HintCode.UNDEFINED_SHOWN_NAME; | |
| 2117 } | |
| 2118 _errorReporter.reportErrorForNode( | |
| 2119 hintCode, name, [library.identifier, nameStr]); | |
| 2120 } | |
| 2121 } | |
| 2122 } | |
| 2123 | |
| 2124 /** | |
| 2063 * Given some [NodeList] of [Statement]s, from either a [Block] or | 2125 * Given some [NodeList] of [Statement]s, from either a [Block] or |
| 2064 * [SwitchMember], this loops through the list in reverse order searching for statements | 2126 * [SwitchMember], this loops through the list in reverse order searching for statements |
| 2065 * after a return, unlabeled break or unlabeled continue statement to mark the m as dead code. | 2127 * after a return, unlabeled break or unlabeled continue statement to mark the m as dead code. |
| 2066 * | 2128 * |
| 2067 * @param statements some ordered list of statements in a [Block] or [SwitchMe mber] | 2129 * @param statements some ordered list of statements in a [Block] or [SwitchMe mber] |
| 2068 */ | 2130 */ |
| 2069 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) { | 2131 void _checkForDeadStatementsInNodeList(NodeList<Statement> statements) { |
| 2070 int size = statements.length; | 2132 int size = statements.length; |
| 2071 for (int i = 0; i < size; i++) { | 2133 for (int i = 0; i < size; i++) { |
| 2072 Statement currentStatement = statements[i]; | 2134 Statement currentStatement = statements[i]; |
| (...skipping 11019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13092 nonFields.add(node); | 13154 nonFields.add(node); |
| 13093 return null; | 13155 return null; |
| 13094 } | 13156 } |
| 13095 | 13157 |
| 13096 @override | 13158 @override |
| 13097 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 13159 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 13098 | 13160 |
| 13099 @override | 13161 @override |
| 13100 Object visitWithClause(WithClause node) => null; | 13162 Object visitWithClause(WithClause node) => null; |
| 13101 } | 13163 } |
| OLD | NEW |