Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: pkg/front_end/lib/src/base/processed_options.dart

Issue 2979623002: Use messages for (some) public API errors (Closed)
Patch Set: wrap - verification error still pending Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/translate_uri.dart'; 13 import 'package:front_end/src/fasta/translate_uri.dart';
13 import 'package:front_end/src/incremental/byte_store.dart'; 14 import 'package:front_end/src/incremental/byte_store.dart';
14 import 'package:front_end/src/multi_root_file_system.dart'; 15 import 'package:front_end/src/multi_root_file_system.dart';
15 import 'package:kernel/kernel.dart' 16 import 'package:kernel/kernel.dart'
16 show Program, loadProgramFromBytes, CanonicalName; 17 show Program, loadProgramFromBytes, CanonicalName;
17 import 'package:kernel/target/targets.dart'; 18 import 'package:kernel/target/targets.dart';
18 import 'package:kernel/target/vm_fasta.dart'; 19 import 'package:kernel/target/vm_fasta.dart';
19 import 'package:package_config/packages_file.dart' as package_config; 20 import 'package:package_config/packages_file.dart' as package_config;
20 import 'package:source_span/source_span.dart' show SourceSpan; 21 import 'package:source_span/source_span.dart' show SourceSpan, SourceLocation;
21 22
22 /// All options needed for the front end implementation. 23 /// All options needed for the front end implementation.
23 /// 24 ///
24 /// This includes: all of [CompilerOptions] in a form useful to the 25 /// This includes: all of [CompilerOptions] in a form useful to the
25 /// implementation, default values for options that were not provided, 26 /// implementation, default values for options that were not provided,
26 /// and information derived from how the compiler was invoked (like the 27 /// and information derived from how the compiler was invoked (like the
27 /// entry-points given to the compiler and whether a modular or whole-program 28 /// entry-points given to the compiler and whether a modular or whole-program
28 /// API was used). 29 /// API was used).
29 /// 30 ///
30 /// The intent is that the front end should immediately wrap any incoming 31 /// The intent is that the front end should immediately wrap any incoming
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 /// The logger to report compilation progress. 102 /// The logger to report compilation progress.
102 PerformanceLog get logger { 103 PerformanceLog get logger {
103 return _raw.logger; 104 return _raw.logger;
104 } 105 }
105 106
106 /// The byte storage to get and put serialized data. 107 /// The byte storage to get and put serialized data.
107 ByteStore get byteStore { 108 ByteStore get byteStore {
108 return _raw.byteStore; 109 return _raw.byteStore;
109 } 110 }
110 111
111 // TODO(sigmund): delete. We should use messages with error codes directly 112 void reportMessage(LocatedMessage message) {
112 // instead. 113 _raw.onError(new _CompilationMessage(message));
113 void reportError(String message) {
114 _raw.onError(new _CompilationError(message));
115 } 114 }
116 115
116 void reportMessageNoLocation(Message message) =>
117 reportMessage(message.withLocation(null, -1));
118
117 /// Runs various validations checks on the input options. For instance, 119 /// Runs various validations checks on the input options. For instance,
118 /// if an option is a path to a file, it checks that the file exists. 120 /// if an option is a path to a file, it checks that the file exists.
119 Future<bool> validateOptions() async { 121 Future<bool> validateOptions() async {
120 for (var source in inputs) { 122 for (var source in inputs) {
121 if (source.scheme == 'file' && 123 if (source.scheme == 'file' &&
122 !await fileSystem.entityForUri(source).exists()) { 124 !await fileSystem.entityForUri(source).exists()) {
123 reportError("Entry-point file not found: $source"); 125 reportMessageNoLocation(
126 templateMissingInputFile.withArguments('$source'));
124 return false; 127 return false;
125 } 128 }
126 } 129 }
127 130
128 if (_raw.sdkRoot != null && 131 if (_raw.sdkRoot != null &&
129 !await fileSystem.entityForUri(sdkRoot).exists()) { 132 !await fileSystem.entityForUri(sdkRoot).exists()) {
130 reportError("SDK root directory not found: ${sdkRoot}"); 133 reportMessageNoLocation(templateMissingSdkRoot.withArguments('$sdkRoot'));
131 return false; 134 return false;
132 } 135 }
133 136
134 var summary = sdkSummary; 137 var summary = sdkSummary;
135 if (summary != null && !await fileSystem.entityForUri(summary).exists()) { 138 if (summary != null && !await fileSystem.entityForUri(summary).exists()) {
136 reportError("SDK summary not found: ${summary}"); 139 reportMessageNoLocation(
140 templateMissingSdkSummary.withArguments('$summary'));
137 return false; 141 return false;
138 } 142 }
139 143
140 if (compileSdk && summary != null) { 144 if (compileSdk && summary != null) {
141 reportError( 145 reportMessageNoLocation(templateUnsupported.withArguments(
142 "The compileSdk and sdkSummary options are mutually exclusive"); 146 "The compileSdk and sdkSummary options are mutually exclusive"));
143 return false; 147 return false;
144 } 148 }
145 return true; 149 return true;
146 } 150 }
147 151
148 /// Determine whether to generate code for the SDK when compiling a 152 /// Determine whether to generate code for the SDK when compiling a
149 /// whole-program. 153 /// whole-program.
150 bool get compileSdk => _raw.compileSdk; 154 bool get compileSdk => _raw.compileSdk;
151 155
152 FileSystem _fileSystem; 156 FileSystem _fileSystem;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 : super( 340 : super(
337 uri, 341 uri,
338 'Invalid access to $uri: ' 342 'Invalid access to $uri: '
339 'the file is accessed in a modular hermetic build, ' 343 'the file is accessed in a modular hermetic build, '
340 'but it was not explicitly listed as an input.'); 344 'but it was not explicitly listed as an input.');
341 345
342 @override 346 @override
343 String toString() => message; 347 String toString() => message;
344 } 348 }
345 349
346 /// An error that only contains a message and no error location. 350 /// Wraps a [LocatedMessage] to implement the public [CompilationError] API.
347 class _CompilationError implements CompilationError { 351 class _CompilationMessage implements CompilationError {
348 String get correction => null; 352 final LocatedMessage original;
349 SourceSpan get span => null; 353
350 final String message; 354 String get message => original.message;
351 _CompilationError(this.message); 355
356 String get tip => original.tip;
357
358 SourceSpan get span =>
359 new SourceLocation(original.charOffset, sourceUrl: original.uri)
360 .pointSpan();
361
362 _CompilationMessage(this.original);
352 363
353 String toString() => message; 364 String toString() => message;
354 } 365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698