@@ -8,17 +8,19 @@ import 'package:front_end/compilation_error.dart';
88import 'package:front_end/compiler_options.dart' ;
99import 'package:front_end/file_system.dart' ;
1010import 'package:front_end/src/base/performace_logger.dart' ;
11+ import 'package:front_end/src/fasta/fasta_codes.dart' ;
1112import 'package:front_end/src/fasta/ticker.dart' ;
1213import 'package:front_end/src/fasta/uri_translator.dart' ;
1314import 'package:front_end/src/fasta/uri_translator_impl.dart' ;
15+ import 'package:front_end/src/fasta/problems.dart' show unimplemented;
1416import 'package:front_end/src/incremental/byte_store.dart' ;
1517import 'package:front_end/src/multi_root_file_system.dart' ;
1618import 'package:kernel/kernel.dart'
1719 show Program, loadProgramFromBytes, CanonicalName;
1820import 'package:kernel/target/targets.dart' ;
1921import 'package:kernel/target/vm_fasta.dart' ;
2022import '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 ;
2224
2325/// All options needed for the front end implementation.
2426///
@@ -111,38 +113,48 @@ class ProcessedOptions {
111113 return _raw.byteStore;
112114 }
113115
114- // TODO(sigmund): delete. We should use messages with error codes directly
115- // instead.
116- void reportError (String message) {
117- _raw.onError (new _CompilationError (message));
116+ // TODO(sigmund,ahe): delete in favor of reportMessage.
117+ void deprecated_reportError (String error) {
118+ _raw.onError (new _StringMessage (error));
118119 }
119120
121+ void reportMessage (LocatedMessage message) {
122+ _raw.onError (new _CompilationMessage (message));
123+ }
124+
125+ void reportMessageWithoutLocation (Message message) =>
126+ reportMessage (message.withLocation (null , - 1 ));
127+
120128 /// Runs various validations checks on the input options. For instance,
121129 /// if an option is a path to a file, it checks that the file exists.
122130 Future <bool > validateOptions () async {
123131 for (var source in inputs) {
124132 if (source.scheme == 'file' &&
125133 ! await fileSystem.entityForUri (source).exists ()) {
126- reportError ("Entry-point file not found: $source " );
134+ reportMessageWithoutLocation (
135+ templateMissingInputFile.withArguments ('$source ' ));
127136 return false ;
128137 }
129138 }
130139
131140 if (_raw.sdkRoot != null &&
132141 ! await fileSystem.entityForUri (sdkRoot).exists ()) {
133- reportError ("SDK root directory not found: ${sdkRoot }" );
142+ reportMessageWithoutLocation (
143+ templateMissingSdkRoot.withArguments ('$sdkRoot ' ));
134144 return false ;
135145 }
136146
137147 var summary = sdkSummary;
138148 if (summary != null && ! await fileSystem.entityForUri (summary).exists ()) {
139- reportError ("SDK summary not found: ${summary }" );
149+ reportMessageWithoutLocation (
150+ templateMissingSdkSummary.withArguments ('$summary ' ));
140151 return false ;
141152 }
142153
143154 if (compileSdk && summary != null ) {
144- reportError (
145- "The compileSdk and sdkSummary options are mutually exclusive" );
155+ reportMessageWithoutLocation (
156+ templateInternalProblemUnsupported.withArguments (
157+ "The compileSdk and sdkSummary options are mutually exclusive" ));
146158 return false ;
147159 }
148160 return true ;
@@ -245,7 +257,7 @@ class ProcessedOptions {
245257 if (_packages == null ) {
246258 if (_raw.packagesFileUri == null ) {
247259 // TODO(sigmund,paulberry): implement
248- throw new UnimplementedError ('search for .packages' );
260+ return unimplemented ('search for .packages' );
249261 } else if (_raw.packagesFileUri.path.isEmpty) {
250262 _packages = {};
251263 } else {
@@ -265,7 +277,7 @@ class ProcessedOptions {
265277 if (_raw.sdkRoot == null ) {
266278 // TODO(paulberry): implement the algorithm for finding the SDK
267279 // automagically.
268- throw new UnimplementedError ('infer the default sdk location' );
280+ return unimplemented ('infer the default sdk location' );
269281 }
270282 var root = _raw.sdkRoot;
271283 if (! root.path.endsWith ('/' )) {
@@ -346,12 +358,30 @@ class HermeticAccessException extends FileSystemException {
346358 String toString () => message;
347359}
348360
349- /// An error that only contains a message and no error location.
350- class _CompilationError implements CompilationError {
351- String get correction => null ;
352- SourceSpan get span => null ;
361+ /// Wraps a [LocatedMessage] to implement the public [CompilationError] API.
362+ class _CompilationMessage implements CompilationError {
363+ final LocatedMessage original;
364+
365+ String get message => original.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);
374+
375+ String toString () => message;
376+ }
377+
378+ /// Wraps an error message as a [CompilationError] API.
379+ class _StringMessage implements CompilationError {
353380 final String message;
354- _CompilationError (this .message);
381+ String get tip => null ;
382+ SourceSpan get span => null ;
383+
384+ _StringMessage (this .message);
355385
356386 String toString () => message;
357387}
0 commit comments