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

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

Issue 2829253002: Add support for external summaries bundle in AnalysisDriver. (Closed)
Patch Set: Fixes for review comments. 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 'package:analyzer/context/declared_variables.dart'; 5 import 'package:analyzer/context/declared_variables.dart';
6 import 'package:analyzer/dart/ast/ast.dart'; 6 import 'package:analyzer/dart/ast/ast.dart';
7 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; 7 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement;
8 import 'package:analyzer/error/error.dart'; 8 import 'package:analyzer/error/error.dart';
9 import 'package:analyzer/src/context/context.dart'; 9 import 'package:analyzer/src/context/context.dart';
10 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 10 import 'package:analyzer/src/dart/analysis/byte_store.dart';
11 import 'package:analyzer/src/dart/analysis/driver.dart'; 11 import 'package:analyzer/src/dart/analysis/driver.dart';
12 import 'package:analyzer/src/dart/analysis/file_state.dart'; 12 import 'package:analyzer/src/dart/analysis/file_state.dart';
13 import 'package:analyzer/src/dart/analysis/file_tracker.dart';
14 import 'package:analyzer/src/generated/engine.dart' 13 import 'package:analyzer/src/generated/engine.dart'
15 show AnalysisContext, AnalysisEngine, AnalysisOptions; 14 show AnalysisContext, AnalysisEngine, AnalysisOptions;
16 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
17 import 'package:analyzer/src/summary/format.dart'; 16 import 'package:analyzer/src/summary/format.dart';
18 import 'package:analyzer/src/summary/idl.dart'; 17 import 'package:analyzer/src/summary/idl.dart';
19 import 'package:analyzer/src/summary/link.dart'; 18 import 'package:analyzer/src/summary/link.dart';
20 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 19 import 'package:analyzer/src/summary/package_bundle_reader.dart';
21 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT; 20 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT;
22 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit; 21 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit;
23 22
(...skipping 16 matching lines...) Expand all
40 * Create a [LibraryContext] which is prepared to analyze [targetLibrary]. 39 * Create a [LibraryContext] which is prepared to analyze [targetLibrary].
41 */ 40 */
42 factory LibraryContext.forSingleLibrary( 41 factory LibraryContext.forSingleLibrary(
43 FileState targetLibrary, 42 FileState targetLibrary,
44 PerformanceLog logger, 43 PerformanceLog logger,
45 PackageBundle sdkBundle, 44 PackageBundle sdkBundle,
46 ByteStore byteStore, 45 ByteStore byteStore,
47 AnalysisOptions options, 46 AnalysisOptions options,
48 DeclaredVariables declaredVariables, 47 DeclaredVariables declaredVariables,
49 SourceFactory sourceFactory, 48 SourceFactory sourceFactory,
50 FileTracker fileTracker) { 49 SummaryDataStore externalSummaries,
50 FileSystemState fsState) {
51 return logger.run('Create library context', () { 51 return logger.run('Create library context', () {
52 Map<String, FileState> libraries = <String, FileState>{}; 52 Map<String, FileState> libraries = <String, FileState>{};
53 SummaryDataStore store = new SummaryDataStore(const <String>[]); 53 SummaryDataStore store = new SummaryDataStore(const <String>[]);
54 54
55 if (externalSummaries != null) {
56 store.addStore(externalSummaries);
57 }
58
55 if (sdkBundle != null) { 59 if (sdkBundle != null) {
56 store.addBundle(null, sdkBundle); 60 store.addBundle(null, sdkBundle);
57 } 61 }
58 62
59 void appendLibraryFiles(FileState library) { 63 void appendLibraryFiles(FileState library) {
60 if (!libraries.containsKey(library.uriStr)) { 64 if (!libraries.containsKey(library.uriStr)) {
61 // Serve 'dart:' URIs from the SDK bundle. 65 // Serve 'dart:' URIs from the SDK bundle.
62 if (sdkBundle != null && library.uri.scheme == 'dart') { 66 if (sdkBundle != null && library.uri.scheme == 'dart') {
63 return; 67 return;
64 } 68 }
65 69
70 if (library.isInExternalSummaries) {
71 return;
72 }
73
66 libraries[library.uriStr] = library; 74 libraries[library.uriStr] = library;
67 75
68 // Append the defining unit. 76 // Append the defining unit.
69 store.addUnlinkedUnit(library.uriStr, library.unlinked); 77 store.addUnlinkedUnit(library.uriStr, library.unlinked);
70 78
71 // Append parts. 79 // Append parts.
72 for (FileState part in library.partedFiles) { 80 for (FileState part in library.partedFiles) {
73 store.addUnlinkedUnit(part.uriStr, part.unlinked); 81 store.addUnlinkedUnit(part.uriStr, part.unlinked);
74 } 82 }
75 83
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 linkedLibraries.forEach((uri, linkedBuilder) { 124 linkedLibraries.forEach((uri, linkedBuilder) {
117 FileState library = libraries[uri]; 125 FileState library = libraries[uri];
118 String key = '${library.transitiveSignature}.linked'; 126 String key = '${library.transitiveSignature}.linked';
119 List<int> bytes = linkedBuilder.toBuffer(); 127 List<int> bytes = linkedBuilder.toBuffer();
120 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes); 128 LinkedLibrary linked = new LinkedLibrary.fromBuffer(bytes);
121 store.addLinkedLibrary(uri, linked); 129 store.addLinkedLibrary(uri, linked);
122 byteStore.put(key, bytes); 130 byteStore.put(key, bytes);
123 }); 131 });
124 132
125 var analysisContext = _createAnalysisContext( 133 var analysisContext = _createAnalysisContext(
126 options, declaredVariables, sourceFactory, fileTracker, store); 134 options, declaredVariables, sourceFactory, fsState, store);
127 135
128 return new LibraryContext._(store, analysisContext); 136 return new LibraryContext._(store, analysisContext);
129 }); 137 });
130 } 138 }
131 139
132 LibraryContext._(this.store, this._analysisContext); 140 LibraryContext._(this.store, this._analysisContext);
133 141
134 /** 142 /**
135 * Computes a [CompilationUnitElement] for the given library/unit pair. 143 * Computes a [CompilationUnitElement] for the given library/unit pair.
136 */ 144 */
(...skipping 21 matching lines...) Expand all
158 CompilationUnit resolvedUnit = 166 CompilationUnit resolvedUnit =
159 _analysisContext.resolveCompilationUnit2(unitSource, librarySource); 167 _analysisContext.resolveCompilationUnit2(unitSource, librarySource);
160 List<AnalysisError> errors = _analysisContext.computeErrors(unitSource); 168 List<AnalysisError> errors = _analysisContext.computeErrors(unitSource);
161 return new ResolutionResult(resolvedUnit, errors); 169 return new ResolutionResult(resolvedUnit, errors);
162 } 170 }
163 171
164 static AnalysisContext _createAnalysisContext( 172 static AnalysisContext _createAnalysisContext(
165 AnalysisOptions _analysisOptions, 173 AnalysisOptions _analysisOptions,
166 DeclaredVariables declaredVariables, 174 DeclaredVariables declaredVariables,
167 SourceFactory _sourceFactory, 175 SourceFactory _sourceFactory,
168 FileTracker fileTracker, 176 FileSystemState fileSystemState,
169 SummaryDataStore store) { 177 SummaryDataStore store) {
170 AnalysisContextImpl analysisContext = 178 AnalysisContextImpl analysisContext =
171 AnalysisEngine.instance.createAnalysisContext(); 179 AnalysisEngine.instance.createAnalysisContext();
172 analysisContext.useSdkCachePartition = false; 180 analysisContext.useSdkCachePartition = false;
173 analysisContext.analysisOptions = _analysisOptions; 181 analysisContext.analysisOptions = _analysisOptions;
174 analysisContext.declaredVariables.addAll(declaredVariables); 182 analysisContext.declaredVariables.addAll(declaredVariables);
175 analysisContext.sourceFactory = _sourceFactory.clone(); 183 analysisContext.sourceFactory = _sourceFactory.clone();
176 analysisContext.contentCache = new _ContentCacheWrapper(fileTracker); 184 analysisContext.contentCache = new _ContentCacheWrapper(fileSystemState);
177 analysisContext.resultProvider = 185 analysisContext.resultProvider =
178 new InputPackagesResultProvider(analysisContext, store); 186 new InputPackagesResultProvider(analysisContext, store);
179 return analysisContext; 187 return analysisContext;
180 } 188 }
181 } 189 }
182 190
183 /** 191 /**
184 * Container object holding the result of a call to 192 * Container object holding the result of a call to
185 * [LibraryContext.resolveUnit]. 193 * [LibraryContext.resolveUnit].
186 */ 194 */
187 class ResolutionResult { 195 class ResolutionResult {
188 final CompilationUnit resolvedUnit; 196 final CompilationUnit resolvedUnit;
189 final List<AnalysisError> errors; 197 final List<AnalysisError> errors;
190 198
191 ResolutionResult(this.resolvedUnit, this.errors); 199 ResolutionResult(this.resolvedUnit, this.errors);
192 } 200 }
193 201
194 /** 202 /**
195 * [ContentCache] wrapper around [FileContentOverlay]. 203 * [ContentCache] wrapper around [FileContentOverlay].
196 */ 204 */
197 class _ContentCacheWrapper implements ContentCache { 205 class _ContentCacheWrapper implements ContentCache {
198 final FileTracker fileTracker; 206 final FileSystemState fsState;
199 207
200 _ContentCacheWrapper(this.fileTracker); 208 _ContentCacheWrapper(this.fsState);
201 209
202 @override 210 @override
203 void accept(ContentCacheVisitor visitor) { 211 void accept(ContentCacheVisitor visitor) {
204 throw new UnimplementedError(); 212 throw new UnimplementedError();
205 } 213 }
206 214
207 @override 215 @override
208 String getContents(Source source) { 216 String getContents(Source source) {
209 return _getFileForSource(source).content; 217 return _getFileForSource(source).content;
210 } 218 }
211 219
212 @override 220 @override
213 bool getExists(Source source) { 221 bool getExists(Source source) {
214 if (source.isInSystemLibrary) { 222 if (source.isInSystemLibrary) {
215 return true; 223 return true;
216 } 224 }
225 String uriStr = source.uri.toString();
226 if (fsState.externalSummaries.hasUnlinkedUnit(uriStr)) {
227 return true;
228 }
217 return _getFileForSource(source).exists; 229 return _getFileForSource(source).exists;
218 } 230 }
219 231
220 @override 232 @override
221 int getModificationStamp(Source source) { 233 int getModificationStamp(Source source) {
222 if (source.isInSystemLibrary) { 234 if (source.isInSystemLibrary) {
223 return 0; 235 return 0;
224 } 236 }
225 return _getFileForSource(source).exists ? 0 : -1; 237 return _getFileForSource(source).exists ? 0 : -1;
226 } 238 }
227 239
228 @override 240 @override
229 String setContents(Source source, String contents) { 241 String setContents(Source source, String contents) {
230 throw new UnimplementedError(); 242 throw new UnimplementedError();
231 } 243 }
232 244
233 FileState _getFileForSource(Source source) { 245 FileState _getFileForSource(Source source) {
234 String path = source.fullName; 246 String path = source.fullName;
235 return fileTracker.fsState.getFileForPath(path); 247 return fsState.getFileForPath(path);
236 } 248 }
237 } 249 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart ('k') | pkg/analyzer/lib/src/summary/package_bundle_reader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698