| 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/error/error.dart'; | 10 import 'package:analyzer/error/error.dart'; |
| 11 import 'package:analyzer/error/listener.dart'; | 11 import 'package:analyzer/error/listener.dart'; |
| 12 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 13 import 'package:analyzer/src/context/context.dart'; | 13 import 'package:analyzer/src/context/context.dart'; |
| 14 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 14 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 15 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 15 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 16 import 'package:analyzer/src/dart/analysis/index.dart'; | 16 import 'package:analyzer/src/dart/analysis/index.dart'; |
| 17 import 'package:analyzer/src/dart/analysis/search.dart'; | 17 import 'package:analyzer/src/dart/analysis/search.dart'; |
| 18 import 'package:analyzer/src/dart/analysis/status.dart'; | 18 import 'package:analyzer/src/dart/analysis/status.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart' | 19 import 'package:analyzer/src/generated/engine.dart' |
| 20 show AnalysisContext, AnalysisEngine, AnalysisOptions, ChangeSet; | 20 show AnalysisContext, AnalysisEngine, AnalysisOptions, ChangeSet; |
| 21 import 'package:analyzer/src/generated/source.dart'; | 21 import 'package:analyzer/src/generated/source.dart'; |
| 22 import 'package:analyzer/src/summary/api_signature.dart'; | 22 import 'package:analyzer/src/summary/api_signature.dart'; |
| 23 import 'package:analyzer/src/summary/format.dart'; | 23 import 'package:analyzer/src/summary/format.dart'; |
| 24 import 'package:analyzer/src/summary/idl.dart'; | 24 import 'package:analyzer/src/summary/idl.dart'; |
| 25 import 'package:analyzer/src/summary/link.dart'; | 25 import 'package:analyzer/src/summary/link.dart'; |
| 26 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 26 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 27 import 'package:analyzer/src/summary/summarize_elements.dart'; | |
| 28 | 27 |
| 29 /** | 28 /** |
| 30 * This class computes [AnalysisResult]s for Dart files. | 29 * This class computes [AnalysisResult]s for Dart files. |
| 31 * | 30 * |
| 32 * Let the set of "explicitly analyzed files" denote the set of paths that have | 31 * Let the set of "explicitly analyzed files" denote the set of paths that have |
| 33 * been passed to [addFile] but not subsequently passed to [removeFile]. Let | 32 * been passed to [addFile] but not subsequently passed to [removeFile]. Let |
| 34 * the "current analysis results" denote the map from the set of explicitly | 33 * the "current analysis results" denote the map from the set of explicitly |
| 35 * analyzed files to the most recent [AnalysisResult] delivered to [results] | 34 * analyzed files to the most recent [AnalysisResult] delivered to [results] |
| 36 * for each file. Let the "current file state" represent a map from file path | 35 * for each file. Let the "current file state" represent a map from file path |
| 37 * to the file contents most recently read from that file, or fetched from the | 36 * to the file contents most recently read from that file, or fetched from the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 62 * | 61 * |
| 63 * | 62 * |
| 64 * TODO(scheglov) Clean up the list of implicitly analyzed files. | 63 * TODO(scheglov) Clean up the list of implicitly analyzed files. |
| 65 * | 64 * |
| 66 * TODO(scheglov) Handle not existing 'dart:x' URIs (while user is typing). | 65 * TODO(scheglov) Handle not existing 'dart:x' URIs (while user is typing). |
| 67 */ | 66 */ |
| 68 class AnalysisDriver { | 67 class AnalysisDriver { |
| 69 /** | 68 /** |
| 70 * The version of data format, should be incremented on every format change. | 69 * The version of data format, should be incremented on every format change. |
| 71 */ | 70 */ |
| 72 static const int DATA_VERSION = 7; | 71 static const int DATA_VERSION = 8; |
| 73 | 72 |
| 74 /** | 73 /** |
| 75 * The name of the driver, e.g. the name of the folder. | 74 * The name of the driver, e.g. the name of the folder. |
| 76 */ | 75 */ |
| 77 String name; | 76 String name; |
| 78 | 77 |
| 79 /** | 78 /** |
| 80 * The scheduler that schedules analysis work in this, and possibly other | 79 * The scheduler that schedules analysis work in this, and possibly other |
| 81 * analysis drivers. | 80 * analysis drivers. |
| 82 */ | 81 */ |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 analysisContext.sourceFactory = _sourceFactory.clone(); | 560 analysisContext.sourceFactory = _sourceFactory.clone(); |
| 562 analysisContext.resultProvider = | 561 analysisContext.resultProvider = |
| 563 new InputPackagesResultProvider(analysisContext, libraryContext.store); | 562 new InputPackagesResultProvider(analysisContext, libraryContext.store); |
| 564 analysisContext | 563 analysisContext |
| 565 .applyChanges(new ChangeSet()..addedSource(libraryContext.file.source)); | 564 .applyChanges(new ChangeSet()..addedSource(libraryContext.file.source)); |
| 566 return analysisContext; | 565 return analysisContext; |
| 567 } | 566 } |
| 568 | 567 |
| 569 /** | 568 /** |
| 570 * Return the context in which the [library] should be analyzed it. | 569 * Return the context in which the [library] should be analyzed it. |
| 571 * | |
| 572 * TODO(scheglov) We often don't need [SummaryDataStore], only dependency | |
| 573 * signature. | |
| 574 */ | 570 */ |
| 575 _LibraryContext _createLibraryContext(FileState library) { | 571 _LibraryContext _createLibraryContext(FileState library) { |
| 576 return _logger.run('Create library context', () { | 572 return _logger.run('Create library context', () { |
| 577 Map<String, FileState> libraries = <String, FileState>{}; | 573 Map<String, FileState> libraries = <String, FileState>{}; |
| 578 SummaryDataStore store = new SummaryDataStore(const <String>[]); | 574 SummaryDataStore store = new SummaryDataStore(const <String>[]); |
| 579 store.addBundle(null, _sdkBundle); | 575 store.addBundle(null, _sdkBundle); |
| 580 | 576 |
| 581 void appendLibraryFiles(FileState library) { | 577 void appendLibraryFiles(FileState library) { |
| 582 // URIs with the 'dart:' scheme are served from the SDK bundle. | 578 // URIs with the 'dart:' scheme are served from the SDK bundle. |
| 583 if (library.uri.scheme == 'dart') { | 579 if (library.uri.scheme == 'dart') { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 608 _logger.run('Append library files', () { | 604 _logger.run('Append library files', () { |
| 609 return appendLibraryFiles(library); | 605 return appendLibraryFiles(library); |
| 610 }); | 606 }); |
| 611 | 607 |
| 612 Set<String> libraryUrisToLink = new Set<String>(); | 608 Set<String> libraryUrisToLink = new Set<String>(); |
| 613 _logger.run('Load linked bundles', () { | 609 _logger.run('Load linked bundles', () { |
| 614 for (FileState library in libraries.values) { | 610 for (FileState library in libraries.values) { |
| 615 String key = '${library.transitiveSignature}.linked'; | 611 String key = '${library.transitiveSignature}.linked'; |
| 616 List<int> bytes = _byteStore.get(key); | 612 List<int> bytes = _byteStore.get(key); |
| 617 if (bytes != null) { | 613 if (bytes != null) { |
| 618 PackageBundle linked = new PackageBundle.fromBuffer(bytes); | 614 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); |
| 619 _addToStoreLinked( | 615 _addToStoreLinked(store, library.uriStr, linked); |
| 620 store, library.uriStr, linked.linkedLibraries.single); | |
| 621 } else { | 616 } else { |
| 622 libraryUrisToLink.add(library.uriStr); | 617 libraryUrisToLink.add(library.uriStr); |
| 623 } | 618 } |
| 624 } | 619 } |
| 625 int numOfLoaded = libraries.length - libraryUrisToLink.length; | 620 int numOfLoaded = libraries.length - libraryUrisToLink.length; |
| 626 _logger.writeln('Loaded $numOfLoaded linked bundles.'); | 621 _logger.writeln('Loaded $numOfLoaded linked bundles.'); |
| 627 }); | 622 }); |
| 628 | 623 |
| 629 Map<String, LinkedLibraryBuilder> linkedLibraries = {}; | 624 Map<String, LinkedLibraryBuilder> linkedLibraries = {}; |
| 630 _logger.run('Link bundles', () { | 625 _logger.run('Link bundles', () { |
| 631 linkedLibraries = link(libraryUrisToLink, (String uri) { | 626 linkedLibraries = link(libraryUrisToLink, (String uri) { |
| 632 LinkedLibrary linkedLibrary = store.linkedMap[uri]; | 627 LinkedLibrary linkedLibrary = store.linkedMap[uri]; |
| 633 return linkedLibrary; | 628 return linkedLibrary; |
| 634 }, (String uri) { | 629 }, (String uri) { |
| 635 UnlinkedUnit unlinkedUnit = store.unlinkedMap[uri]; | 630 UnlinkedUnit unlinkedUnit = store.unlinkedMap[uri]; |
| 636 return unlinkedUnit; | 631 return unlinkedUnit; |
| 637 }, (_) => null, _analysisOptions.strongMode); | 632 }, (_) => null, _analysisOptions.strongMode); |
| 638 _logger.writeln('Linked ${linkedLibraries.length} bundles.'); | 633 _logger.writeln('Linked ${linkedLibraries.length} bundles.'); |
| 639 }); | 634 }); |
| 640 | 635 |
| 641 linkedLibraries.forEach((uri, linkedBuilder) { | 636 linkedLibraries.forEach((uri, linkedBuilder) { |
| 642 FileState library = libraries[uri]; | 637 FileState library = libraries[uri]; |
| 643 String key = '${library.transitiveSignature}.linked'; | 638 String key = '${library.transitiveSignature}.linked'; |
| 644 List<int> bytes; | 639 List<int> bytes = linkedBuilder.toBuffer(); |
| 645 { | 640 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); |
| 646 PackageBundleAssembler assembler = new PackageBundleAssembler(); | 641 _addToStoreLinked(store, uri, linked); |
| 647 assembler.addLinkedLibrary(uri, linkedBuilder); | |
| 648 bytes = assembler.assemble().toBuffer(); | |
| 649 } | |
| 650 PackageBundle linked = new PackageBundle.fromBuffer(bytes); | |
| 651 _addToStoreLinked(store, uri, linked.linkedLibraries.single); | |
| 652 _byteStore.put(key, bytes); | 642 _byteStore.put(key, bytes); |
| 653 }); | 643 }); |
| 654 | 644 |
| 655 return new _LibraryContext(library, store); | 645 return new _LibraryContext(library, store); |
| 656 }); | 646 }); |
| 657 } | 647 } |
| 658 | 648 |
| 659 /** | 649 /** |
| 660 * Fill [_salt] with data. | 650 * Fill [_salt] with data. |
| 661 */ | 651 */ |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 } | 1188 } |
| 1199 | 1189 |
| 1200 /** | 1190 /** |
| 1201 * TODO(scheglov) document | 1191 * TODO(scheglov) document |
| 1202 */ | 1192 */ |
| 1203 class _LibraryContext { | 1193 class _LibraryContext { |
| 1204 final FileState file; | 1194 final FileState file; |
| 1205 final SummaryDataStore store; | 1195 final SummaryDataStore store; |
| 1206 _LibraryContext(this.file, this.store); | 1196 _LibraryContext(this.file, this.store); |
| 1207 } | 1197 } |
| OLD | NEW |