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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2829253002: Add support for external summaries bundle in AnalysisDriver. (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
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:convert'; 6 import 'dart:convert';
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/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 11 matching lines...) Expand all
22 import 'package:analyzer/src/fasta/mock_element.dart' as fasta; 22 import 'package:analyzer/src/fasta/mock_element.dart' as fasta;
23 import 'package:analyzer/src/generated/engine.dart'; 23 import 'package:analyzer/src/generated/engine.dart';
24 import 'package:analyzer/src/generated/parser.dart'; 24 import 'package:analyzer/src/generated/parser.dart';
25 import 'package:analyzer/src/generated/source.dart'; 25 import 'package:analyzer/src/generated/source.dart';
26 import 'package:analyzer/src/generated/utilities_dart.dart'; 26 import 'package:analyzer/src/generated/utilities_dart.dart';
27 import 'package:analyzer/src/source/source_resource.dart'; 27 import 'package:analyzer/src/source/source_resource.dart';
28 import 'package:analyzer/src/summary/api_signature.dart'; 28 import 'package:analyzer/src/summary/api_signature.dart';
29 import 'package:analyzer/src/summary/format.dart'; 29 import 'package:analyzer/src/summary/format.dart';
30 import 'package:analyzer/src/summary/idl.dart'; 30 import 'package:analyzer/src/summary/idl.dart';
31 import 'package:analyzer/src/summary/name_filter.dart'; 31 import 'package:analyzer/src/summary/name_filter.dart';
32 import 'package:analyzer/src/summary/package_bundle_reader.dart';
32 import 'package:analyzer/src/summary/summarize_ast.dart'; 33 import 'package:analyzer/src/summary/summarize_ast.dart';
33 import 'package:convert/convert.dart'; 34 import 'package:convert/convert.dart';
34 import 'package:crypto/crypto.dart'; 35 import 'package:crypto/crypto.dart';
35 import 'package:front_end/src/fasta/builder/builder.dart' as fasta; 36 import 'package:front_end/src/fasta/builder/builder.dart' as fasta;
36 import 'package:front_end/src/fasta/parser/parser.dart' as fasta; 37 import 'package:front_end/src/fasta/parser/parser.dart' as fasta;
37 import 'package:front_end/src/fasta/scanner.dart' as fasta; 38 import 'package:front_end/src/fasta/scanner.dart' as fasta;
38 import 'package:meta/meta.dart'; 39 import 'package:meta/meta.dart';
39 40
40 /** 41 /**
41 * [FileContentOverlay] is used to temporary override content of files. 42 * [FileContentOverlay] is used to temporary override content of files.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 final String path; 86 final String path;
86 87
87 /** 88 /**
88 * The absolute URI of the file. 89 * The absolute URI of the file.
89 */ 90 */
90 final Uri uri; 91 final Uri uri;
91 92
92 /** 93 /**
93 * The [Source] of the file with the [uri]. 94 * The [Source] of the file with the [uri].
94 */ 95 */
95 Source source; 96 final Source source;
97
98 /**
99 * Return `true` is this file is a stub created for a file in the provided
Brian Wilkerson 2017/04/21 16:19:39 "is" --> "if"
100 * external summary store. The values of the most properties are not the same
Brian Wilkerson 2017/04/21 16:19:39 "the most" --> "most"
101 * as they would be if the file were actually read from the file system.
102 * The value of the property [uri] is correct.
103 */
104 final bool isInExternalSummaries;
96 105
97 bool _exists; 106 bool _exists;
98 List<int> _contentBytes; 107 List<int> _contentBytes;
99 String _content; 108 String _content;
100 String _contentHash; 109 String _contentHash;
101 LineInfo _lineInfo; 110 LineInfo _lineInfo;
102 Set<String> _definedTopLevelNames; 111 Set<String> _definedTopLevelNames;
103 Set<String> _definedClassMemberNames; 112 Set<String> _definedClassMemberNames;
104 Set<String> _referencedNames; 113 Set<String> _referencedNames;
105 UnlinkedUnit _unlinked; 114 UnlinkedUnit _unlinked;
(...skipping 10 matching lines...) Expand all
116 125
117 Map<String, TopLevelDeclaration> _topLevelDeclarations; 126 Map<String, TopLevelDeclaration> _topLevelDeclarations;
118 Map<String, TopLevelDeclaration> _exportedTopLevelDeclarations; 127 Map<String, TopLevelDeclaration> _exportedTopLevelDeclarations;
119 128
120 /** 129 /**
121 * The flag that shows whether the file has an error or warning that 130 * The flag that shows whether the file has an error or warning that
122 * might be fixed by a change to another file. 131 * might be fixed by a change to another file.
123 */ 132 */
124 bool hasErrorOrWarning = false; 133 bool hasErrorOrWarning = false;
125 134
126 FileState._(this._fsState, this.path, this.uri, this.source); 135 FileState._(this._fsState, this.path, this.uri, this.source)
136 : isInExternalSummaries = false;
137
138 FileState._external(this._fsState, this.uri)
139 : isInExternalSummaries = true,
140 path = null,
141 source = null {
142 _apiSignature = new Uint8List(16);
143 }
127 144
128 /** 145 /**
129 * The unlinked API signature of the file. 146 * The unlinked API signature of the file.
130 */ 147 */
131 List<int> get apiSignature => _apiSignature; 148 List<int> get apiSignature => _apiSignature;
132 149
133 /** 150 /**
134 * The content of the file. 151 * The content of the file.
135 */ 152 */
136 String get content => _content; 153 String get content => _content;
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 class FileSystemState { 617 class FileSystemState {
601 final PerformanceLog _logger; 618 final PerformanceLog _logger;
602 final ResourceProvider _resourceProvider; 619 final ResourceProvider _resourceProvider;
603 final ByteStore _byteStore; 620 final ByteStore _byteStore;
604 final FileContentOverlay _contentOverlay; 621 final FileContentOverlay _contentOverlay;
605 final SourceFactory _sourceFactory; 622 final SourceFactory _sourceFactory;
606 final AnalysisOptions _analysisOptions; 623 final AnalysisOptions _analysisOptions;
607 final Uint32List _salt; 624 final Uint32List _salt;
608 625
609 /** 626 /**
627 * The optional store with externally provided unlinked and corresponding
628 * linked summaries. These summaries are always added to the store for any
629 * file analysis.
630 *
631 * While walking the file graph, when we reach a file that exists in the
632 * external store, we add a stub [FileState], but don't attempt to read its
633 * content, or its unlinked unit, or imported libraries, etc.
634 */
635 final SummaryDataStore externalSummaries;
636
637 /**
610 * Mapping from a URI to the corresponding [FileState]. 638 * Mapping from a URI to the corresponding [FileState].
611 */ 639 */
612 final Map<Uri, FileState> _uriToFile = {}; 640 final Map<Uri, FileState> _uriToFile = {};
613 641
614 /** 642 /**
615 * All known file paths. 643 * All known file paths.
616 */ 644 */
617 final Set<String> knownFilePaths = new Set<String>(); 645 final Set<String> knownFilePaths = new Set<String>();
618 646
619 /** 647 /**
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 695
668 FileSystemStateTestView _testView; 696 FileSystemStateTestView _testView;
669 697
670 FileSystemState( 698 FileSystemState(
671 this._logger, 699 this._logger,
672 this._byteStore, 700 this._byteStore,
673 this._contentOverlay, 701 this._contentOverlay,
674 this._resourceProvider, 702 this._resourceProvider,
675 this._sourceFactory, 703 this._sourceFactory,
676 this._analysisOptions, 704 this._analysisOptions,
677 this._salt) { 705 this._salt,
706 {this.externalSummaries}) {
678 _testView = new FileSystemStateTestView(this); 707 _testView = new FileSystemStateTestView(this);
679 } 708 }
680 709
681 /** 710 /**
682 * Return the known files. 711 * Return the known files.
683 */ 712 */
684 List<FileState> get knownFiles => 713 List<FileState> get knownFiles =>
685 _pathToFiles.values.map((files) => files.first).toList(); 714 _pathToFiles.values.map((files) => files.first).toList();
686 715
687 /** 716 /**
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 766 }
738 767
739 /** 768 /**
740 * Return the [FileState] for the given absolute [uri]. May return `null` if 769 * Return the [FileState] for the given absolute [uri]. May return `null` if
741 * the [uri] is invalid, e.g. a `package:` URI without a package name. The 770 * the [uri] is invalid, e.g. a `package:` URI without a package name. The
742 * returned file has the last known state since if was last refreshed. 771 * returned file has the last known state since if was last refreshed.
743 */ 772 */
744 FileState getFileForUri(Uri uri) { 773 FileState getFileForUri(Uri uri) {
745 FileState file = _uriToFile[uri]; 774 FileState file = _uriToFile[uri];
746 if (file == null) { 775 if (file == null) {
776 // If the external store has this URI, create a stub file for it.
777 // We are given all required unlinked and linked summaries for it.
778 if (externalSummaries != null) {
779 String uriStr = uri.toString();
780 if (externalSummaries.hasUnlinkedUnit(uriStr)) {
781 file = new FileState._external(this, uri);
782 _uriToFile[uri] = file;
783 return file;
784 }
785 }
786
747 Source uriSource = _sourceFactory.resolveUri(null, uri.toString()); 787 Source uriSource = _sourceFactory.resolveUri(null, uri.toString());
748 788
749 // If the URI cannot be resolved, for example because the factory 789 // If the URI cannot be resolved, for example because the factory
750 // does not understand the scheme, return the unresolved file instance. 790 // does not understand the scheme, return the unresolved file instance.
751 if (uriSource == null) { 791 if (uriSource == null) {
752 _uriToFile[uri] = unresolvedFile; 792 _uriToFile[uri] = unresolvedFile;
753 return unresolvedFile; 793 return unresolvedFile;
754 } 794 }
755 795
756 String path = uriSource.fullName; 796 String path = uriSource.fullName;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 _FastaElementProxy operator [](fasta.Builder builder) => 926 _FastaElementProxy operator [](fasta.Builder builder) =>
887 _elements.putIfAbsent(builder, () => new _FastaElementProxy()); 927 _elements.putIfAbsent(builder, () => new _FastaElementProxy());
888 928
889 @override 929 @override
890 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 930 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
891 } 931 }
892 932
893 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType { 933 class _FastaInterfaceTypeProxy implements fasta.KernelInterfaceType {
894 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 934 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
895 } 935 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698