2001-09-27 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / mcs / report.cs
1 //
2 // report.cs: report errors and warnings.
3 //
4 // Author: Miguel de Icaza (miguel@ximian.com)
5 //
6 // (C) 2001 Ximian, Inc. (http://www.ximian.com)
7 //
8
9 using System;
10
11 namespace CIR {
12
13         public class Report {
14                 int errors;
15                 int warnings;
16                 bool fatal;
17
18                 public void RealError (string msg)
19                 {
20                         errors++;
21                         Console.WriteLine (msg);
22
23                         if (fatal)
24                                 throw new Exception (msg);
25                 }
26                        
27                 public void Error (int code, Location l, string text)
28                 {
29                         string msg = l.Name + "(" + l.Row + "," + l.Col +
30                                 "): Error CS"+code+": " + text;
31
32                         RealError (msg);
33                 }
34
35                 public void Warning (int code, Location l, string text)
36                 {
37                         Console.WriteLine (l.Name + "(" + l.Row + "," + l.Col +
38                                            "): Warning CS"+code+": " + text);
39                         warnings++;
40                 }
41                 
42                 public void Error (int code, string text)
43                 {
44                         string msg = "Error CS"+code+": "+text;
45
46                         RealError (msg);
47                 }
48
49                 public void Warning (int code, string text)
50                 {
51                         Console.WriteLine ("Warning CS"+code+": "+text);
52                         warnings++;
53                 }
54
55                 public void Message (Message m)
56                 {
57                         if (m is ErrorMessage)
58                                 Error (m.code, m.text);
59                         else
60                                 Warning (m.code, m.text);
61                 }
62                         
63                 public int Errors {
64                         get {
65                                 return errors;
66                         }
67                 }
68
69                 public int Warnings {
70                         get {
71                                 return warnings;
72                         }
73                 }
74
75                 public bool Fatal {
76                         set {
77                                 fatal = true;
78                         }
79
80                         get {
81                                 return fatal;
82                         }
83                 }
84         }
85
86         public class Message {
87                 public int code;
88                 public string text;
89                 
90                 public Message (int code, string text)
91                 {
92                         this.code = code;
93                         this.text = text;
94                 }
95         }
96
97         public class WarningMessage : Message {
98                 public WarningMessage (int code, string text) : base (code, text)
99                 {
100                 }
101         }
102
103         public class ErrorMessage : Message {
104                 public ErrorMessage (int code, string text) : base (code, text)
105                 {
106                 }
107
108                 //
109                 // For compatibility reasons with old code.
110                 //
111                 public static void report_error (string error)
112                 {
113                         Console.Write ("ERROR: ");
114                         Console.WriteLine (error);
115                 }
116         }
117 }
118
119