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 'deprecated_problems.dart' show deprecated_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 import 'fasta_codes.dart' show Message; |
| 18 |
| 19 export 'fasta_codes.dart'; |
| 20 |
17 const bool hideWarnings = false; | 21 const bool hideWarnings = false; |
18 | 22 |
19 bool get errorsAreFatal => CompilerContext.current.options.errorsAreFatal; | 23 bool get errorsAreFatal => CompilerContext.current.options.errorsAreFatal; |
20 | 24 |
21 bool get nitsAreFatal => CompilerContext.current.options.nitsAreFatal; | 25 bool get nitsAreFatal => CompilerContext.current.options.nitsAreFatal; |
22 | 26 |
23 bool get warningsAreFatal => CompilerContext.current.options.warningsAreFatal; | 27 bool get warningsAreFatal => CompilerContext.current.options.warningsAreFatal; |
24 | 28 |
25 bool get isVerbose => CompilerContext.current.options.verbose; | 29 bool get isVerbose => CompilerContext.current.options.verbose; |
26 | 30 |
27 bool get hideNits => !isVerbose; | 31 bool get hideNits => !isVerbose; |
28 | 32 |
| 33 void warning(Message message, int charOffset, Uri uri) { |
| 34 if (hideWarnings) return; |
| 35 print(deprecated_format( |
| 36 uri, charOffset, colorWarning("Warning: ${message.message}"))); |
| 37 if (warningsAreFatal) { |
| 38 if (isVerbose) print(StackTrace.current); |
| 39 throw new deprecated_InputError( |
| 40 uri, charOffset, "Compilation aborted due to fatal warnings."); |
| 41 } |
| 42 } |
| 43 |
| 44 void nit(Message message, int charOffset, Uri uri) { |
| 45 if (hideNits) return; |
| 46 print( |
| 47 deprecated_format(uri, charOffset, colorNit("Nit: ${message.message}"))); |
| 48 if (nitsAreFatal) { |
| 49 if (isVerbose) print(StackTrace.current); |
| 50 throw new deprecated_InputError( |
| 51 uri, charOffset, "Compilation aborted due to fatal nits."); |
| 52 } |
| 53 } |
| 54 |
29 void deprecated_warning(Uri uri, int charOffset, String message) { | 55 void deprecated_warning(Uri uri, int charOffset, String message) { |
30 if (hideWarnings) return; | 56 if (hideWarnings) return; |
31 print(deprecated_format(uri, charOffset, colorWarning("Warning: $message"))); | 57 print(deprecated_format(uri, charOffset, colorWarning("Warning: $message"))); |
32 if (warningsAreFatal) { | 58 if (warningsAreFatal) { |
33 if (isVerbose) print(StackTrace.current); | 59 if (isVerbose) print(StackTrace.current); |
34 throw new deprecated_InputError( | 60 throw new deprecated_InputError( |
35 uri, charOffset, "Compilation aborted due to fatal warnings."); | 61 uri, charOffset, "Compilation aborted due to fatal warnings."); |
36 } | 62 } |
37 } | 63 } |
38 | 64 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 program.libraries.clear(); | 134 program.libraries.clear(); |
109 parent.parent = null; | 135 parent.parent = null; |
110 return result; | 136 return result; |
111 } else { | 137 } else { |
112 return null; | 138 return null; |
113 } | 139 } |
114 } else { | 140 } else { |
115 return node.location; | 141 return node.location; |
116 } | 142 } |
117 } | 143 } |
OLD | NEW |