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