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

Unified Diff: pkg/compiler/lib/src/compiler.dart

Issue 1911443002: Associate compile-time errors with elements. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged with 111a794141cd313460e4fe2593cfea9862fe1c0f Created 4 years, 8 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 | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/compiler.dart
diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart
index 9477e8af6519711891332db098aa200b58fef218..521d64abb61c96ec411e6de3529a7cbb2e6ca142 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -213,8 +213,11 @@ abstract class Compiler implements LibraryLoaderListener {
/// The [String.fromEnvironment] constructor.
ConstructorElement stringEnvironment;
+ // TODO(zarah): Remove this map and incorporate compile-time errors
+ // in the model.
/// Tracks elements with compile-time errors.
- final Set<Element> elementsWithCompileTimeErrors = new Set<Element>();
+ final Map<Element, List<DiagnosticMessage>> elementsWithCompileTimeErrors =
+ new Map<Element, List<DiagnosticMessage>>();
final Environment environment;
// TODO(sigmund): delete once we migrate the rest of the compiler to use
@@ -272,16 +275,7 @@ abstract class Compiler implements LibraryLoaderListener {
static const int PHASE_COMPILING = 3;
int phase;
- bool compilationFailedInternal = false;
-
- bool get compilationFailed => compilationFailedInternal;
-
- void set compilationFailed(bool value) {
- if (value) {
- elementsWithCompileTimeErrors.add(currentElement);
- }
- compilationFailedInternal = value;
- }
+ bool compilationFailed = false;
Compiler(
{CompilerOptions options,
@@ -1096,6 +1090,7 @@ abstract class Compiler implements LibraryLoaderListener {
if (markCompilationAsFailed(message, kind)) {
compilationFailed = true;
}
+ registerCompiletimeError(currentElement, message);
}
/**
@@ -1231,8 +1226,24 @@ abstract class Compiler implements LibraryLoaderListener {
backend.forgetElement(element);
}
+ /// Returns [true] if a compile-time error has been reported for element.
bool elementHasCompileTimeError(Element element) {
- return elementsWithCompileTimeErrors.contains(element);
+ return elementsWithCompileTimeErrors.containsKey(element);
+ }
+
+ /// Associate [element] with a compile-time error [message].
+ void registerCompiletimeError(Element element, DiagnosticMessage message) {
+ // The information is only needed if [generateCodeWithCompileTimeErrors].
+ if (options.generateCodeWithCompileTimeErrors) {
+ if (element == null) {
+ // Record as global error.
+ // TODO(zarah): Extend element model to represent compile-time
+ // errors instead of using a map.
+ element = mainFunction;
+ }
+ elementsWithCompileTimeErrors.
+ putIfAbsent(element, () => <DiagnosticMessage>[]).add(message);
+ }
}
EventSink<String> outputProvider(String name, String extension) {
@@ -1495,6 +1506,13 @@ class CompilerDiagnosticReporter extends DiagnosticReporter {
if (kind == api.Diagnostic.ERROR ||
kind == api.Diagnostic.CRASH ||
(options.fatalWarnings && kind == api.Diagnostic.WARNING)) {
+ Element errorElement;
+ if (message.spannable is Element) {
+ errorElement = message.spannable;
+ } else {
+ errorElement = currentElement;
+ }
+ compiler.registerCompiletimeError(errorElement, message);
compiler.fatalDiagnosticReported(message, infos, kind);
}
}
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698