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

Side by Side Diff: pkg/analyzer/lib/src/analyzer_impl.dart

Issue 633803002: Check parameter types when evaluating constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_impl; 5 library analyzer_impl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'generated/constant.dart'; 10 import 'generated/constant.dart';
(...skipping 16 matching lines...) Expand all
27 27
28 /** 28 /**
29 * The maximum number of sources for which AST structures should be kept in the cache. 29 * The maximum number of sources for which AST structures should be kept in the cache.
30 */ 30 */
31 const int _MAX_CACHE_SIZE = 512; 31 const int _MAX_CACHE_SIZE = 512;
32 32
33 DirectoryBasedDartSdk sdk; 33 DirectoryBasedDartSdk sdk;
34 34
35 /// Analyzes single library [File]. 35 /// Analyzes single library [File].
36 class AnalyzerImpl { 36 class AnalyzerImpl {
37 /**
38 * Compute the severity of the error; however, if
39 * [escalateCheckedModeCompileTimeErrors] is true, then escalate it to
40 * [ErrorSeverity.ERROR].
41 */
42 static ErrorSeverity computeSeverity(
43 AnalysisError error, bool escalateCheckedModeCompileTimeErrors) {
44 if (escalateCheckedModeCompileTimeErrors
45 && error.errorCode.type == ErrorType.CHECKED_MODE_COMPILE_TIME_ERROR) {
46 return ErrorSeverity.ERROR;
47 }
48 return error.errorCode.errorSeverity;
49 }
50
37 final String sourcePath; 51 final String sourcePath;
38 final CommandLineOptions options; 52 final CommandLineOptions options;
39 final int startTime; 53 final int startTime;
40 54
41 ContentCache contentCache = new ContentCache(); 55 ContentCache contentCache = new ContentCache();
42 SourceFactory sourceFactory; 56 SourceFactory sourceFactory;
43 AnalysisContext context; 57 AnalysisContext context;
44 Source librarySource; 58 Source librarySource;
45 59
46 /// All [Source]s references by the analyzed library. 60 /// All [Source]s references by the analyzed library.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ErrorSeverity status = maxErrorSeverity; 169 ErrorSeverity status = maxErrorSeverity;
156 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) { 170 if (status == ErrorSeverity.WARNING && options.warningsAreFatal) {
157 status = ErrorSeverity.ERROR; 171 status = ErrorSeverity.ERROR;
158 } 172 }
159 exitCode = status.ordinal; 173 exitCode = status.ordinal;
160 }).catchError((ex, st) { 174 }).catchError((ex, st) {
161 AnalysisEngine.instance.logger.logError("${ex}\n${st}"); 175 AnalysisEngine.instance.logger.logError("${ex}\n${st}");
162 }); 176 });
163 } 177 }
164 178
165 bool _excludeTodo(AnalysisError error) => 179 bool _isDesiredError(AnalysisError error) {
166 error.errorCode.type != ErrorType.TODO; 180 if (error.errorCode.type == ErrorType.TODO) {
181 return false;
182 }
183 if (computeSeverity(error, options.enableTypeChecks) == ErrorSeverity.INFO
184 && options.disableHints) {
185 return false;
186 }
187 return true;
188 }
167 189
168 _printErrorsAndPerf() { 190 _printErrorsAndPerf() {
169 // The following is a hack. We currently print out to stderr to ensure that 191 // The following is a hack. We currently print out to stderr to ensure that
170 // when in batch mode we print to stderr, this is because the prints from 192 // when in batch mode we print to stderr, this is because the prints from
171 // batch are made to stderr. The reason that options.shouldBatch isn't used 193 // batch are made to stderr. The reason that options.shouldBatch isn't used
172 // is because when the argument flags are constructed in BatchRunner and 194 // is because when the argument flags are constructed in BatchRunner and
173 // passed in from batch mode which removes the batch flag to prevent the 195 // passed in from batch mode which removes the batch flag to prevent the
174 // "cannot have the batch flag and source file" error message. 196 // "cannot have the batch flag and source file" error message.
175 IOSink sink = options.machineFormat ? stderr : stdout; 197 IOSink sink = options.machineFormat ? stderr : stdout;
176 198
177 // print errors 199 // print errors
178 ErrorFormatter formatter = new ErrorFormatter(sink, options, _excludeTodo); 200 ErrorFormatter formatter = new ErrorFormatter(sink, options, _isDesiredError );
179 formatter.formatErrors(errorInfos); 201 formatter.formatErrors(errorInfos);
180 202
181 // print performance numbers 203 // print performance numbers
182 if (options.perf || options.warmPerf) { 204 if (options.perf || options.warmPerf) {
183 int totalTime = JavaSystem.currentTimeMillis() - startTime; 205 int totalTime = JavaSystem.currentTimeMillis() - startTime;
184 int ioTime = PerformanceStatistics.io.result; 206 int ioTime = PerformanceStatistics.io.result;
185 int scanTime = PerformanceStatistics.scan.result; 207 int scanTime = PerformanceStatistics.scan.result;
186 int parseTime = PerformanceStatistics.parse.result; 208 int parseTime = PerformanceStatistics.parse.result;
187 int resolveTime = PerformanceStatistics.resolve.result; 209 int resolveTime = PerformanceStatistics.resolve.result;
188 int errorsTime = PerformanceStatistics.errors.result; 210 int errorsTime = PerformanceStatistics.errors.result;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTime 245 - (ioTime + scanTime + parseTime + resolveTime + errorsTime + hintsTime
224 + angularTime)}"); 246 + angularTime)}");
225 stdout.writeln("total-cold:$totalTime"); 247 stdout.writeln("total-cold:$totalTime");
226 } 248 }
227 249
228 /// Returns the maximal [ErrorSeverity] of the recorded errors. 250 /// Returns the maximal [ErrorSeverity] of the recorded errors.
229 ErrorSeverity get maxErrorSeverity { 251 ErrorSeverity get maxErrorSeverity {
230 var status = ErrorSeverity.NONE; 252 var status = ErrorSeverity.NONE;
231 for (AnalysisErrorInfo errorInfo in errorInfos) { 253 for (AnalysisErrorInfo errorInfo in errorInfos) {
232 for (AnalysisError error in errorInfo.errors) { 254 for (AnalysisError error in errorInfo.errors) {
233 var severity = error.errorCode.errorSeverity; 255 if (!_isDesiredError(error)) {
256 continue;
257 }
258 var severity = computeSeverity(error, options.enableTypeChecks);
234 status = status.max(severity); 259 status = status.max(severity);
235 } 260 }
236 } 261 }
237 return status; 262 return status;
238 } 263 }
239 264
240 void prepareAnalysisContext(JavaFile sourceFile, Source source) { 265 void prepareAnalysisContext(JavaFile sourceFile, Source source) {
241 List<UriResolver> resolvers = [ 266 List<UriResolver> resolvers = [
242 new DartUriResolver(sdk), 267 new DartUriResolver(sdk),
243 new FileUriResolver()]; 268 new FileUriResolver()];
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 427 }
403 } 428 }
404 429
405 @override 430 @override
406 void logInformation2(String message, Exception exception) { 431 void logInformation2(String message, Exception exception) {
407 if (log) { 432 if (log) {
408 stdout.writeln(message); 433 stdout.writeln(message);
409 } 434 }
410 } 435 }
411 } 436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698