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:front_end/compilation_error.dart'; | 7 import 'package:front_end/compilation_error.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/performace_logger.dart'; | 10 import 'package:front_end/src/base/performace_logger.dart'; |
| 11 import 'package:front_end/src/fasta/fasta_codes.dart'; | |
| 11 import 'package:front_end/src/fasta/ticker.dart'; | 12 import 'package:front_end/src/fasta/ticker.dart'; |
| 12 import 'package:front_end/src/fasta/uri_translator.dart'; | 13 import 'package:front_end/src/fasta/uri_translator.dart'; |
| 13 import 'package:front_end/src/fasta/uri_translator_impl.dart'; | 14 import 'package:front_end/src/fasta/uri_translator_impl.dart'; |
| 15 import 'package:front_end/src/fasta/problems.dart' show unimplemented; | |
| 14 import 'package:front_end/src/incremental/byte_store.dart'; | 16 import 'package:front_end/src/incremental/byte_store.dart'; |
| 15 import 'package:front_end/src/multi_root_file_system.dart'; | 17 import 'package:front_end/src/multi_root_file_system.dart'; |
| 16 import 'package:kernel/kernel.dart' | 18 import 'package:kernel/kernel.dart' |
| 17 show Program, loadProgramFromBytes, CanonicalName; | 19 show Program, loadProgramFromBytes, CanonicalName; |
| 18 import 'package:kernel/target/targets.dart'; | 20 import 'package:kernel/target/targets.dart'; |
| 19 import 'package:kernel/target/vm_fasta.dart'; | 21 import 'package:kernel/target/vm_fasta.dart'; |
| 20 import 'package:package_config/packages_file.dart' as package_config; | 22 import 'package:package_config/packages_file.dart' as package_config; |
| 21 import 'package:source_span/source_span.dart' show SourceSpan; | 23 import 'package:source_span/source_span.dart' show SourceSpan, SourceLocation; |
| 22 | 24 |
| 23 /// All options needed for the front end implementation. | 25 /// All options needed for the front end implementation. |
| 24 /// | 26 /// |
| 25 /// This includes: all of [CompilerOptions] in a form useful to the | 27 /// This includes: all of [CompilerOptions] in a form useful to the |
| 26 /// implementation, default values for options that were not provided, | 28 /// implementation, default values for options that were not provided, |
| 27 /// and information derived from how the compiler was invoked (like the | 29 /// and information derived from how the compiler was invoked (like the |
| 28 /// entry-points given to the compiler and whether a modular or whole-program | 30 /// entry-points given to the compiler and whether a modular or whole-program |
| 29 /// API was used). | 31 /// API was used). |
| 30 /// | 32 /// |
| 31 /// The intent is that the front end should immediately wrap any incoming | 33 /// The intent is that the front end should immediately wrap any incoming |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 /// The logger to report compilation progress. | 106 /// The logger to report compilation progress. |
| 105 PerformanceLog get logger { | 107 PerformanceLog get logger { |
| 106 return _raw.logger; | 108 return _raw.logger; |
| 107 } | 109 } |
| 108 | 110 |
| 109 /// The byte storage to get and put serialized data. | 111 /// The byte storage to get and put serialized data. |
| 110 ByteStore get byteStore { | 112 ByteStore get byteStore { |
| 111 return _raw.byteStore; | 113 return _raw.byteStore; |
| 112 } | 114 } |
| 113 | 115 |
| 114 // TODO(sigmund): delete. We should use messages with error codes directly | 116 // TODO(sigmund,ahe): delete in favor of reportMessage. |
| 115 // instead. | 117 void deprecated_reportError(String error) { |
| 116 void reportError(String message) { | 118 _raw.onError(new _StringMessage(error)); |
| 117 _raw.onError(new _CompilationError(message)); | |
| 118 } | 119 } |
| 119 | 120 |
| 121 void reportMessage(LocatedMessage message) { | |
| 122 _raw.onError(new _CompilationMessage(message)); | |
|
ahe
2017/07/13 00:03:38
We need to think about how these methods deal with
Siggi Cherem (dart-lang)
2017/07/18 00:32:57
Acknowledged.
| |
| 123 } | |
| 124 | |
| 125 void reportMessageWithoutLocation(Message message) => | |
| 126 reportMessage(message.withLocation(null, -1)); | |
| 127 | |
| 120 /// Runs various validations checks on the input options. For instance, | 128 /// Runs various validations checks on the input options. For instance, |
| 121 /// if an option is a path to a file, it checks that the file exists. | 129 /// if an option is a path to a file, it checks that the file exists. |
| 122 Future<bool> validateOptions() async { | 130 Future<bool> validateOptions() async { |
| 123 for (var source in inputs) { | 131 for (var source in inputs) { |
| 124 if (source.scheme == 'file' && | 132 if (source.scheme == 'file' && |
| 125 !await fileSystem.entityForUri(source).exists()) { | 133 !await fileSystem.entityForUri(source).exists()) { |
| 126 reportError("Entry-point file not found: $source"); | 134 reportMessageWithoutLocation( |
| 135 templateMissingInputFile.withArguments('$source')); | |
|
ahe
2017/07/13 00:03:38
There's a #uri parameter you can use now. It will
Siggi Cherem (dart-lang)
2017/07/18 00:32:57
Done.
| |
| 127 return false; | 136 return false; |
| 128 } | 137 } |
| 129 } | 138 } |
| 130 | 139 |
| 131 if (_raw.sdkRoot != null && | 140 if (_raw.sdkRoot != null && |
| 132 !await fileSystem.entityForUri(sdkRoot).exists()) { | 141 !await fileSystem.entityForUri(sdkRoot).exists()) { |
| 133 reportError("SDK root directory not found: ${sdkRoot}"); | 142 reportMessageWithoutLocation( |
| 143 templateMissingSdkRoot.withArguments('$sdkRoot')); | |
|
ahe
2017/07/13 00:03:38
Ditto.
Siggi Cherem (dart-lang)
2017/07/18 00:32:57
Done.
| |
| 134 return false; | 144 return false; |
| 135 } | 145 } |
| 136 | 146 |
| 137 var summary = sdkSummary; | 147 var summary = sdkSummary; |
| 138 if (summary != null && !await fileSystem.entityForUri(summary).exists()) { | 148 if (summary != null && !await fileSystem.entityForUri(summary).exists()) { |
| 139 reportError("SDK summary not found: ${summary}"); | 149 reportMessageWithoutLocation( |
| 150 templateMissingSdkSummary.withArguments('$summary')); | |
|
ahe
2017/07/13 00:03:38
Ditto.
Siggi Cherem (dart-lang)
2017/07/18 00:32:57
Done.
| |
| 140 return false; | 151 return false; |
| 141 } | 152 } |
| 142 | 153 |
| 143 if (compileSdk && summary != null) { | 154 if (compileSdk && summary != null) { |
| 144 reportError( | 155 reportMessageWithoutLocation( |
| 145 "The compileSdk and sdkSummary options are mutually exclusive"); | 156 templateInternalProblemUnsupported.withArguments( |
| 157 "The compileSdk and sdkSummary options are mutually exclusive")); | |
|
ahe
2017/07/13 00:03:37
I think this should be its own error code, but I c
Siggi Cherem (dart-lang)
2017/07/18 00:32:57
Done.
| |
| 146 return false; | 158 return false; |
| 147 } | 159 } |
| 148 return true; | 160 return true; |
| 149 } | 161 } |
| 150 | 162 |
| 151 /// Determine whether to generate code for the SDK when compiling a | 163 /// Determine whether to generate code for the SDK when compiling a |
| 152 /// whole-program. | 164 /// whole-program. |
| 153 bool get compileSdk => _raw.compileSdk; | 165 bool get compileSdk => _raw.compileSdk; |
| 154 | 166 |
| 155 FileSystem _fileSystem; | 167 FileSystem _fileSystem; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 } | 250 } |
| 239 | 251 |
| 240 /// Get the package map which maps package names to URIs. | 252 /// Get the package map which maps package names to URIs. |
| 241 /// | 253 /// |
| 242 /// This is an asynchronous getter since file system operations may be | 254 /// This is an asynchronous getter since file system operations may be |
| 243 /// required to locate/read the packages file. | 255 /// required to locate/read the packages file. |
| 244 Future<Map<String, Uri>> _getPackages() async { | 256 Future<Map<String, Uri>> _getPackages() async { |
| 245 if (_packages == null) { | 257 if (_packages == null) { |
| 246 if (_raw.packagesFileUri == null) { | 258 if (_raw.packagesFileUri == null) { |
| 247 // TODO(sigmund,paulberry): implement | 259 // TODO(sigmund,paulberry): implement |
| 248 throw new UnimplementedError('search for .packages'); | 260 return unimplemented('search for .packages'); |
| 249 } else if (_raw.packagesFileUri.path.isEmpty) { | 261 } else if (_raw.packagesFileUri.path.isEmpty) { |
| 250 _packages = {}; | 262 _packages = {}; |
| 251 } else { | 263 } else { |
| 252 var contents = | 264 var contents = |
| 253 await fileSystem.entityForUri(_raw.packagesFileUri).readAsBytes(); | 265 await fileSystem.entityForUri(_raw.packagesFileUri).readAsBytes(); |
| 254 _packages = package_config.parse(contents, _raw.packagesFileUri); | 266 _packages = package_config.parse(contents, _raw.packagesFileUri); |
| 255 } | 267 } |
| 256 } | 268 } |
| 257 return _packages; | 269 return _packages; |
| 258 } | 270 } |
| 259 | 271 |
| 260 /// Get the location of the SDK. | 272 /// Get the location of the SDK. |
| 261 Uri _normalizeSdkRoot() { | 273 Uri _normalizeSdkRoot() { |
| 262 // If an SDK summary location was provided, the SDK itself should not be | 274 // If an SDK summary location was provided, the SDK itself should not be |
| 263 // needed. | 275 // needed. |
| 264 assert(_raw.sdkSummary == null); | 276 assert(_raw.sdkSummary == null); |
| 265 if (_raw.sdkRoot == null) { | 277 if (_raw.sdkRoot == null) { |
| 266 // TODO(paulberry): implement the algorithm for finding the SDK | 278 // TODO(paulberry): implement the algorithm for finding the SDK |
| 267 // automagically. | 279 // automagically. |
| 268 throw new UnimplementedError('infer the default sdk location'); | 280 return unimplemented('infer the default sdk location'); |
| 269 } | 281 } |
| 270 var root = _raw.sdkRoot; | 282 var root = _raw.sdkRoot; |
| 271 if (!root.path.endsWith('/')) { | 283 if (!root.path.endsWith('/')) { |
| 272 root = root.replace(path: root.path + '/'); | 284 root = root.replace(path: root.path + '/'); |
| 273 } | 285 } |
| 274 return root; | 286 return root; |
| 275 } | 287 } |
| 276 | 288 |
| 277 /// Get or infer the location of the SDK summary. | 289 /// Get or infer the location of the SDK summary. |
| 278 Uri _computeSdkSummaryUri() { | 290 Uri _computeSdkSummaryUri() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 : super( | 351 : super( |
| 340 uri, | 352 uri, |
| 341 'Invalid access to $uri: ' | 353 'Invalid access to $uri: ' |
| 342 'the file is accessed in a modular hermetic build, ' | 354 'the file is accessed in a modular hermetic build, ' |
| 343 'but it was not explicitly listed as an input.'); | 355 'but it was not explicitly listed as an input.'); |
| 344 | 356 |
| 345 @override | 357 @override |
| 346 String toString() => message; | 358 String toString() => message; |
| 347 } | 359 } |
| 348 | 360 |
| 349 /// An error that only contains a message and no error location. | 361 /// Wraps a [LocatedMessage] to implement the public [CompilationError] API. |
| 350 class _CompilationError implements CompilationError { | 362 class _CompilationMessage implements CompilationError { |
| 351 String get correction => null; | 363 final LocatedMessage original; |
|
ahe
2017/07/13 00:03:38
This should probably be private as you've stated s
Siggi Cherem (dart-lang)
2017/07/18 00:32:57
Ok, I've added this to the CL where I'm unifying C
| |
| 352 SourceSpan get span => null; | 364 |
| 353 final String message; | 365 String get message => original.message; |
| 354 _CompilationError(this.message); | 366 |
| 367 String get tip => original.tip; | |
| 368 | |
| 369 SourceSpan get span => | |
| 370 new SourceLocation(original.charOffset, sourceUrl: original.uri) | |
| 371 .pointSpan(); | |
| 372 | |
| 373 _CompilationMessage(this.original); | |
| 355 | 374 |
| 356 String toString() => message; | 375 String toString() => message; |
| 357 } | 376 } |
| 377 | |
| 378 /// Wraps an error message as a [CompilationError] API. | |
|
ahe
2017/07/13 00:03:38
Use templateUnspecified instead?
Siggi Cherem (dart-lang)
2017/07/18 00:32:57
This is now gone.
| |
| 379 class _StringMessage implements CompilationError { | |
| 380 final String message; | |
| 381 String get tip => null; | |
| 382 SourceSpan get span => null; | |
| 383 | |
| 384 _StringMessage(this.message); | |
| 385 | |
| 386 String toString() => message; | |
| 387 } | |
| OLD | NEW |