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 // FIXME: currently our class library does not support custom number format strings
13 using System.Collections;
14 using System.Diagnostics;
16 namespace Mono.CSharp {
19 /// This class is used to report errors and warnings t te user.
23 /// Errors encountered so far
25 static public int Errors;
28 /// Warnings encountered so far
30 static public int Warnings;
33 /// Whether errors should be throw an exception
35 static public bool Fatal;
38 /// Whether warnings should be considered errors
40 static public bool WarningsAreErrors;
43 /// Whether to dump a stack trace on errors.
45 static public bool Stacktrace;
48 // If the 'expected' error code is reported then the
49 // compilation succeeds.
51 // Used for the test suite to excercise the error codes
53 static int expected_error = 0;
56 // Keeps track of the warnings that we are ignoring
58 static Hashtable warning_ignore_table;
60 static void Check (int code)
62 if (code == expected_error){
64 throw new Exception ();
70 static public void RealError (string msg)
73 Console.WriteLine (msg);
76 Console.WriteLine (new StackTrace ().ToString ());
78 throw new Exception (msg);
81 static public void Error (int code, Location l, string text)
83 string msg = String.Format (
84 "{0}({1}) error CS{2:0000}: {3}", l.Name, l.Row, code, text);
85 // "{0}({1}) error CS{2}: {3}", l.Name, l.Row, code, text);
91 static public void Warning (int code, Location l, string text)
93 if (warning_ignore_table != null){
94 if (warning_ignore_table.Contains (code))
98 if (WarningsAreErrors)
99 Error (code, l, text);
103 if (Location.IsNull (l))
106 row = l.Row.ToString ();
108 Console.WriteLine (String.Format (
109 "{0}({1}) warning CS{2:0000}: {3}",
110 // "{0}({1}) warning CS{2}: {3}",
111 l.Name, row, code, text));
116 Console.WriteLine (new StackTrace ().ToString ());
120 static public void Warning (int code, string text)
122 Warning (code, Location.Null, text);
125 static public void Error (int code, string text)
127 string msg = String.Format ("error CS{0:0000}: {1}", code, text);
128 // string msg = String.Format ("error CS{0}: {1}", code, text);
134 static public void Message (Message m)
136 if (m is ErrorMessage)
137 Error (m.code, m.text);
139 Warning (m.code, m.text);
142 static public void SetIgnoreWarning (int code)
144 if (warning_ignore_table == null)
145 warning_ignore_table = new Hashtable ();
147 warning_ignore_table [code] = true;
150 static public int ExpectedError {
152 expected_error = value;
155 return expected_error;
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);