[w32file] Move MonoIO.Find{First,Next,Close} to managed
[mono.git] / mcs / ilasm / Report.cs
1 //
2 // Mono.ILASM.Report
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10
11 using System;
12 using System.IO;
13
14 namespace Mono.ILASM {
15
16         public abstract class Report {
17
18                 private static int error_count;
19                 private static bool quiet;
20                 /* Current file being processed */
21                 private static string file_path;
22
23                 static Report ()
24                 {
25                         error_count = 0;
26                         quiet = false;
27                 }
28
29                 public static int ErrorCount {
30                         get { return error_count; }
31                 }
32
33                 public static bool Quiet {
34                         get { return quiet; }
35                         set { quiet = value; }
36                 }
37
38                 public static string FilePath {
39                         get { return file_path; }
40                         set { file_path = value; }
41                 }
42
43                 public static void AssembleFile (string file, string listing,
44                                           string target, string output)
45                 {
46                         if (quiet)
47                                 return;
48                         Console.WriteLine ("Assembling '{0}' , {1}, to {2} --> '{3}'", file,
49                                            GetListing (listing), target, output);
50                         Console.WriteLine ();
51                 }
52
53                 public static void Error (string message)
54                 {
55                         Error (null, message);
56                 }
57
58                 public static void Error (Location location, string message)
59                 {
60                         error_count++;
61                         throw new ILAsmException (file_path, location, message);
62                 }
63                 
64                 public static void Warning (string message)
65                 {
66                         Warning (null, message);
67                 }
68
69                 public static void Warning (Location location, string message)
70                 {
71                         string location_str = " : ";
72                         if (location != null)
73                                 location_str = " (" + location.line + ", " + location.column + ") : ";
74
75                         Console.Error.WriteLine (String.Format ("{0}{1}Warning -- {2}",
76                                 (file_path != null ? file_path : ""), location_str, message));
77                 }
78
79                 public static void Message (string message)
80                 {
81                         if (quiet)
82                                 return;
83                         Console.WriteLine (message);
84                 }
85                 
86                 private static string GetListing (string listing)
87                 {
88                         if (listing == null)
89                                 return "no listing file";
90                         return listing;
91                 }
92
93         }
94
95         public class ILAsmException : Exception {
96
97                 string message;
98                 string file_path;
99                 Location location;
100                 
101                 public ILAsmException (string file_path, Location location, string message)
102                 {
103                         this.file_path = file_path;
104                         this.location = location;
105                         this.message = message;
106                 }
107
108                 public ILAsmException (Location location, string message)
109                         : this (null, location, message)
110                 {
111                 }
112
113                 public ILAsmException (string message)
114                         : this (null, null, message)
115                 {
116                 }
117
118                 public override string Message {
119                         get { return message; }
120                 }
121
122                 public Location Location {
123                         get { return location; }
124                         set { location = value; }
125                 }
126
127                 public string FilePath {
128                         get { return file_path; }
129                         set { file_path = value; }
130                 }
131
132                 public override string ToString ()
133                 {
134                         string location_str = " : ";
135                         if (location != null)
136                                 location_str = " (" + location.line + ", " + location.column + ") : ";
137
138                         return String.Format ("{0}{1}Error : {2}",
139                                 (file_path != null ? file_path : ""), location_str, message);
140                 }
141
142         }
143
144         public class InternalErrorException : Exception {
145                 public InternalErrorException ()
146                         : base ("Internal error")
147                 {
148                 }
149
150                 public InternalErrorException (string message)
151                         : base (message)
152                 {
153                 }
154         }
155
156 }
157