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;
11 using System.Diagnostics;
13 namespace Mono.CSharp {
16 /// This class is used to report errors and warnings t te user.
20 /// Errors encountered so far
22 static public int Errors;
25 /// Warnings encountered so far
27 static public int Warnings;
30 /// Whether errors should be throw an exception
32 static public bool Fatal;
35 /// Whether warnings should be considered errors
37 static public bool WarningsAreErrors;
40 /// Whether to dump a stack trace on errors.
42 static public bool Stacktrace;
45 // If the error code is reported on the given line,
46 // then the process exits with a unique error code.
48 // Used for the test suite to excercise the error codes
50 static int probe_error = 0;
51 static int probe_line = 0;
54 // Keeps track of the warnings that we are ignoring
56 static Hashtable warning_ignore_table;
58 static void Check (int code)
60 if (code == probe_error){
61 Environment.Exit (123);
65 static public void RealError (string msg)
68 Console.WriteLine (msg);
71 Console.WriteLine (new StackTrace ().ToString ());
73 throw new Exception (msg);
76 static public void Error (int code, Location l, string text)
78 string msg = String.Format (
79 "{0}({1}) error CS{2:0000}: {3}", l.Name, l.Row, code, text);
85 static public void Warning (int code, Location l, string text)
87 if (warning_ignore_table != null){
88 if (warning_ignore_table.Contains (code))
92 if (WarningsAreErrors)
93 Error (code, l, text);
97 if (Location.IsNull (l))
100 row = l.Row.ToString ();
102 Console.WriteLine (String.Format (
103 "{0}({1}) warning CS{2:0000}: {3}",
104 l.Name, row, code, text));
110 static public void Warning (int code, string text)
112 Warning (code, Location.Null, text);
115 static public void Error (int code, string text)
117 string msg = String.Format ("error CS{1:0000}: {2}", code, text);
123 static public void Message (Message m)
125 if (m is ErrorMessage)
126 Error (m.code, m.text);
128 Warning (m.code, m.text);
131 static public void SetIgnoreWarning (int code)
133 if (warning_ignore_table == null)
134 warning_ignore_table = new Hashtable ();
136 warning_ignore_table [code] = true;
139 static public void SetProbe (int code, int line)
145 static public int ProbeCode {
152 public class Message {
156 public Message (int code, string text)
163 public class WarningMessage : Message {
164 public WarningMessage (int code, string text) : base (code, text)
169 public class ErrorMessage : Message {
170 public ErrorMessage (int code, string text) : base (code, text)
175 // For compatibility reasons with old code.
177 public static void report_error (string error)
179 Console.Write ("ERROR: ");
180 Console.WriteLine (error);