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:convert'; | 5 import 'dart:convert'; |
6 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
7 | 7 |
8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
12 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 12 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
13 import 'package:analyzer/src/dart/analysis/driver.dart'; | 13 import 'package:analyzer/src/dart/analysis/driver.dart'; |
14 import 'package:analyzer/src/dart/analysis/referenced_names.dart'; | |
14 import 'package:analyzer/src/dart/scanner/reader.dart'; | 15 import 'package:analyzer/src/dart/scanner/reader.dart'; |
15 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 16 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
16 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
17 import 'package:analyzer/src/generated/parser.dart'; | 18 import 'package:analyzer/src/generated/parser.dart'; |
18 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
19 import 'package:analyzer/src/generated/utilities_dart.dart'; | 20 import 'package:analyzer/src/generated/utilities_dart.dart'; |
20 import 'package:analyzer/src/source/source_resource.dart'; | 21 import 'package:analyzer/src/source/source_resource.dart'; |
21 import 'package:analyzer/src/summary/api_signature.dart'; | 22 import 'package:analyzer/src/summary/api_signature.dart'; |
22 import 'package:analyzer/src/summary/format.dart'; | 23 import 'package:analyzer/src/summary/format.dart'; |
23 import 'package:analyzer/src/summary/idl.dart'; | 24 import 'package:analyzer/src/summary/idl.dart'; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 final Uri uri; | 79 final Uri uri; |
79 | 80 |
80 /** | 81 /** |
81 * The [Source] of the file with the [uri]. | 82 * The [Source] of the file with the [uri]. |
82 */ | 83 */ |
83 Source source; | 84 Source source; |
84 | 85 |
85 String _content; | 86 String _content; |
86 String _contentHash; | 87 String _contentHash; |
87 LineInfo _lineInfo; | 88 LineInfo _lineInfo; |
89 Set<String> _referencedNames; | |
88 UnlinkedUnit _unlinked; | 90 UnlinkedUnit _unlinked; |
89 List<int> _apiSignature; | 91 List<int> _apiSignature; |
90 | 92 |
91 List<FileState> _importedFiles; | 93 List<FileState> _importedFiles; |
92 List<FileState> _exportedFiles; | 94 List<FileState> _exportedFiles; |
93 List<FileState> _partedFiles; | 95 List<FileState> _partedFiles; |
94 Set<FileState> _directReferencedFiles = new Set<FileState>(); | 96 Set<FileState> _directReferencedFiles = new Set<FileState>(); |
95 Set<FileState> _transitiveFiles; | 97 Set<FileState> _transitiveFiles; |
96 | 98 |
97 FileState._(this._fsState, this.path, this.uri, this.source); | 99 FileState._(this._fsState, this.path, this.uri, this.source); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 * Return information about line in the file. | 155 * Return information about line in the file. |
154 */ | 156 */ |
155 LineInfo get lineInfo => _lineInfo; | 157 LineInfo get lineInfo => _lineInfo; |
156 | 158 |
157 /** | 159 /** |
158 * The list of files this library file references as parts. | 160 * The list of files this library file references as parts. |
159 */ | 161 */ |
160 List<FileState> get partedFiles => _partedFiles; | 162 List<FileState> get partedFiles => _partedFiles; |
161 | 163 |
162 /** | 164 /** |
165 * The external names referenced by the file. | |
166 */ | |
167 Set<String> get referencedNames => _referencedNames; | |
168 | |
169 /** | |
163 * Return the set of transitive files - the file itself and all of the | 170 * Return the set of transitive files - the file itself and all of the |
164 * directly or indirectly referenced files. | 171 * directly or indirectly referenced files. |
165 */ | 172 */ |
166 Set<FileState> get transitiveFiles { | 173 Set<FileState> get transitiveFiles { |
167 if (_transitiveFiles == null) { | 174 if (_transitiveFiles == null) { |
168 _transitiveFiles = new Set<FileState>(); | 175 _transitiveFiles = new Set<FileState>(); |
169 | 176 |
170 void appendReferenced(FileState file) { | 177 void appendReferenced(FileState file) { |
171 if (_transitiveFiles.add(file)) { | 178 if (_transitiveFiles.add(file)) { |
172 file._directReferencedFiles.forEach(appendReferenced); | 179 file._directReferencedFiles.forEach(appendReferenced); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 } | 253 } |
247 | 254 |
248 // Prepare bytes of the unlinked bundle - existing or new. | 255 // Prepare bytes of the unlinked bundle - existing or new. |
249 List<int> bytes; | 256 List<int> bytes; |
250 { | 257 { |
251 bytes = _fsState._byteStore.get(unlinkedKey); | 258 bytes = _fsState._byteStore.get(unlinkedKey); |
252 if (bytes == null) { | 259 if (bytes == null) { |
253 CompilationUnit unit = parse(AnalysisErrorListener.NULL_LISTENER); | 260 CompilationUnit unit = parse(AnalysisErrorListener.NULL_LISTENER); |
254 _fsState._logger.run('Create unlinked for $path', () { | 261 _fsState._logger.run('Create unlinked for $path', () { |
255 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); | 262 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); |
256 bytes = unlinkedUnit.toBuffer(); | 263 List<String> referencedNames = computeReferencedNames(unit).toList(); |
264 bytes = new AnalysisDriverUnlinkedUnitBuilder( | |
265 unit: unlinkedUnit, referencedNames: referencedNames) | |
266 .toBuffer(); | |
257 _fsState._byteStore.put(unlinkedKey, bytes); | 267 _fsState._byteStore.put(unlinkedKey, bytes); |
258 }); | 268 }); |
259 } | 269 } |
260 } | 270 } |
261 | 271 |
262 // Read the unlinked bundle. | 272 // Read the unlinked bundle. |
263 _unlinked = new UnlinkedUnit.fromBuffer(bytes); | 273 var driverUnlinkedUnit = new AnalysisDriverUnlinkedUnit.fromBuffer(bytes); |
274 _referencedNames = new Set<String>.from(driverUnlinkedUnit.referencedNames); | |
Brian Wilkerson
2016/11/21 15:54:37
This is kind of ugly. Consider adding a getter to
scheglov
2016/11/21 17:04:54
We use flat buffers just as data.
Any additional s
| |
275 _unlinked = driverUnlinkedUnit.unit; | |
264 _lineInfo = new LineInfo(_unlinked.lineStarts); | 276 _lineInfo = new LineInfo(_unlinked.lineStarts); |
265 List<int> newApiSignature = _unlinked.apiSignature; | 277 List<int> newApiSignature = _unlinked.apiSignature; |
266 bool apiSignatureChanged = _apiSignature != null && | 278 bool apiSignatureChanged = _apiSignature != null && |
267 !_equalByteLists(_apiSignature, newApiSignature); | 279 !_equalByteLists(_apiSignature, newApiSignature); |
268 _apiSignature = newApiSignature; | 280 _apiSignature = newApiSignature; |
269 | 281 |
270 // This file is potentially not a library for its previous parts anymore. | 282 // This file is potentially not a library for its previous parts anymore. |
271 if (_partedFiles != null) { | 283 if (_partedFiles != null) { |
272 for (FileState part in _partedFiles) { | 284 for (FileState part in _partedFiles) { |
273 _fsState._partToLibraries[part]?.remove(this); | 285 _fsState._partToLibraries[part]?.remove(this); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 final FileSystemState state; | 513 final FileSystemState state; |
502 | 514 |
503 FileSystemStateTestView(this.state); | 515 FileSystemStateTestView(this.state); |
504 | 516 |
505 Set<FileState> get filesWithoutTransitive { | 517 Set<FileState> get filesWithoutTransitive { |
506 return state._uriToFile.values | 518 return state._uriToFile.values |
507 .where((f) => f._transitiveFiles == null) | 519 .where((f) => f._transitiveFiles == null) |
508 .toSet(); | 520 .toSet(); |
509 } | 521 } |
510 } | 522 } |
OLD | NEW |