namespace CIR {
public class Report {
- int errors;
- int warnings;
+ static int errors;
+ static int warnings;
+
+ //
+ // whether errors are fatal (they throw an exception), useful
+ // for debugging the compiler
+ //
+ static bool fatal;
+
+ //
+ // If the error code is reported on the given line,
+ // then the process exits with a unique error code.
+ //
+ // Used for the test suite to excercise the error codes
+ //
+ static int probe_error = 0;
+ static int probe_line = 0;
+
+ static void Check (int code)
+ {
+ if (code == probe_error){
+ Environment.Exit (123);
+ }
+ }
- public void Error (int code, string text)
+ static public void RealError (string msg)
{
- Console.WriteLine ("Error CS"+code+": "+text);
errors++;
+ Console.WriteLine (msg);
+
+ if (fatal)
+ throw new Exception (msg);
+ }
+
+ static public void Error (int code, Location l, string text)
+ {
+ string msg = l.Name + "(" + l.Row +
+ "): Error CS"+code+": " + text;
+
+ RealError (msg);
+ Check (code);
+ }
+
+ static public void Warning (int code, Location l, string text)
+ {
+ Console.WriteLine (l.Name + "(" + l.Row +
+ "): Warning CS"+code+": " + text);
+ warnings++;
+ Check (code);
+ }
+
+ static public void Error (int code, string text)
+ {
+ string msg = "Error CS"+code+": "+text;
+
+ RealError (msg);
+ Check (code);
}
- public void Warning (int code, string text)
+ static public void Warning (int code, string text)
{
Console.WriteLine ("Warning CS"+code+": "+text);
warnings++;
+ Check (code);
}
- public void Message (Message m)
+ static public void Message (Message m)
{
- if (m is Error)
+ if (m is ErrorMessage)
Error (m.code, m.text);
else
Warning (m.code, m.text);
}
-
- public int Errors {
+
+ static public void SetProbe (int code, int line)
+ {
+ probe_error = code;
+ probe_line = line;
+ }
+
+ static public int Errors {
get {
return errors;
}
}
- public int Warnings {
+ static public int Warnings {
get {
return warnings;
}
}
+
+ static public bool Fatal {
+ set {
+ fatal = true;
+ }
+
+ get {
+ return fatal;
+ }
+ }
}
public class Message {
}
}
- public class Warning : Message {
- public Warning (int code, string text) : base (code, text)
+ public class WarningMessage : Message {
+ public WarningMessage (int code, string text) : base (code, text)
{
}
}
- public class Error : Message {
- public Error (int code, string text) : base (code, text)
+ public class ErrorMessage : Message {
+ public ErrorMessage (int code, string text) : base (code, text)
{
}