OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import 'package:analyzer/context/context_root.dart'; | 9 import 'package:analyzer/context/context_root.dart'; |
10 import 'package:analyzer/context/declared_variables.dart'; | 10 import 'package:analyzer/context/declared_variables.dart'; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 * from file paths. | 125 * from file paths. |
126 */ | 126 */ |
127 SourceFactory _sourceFactory; | 127 SourceFactory _sourceFactory; |
128 | 128 |
129 /** | 129 /** |
130 * The declared environment variables. | 130 * The declared environment variables. |
131 */ | 131 */ |
132 final DeclaredVariables declaredVariables = new DeclaredVariables(); | 132 final DeclaredVariables declaredVariables = new DeclaredVariables(); |
133 | 133 |
134 /** | 134 /** |
135 * If `true`, then analysis should be done without using tasks model. | |
136 */ | |
137 final bool analyzeWithoutTasks; | |
138 | |
139 /** | |
140 * Information about the context root being analyzed by this driver. | 135 * Information about the context root being analyzed by this driver. |
141 */ | 136 */ |
142 final ContextRoot contextRoot; | 137 final ContextRoot contextRoot; |
143 | 138 |
144 /** | 139 /** |
145 * The salt to mix into all hashes used as keys for serialized data. | 140 * The salt to mix into all hashes used as keys for serialized data. |
146 */ | 141 */ |
147 final Uint32List _salt = new Uint32List(1 + AnalysisOptions.signatureLength); | 142 final Uint32List _salt = new Uint32List(1 + AnalysisOptions.signatureLength); |
148 | 143 |
149 /** | 144 /** |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 */ | 245 */ |
251 AnalysisDriver( | 246 AnalysisDriver( |
252 this._scheduler, | 247 this._scheduler, |
253 PerformanceLog logger, | 248 PerformanceLog logger, |
254 this._resourceProvider, | 249 this._resourceProvider, |
255 this._byteStore, | 250 this._byteStore, |
256 this._contentOverlay, | 251 this._contentOverlay, |
257 this.contextRoot, | 252 this.contextRoot, |
258 SourceFactory sourceFactory, | 253 SourceFactory sourceFactory, |
259 this._analysisOptions, | 254 this._analysisOptions, |
260 {PackageBundle sdkBundle, | 255 {PackageBundle sdkBundle}) |
261 this.analyzeWithoutTasks: true}) | |
262 : _logger = logger, | 256 : _logger = logger, |
263 _sourceFactory = sourceFactory.clone(), | 257 _sourceFactory = sourceFactory.clone(), |
264 _sdkBundle = sdkBundle { | 258 _sdkBundle = sdkBundle { |
265 _onResults = _resultController.stream.asBroadcastStream(); | 259 _onResults = _resultController.stream.asBroadcastStream(); |
266 _testView = new AnalysisDriverTestView(this); | 260 _testView = new AnalysisDriverTestView(this); |
267 _createFileTracker(logger); | 261 _createFileTracker(logger); |
268 _scheduler.add(this); | 262 _scheduler.add(this); |
269 _search = new Search(this); | 263 _search = new Search(this); |
270 } | 264 } |
271 | 265 |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 if (bytes != null) { | 940 if (bytes != null) { |
947 return _getAnalysisResultFromBytes(file, signature, bytes); | 941 return _getAnalysisResultFromBytes(file, signature, bytes); |
948 } | 942 } |
949 } | 943 } |
950 | 944 |
951 // We need the fully resolved unit, or the result is not cached. | 945 // We need the fully resolved unit, or the result is not cached. |
952 return _logger.run('Compute analysis result for $path', () { | 946 return _logger.run('Compute analysis result for $path', () { |
953 try { | 947 try { |
954 LibraryContext libraryContext = _createLibraryContext(library); | 948 LibraryContext libraryContext = _createLibraryContext(library); |
955 try { | 949 try { |
| 950 LibraryAnalyzer analyzer = new LibraryAnalyzer( |
| 951 analysisOptions, |
| 952 declaredVariables, |
| 953 sourceFactory, |
| 954 _fileTracker.fsState, |
| 955 libraryContext.store, |
| 956 library); |
| 957 Map<FileState, UnitAnalysisResult> results = analyzer.analyze(); |
| 958 |
| 959 List<int> bytes; |
956 CompilationUnit resolvedUnit; | 960 CompilationUnit resolvedUnit; |
957 List<int> bytes; | 961 for (FileState unitFile in results.keys) { |
958 if (analyzeWithoutTasks) { | 962 UnitAnalysisResult unitResult = results[unitFile]; |
959 LibraryAnalyzer analyzer = new LibraryAnalyzer( | 963 List<int> unitBytes = |
960 analysisOptions, | 964 _serializeResolvedUnit(unitResult.unit, unitResult.errors); |
961 declaredVariables, | 965 String unitSignature = _getResolvedUnitSignature(library, unitFile); |
962 sourceFactory, | 966 String unitKey = _getResolvedUnitKey(unitSignature); |
963 _fileTracker.fsState, | 967 _byteStore.put(unitKey, unitBytes); |
964 libraryContext.store, | 968 if (unitFile == file) { |
965 library); | 969 bytes = unitBytes; |
966 Map<FileState, UnitAnalysisResult> results = analyzer.analyze(); | 970 resolvedUnit = unitResult.unit; |
967 for (FileState unitFile in results.keys) { | |
968 UnitAnalysisResult unitResult = results[unitFile]; | |
969 List<int> unitBytes = | |
970 _serializeResolvedUnit(unitResult.unit, unitResult.errors); | |
971 String unitSignature = | |
972 _getResolvedUnitSignature(library, unitFile); | |
973 String unitKey = _getResolvedUnitKey(unitSignature); | |
974 _byteStore.put(unitKey, unitBytes); | |
975 if (unitFile == file) { | |
976 bytes = unitBytes; | |
977 resolvedUnit = unitResult.unit; | |
978 } | |
979 } | 971 } |
980 } else { | |
981 ResolutionResult resolutionResult = | |
982 libraryContext.resolveUnit(library.source, file.source); | |
983 resolvedUnit = resolutionResult.resolvedUnit; | |
984 List<AnalysisError> errors = resolutionResult.errors; | |
985 | |
986 // Store the result into the cache. | |
987 bytes = _serializeResolvedUnit(resolvedUnit, errors); | |
988 _byteStore.put(key, bytes); | |
989 } | 972 } |
990 | 973 |
991 // Return the result, full or partial. | 974 // Return the result, full or partial. |
992 _logger.writeln('Computed new analysis result.'); | 975 _logger.writeln('Computed new analysis result.'); |
993 AnalysisResult result = _getAnalysisResultFromBytes( | 976 AnalysisResult result = _getAnalysisResultFromBytes( |
994 file, signature, bytes, | 977 file, signature, bytes, |
995 content: withUnit ? file.content : null, | 978 content: withUnit ? file.content : null, |
996 resolvedUnit: withUnit ? resolvedUnit : null); | 979 resolvedUnit: withUnit ? resolvedUnit : null); |
997 if (withUnit && _priorityFiles.contains(path)) { | 980 if (withUnit && _priorityFiles.contains(path)) { |
998 _priorityResults[path] = result; | 981 _priorityResults[path] = result; |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 libraryDeclarations.add(new TopLevelDeclarationInSource( | 1970 libraryDeclarations.add(new TopLevelDeclarationInSource( |
1988 file.source, declaration, isExported)); | 1971 file.source, declaration, isExported)); |
1989 } | 1972 } |
1990 } | 1973 } |
1991 } | 1974 } |
1992 | 1975 |
1993 // We're not done yet. | 1976 // We're not done yet. |
1994 return false; | 1977 return false; |
1995 } | 1978 } |
1996 } | 1979 } |
OLD | NEW |