2007-04-02 Chris Toshok <toshok@ximian.com>
[mcs.git] / ilasm / Report.cs
blobdd2afd2ee27ff30c1a48c16f37c50334227f785e
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 //
11 using System;
12 using System.IO;
14 namespace Mono.ILASM {
16 public abstract class Report {
18 private static int error_count;
19 private static int mark_count;
20 private static bool quiet;
21 /* Current file being processed */
22 private static string file_path;
24 static Report ()
26 error_count = 0;
27 quiet = false;
30 public static int ErrorCount {
31 get { return error_count; }
34 public static bool Quiet {
35 get { return quiet; }
36 set { quiet = value; }
39 public static string FilePath {
40 get { return file_path; }
41 set { file_path = value; }
44 public static void AssembleFile (string file, string listing,
45 string target, string output)
47 Console.WriteLine ("Assembling '{0}' , {1}, to {2} --> '{3}'", file,
48 GetListing (listing), target, output);
49 Console.WriteLine ();
52 public static void Error (string message)
54 Error (null, message);
57 public static void Error (Location location, string message)
59 error_count++;
60 throw new ILAsmException (file_path, location, message);
63 public static void Warning (string message)
65 Warning (null, message);
68 public static void Warning (Location location, string message)
70 string location_str = " : ";
71 if (location != null)
72 location_str = " (" + location.line + ", " + location.column + ") : ";
74 Console.Error.WriteLine (String.Format ("{0}{1}Warning -- {2}",
75 (file_path != null ? file_path : ""), location_str, message));
78 public static void Message (string message)
80 if (quiet)
81 return;
82 Console.WriteLine (message);
85 private static string GetListing (string listing)
87 if (listing == null)
88 return "no listing file";
89 return listing;
94 public class ILAsmException : Exception {
96 string message;
97 string file_path;
98 Location location;
100 public ILAsmException (string file_path, Location location, string message)
102 this.file_path = file_path;
103 this.location = location;
104 this.message = message;
107 public ILAsmException (Location location, string message)
108 : this (null, location, message)
112 public ILAsmException (string message)
113 : this (null, null, message)
117 public override string Message {
118 get { return message; }
121 public Location Location {
122 get { return location; }
123 set { location = value; }
126 public string FilePath {
127 get { return file_path; }
128 set { file_path = value; }
131 public override string ToString ()
133 string location_str = " : ";
134 if (location != null)
135 location_str = " (" + location.line + ", " + location.column + ") : ";
137 return String.Format ("{0}{1}Error : {2}",
138 (file_path != null ? file_path : ""), location_str, message);
143 public class InternalErrorException : Exception {
144 public InternalErrorException ()
145 : base ("Internal error")
149 public InternalErrorException (string message)
150 : base (message)