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

Unified Diff: pkg/kernel/lib/target/targets.dart

Issue 2931423002: Prepare for improved error recovery from compile-time errors. (Closed)
Patch Set: Rebased on 11f82b12d2fb4f2c323cbc5a25de9835cc8e5031 Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/kernel/lib/core_types.dart ('k') | runtime/lib/errors_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/target/targets.dart
diff --git a/pkg/kernel/lib/target/targets.dart b/pkg/kernel/lib/target/targets.dart
index 57fdd758da872d77702906cb4bf3c344fb64cd8d..ad94b8e4c9c122cf15c2f9d80861d3032ae2bba1 100644
--- a/pkg/kernel/lib/target/targets.dart
+++ b/pkg/kernel/lib/target/targets.dart
@@ -130,6 +130,34 @@ abstract class Target {
bool isConstructor: false,
bool isTopLevel: false});
+ /// Builds an expression that throws [error] as compile-time error. The
+ /// target must be able to handle this expression in a constant expression.
+ Expression throwCompileConstantError(CoreTypes coreTypes, Expression error) {
+ // This method returns `const _ConstantExpressionError()._throw(error)`.
+ int offset = error.fileOffset;
+ var receiver = new ConstructorInvocation(
+ coreTypes.constantExpressionErrorDefaultConstructor,
+ new Arguments.empty()..fileOffset = offset,
+ isConst: true)
+ ..fileOffset = offset;
+ return new MethodInvocation(
+ receiver,
+ new Name("_throw", coreTypes.coreLibrary),
+ new Arguments(<Expression>[error])..fileOffset = error.fileOffset)
+ ..fileOffset = offset;
+ }
+
+ /// Builds an expression that represents a compile-time error which is
+ /// suitable for being passed to [throwCompileConstantError].
+ Expression buildCompileTimeError(
+ CoreTypes coreTypes, String message, int offset) {
+ return new ConstructorInvocation(
+ coreTypes.compileTimeErrorDefaultConstructor,
+ new Arguments(<Expression>[new StringLiteral(message)])
+ ..fileOffset = offset)
+ ..fileOffset = offset;
+ }
+
String toString() => 'Target($name)';
}
« no previous file with comments | « pkg/kernel/lib/core_types.dart ('k') | runtime/lib/errors_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698