2001-10-04 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / mcs / report.cs
index 99d1bff5e35614d1612d8c70e604c3d7a0efd657..2f276f907b10f74e5b103d5eb02ee2c908f84b44 100644 (file)
@@ -11,40 +11,107 @@ using System;
 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 {
@@ -58,14 +125,14 @@ namespace CIR {
                }
        }
 
-       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)
                {
                }