OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library fasta.messages; |
| 6 |
| 7 import 'package:kernel/ast.dart' show |
| 8 Location, |
| 9 Program; |
| 10 |
| 11 import 'util/relativize.dart' show |
| 12 relativizeUri; |
| 13 |
| 14 import 'compiler_context.dart' show |
| 15 CompilerContext; |
| 16 |
| 17 import 'errors.dart' show |
| 18 InputError; |
| 19 |
| 20 import 'colors.dart' show |
| 21 cyan, |
| 22 magenta; |
| 23 |
| 24 const bool hideNits = false; |
| 25 |
| 26 const bool hideWarnings = false; |
| 27 |
| 28 void warning(Uri uri, int charOffset, String message) { |
| 29 if (hideWarnings) return; |
| 30 print(format(uri, charOffset, colorWarning("Warning: $message"))); |
| 31 if (CompilerContext.current.options.areWarningsFatal) { |
| 32 if (CompilerContext.current.options.verbose) print(StackTrace.current); |
| 33 throw new InputError( |
| 34 uri, charOffset, "Compilation aborted due to fatal warnings."); |
| 35 } |
| 36 } |
| 37 |
| 38 void nit(Uri uri, int charOffset, String message) { |
| 39 if (hideNits) return; |
| 40 print(format(uri, charOffset, colorNit("Nit: $message"))); |
| 41 if (CompilerContext.current.options.areNitsFatal) { |
| 42 if (CompilerContext.current.options.verbose) print(StackTrace.current); |
| 43 throw new InputError( |
| 44 uri, charOffset, "Compilation aborted due to fatal nits."); |
| 45 } |
| 46 } |
| 47 |
| 48 String colorWarning(String message) { |
| 49 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
| 50 // Windows. |
| 51 return magenta(message); |
| 52 } |
| 53 |
| 54 String colorNit(String message) { |
| 55 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
| 56 // Windows. |
| 57 return cyan(message); |
| 58 } |
| 59 |
| 60 String format(Uri uri, int charOffset, String message) { |
| 61 if (uri != null) { |
| 62 String path = relativizeUri(uri); |
| 63 String position = charOffset == -1 |
| 64 ? path : "${getLocation(path, charOffset)}"; |
| 65 return "$position: $message"; |
| 66 } else { |
| 67 return message; |
| 68 } |
| 69 } |
| 70 |
| 71 Location getLocation(String path, int charOffset) { |
| 72 return new Program(null, CompilerContext.current.uriToSource) |
| 73 .getLocation(path, charOffset); |
| 74 } |
OLD | NEW |