| OLD | NEW |
| 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:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 /// All [Source]s references by the analyzed library. | 54 /// All [Source]s references by the analyzed library. |
| 55 final Set<Source> sources = new Set<Source>(); | 55 final Set<Source> sources = new Set<Source>(); |
| 56 | 56 |
| 57 /// All [AnalysisErrorInfo]s in the analyzed library. | 57 /// All [AnalysisErrorInfo]s in the analyzed library. |
| 58 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); | 58 final List<AnalysisErrorInfo> errorInfos = new List<AnalysisErrorInfo>(); |
| 59 | 59 |
| 60 /// [HashMap] between sources and analysis error infos. | 60 /// [HashMap] between sources and analysis error infos. |
| 61 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = | 61 final HashMap<Source, AnalysisErrorInfo> sourceErrorsMap = |
| 62 new HashMap<Source, AnalysisErrorInfo>(); | 62 new HashMap<Source, AnalysisErrorInfo>(); |
| 63 | 63 |
| 64 /** |
| 65 * If the file specified on the command line is part of a package, the name |
| 66 * of that package. Otherwise `null`. This allows us to analyze the file |
| 67 * specified on the command line as though it is reached via a "package:" |
| 68 * URI, but avoid suppressing its output in the event that the user has not |
| 69 * specified the "--package-warnings" option. |
| 70 */ |
| 71 String _selfPackageName; |
| 72 |
| 64 AnalyzerImpl(String sourcePath, this.options, this.startTime, this.isBatch) | 73 AnalyzerImpl(String sourcePath, this.options, this.startTime, this.isBatch) |
| 65 : sourcePath = _normalizeSourcePath(sourcePath) { | 74 : sourcePath = _normalizeSourcePath(sourcePath) { |
| 66 if (sdk == null) { | 75 if (sdk == null) { |
| 67 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); | 76 sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); |
| 68 } | 77 } |
| 69 } | 78 } |
| 70 | 79 |
| 71 /// Returns the maximal [ErrorSeverity] of the recorded errors. | 80 /// Returns the maximal [ErrorSeverity] of the recorded errors. |
| 72 ErrorSeverity get maxErrorSeverity { | 81 ErrorSeverity get maxErrorSeverity { |
| 73 var status = ErrorSeverity.NONE; | 82 var status = ErrorSeverity.NONE; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 94 | 103 |
| 95 void addLibrarySources(LibraryElement library, Set<LibraryElement> libraries, | 104 void addLibrarySources(LibraryElement library, Set<LibraryElement> libraries, |
| 96 Set<CompilationUnitElement> units) { | 105 Set<CompilationUnitElement> units) { |
| 97 if (library == null || !libraries.add(library)) { | 106 if (library == null || !libraries.add(library)) { |
| 98 return; | 107 return; |
| 99 } | 108 } |
| 100 // may be skip library | 109 // may be skip library |
| 101 { | 110 { |
| 102 UriKind uriKind = library.source.uriKind; | 111 UriKind uriKind = library.source.uriKind; |
| 103 // Optionally skip package: libraries. | 112 // Optionally skip package: libraries. |
| 104 if (!options.showPackageWarnings && uriKind == UriKind.PACKAGE_URI) { | 113 if (!options.showPackageWarnings && _isOtherPackage(library.source.uri)) { |
| 105 return; | 114 return; |
| 106 } | 115 } |
| 107 // Optionally skip SDK libraries. | 116 // Optionally skip SDK libraries. |
| 108 if (!options.showSdkWarnings && uriKind == UriKind.DART_URI) { | 117 if (!options.showSdkWarnings && uriKind == UriKind.DART_URI) { |
| 109 return; | 118 return; |
| 110 } | 119 } |
| 111 } | 120 } |
| 112 // add compilation units | 121 // add compilation units |
| 113 addCompilationUnitSource(library.definingCompilationUnit, libraries, units); | 122 addCompilationUnitSource(library.definingCompilationUnit, libraries, units); |
| 114 for (CompilationUnitElement child in library.parts) { | 123 for (CompilationUnitElement child in library.parts) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 contextOptions.cacheSize = _MAX_CACHE_SIZE; | 212 contextOptions.cacheSize = _MAX_CACHE_SIZE; |
| 204 contextOptions.hint = !options.disableHints; | 213 contextOptions.hint = !options.disableHints; |
| 205 contextOptions.analyzeFunctionBodiesPredicate = | 214 contextOptions.analyzeFunctionBodiesPredicate = |
| 206 _analyzeFunctionBodiesPredicate; | 215 _analyzeFunctionBodiesPredicate; |
| 207 contextOptions.generateImplicitErrors = options.showPackageWarnings; | 216 contextOptions.generateImplicitErrors = options.showPackageWarnings; |
| 208 contextOptions.generateSdkErrors = options.showSdkWarnings; | 217 contextOptions.generateSdkErrors = options.showSdkWarnings; |
| 209 context.analysisOptions = contextOptions; | 218 context.analysisOptions = contextOptions; |
| 210 | 219 |
| 211 librarySource = computeLibrarySource(); | 220 librarySource = computeLibrarySource(); |
| 212 | 221 |
| 222 Uri libraryUri = librarySource.uri; |
| 223 if (libraryUri.scheme == 'package' && libraryUri.pathSegments.length > 0) { |
| 224 _selfPackageName = libraryUri.pathSegments[0]; |
| 225 } |
| 226 |
| 213 // Create and add a ChangeSet | 227 // Create and add a ChangeSet |
| 214 ChangeSet changeSet = new ChangeSet(); | 228 ChangeSet changeSet = new ChangeSet(); |
| 215 changeSet.addedSource(librarySource); | 229 changeSet.addedSource(librarySource); |
| 216 context.applyChanges(changeSet); | 230 context.applyChanges(changeSet); |
| 217 } | 231 } |
| 218 | 232 |
| 219 /// Fills [errorInfos] using [sources]. | 233 /// Fills [errorInfos] using [sources]. |
| 220 void prepareErrors() { | 234 void prepareErrors() { |
| 221 for (Source source in sources) { | 235 for (Source source in sources) { |
| 222 context.computeErrors(source); | 236 context.computeErrors(source); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 if (source.uri.scheme == 'dart') { | 302 if (source.uri.scheme == 'dart') { |
| 289 if (isBatch) { | 303 if (isBatch) { |
| 290 // When running in batch mode, the SDK files are cached from one | 304 // When running in batch mode, the SDK files are cached from one |
| 291 // analysis run to the next. So we need to parse function bodies even | 305 // analysis run to the next. So we need to parse function bodies even |
| 292 // if the user hasn't asked for errors/warnings from the SDK, since | 306 // if the user hasn't asked for errors/warnings from the SDK, since |
| 293 // they might ask for errors/warnings from the SDK in the future. | 307 // they might ask for errors/warnings from the SDK in the future. |
| 294 return true; | 308 return true; |
| 295 } | 309 } |
| 296 return options.showSdkWarnings; | 310 return options.showSdkWarnings; |
| 297 } | 311 } |
| 298 if (source.uri.scheme == 'package') { | 312 if (_isOtherPackage(source.uri)) { |
| 299 return options.showPackageWarnings; | 313 return options.showPackageWarnings; |
| 300 } | 314 } |
| 301 return true; | 315 return true; |
| 302 } | 316 } |
| 303 | 317 |
| 304 /// The sync version of analysis. | 318 /// The sync version of analysis. |
| 305 ErrorSeverity _analyzeSync(int printMode) { | 319 ErrorSeverity _analyzeSync(int printMode) { |
| 306 // don't try to analyze parts | 320 // don't try to analyze parts |
| 307 if (context.computeKindOf(librarySource) == SourceKind.PART) { | 321 if (context.computeKindOf(librarySource) == SourceKind.PART) { |
| 308 print("Only libraries can be analyzed."); | 322 print("Only libraries can be analyzed."); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 335 return false; | 349 return false; |
| 336 } | 350 } |
| 337 if (computeSeverity(error, options.enableTypeChecks) == | 351 if (computeSeverity(error, options.enableTypeChecks) == |
| 338 ErrorSeverity.INFO && | 352 ErrorSeverity.INFO && |
| 339 options.disableHints) { | 353 options.disableHints) { |
| 340 return false; | 354 return false; |
| 341 } | 355 } |
| 342 return true; | 356 return true; |
| 343 } | 357 } |
| 344 | 358 |
| 359 /** |
| 360 * Determine whether the given URI refers to a package other than the package |
| 361 * being analyzed. |
| 362 */ |
| 363 bool _isOtherPackage(Uri uri) { |
| 364 if (uri.scheme != 'package') { |
| 365 return false; |
| 366 } |
| 367 if (_selfPackageName != null && |
| 368 uri.pathSegments.length > 0 && |
| 369 uri.pathSegments[0] == _selfPackageName) { |
| 370 return false; |
| 371 } |
| 372 return true; |
| 373 } |
| 374 |
| 345 _printColdPerf() { | 375 _printColdPerf() { |
| 346 // print cold VM performance numbers | 376 // print cold VM performance numbers |
| 347 int totalTime = JavaSystem.currentTimeMillis() - startTime; | 377 int totalTime = JavaSystem.currentTimeMillis() - startTime; |
| 348 int otherTime = totalTime; | 378 int otherTime = totalTime; |
| 349 for (PerformanceTag tag in PerformanceTag.all) { | 379 for (PerformanceTag tag in PerformanceTag.all) { |
| 350 if (tag != PerformanceTag.UNKNOWN) { | 380 if (tag != PerformanceTag.UNKNOWN) { |
| 351 int tagTime = tag.elapsedMs; | 381 int tagTime = tag.elapsedMs; |
| 352 stdout.writeln('${tag.label}-cold:$tagTime'); | 382 stdout.writeln('${tag.label}-cold:$tagTime'); |
| 353 otherTime -= tagTime; | 383 otherTime -= tagTime; |
| 354 } | 384 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 487 } |
| 458 } | 488 } |
| 459 | 489 |
| 460 @override | 490 @override |
| 461 void logInformation2(String message, Object exception) { | 491 void logInformation2(String message, Object exception) { |
| 462 if (log) { | 492 if (log) { |
| 463 stdout.writeln(message); | 493 stdout.writeln(message); |
| 464 } | 494 } |
| 465 } | 495 } |
| 466 } | 496 } |
| OLD | NEW |