OLD | NEW |
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 '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:convert/convert.dart'; | 9 import 'package:convert/convert.dart'; |
10 import 'package:crypto/crypto.dart'; | 10 import 'package:crypto/crypto.dart'; |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 /// The resolved URI of the file in the file system. | 40 /// The resolved URI of the file in the file system. |
41 final Uri fileUri; | 41 final Uri fileUri; |
42 | 42 |
43 bool _exists; | 43 bool _exists; |
44 List<int> _content; | 44 List<int> _content; |
45 List<int> _contentHash; | 45 List<int> _contentHash; |
46 bool _hasMixinApplication; | 46 bool _hasMixinApplication; |
47 List<int> _apiSignature; | 47 List<int> _apiSignature; |
48 | 48 |
49 List<NamespaceExport> _exports; | |
50 List<FileState> _importedLibraries; | 49 List<FileState> _importedLibraries; |
51 List<FileState> _exportedLibraries; | 50 List<FileState> _exportedLibraries; |
52 List<FileState> _partFiles; | 51 List<FileState> _partFiles; |
53 | 52 |
54 Set<FileState> _directReferencedFiles = new Set<FileState>(); | 53 Set<FileState> _directReferencedFiles = new Set<FileState>(); |
55 List<FileState> _directReferencedLibraries = <FileState>[]; | 54 List<FileState> _directReferencedLibraries = <FileState>[]; |
56 Set<FileState> _transitiveFiles; | 55 Set<FileState> _transitiveFiles; |
57 | 56 |
58 /// This flag is set to `true` during the mark phase of garbage collection | 57 /// This flag is set to `true` during the mark phase of garbage collection |
59 /// and set back to `false` for survived instances. | 58 /// and set back to `false` for survived instances. |
(...skipping 14 matching lines...) Expand all Loading... |
74 | 73 |
75 /// Libraries that this library file directly imports or exports. | 74 /// Libraries that this library file directly imports or exports. |
76 List<FileState> get directReferencedLibraries => _directReferencedLibraries; | 75 List<FileState> get directReferencedLibraries => _directReferencedLibraries; |
77 | 76 |
78 /// Whether the file exists. | 77 /// Whether the file exists. |
79 bool get exists => _exists; | 78 bool get exists => _exists; |
80 | 79 |
81 /// The list of the libraries exported by this library. | 80 /// The list of the libraries exported by this library. |
82 List<FileState> get exportedLibraries => _exportedLibraries; | 81 List<FileState> get exportedLibraries => _exportedLibraries; |
83 | 82 |
84 /// The list of the exported files with combinators. | |
85 List<NamespaceExport> get exports => _exports; | |
86 | |
87 @override | 83 @override |
88 int get hashCode => uri.hashCode; | 84 int get hashCode => uri.hashCode; |
89 | 85 |
90 /// Whether the file has a mixin application. | 86 /// Whether the file has a mixin application. |
91 bool get hasMixinApplication => _hasMixinApplication; | 87 bool get hasMixinApplication => _hasMixinApplication; |
92 | 88 |
93 /// Whether a unit of the library has a mixin application. | 89 /// Whether a unit of the library has a mixin application. |
94 bool get hasMixinApplicationLibrary { | 90 bool get hasMixinApplicationLibrary { |
95 return _hasMixinApplication || | 91 return _hasMixinApplication || |
96 _partFiles.any((part) => part._hasMixinApplication); | 92 _partFiles.any((part) => part._hasMixinApplication); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 157 |
162 // Read the unlinked unit. | 158 // Read the unlinked unit. |
163 UnlinkedUnit unlinkedUnit = new UnlinkedUnit(unlinkedBytes); | 159 UnlinkedUnit unlinkedUnit = new UnlinkedUnit(unlinkedBytes); |
164 _apiSignature = unlinkedUnit.apiSignature; | 160 _apiSignature = unlinkedUnit.apiSignature; |
165 _hasMixinApplication = unlinkedUnit.hasMixinApplication; | 161 _hasMixinApplication = unlinkedUnit.hasMixinApplication; |
166 | 162 |
167 // Build the graph. | 163 // Build the graph. |
168 _importedLibraries = <FileState>[]; | 164 _importedLibraries = <FileState>[]; |
169 _exportedLibraries = <FileState>[]; | 165 _exportedLibraries = <FileState>[]; |
170 _partFiles = <FileState>[]; | 166 _partFiles = <FileState>[]; |
171 _exports = <NamespaceExport>[]; | |
172 { | 167 { |
173 FileState coreFile = await _getFileForRelativeUri('dart:core'); | 168 FileState coreFile = await _getFileForRelativeUri('dart:core'); |
174 // TODO(scheglov) add error handling | 169 // TODO(scheglov) add error handling |
175 if (coreFile != null) { | 170 if (coreFile != null) { |
176 _importedLibraries.add(coreFile); | 171 _importedLibraries.add(coreFile); |
177 } | 172 } |
178 } | 173 } |
179 for (var import_ in unlinkedUnit.imports) { | 174 for (var import_ in unlinkedUnit.imports) { |
180 FileState file = await _getFileForRelativeUri(import_.uri); | 175 FileState file = await _getFileForRelativeUri(import_.uri); |
181 if (file != null) { | 176 if (file != null) { |
182 _importedLibraries.add(file); | 177 _importedLibraries.add(file); |
183 } | 178 } |
184 } | 179 } |
185 await _addTargetExtraRequiredLibraries(); | 180 await _addTargetExtraRequiredLibraries(); |
186 for (var export_ in unlinkedUnit.exports) { | 181 for (var export_ in unlinkedUnit.exports) { |
187 FileState file = await _getFileForRelativeUri(export_.uri); | 182 FileState file = await _getFileForRelativeUri(export_.uri); |
188 if (file != null) { | 183 if (file != null) { |
189 _exportedLibraries.add(file); | 184 _exportedLibraries.add(file); |
190 _exports.add(new NamespaceExport(file, export_.combinators)); | |
191 } | 185 } |
192 } | 186 } |
193 for (var part_ in unlinkedUnit.parts) { | 187 for (var part_ in unlinkedUnit.parts) { |
194 FileState file = await _getFileForRelativeUri(part_); | 188 FileState file = await _getFileForRelativeUri(part_); |
195 if (file != null) { | 189 if (file != null) { |
196 _partFiles.add(file); | 190 _partFiles.add(file); |
197 } | 191 } |
198 } | 192 } |
199 | 193 |
200 // Compute referenced files. | 194 // Compute referenced files. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 385 |
392 @override | 386 @override |
393 String toString() { | 387 String toString() { |
394 if (_isForVm) { | 388 if (_isForVm) { |
395 return '[core + vm]'; | 389 return '[core + vm]'; |
396 } | 390 } |
397 return '[' + libraries.join(', ') + ']'; | 391 return '[' + libraries.join(', ') + ']'; |
398 } | 392 } |
399 } | 393 } |
400 | 394 |
401 /// Information about a single `export` directive. | |
402 class NamespaceExport { | |
403 final FileState library; | |
404 final List<UnlinkedCombinator> combinators; | |
405 | |
406 NamespaceExport(this.library, this.combinators); | |
407 | |
408 /// Return `true` if the [name] satisfies the sequence of the [combinators]. | |
409 bool isExposed(String name) { | |
410 for (var combinator in combinators) { | |
411 if (combinator.isShow) { | |
412 if (!combinator.names.contains(name)) { | |
413 return false; | |
414 } | |
415 } else { | |
416 if (combinator.names.contains(name)) { | |
417 return false; | |
418 } | |
419 } | |
420 } | |
421 return true; | |
422 } | |
423 } | |
424 | |
425 /// [FileSystemState] based implementation of [FileSystem]. | 395 /// [FileSystemState] based implementation of [FileSystem]. |
426 /// It provides a consistent view on the known file system state. | 396 /// It provides a consistent view on the known file system state. |
427 class _FileSystemView implements FileSystem { | 397 class _FileSystemView implements FileSystem { |
428 final FileSystemState fsState; | 398 final FileSystemState fsState; |
429 | 399 |
430 _FileSystemView(this.fsState); | 400 _FileSystemView(this.fsState); |
431 | 401 |
432 @override | 402 @override |
433 FileSystemEntity entityForUri(Uri uri) { | 403 FileSystemEntity entityForUri(Uri uri) { |
434 FileState file = fsState._fileUriToFile[uri]; | 404 FileState file = fsState._fileUriToFile[uri]; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 fileToCycleMap[node.file] = cycle; | 499 fileToCycleMap[node.file] = cycle; |
530 } | 500 } |
531 | 501 |
532 topologicallySortedCycles.add(cycle); | 502 topologicallySortedCycles.add(cycle); |
533 } | 503 } |
534 | 504 |
535 _LibraryNode getNode(FileState file) { | 505 _LibraryNode getNode(FileState file) { |
536 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file)); | 506 return nodesOfFiles.putIfAbsent(file, () => new _LibraryNode(this, file)); |
537 } | 507 } |
538 } | 508 } |
OLD | NEW |