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 Library, Location, Program, TreeNode; | 7 import 'package:kernel/ast.dart' show Library, Location, Program, TreeNode; |
8 | 8 |
9 import 'util/relativize.dart' show relativizeUri; | 9 import 'util/relativize.dart' show relativizeUri; |
10 | 10 |
11 import 'compiler_context.dart' show CompilerContext; | 11 import 'compiler_context.dart' show CompilerContext; |
12 | 12 |
13 import 'errors.dart' show InputError; | 13 import 'deprecated_problems.dart' show deprecated_InputError; |
14 | 14 |
15 import 'colors.dart' show cyan, magenta; | 15 import 'colors.dart' show cyan, magenta; |
16 | 16 |
17 const bool hideWarnings = false; | 17 const bool hideWarnings = false; |
18 | 18 |
19 bool get errorsAreFatal => CompilerContext.current.options.errorsAreFatal; | 19 bool get errorsAreFatal => CompilerContext.current.options.errorsAreFatal; |
20 | 20 |
21 bool get nitsAreFatal => CompilerContext.current.options.nitsAreFatal; | 21 bool get nitsAreFatal => CompilerContext.current.options.nitsAreFatal; |
22 | 22 |
23 bool get warningsAreFatal => CompilerContext.current.options.warningsAreFatal; | 23 bool get warningsAreFatal => CompilerContext.current.options.warningsAreFatal; |
24 | 24 |
25 bool get isVerbose => CompilerContext.current.options.verbose; | 25 bool get isVerbose => CompilerContext.current.options.verbose; |
26 | 26 |
27 bool get hideNits => !isVerbose; | 27 bool get hideNits => !isVerbose; |
28 | 28 |
29 void warning(Uri uri, int charOffset, String message) { | 29 void deprecated_warning(Uri uri, int charOffset, String message) { |
30 if (hideWarnings) return; | 30 if (hideWarnings) return; |
31 print(format(uri, charOffset, colorWarning("Warning: $message"))); | 31 print(deprecated_format(uri, charOffset, colorWarning("Warning: $message"))); |
32 if (warningsAreFatal) { | 32 if (warningsAreFatal) { |
33 if (isVerbose) print(StackTrace.current); | 33 if (isVerbose) print(StackTrace.current); |
34 throw new InputError( | 34 throw new deprecated_InputError( |
35 uri, charOffset, "Compilation aborted due to fatal warnings."); | 35 uri, charOffset, "Compilation aborted due to fatal warnings."); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 void nit(Uri uri, int charOffset, String message) { | 39 void deprecated_nit(Uri uri, int charOffset, String message) { |
40 if (hideNits) return; | 40 if (hideNits) return; |
41 print(format(uri, charOffset, colorNit("Nit: $message"))); | 41 print(deprecated_format(uri, charOffset, colorNit("Nit: $message"))); |
42 if (nitsAreFatal) { | 42 if (nitsAreFatal) { |
43 if (isVerbose) print(StackTrace.current); | 43 if (isVerbose) print(StackTrace.current); |
44 throw new InputError( | 44 throw new deprecated_InputError( |
45 uri, charOffset, "Compilation aborted due to fatal nits."); | 45 uri, charOffset, "Compilation aborted due to fatal nits."); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 String colorWarning(String message) { | 49 String colorWarning(String message) { |
50 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on | 50 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
51 // Windows. | 51 // Windows. |
52 return magenta(message); | 52 return magenta(message); |
53 } | 53 } |
54 | 54 |
55 String colorNit(String message) { | 55 String colorNit(String message) { |
56 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on | 56 // TODO(ahe): Colors need to be optional. Doesn't work well in Emacs or on |
57 // Windows. | 57 // Windows. |
58 return cyan(message); | 58 return cyan(message); |
59 } | 59 } |
60 | 60 |
61 String format(Uri uri, int charOffset, String message) { | 61 String deprecated_format(Uri uri, int charOffset, String message) { |
62 if (uri != null) { | 62 if (uri != null) { |
63 String path = relativizeUri(uri); | 63 String path = relativizeUri(uri); |
64 Location location = charOffset == -1 ? null : getLocation(path, charOffset); | 64 Location location = charOffset == -1 ? null : getLocation(path, charOffset); |
65 String sourceLine = getSourceLine(location); | 65 String sourceLine = getSourceLine(location); |
66 if (sourceLine == null) { | 66 if (sourceLine == null) { |
67 sourceLine = ""; | 67 sourceLine = ""; |
68 } else { | 68 } else { |
69 sourceLine = "\n$sourceLine\n" | 69 sourceLine = "\n$sourceLine\n" |
70 "${' ' * (location.column - 1)}^"; | 70 "${' ' * (location.column - 1)}^"; |
71 } | 71 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 program.libraries.clear(); | 108 program.libraries.clear(); |
109 parent.parent = null; | 109 parent.parent = null; |
110 return result; | 110 return result; |
111 } else { | 111 } else { |
112 return null; | 112 return null; |
113 } | 113 } |
114 } else { | 114 } else { |
115 return node.location; | 115 return node.location; |
116 } | 116 } |
117 } | 117 } |
OLD | NEW |