Chromium Code Reviews| 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 | 6 |
| 7 import 'package:analyzer/src/summary/idl.dart'; | 7 import 'package:analyzer/src/summary/idl.dart'; |
| 8 import 'package:front_end/compiler_options.dart'; | 8 import 'package:front_end/compiler_options.dart'; |
| 9 import 'package:front_end/file_system.dart'; | 9 import 'package:front_end/file_system.dart'; |
| 10 import 'package:front_end/src/base/uri_resolver.dart'; | 10 import 'package:front_end/src/fasta/translate_uri.dart'; |
|
Siggi Cherem (dart-lang)
2017/05/08 17:44:29
a very low priority comment - nothing to do on thi
| |
| 11 import 'package:package_config/packages_file.dart' as package_config; | 11 import 'package:package_config/packages_file.dart' as package_config; |
| 12 | 12 |
| 13 /// Wrapper around [CompilerOptions] which exposes the options in a form useful | 13 /// Wrapper around [CompilerOptions] which exposes the options in a form useful |
| 14 /// to the front end implementation. | 14 /// to the front end implementation. |
| 15 /// | 15 /// |
| 16 /// The intent is that the front end should immediately wrap any incoming | 16 /// The intent is that the front end should immediately wrap any incoming |
| 17 /// [CompilerOptions] object in this class before doing further processing, and | 17 /// [CompilerOptions] object in this class before doing further processing, and |
| 18 /// should thereafter access all options via the wrapper. This ensures that | 18 /// should thereafter access all options via the wrapper. This ensures that |
| 19 /// options are interpreted in a consistent way and that data derived from | 19 /// options are interpreted in a consistent way and that data derived from |
| 20 /// options is not unnecessarily recomputed. | 20 /// options is not unnecessarily recomputed. |
| 21 class ProcessedOptions { | 21 class ProcessedOptions { |
| 22 /// The raw [CompilerOptions] which this class wraps. | 22 /// The raw [CompilerOptions] which this class wraps. |
| 23 final CompilerOptions _raw; | 23 final CompilerOptions _raw; |
| 24 | 24 |
| 25 /// The package map derived from the options, or `null` if the package map has | 25 /// The package map derived from the options, or `null` if the package map has |
| 26 /// not been computed yet. | 26 /// not been computed yet. |
| 27 Map<String, Uri> _packages; | 27 Map<String, Uri> _packages; |
| 28 | 28 |
| 29 /// A URI resolver based on the options, or `null` if the URI resolver has not | 29 /// The object that knows how to resolve "package:" and "dart:" URIs, |
| 30 /// been computed yet. | 30 /// or `null` if it has not been computed yet. |
| 31 UriResolver _uriResolver; | 31 TranslateUri _uriTranslator; |
| 32 | 32 |
| 33 /// The summary bundle for the SDK, or `null` if it has not been read yet. | 33 /// The summary bundle for the SDK, or `null` if it has not been read yet. |
| 34 PackageBundle _sdkSummary; | 34 PackageBundle _sdkSummary; |
| 35 | 35 |
| 36 /// The location of the SDK, or `null` if the location hasn't been determined | 36 /// The location of the SDK, or `null` if the location hasn't been determined |
| 37 /// yet. | 37 /// yet. |
| 38 Uri _sdkRoot; | 38 Uri _sdkRoot; |
| 39 | 39 |
| 40 /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions]. | 40 /// Initializes a [ProcessedOptions] object wrapping the given [rawOptions]. |
| 41 ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions; | 41 ProcessedOptions(CompilerOptions rawOptions) : this._raw = rawOptions; |
| 42 | 42 |
| 43 /// Determine whether to generate code for the SDK when compiling a | 43 /// Determine whether to generate code for the SDK when compiling a |
| 44 /// whole-program. | 44 /// whole-program. |
| 45 bool get compileSdk => _raw.compileSdk; | 45 bool get compileSdk => _raw.compileSdk; |
| 46 | 46 |
| 47 /// Get the [FileSystem] which should be used by the front end to access | 47 /// Get the [FileSystem] which should be used by the front end to access |
| 48 /// files. | 48 /// files. |
| 49 /// | 49 /// |
| 50 /// If the client supplied roots using [CompilerOptions.multiRoots], the | 50 /// If the client supplied roots using [CompilerOptions.multiRoots], the |
| 51 /// returned [FileSystem] will automatically perform the appropriate mapping. | 51 /// returned [FileSystem] will automatically perform the appropriate mapping. |
| 52 FileSystem get fileSystem { | 52 FileSystem get fileSystem { |
| 53 // TODO(paulberry): support multiRoots. | 53 // TODO(paulberry): support multiRoots. |
| 54 assert(_raw.multiRoots.isEmpty); | 54 assert(_raw.multiRoots.isEmpty); |
| 55 return _raw.fileSystem; | 55 return _raw.fileSystem; |
| 56 } | 56 } |
| 57 | 57 |
| 58 /// Whether to interpret Dart sources in strong-mode. | |
| 59 bool get strongMode => _raw.strongMode; | |
| 60 | |
| 58 /// Get the summary bundle for the SDK. | 61 /// Get the summary bundle for the SDK. |
| 59 /// | 62 /// |
| 60 /// This is an asynchronous getter since file system operations are required. | 63 /// This is an asynchronous getter since file system operations are required. |
| 61 Future<PackageBundle> getSdkSummary() async { | 64 Future<PackageBundle> getSdkSummary() async { |
| 62 if (_sdkSummary == null) { | 65 if (_sdkSummary == null) { |
| 63 Uri summaryLocation; | 66 Uri summaryLocation; |
| 64 if (_raw.sdkSummary != null) { | 67 if (_raw.sdkSummary != null) { |
| 65 // Options sdkSummary and sdkRoot are mutually exclusive. | 68 // Options sdkSummary and sdkRoot are mutually exclusive. |
| 66 assert(_raw.sdkRoot == null); | 69 assert(_raw.sdkRoot == null); |
| 67 // No need to look for the SDK; we were told where the SDK summary is. | 70 // No need to look for the SDK; we were told where the SDK summary is. |
| 68 summaryLocation = _raw.sdkSummary; | 71 summaryLocation = _raw.sdkSummary; |
| 69 } else { | 72 } else { |
| 70 // Need to look for the SDK summary inside the SDK. | 73 // Need to look for the SDK summary inside the SDK. |
| 71 var sdkRoot = await _getSdkRoot(); | 74 var sdkRoot = await _getSdkRoot(); |
| 72 summaryLocation = sdkRoot.resolve( | 75 summaryLocation = sdkRoot.resolve( |
| 73 'lib/_internal/' + (_raw.strongMode ? 'strong.sum' : 'spec.sum')); | 76 'lib/_internal/' + (_raw.strongMode ? 'strong.sum' : 'spec.sum')); |
| 74 } | 77 } |
| 75 var summaryBytes = | 78 var summaryBytes = |
| 76 await fileSystem.entityForUri(summaryLocation).readAsBytes(); | 79 await fileSystem.entityForUri(summaryLocation).readAsBytes(); |
| 77 _sdkSummary = new PackageBundle.fromBuffer(summaryBytes); | 80 _sdkSummary = new PackageBundle.fromBuffer(summaryBytes); |
| 78 } | 81 } |
| 79 return _sdkSummary; | 82 return _sdkSummary; |
| 80 } | 83 } |
| 81 | 84 |
| 82 /// Get the [UriResolver] which resolves "package:" and "dart:" URIs. | 85 /// Get the [TranslateUri] which resolves "package:" and "dart:" URIs. |
| 83 /// | 86 /// |
| 84 /// This is an asynchronous getter since file system operations may be | 87 /// This is an asynchronous method since file system operations may be |
| 85 /// required to locate/read the packages file as well as SDK metadata. | 88 /// required to locate/read the packages file as well as SDK metadata. |
| 86 Future<UriResolver> getUriResolver() async { | 89 Future<TranslateUri> getUriTranslator() async { |
| 87 if (_uriResolver == null) { | 90 if (_uriTranslator == null) { |
| 88 await _getPackages(); | 91 await _getPackages(); |
| 89 var sdkLibraries = | 92 // TODO(scheglov) Load SDK libraries from whatever format we decide. |
| 90 <String, Uri>{}; // TODO(paulberry): support SDK libraries | 93 // TODO(scheglov) Remove the field "_raw.dartLibraries". |
| 91 _uriResolver = new UriResolver(_packages, sdkLibraries); | 94 _uriTranslator = new TranslateUri(_packages, _raw.dartLibraries); |
| 95 _uriTranslator.dartLibraries.addAll(_raw.dartLibraries); | |
| 92 } | 96 } |
| 93 return _uriResolver; | 97 return _uriTranslator; |
| 94 } | 98 } |
| 95 | 99 |
| 96 /// Get the package map which maps package names to URIs. | 100 /// Get the package map which maps package names to URIs. |
| 97 /// | 101 /// |
| 98 /// This is an asynchronous getter since file system operations may be | 102 /// This is an asynchronous getter since file system operations may be |
| 99 /// required to locate/read the packages file. | 103 /// required to locate/read the packages file. |
| 100 Future<Map<String, Uri>> _getPackages() async { | 104 Future<Map<String, Uri>> _getPackages() async { |
| 101 if (_packages == null) { | 105 if (_packages == null) { |
| 102 if (_raw.packagesFileUri == null) { | 106 if (_raw.packagesFileUri == null) { |
| 103 throw new UnimplementedError(); // TODO(paulberry): search for .packages | 107 throw new UnimplementedError(); // TODO(paulberry): search for .packages |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 127 throw new UnimplementedError(); | 131 throw new UnimplementedError(); |
| 128 } | 132 } |
| 129 _sdkRoot = _raw.sdkRoot; | 133 _sdkRoot = _raw.sdkRoot; |
| 130 if (!_sdkRoot.path.endsWith('/')) { | 134 if (!_sdkRoot.path.endsWith('/')) { |
| 131 _sdkRoot = _sdkRoot.replace(path: _sdkRoot.path + '/'); | 135 _sdkRoot = _sdkRoot.replace(path: _sdkRoot.path + '/'); |
| 132 } | 136 } |
| 133 } | 137 } |
| 134 return _sdkRoot; | 138 return _sdkRoot; |
| 135 } | 139 } |
| 136 } | 140 } |
| OLD | NEW |