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

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

Issue 1363993004: Report info messages together with their error, warning, or hint. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. Created 5 years, 3 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/compiler/lib/src/compile_time_constants.dart ('k') | pkg/compiler/lib/src/dart_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 0ccc51ae8d132fa41d54e278714fc11cb4fcc755..f73f6966dfe3733cb1625c473777b1162f81d0e5 100644
--- a/pkg/compiler/lib/src/compiler.dart
+++ b/pkg/compiler/lib/src/compiler.dart
@@ -138,7 +138,7 @@ import 'util/util.dart' show
import 'world.dart' show
World;
-abstract class Compiler implements DiagnosticListener {
+abstract class Compiler extends DiagnosticListener {
final Stopwatch totalCompileTime = new Stopwatch();
int nextFreeClassId = 0;
@@ -616,10 +616,12 @@ abstract class Compiler implements DiagnosticListener {
internalError(spannable, "$methodName not implemented.");
}
- void internalError(Spannable node, reason) {
+ internalError(Spannable node, reason) {
String message = tryToString(reason);
reportDiagnosticInternal(
- node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH);
+ createMessage(node, MessageKind.GENERIC, {'text': message}),
+ const <DiagnosticMessage>[],
+ api.Diagnostic.CRASH);
throw 'Internal Error: $message';
}
@@ -627,8 +629,8 @@ abstract class Compiler implements DiagnosticListener {
if (hasCrashed) return;
hasCrashed = true;
reportDiagnostic(
- element,
- MessageTemplate.TEMPLATES[MessageKind.COMPILER_CRASHED].message(),
+ createMessage(element, MessageKind.COMPILER_CRASHED),
+ const <DiagnosticMessage>[],
api.Diagnostic.CRASH);
pleaseReportCrash();
}
@@ -691,9 +693,11 @@ abstract class Compiler implements DiagnosticListener {
}
void log(message) {
- reportDiagnostic(null,
- MessageTemplate.TEMPLATES[MessageKind.GENERIC]
- .message({'text': '$message'}),
+ Message msg = MessageTemplate.TEMPLATES[MessageKind.GENERIC]
+ .message({'text': '$message'});
+ reportDiagnostic(
+ new DiagnosticMessage(null, null, msg),
+ const <DiagnosticMessage>[],
api.Diagnostic.VERBOSE_INFO);
}
@@ -708,9 +712,10 @@ abstract class Compiler implements DiagnosticListener {
reportAssertionFailure(error);
} else {
reportDiagnostic(
- new SourceSpan(uri, 0, 0),
- MessageTemplate.TEMPLATES[MessageKind.COMPILER_CRASHED]
- .message(),
+ createMessage(
+ new SourceSpan(uri, 0, 0),
+ MessageKind.COMPILER_CRASHED),
+ const <DiagnosticMessage>[],
api.Diagnostic.CRASH);
}
pleaseReportCrash();
@@ -875,11 +880,13 @@ abstract class Compiler implements DiagnosticListener {
Set<String> importChains =
computeImportChainsFor(loadedLibraries, Uris.dart_mirrors);
if (!backend.supportsReflection) {
- reportError(NO_LOCATION_SPANNABLE,
- MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND);
+ reportErrorMessage(
+ NO_LOCATION_SPANNABLE,
+ MessageKind.MIRRORS_LIBRARY_NOT_SUPPORT_BY_BACKEND);
} else {
- reportWarning(NO_LOCATION_SPANNABLE,
- MessageKind.IMPORT_EXPERIMENTAL_MIRRORS,
+ reportWarningMessage(
+ NO_LOCATION_SPANNABLE,
+ MessageKind.IMPORT_EXPERIMENTAL_MIRRORS,
{'importChain': importChains.join(
MessageTemplate.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)});
}
@@ -1086,7 +1093,7 @@ abstract class Compiler implements DiagnosticListener {
if (errorElement != null &&
errorElement.isSynthesized &&
!mainApp.isSynthesized) {
- reportWarning(
+ reportWarningMessage(
errorElement, errorElement.messageKind,
errorElement.messageArguments);
}
@@ -1154,12 +1161,14 @@ abstract class Compiler implements DiagnosticListener {
kind = MessageKind.HIDDEN_WARNINGS;
}
MessageTemplate template = MessageTemplate.TEMPLATES[kind];
- reportDiagnostic(null,
- template.message(
- {'warnings': info.warnings,
- 'hints': info.hints,
- 'uri': uri},
- terseDiagnostics),
+ Message message = template.message(
+ {'warnings': info.warnings,
+ 'hints': info.hints,
+ 'uri': uri},
+ terseDiagnostics);
+ reportDiagnostic(
+ new DiagnosticMessage(null, null, message),
+ const <DiagnosticMessage>[],
api.Diagnostic.HINT);
});
}
@@ -1326,7 +1335,7 @@ abstract class Compiler implements DiagnosticListener {
}
log('Excess resolution work: ${resolved.length}.');
for (Element e in resolved) {
- reportWarning(e,
+ reportWarningMessage(e,
MessageKind.GENERIC,
{'text': 'Warning: $e resolved but not compiled.'});
}
@@ -1393,38 +1402,51 @@ abstract class Compiler implements DiagnosticListener {
return backend.codegen(work);
}
- void reportError(Spannable node,
- MessageKind messageKind,
- [Map arguments = const {}]) {
- reportDiagnosticInternal(
- node, messageKind, arguments, api.Diagnostic.ERROR);
+ DiagnosticMessage createMessage(
+ Spannable spannable,
+ MessageKind messageKind,
+ [Map arguments = const {}]) {
+ SourceSpan span = spanFromSpannable(spannable);
+ MessageTemplate template = MessageTemplate.TEMPLATES[messageKind];
+ Message message = template.message(arguments, terseDiagnostics);
+ return new DiagnosticMessage(span, spannable, message);
}
- void reportWarning(Spannable node, MessageKind messageKind,
- [Map arguments = const {}]) {
- reportDiagnosticInternal(
- node, messageKind, arguments, api.Diagnostic.WARNING);
+ void reportError(
+ DiagnosticMessage message,
+ [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) {
+ reportDiagnosticInternal(message, infos, api.Diagnostic.ERROR);
}
- void reportInfo(Spannable node, MessageKind messageKind,
- [Map arguments = const {}]) {
- reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.INFO);
+ void reportWarning(
+ DiagnosticMessage message,
+ [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) {
+ reportDiagnosticInternal(message, infos, api.Diagnostic.WARNING);
}
- void reportHint(Spannable node, MessageKind messageKind,
+ void reportHint(
+ DiagnosticMessage message,
+ [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) {
+ reportDiagnosticInternal(message, infos, api.Diagnostic.HINT);
+ }
+
+ @deprecated
+ void reportInfo(Spannable node, MessageKind messageKind,
[Map arguments = const {}]) {
- reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.HINT);
+ reportDiagnosticInternal(
+ createMessage(node, messageKind, arguments),
+ const <DiagnosticMessage>[],
+ api.Diagnostic.INFO);
}
- void reportDiagnosticInternal(Spannable node,
- MessageKind messageKind,
- Map arguments,
+ void reportDiagnosticInternal(DiagnosticMessage message,
+ List<DiagnosticMessage> infos,
api.Diagnostic kind) {
- if (!showPackageWarnings && node != NO_LOCATION_SPANNABLE) {
+ if (!showPackageWarnings && message.spannable != NO_LOCATION_SPANNABLE) {
switch (kind) {
case api.Diagnostic.WARNING:
case api.Diagnostic.HINT:
- Element element = elementFromSpannable(node);
+ Element element = elementFromSpannable(message.spannable);
if (!inUserCode(element, assumeInUserCode: true)) {
Uri uri = getCanonicalUri(element);
SuppressionInfo info =
@@ -1446,22 +1468,20 @@ abstract class Compiler implements DiagnosticListener {
}
}
lastDiagnosticWasFiltered = false;
- MessageTemplate template = MessageTemplate.TEMPLATES[messageKind];
- reportDiagnostic(
- node,
- template.message(arguments, terseDiagnostics),
- kind);
+ reportDiagnostic(message, infos, kind);
}
- void reportDiagnostic(Spannable span,
- Message message,
+ void reportDiagnostic(DiagnosticMessage message,
+ List<DiagnosticMessage> infos,
api.Diagnostic kind);
void reportAssertionFailure(SpannableAssertionFailure ex) {
String message = (ex.message != null) ? tryToString(ex.message)
: tryToString(ex);
reportDiagnosticInternal(
- ex.node, MessageKind.GENERIC, {'text': message}, api.Diagnostic.CRASH);
+ createMessage(ex.node, MessageKind.GENERIC, {'text': message}),
+ const <DiagnosticMessage>[],
+ api.Diagnostic.CRASH);
}
SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) {
@@ -1598,20 +1618,20 @@ abstract class Compiler implements DiagnosticListener {
if (member.isErroneous) return;
if (member.isFunction) {
if (!enqueuer.resolution.hasBeenResolved(member)) {
- reportHint(member, MessageKind.UNUSED_METHOD,
- {'name': member.name});
+ reportHintMessage(
+ member, MessageKind.UNUSED_METHOD, {'name': member.name});
}
} else if (member.isClass) {
if (!member.isResolved) {
- reportHint(member, MessageKind.UNUSED_CLASS,
- {'name': member.name});
+ reportHintMessage(
+ member, MessageKind.UNUSED_CLASS, {'name': member.name});
} else {
member.forEachLocalMember(checkLive);
}
} else if (member.isTypedef) {
if (!member.isResolved) {
- reportHint(member, MessageKind.UNUSED_TYPEDEF,
- {'name': member.name});
+ reportHintMessage(
+ member, MessageKind.UNUSED_TYPEDEF, {'name': member.name});
}
}
}
« no previous file with comments | « pkg/compiler/lib/src/compile_time_constants.dart ('k') | pkg/compiler/lib/src/dart_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698