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

Unified Diff: pkg/front_end/lib/src/fasta/messages.dart

Issue 2704753002: Implement line and column numbers. (Closed)
Patch Set: Change message. Created 3 years, 10 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/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | pkg/front_end/lib/src/fasta/outline.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/messages.dart
diff --git a/pkg/front_end/lib/src/fasta/messages.dart b/pkg/front_end/lib/src/fasta/messages.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a4e4939fd401865d9ea6f321bd02275245977b83
--- /dev/null
+++ b/pkg/front_end/lib/src/fasta/messages.dart
@@ -0,0 +1,74 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library fasta.messages;
+
+import 'package:kernel/ast.dart' show
+ Location,
+ Program;
+
+import 'util/relativize.dart' show
+ relativizeUri;
+
+import 'compiler_context.dart' show
+ CompilerContext;
+
+import 'errors.dart' show
+ InputError;
+
+import 'colors.dart' show
+ cyan,
+ magenta;
+
+const bool hideNits = false;
+
+const bool hideWarnings = false;
+
+void warning(Uri uri, int charOffset, String message) {
+ if (hideWarnings) return;
+ print(format(uri, charOffset, colorWarning("Warning: $message")));
+ if (CompilerContext.current.options.areWarningsFatal) {
+ if (CompilerContext.current.options.verbose) print(StackTrace.current);
+ throw new InputError(
+ uri, charOffset, "Compilation aborted due to fatal warnings.");
+ }
+}
+
+void nit(Uri uri, int charOffset, String message) {
+ if (hideNits) return;
+ print(format(uri, charOffset, colorNit("Nit: $message")));
+ if (CompilerContext.current.options.areNitsFatal) {
+ if (CompilerContext.current.options.verbose) print(StackTrace.current);
+ throw new InputError(
+ uri, charOffset, "Compilation aborted due to fatal nits.");
+ }
+}
+
+String colorWarning(String message) {
+ // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on
+ // Windows.
+ return magenta(message);
+}
+
+String colorNit(String message) {
+ // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on
+ // Windows.
+ return cyan(message);
+}
+
+String format(Uri uri, int charOffset, String message) {
+ if (uri != null) {
+ String path = relativizeUri(uri);
+ String position = charOffset == -1
+ ? path : "${getLocation(path, charOffset)}";
+ return "$position: $message";
+ } else {
+ return message;
+ }
+}
+
+Location getLocation(String path, int charOffset) {
+ return new Program(null, CompilerContext.current.uriToSource)
+ .getLocation(path, charOffset);
+}
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | pkg/front_end/lib/src/fasta/outline.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698