Report.cs 4.9 KB

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