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

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

Issue 10389143: Add locations to diagnostics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove all references to unreachable() Created 8 years, 7 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
Index: dart/lib/compiler/implementation/compiler.dart
diff --git a/dart/lib/compiler/implementation/compiler.dart b/dart/lib/compiler/implementation/compiler.dart
index 0f69630d11bc9ec81b9e5f1d5b9e260e0d71b121..092ba2ecc561c959c277435ae5aa175ed247e708 100644
--- a/dart/lib/compiler/implementation/compiler.dart
+++ b/dart/lib/compiler/implementation/compiler.dart
@@ -149,11 +149,20 @@ class Compiler implements DiagnosticListener {
span = spanFromElement(currentElement);
} else if (element !== null) {
span = spanFromElement(element);
+ } else {
+ throw 'No error location for error: $reason';
}
reportDiagnostic(span, red(reason), true);
throw new CompilerCancelledException(reason);
}
+ void reportFatalError(String reason, Element element,
+ [Node node, Token token, HInstruction instruction]) {
+ withCurrentElement(element, () {
+ cancel(reason, node, token, instruction, element);
+ });
+ }
+
void log(message) {
reportDiagnostic(null, message, false);
}
@@ -273,17 +282,13 @@ class Compiler implements DiagnosticListener {
mainApp = scanner.loadLibrary(uri, null);
final Element main = mainApp.find(MAIN);
if (main === null) {
- withCurrentElement(mainApp, () => cancel('Could not find $MAIN'));
+ reportFatalError('Could not find $MAIN', mainApp);
} else {
- withCurrentElement(main, () {
- if (!main.isFunction()) {
- cancel('main is not a function', element: main);
- }
- FunctionElement mainMethod = main;
- FunctionSignature parameters = mainMethod.computeSignature(this);
- if (parameters.parameterCount > 0) {
- cancel('main cannot have parameters', element: mainMethod);
- }
+ if (!main.isFunction()) reportFatalError('main is not a function', main);
+ FunctionElement mainMethod = main;
+ FunctionSignature parameters = mainMethod.computeSignature(this);
+ parameters.forEachParameter((Element parameter) {
+ reportFatalError('main cannot have parameters', parameter);
});
}
Collection<LibraryElement> libraries = universe.libraries.getValues();
@@ -475,8 +480,8 @@ class Compiler implements DiagnosticListener {
}
Token position = element.position();
if (position === null) {
- // TODO(ahe): Find the enclosing library.
- return const SourceSpan(null, null, null);
+ Uri uri = element.getCompilationUnit().script.uri;
+ return new SourceSpan(uri, 0, 0);
}
return spanFromTokens(position, position);
}
« no previous file with comments | « dart/lib/compiler/implementation/compile_time_constants.dart ('k') | dart/lib/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698