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/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; | 10 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 /** | 104 /** |
105 * This [ContentCache] is consulted for a file content before reading | 105 * This [ContentCache] is consulted for a file content before reading |
106 * the content from the file. | 106 * the content from the file. |
107 */ | 107 */ |
108 final FileContentOverlay _contentOverlay; | 108 final FileContentOverlay _contentOverlay; |
109 | 109 |
110 /** | 110 /** |
111 * The [SourceFactory] is used to resolve URIs to paths and restore URIs | 111 * The [SourceFactory] is used to resolve URIs to paths and restore URIs |
112 * from file paths. | 112 * from file paths. |
113 */ | 113 */ |
114 final SourceFactory _sourceFactory; | 114 final SourceFactory sourceFactory; |
115 | 115 |
116 /** | 116 /** |
117 * The analysis options to analyze with. | 117 * The analysis options to analyze with. |
118 */ | 118 */ |
119 final AnalysisOptions _analysisOptions; | 119 final AnalysisOptions analysisOptions; |
120 | 120 |
121 /** | 121 /** |
122 * The salt to mix into all hashes used as keys for serialized data. | 122 * The salt to mix into all hashes used as keys for serialized data. |
123 */ | 123 */ |
124 final Uint32List _salt = | 124 final Uint32List _salt = |
125 new Uint32List(1 + AnalysisOptions.crossContextOptionsLength); | 125 new Uint32List(1 + AnalysisOptions.crossContextOptionsLength); |
126 | 126 |
127 /** | 127 /** |
128 * The current file system state. | 128 * The current file system state. |
129 */ | 129 */ |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 * The given [SourceFactory] is cloned to ensure that it does not contain a | 206 * The given [SourceFactory] is cloned to ensure that it does not contain a |
207 * reference to a [AnalysisContext] in which it could have been used. | 207 * reference to a [AnalysisContext] in which it could have been used. |
208 */ | 208 */ |
209 AnalysisDriver( | 209 AnalysisDriver( |
210 this._scheduler, | 210 this._scheduler, |
211 this._logger, | 211 this._logger, |
212 this._resourceProvider, | 212 this._resourceProvider, |
213 this._byteStore, | 213 this._byteStore, |
214 this._contentOverlay, | 214 this._contentOverlay, |
215 SourceFactory sourceFactory, | 215 SourceFactory sourceFactory, |
216 this._analysisOptions) | 216 this.analysisOptions) |
217 : _sourceFactory = sourceFactory.clone() { | 217 : sourceFactory = sourceFactory.clone() { |
218 _fillSalt(); | 218 _fillSalt(); |
219 _sdkBundle = sourceFactory.dartSdk.getLinkedBundle(); | 219 _sdkBundle = sourceFactory.dartSdk.getLinkedBundle(); |
220 _fsState = new FileSystemState( | 220 _fsState = new FileSystemState( |
221 _logger, | 221 _logger, |
222 _byteStore, | 222 _byteStore, |
223 _contentOverlay, | 223 _contentOverlay, |
224 _resourceProvider, | 224 _resourceProvider, |
225 _sourceFactory, | 225 sourceFactory, |
226 _analysisOptions, | 226 analysisOptions, |
227 _salt, | 227 _salt, |
228 _sdkBundle.apiSignature); | 228 _sdkBundle.apiSignature); |
229 _scheduler._add(this); | 229 _scheduler._add(this); |
230 _search = new Search(this); | 230 _search = new Search(this); |
231 } | 231 } |
232 | 232 |
233 /** | 233 /** |
234 * Return the set of files added to analysis using [addFile]. | 234 * Return the set of files added to analysis using [addFile]. |
235 */ | 235 */ |
236 Set<String> get addedFiles => _explicitFiles; | 236 Set<String> get addedFiles => _explicitFiles; |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 new LibrarySpecificUnit(libraryFile.source, file.source), | 596 new LibrarySpecificUnit(libraryFile.source, file.source), |
597 COMPILATION_UNIT_ELEMENT); | 597 COMPILATION_UNIT_ELEMENT); |
598 | 598 |
599 // Return as IndexResult. | 599 // Return as IndexResult. |
600 return new IndexResult(unitElement, analysisResult._index); | 600 return new IndexResult(unitElement, analysisResult._index); |
601 } | 601 } |
602 | 602 |
603 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) { | 603 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) { |
604 AnalysisContextImpl analysisContext = | 604 AnalysisContextImpl analysisContext = |
605 AnalysisEngine.instance.createAnalysisContext(); | 605 AnalysisEngine.instance.createAnalysisContext(); |
606 analysisContext.analysisOptions = _analysisOptions; | 606 analysisContext.analysisOptions = analysisOptions; |
607 | 607 |
608 analysisContext.sourceFactory = _sourceFactory.clone(); | 608 analysisContext.sourceFactory = sourceFactory.clone(); |
609 analysisContext.resultProvider = | 609 analysisContext.resultProvider = |
610 new InputPackagesResultProvider(analysisContext, libraryContext.store); | 610 new InputPackagesResultProvider(analysisContext, libraryContext.store); |
611 analysisContext | 611 analysisContext |
612 .applyChanges(new ChangeSet()..addedSource(libraryContext.file.source)); | 612 .applyChanges(new ChangeSet()..addedSource(libraryContext.file.source)); |
613 return analysisContext; | 613 return analysisContext; |
614 } | 614 } |
615 | 615 |
616 /** | 616 /** |
617 * Return the context in which the [library] should be analyzed it. | 617 * Return the context in which the [library] should be analyzed it. |
618 */ | 618 */ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 }); | 670 }); |
671 | 671 |
672 Map<String, LinkedLibraryBuilder> linkedLibraries = {}; | 672 Map<String, LinkedLibraryBuilder> linkedLibraries = {}; |
673 _logger.run('Link bundles', () { | 673 _logger.run('Link bundles', () { |
674 linkedLibraries = link(libraryUrisToLink, (String uri) { | 674 linkedLibraries = link(libraryUrisToLink, (String uri) { |
675 LinkedLibrary linkedLibrary = store.linkedMap[uri]; | 675 LinkedLibrary linkedLibrary = store.linkedMap[uri]; |
676 return linkedLibrary; | 676 return linkedLibrary; |
677 }, (String uri) { | 677 }, (String uri) { |
678 UnlinkedUnit unlinkedUnit = store.unlinkedMap[uri]; | 678 UnlinkedUnit unlinkedUnit = store.unlinkedMap[uri]; |
679 return unlinkedUnit; | 679 return unlinkedUnit; |
680 }, (_) => null, _analysisOptions.strongMode); | 680 }, (_) => null, analysisOptions.strongMode); |
681 _logger.writeln('Linked ${linkedLibraries.length} bundles.'); | 681 _logger.writeln('Linked ${linkedLibraries.length} bundles.'); |
682 }); | 682 }); |
683 | 683 |
684 linkedLibraries.forEach((uri, linkedBuilder) { | 684 linkedLibraries.forEach((uri, linkedBuilder) { |
685 FileState library = libraries[uri]; | 685 FileState library = libraries[uri]; |
686 String key = '${library.transitiveSignature}.linked'; | 686 String key = '${library.transitiveSignature}.linked'; |
687 List<int> bytes = linkedBuilder.toBuffer(); | 687 List<int> bytes = linkedBuilder.toBuffer(); |
688 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); | 688 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); |
689 _addToStoreLinked(store, uri, linked); | 689 _addToStoreLinked(store, uri, linked); |
690 _byteStore.put(key, bytes); | 690 _byteStore.put(key, bytes); |
691 }); | 691 }); |
692 | 692 |
693 return new _LibraryContext(library, store); | 693 return new _LibraryContext(library, store); |
694 }); | 694 }); |
695 } | 695 } |
696 | 696 |
697 /** | 697 /** |
698 * Fill [_salt] with data. | 698 * Fill [_salt] with data. |
699 */ | 699 */ |
700 void _fillSalt() { | 700 void _fillSalt() { |
701 _salt[0] = DATA_VERSION; | 701 _salt[0] = DATA_VERSION; |
702 List<int> crossContextOptions = | 702 List<int> crossContextOptions = analysisOptions.encodeCrossContextOptions(); |
703 _analysisOptions.encodeCrossContextOptions(); | |
704 assert(crossContextOptions.length == | 703 assert(crossContextOptions.length == |
705 AnalysisOptions.crossContextOptionsLength); | 704 AnalysisOptions.crossContextOptionsLength); |
706 for (int i = 0; i < crossContextOptions.length; i++) { | 705 for (int i = 0; i < crossContextOptions.length; i++) { |
707 _salt[i + 1] = crossContextOptions[i]; | 706 _salt[i + 1] = crossContextOptions[i]; |
708 } | 707 } |
709 } | 708 } |
710 | 709 |
711 /** | 710 /** |
712 * Load the [AnalysisResult] for the given [file] from the [bytes]. Set | 711 * Load the [AnalysisResult] for the given [file] from the [bytes]. Set |
713 * optional [content] and [resolvedUnit]. | 712 * optional [content] and [resolvedUnit]. |
714 */ | 713 */ |
715 AnalysisResult _getAnalysisResultFromBytes( | 714 AnalysisResult _getAnalysisResultFromBytes( |
716 FileState libraryFile, FileState file, List<int> bytes, | 715 FileState libraryFile, FileState file, List<int> bytes, |
717 {String content, CompilationUnit resolvedUnit}) { | 716 {String content, CompilationUnit resolvedUnit}) { |
718 var unit = new AnalysisDriverResolvedUnit.fromBuffer(bytes); | 717 var unit = new AnalysisDriverResolvedUnit.fromBuffer(bytes); |
719 List<AnalysisError> errors = unit.errors | 718 List<AnalysisError> errors = unit.errors |
720 .map((error) => new AnalysisError.forValues( | 719 .map((error) => new AnalysisError.forValues( |
721 file.source, | 720 file.source, |
722 error.offset, | 721 error.offset, |
723 error.length, | 722 error.length, |
724 errorCodeByUniqueName(error.uniqueName), | 723 errorCodeByUniqueName(error.uniqueName), |
725 error.message, | 724 error.message, |
726 error.correction)) | 725 error.correction)) |
727 .toList(); | 726 .toList(); |
728 return new AnalysisResult( | 727 return new AnalysisResult( |
729 libraryFile, | 728 libraryFile, |
730 file, | 729 file, |
731 _sourceFactory, | 730 sourceFactory, |
732 file.path, | 731 file.path, |
733 file.uri, | 732 file.uri, |
734 content, | 733 content, |
735 file.contentHash, | 734 file.contentHash, |
736 file.lineInfo, | 735 file.lineInfo, |
737 resolvedUnit, | 736 resolvedUnit, |
738 errors, | 737 errors, |
739 unit.index); | 738 unit.index); |
740 } | 739 } |
741 | 740 |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 } | 1287 } |
1289 | 1288 |
1290 /** | 1289 /** |
1291 * TODO(scheglov) document | 1290 * TODO(scheglov) document |
1292 */ | 1291 */ |
1293 class _LibraryContext { | 1292 class _LibraryContext { |
1294 final FileState file; | 1293 final FileState file; |
1295 final SummaryDataStore store; | 1294 final SummaryDataStore store; |
1296 _LibraryContext(this.file, this.store); | 1295 _LibraryContext(this.file, this.store); |
1297 } | 1296 } |
OLD | NEW |