2 // report.cs: report errors and warnings.
4 // Author: Miguel de Icaza (miguel@ximian.com)
6 // (C) 2001 Ximian, Inc. (http://www.ximian.com)
10 using System.Collections;
12 namespace Mono.CSharp {
15 /// This class is used to report errors and warnings t te user.
21 // whether errors are fatal (they throw an exception), useful
22 // for debugging the compiler
25 // whether we consider warnings to be errors.
26 static bool warnings_are_errors;
29 // If the error code is reported on the given line,
30 // then the process exits with a unique error code.
32 // Used for the test suite to excercise the error codes
34 static int probe_error = 0;
35 static int probe_line = 0;
38 // Keeps track of the warnings that we are ignoring
40 static Hashtable warning_ignore_table;
42 static void Check (int code)
44 if (code == probe_error){
45 Environment.Exit (123);
49 static public void RealError (string msg)
52 Console.WriteLine (msg);
55 throw new Exception (msg);
58 static public void Error (int code, Location l, string text)
60 string msg = l.Name + "(" + l.Row +
61 "): error CS"+code+": " + text;
67 static public void Warning (int code, Location l, string text)
69 if (warning_ignore_table != null){
70 if (warning_ignore_table.Contains (code))
74 if (warnings_are_errors)
75 Error (code, l, text);
79 if (Location.IsNull (l))
82 row = l.Row.ToString ();
84 Console.WriteLine (l.Name + "(" + row + "): warning CS"+code+": " + text);
90 static public void Warning (int code, string text)
92 Warning (code, Location.Null, text);
95 static public void Error (int code, string text)
97 string msg = "error CS"+code+": "+text;
103 static public void Message (Message m)
105 if (m is ErrorMessage)
106 Error (m.code, m.text);
108 Warning (m.code, m.text);
111 static public void SetIgnoreWarning (int code)
113 if (warning_ignore_table == null)
114 warning_ignore_table = new Hashtable ();
116 warning_ignore_table [code] = true;
119 static public void SetProbe (int code, int line)
125 static public int ProbeCode {
131 static public int Errors {
137 static public int Warnings {
143 static public bool Fatal {
153 static public bool WarningsAreErrors {
155 warnings_are_errors = true;
160 public class Message {
164 public Message (int code, string text)
171 public class WarningMessage : Message {
172 public WarningMessage (int code, string text) : base (code, text)
177 public class ErrorMessage : Message {
178 public ErrorMessage (int code, string text) : base (code, text)
183 // For compatibility reasons with old code.
185 public static void report_error (string error)
187 Console.Write ("ERROR: ");
188 Console.WriteLine (error);