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

Unified Diff: dart/lib/compiler/implementation/compiler.dart

Issue 11308006: Throw an exception when invariant fails and report nice diagnostic. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 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 | « no previous file | dart/lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/lib/compiler/implementation/compiler.dart
diff --git a/dart/lib/compiler/implementation/compiler.dart b/dart/lib/compiler/implementation/compiler.dart
index c327d7dafd60863ed63f269907da3e76f64e6469..00d73cfcecc2562c62b746783c2bb678a7a0e51d 100644
--- a/dart/lib/compiler/implementation/compiler.dart
+++ b/dart/lib/compiler/implementation/compiler.dart
@@ -142,6 +142,13 @@ abstract class Compiler implements DiagnosticListener {
_currentElement = element;
try {
return f();
+ } on SpannableAssertionFailure catch (ex) {
+ if (!hasCrashed) {
+ SourceSpan span = spanFromSpannable(ex.node);
+ reportDiagnostic(span, ex.message, api.Diagnostic.ERROR);
+ }
+ hasCrashed = true;
+ throw;
} on CompilerCancelledException catch (ex) {
throw;
} on StackOverflowError catch (ex) {
@@ -279,7 +286,7 @@ abstract class Compiler implements DiagnosticListener {
} else if (token != null) {
span = spanFromTokens(token, token);
} else if (instruction != null) {
- span = spanFromElement(currentElement);
+ span = spanFromHInstruction(instruction);
} else if (element != null) {
span = spanFromElement(element);
} else {
@@ -289,6 +296,20 @@ abstract class Compiler implements DiagnosticListener {
throw new CompilerCancelledException(reason);
}
+ SourceSpan spanFromSpannable(Spannable node) {
+ if (node is Node) {
+ return spanFromNode(node);
+ } else if (node is Token) {
+ return spanFromTokens(node, node);
+ } else if (node is HInstruction) {
+ return spanFromHInstruction(node);
+ } else if (node is Element) {
+ return spanFromElement(node);
+ } else {
+ throw 'No error location for error: $reason';
+ }
+ }
+
void reportFatalError(String reason, Element element,
{Node node, Token token, HInstruction instruction}) {
withCurrentElement(element, () {
@@ -759,6 +780,17 @@ abstract class Compiler implements DiagnosticListener {
: spanFromTokens(position, position, uri);
}
+ SourceSpan spanFromHInstruction(HInstruction instruction) {
+ Element element = instruction.sourceElement;
+ if (element == null) element = currentElement;
+ var position = instruction.sourcePosition;
+ if (position == null) return spanFromElement(element);
+ Token token = position.token;
+ if (token == null) return spanFromElement(element);
+ Uri uri = element.getCompilationUnit().script.uri;
+ return spanFromTokens(token, token, uri);
+ }
+
Script readScript(Uri uri, [Node node]) {
unimplemented('Compiler.readScript');
}
@@ -864,8 +896,8 @@ bool invariant(Spannable spannable, var condition, {String message: null}) {
if (condition is Function){
condition = condition();
}
- if (!condition && message != null) {
- print('assertion failed: $message');
+ if (spannable == null || !condition) {
+ throw new SpannableAssertionFailure(spannable, message);
}
- return spannable != null && condition;
+ return true;
}
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698