2009-11-15 Jb Evain <jbevain@novell.com>
[mcs.git] / mcs / report.cs
blobb4fe05f8e1e16c99eaa5c7889fff1b326a645e06
1 //
2 // report.cs: report errors and warnings.
3 //
4 // Author: Miguel de Icaza (miguel@ximian.com)
5 // Marek Safar (marek.safar@seznam.cz)
6 //
7 // Copyright 2001 Ximian, Inc. (http://www.ximian.com)
8 //
10 using System;
11 using System.IO;
12 using System.Text;
13 using System.Collections;
14 using System.Collections.Specialized;
15 using System.Diagnostics;
16 using System.Reflection;
17 using System.Reflection.Emit;
19 namespace Mono.CSharp {
22 // Errors and warnings manager
24 public class Report {
25 /// <summary>
26 /// Whether errors should be throw an exception
27 /// </summary>
28 public bool Fatal;
30 /// <summary>
31 /// Whether warnings should be considered errors
32 /// </summary>
33 public bool WarningsAreErrors;
34 ArrayList warnings_as_error;
35 ArrayList warnings_only;
37 public static int DebugFlags = 0;
40 // Keeps track of the warnings that we are ignoring
42 public Hashtable warning_ignore_table;
44 Hashtable warning_regions_table;
46 int warning_level;
48 ReportPrinter printer;
50 int reporting_disabled;
52 /// <summary>
53 /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
54 /// </summary>
55 ArrayList extra_information = new ArrayList ();
57 //
58 // IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
60 public static readonly int[] AllWarnings = new int[] {
61 28, 67, 78,
62 105, 108, 109, 114, 162, 164, 168, 169, 183, 184, 197,
63 219, 251, 252, 253, 278, 282,
64 402, 414, 419, 420, 429, 436, 440, 458, 464, 465, 467, 469, 472,
65 612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675, 693,
66 809,
67 1030, 1058, 1066,
68 1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592,
69 1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692,
70 1700, 1717, 1718, 1720,
71 1901,
72 2002, 2023, 2029,
73 3000, 3001, 3002, 3003, 3005, 3006, 3007, 3008, 3009,
74 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019,
75 3021, 3022, 3023, 3024, 3026, 3027
78 static Report ()
80 // Just to be sure that binary search is working
81 Array.Sort (AllWarnings);
84 public Report (ReportPrinter printer)
86 if (printer == null)
87 throw new ArgumentNullException ("printer");
89 this.printer = printer;
90 warning_level = 4;
93 public void DisableReporting ()
95 ++reporting_disabled;
98 public void EnableReporting ()
100 --reporting_disabled;
103 public void FeatureIsNotAvailable (Location loc, string feature)
105 string version;
106 switch (RootContext.Version) {
107 case LanguageVersion.ISO_1:
108 version = "1.0";
109 break;
110 case LanguageVersion.ISO_2:
111 version = "2.0";
112 break;
113 case LanguageVersion.V_3:
114 version = "3.0";
115 break;
116 default:
117 throw new InternalErrorException ("Invalid feature version", RootContext.Version);
120 Error (1644, loc,
121 "Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
122 feature, version);
125 public void FeatureIsNotSupported (Location loc, string feature)
127 Error (1644, loc,
128 "Feature `{0}' is not supported in Mono mcs1 compiler. Consider using the `gmcs' compiler instead",
129 feature);
132 static bool IsValidWarning (int code)
134 return Array.BinarySearch (AllWarnings, code) >= 0;
137 bool IsWarningEnabled (int code, int level, Location loc)
139 if (WarningLevel < level)
140 return false;
142 if (warning_ignore_table != null) {
143 if (warning_ignore_table.Contains (code)) {
144 return false;
148 if (warning_regions_table == null || loc.IsNull)
149 return true;
151 WarningRegions regions = (WarningRegions) warning_regions_table [loc.Name];
152 if (regions == null)
153 return true;
155 return regions.IsWarningEnabled (code, loc.Row);
158 bool IsWarningAsError (int code)
160 bool is_error = WarningsAreErrors;
162 // Check specific list
163 if (warnings_as_error != null)
164 is_error |= warnings_as_error.Contains (code);
166 // Ignore excluded warnings
167 if (warnings_only != null && warnings_only.Contains (code))
168 is_error = false;
170 return is_error;
173 public void RuntimeMissingSupport (Location loc, string feature)
175 Error (-88, loc, "Your .NET Runtime does not support `{0}'. Please use the latest Mono runtime instead.", feature);
178 /// <summary>
179 /// In most error cases is very useful to have information about symbol that caused the error.
180 /// Call this method before you call Report.Error when it makes sense.
181 /// </summary>
182 public void SymbolRelatedToPreviousError (Location loc, string symbol)
184 SymbolRelatedToPreviousError (loc.ToString (), symbol);
187 public void SymbolRelatedToPreviousError (MemberInfo mi)
189 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
190 return;
192 Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
193 if (TypeManager.IsDelegateType (dt)) {
194 SymbolRelatedToPreviousError (dt);
195 return;
198 DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
199 if (temp_ds == null) {
200 SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
201 } else {
202 MethodBase mb = mi as MethodBase;
203 if (mb != null) {
204 mb = TypeManager.DropGenericMethodArguments (mb);
205 IMethodData md = TypeManager.GetMethod (mb);
206 if (md != null)
207 SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
209 return;
212 // FIXME: Completely wrong, it has to use FindMembers
213 MemberCore mc = temp_ds.GetDefinition (mi.Name);
214 if (mc != null)
215 SymbolRelatedToPreviousError (mc);
219 public void SymbolRelatedToPreviousError (MemberCore mc)
221 SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
224 public void SymbolRelatedToPreviousError (Type type)
226 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
227 return;
229 type = TypeManager.DropGenericTypeArguments (type);
231 if (TypeManager.IsGenericParameter (type)) {
232 TypeParameter tp = TypeManager.LookupTypeParameter (type);
233 if (tp != null) {
234 SymbolRelatedToPreviousError (tp.Location, "");
235 return;
239 if (type is TypeBuilder) {
240 DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
241 SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
242 } else if (TypeManager.HasElementType (type)) {
243 SymbolRelatedToPreviousError (TypeManager.GetElementType (type));
244 } else {
245 SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
249 void SymbolRelatedToPreviousError (string loc, string symbol)
251 string msg = String.Format ("{0} (Location of the symbol related to previous ", loc);
252 if (extra_information.Contains (msg))
253 return;
255 extra_information.Add (msg);
258 public void AddWarningAsError (string warningId)
260 int id;
261 try {
262 id = int.Parse (warningId);
263 } catch {
264 id = -1;
267 if (!CheckWarningCode (id, warningId, Location.Null))
268 return;
270 if (warnings_as_error == null)
271 warnings_as_error = new ArrayList ();
273 warnings_as_error.Add (id);
276 public void RemoveWarningAsError (string warningId)
278 int id;
279 try {
280 id = int.Parse (warningId);
281 } catch {
282 id = -1;
285 if (!CheckWarningCode (id, warningId, Location.Null))
286 return;
288 if (warnings_only == null)
289 warnings_only = new ArrayList ();
291 warnings_only.Add (id);
294 public bool CheckWarningCode (int code, Location loc)
296 return CheckWarningCode (code, code.ToString (), loc);
299 public bool CheckWarningCode (int code, string scode, Location loc)
301 if (IsValidWarning (code))
302 return true;
304 Warning (1691, 1, loc, "`{0}' is not a valid warning number", scode);
305 return false;
308 public void ExtraInformation (Location loc, string msg)
310 extra_information.Add (String.Format ("{0} {1}", loc, msg));
313 public WarningRegions RegisterWarningRegion (Location location)
315 if (warning_regions_table == null)
316 warning_regions_table = new Hashtable ();
318 WarningRegions regions = (WarningRegions)warning_regions_table [location.Name];
319 if (regions == null) {
320 regions = new WarningRegions ();
321 warning_regions_table.Add (location.Name, regions);
323 return regions;
326 public void Warning (int code, int level, Location loc, string message)
328 if (reporting_disabled > 0)
329 return;
331 if (!IsWarningEnabled (code, level, loc))
332 return;
334 AbstractMessage msg;
335 if (IsWarningAsError (code))
336 msg = new ErrorMessage (code, loc, message, extra_information);
337 else
338 msg = new WarningMessage (code, loc, message, extra_information);
340 extra_information.Clear ();
341 printer.Print (msg);
344 public void Warning (int code, int level, Location loc, string format, string arg)
346 Warning (code, level, loc, String.Format (format, arg));
349 public void Warning (int code, int level, Location loc, string format, string arg1, string arg2)
351 Warning (code, level, loc, String.Format (format, arg1, arg2));
354 public void Warning (int code, int level, Location loc, string format, params object[] args)
356 Warning (code, level, loc, String.Format (format, args));
359 public void Warning (int code, int level, string message)
361 Warning (code, level, Location.Null, message);
364 public void Warning (int code, int level, string format, string arg)
366 Warning (code, level, Location.Null, format, arg);
369 public void Warning (int code, int level, string format, string arg1, string arg2)
371 Warning (code, level, Location.Null, format, arg1, arg2);
374 public void Warning (int code, int level, string format, params string[] args)
376 Warning (code, level, Location.Null, String.Format (format, args));
380 // Warnings encountered so far
382 public int Warnings {
383 get { return printer.WarningsCount; }
386 public void Error (int code, Location loc, string error)
388 if (reporting_disabled > 0)
389 return;
391 ErrorMessage msg = new ErrorMessage (code, loc, error, extra_information);
392 extra_information.Clear ();
394 printer.Print (msg);
396 if (Fatal)
397 throw new Exception (msg.Text);
400 public void Error (int code, Location loc, string format, string arg)
402 Error (code, loc, String.Format (format, arg));
405 public void Error (int code, Location loc, string format, string arg1, string arg2)
407 Error (code, loc, String.Format (format, arg1, arg2));
410 public void Error (int code, Location loc, string format, params object[] args)
412 Error (code, loc, String.Format (format, args));
415 public void Error (int code, string error)
417 Error (code, Location.Null, error);
420 public void Error (int code, string format, string arg)
422 Error (code, Location.Null, format, arg);
425 public void Error (int code, string format, string arg1, string arg2)
427 Error (code, Location.Null, format, arg1, arg2);
430 public void Error (int code, string format, params string[] args)
432 Error (code, Location.Null, String.Format (format, args));
436 // Errors encountered so far
438 public int Errors {
439 get { return printer.ErrorsCount; }
442 public ReportPrinter Printer {
443 get { return printer; }
446 public void SetIgnoreWarning (int code)
448 if (warning_ignore_table == null)
449 warning_ignore_table = new Hashtable ();
451 warning_ignore_table [code] = true;
454 public ReportPrinter SetPrinter (ReportPrinter printer)
456 ReportPrinter old = this.printer;
457 this.printer = printer;
458 return old;
461 public int WarningLevel {
462 get {
463 return warning_level;
465 set {
466 warning_level = value;
470 [Conditional ("MCS_DEBUG")]
471 static public void Debug (string message, params object[] args)
473 Debug (4, message, args);
476 [Conditional ("MCS_DEBUG")]
477 static public void Debug (int category, string message, params object[] args)
479 if ((category & DebugFlags) == 0)
480 return;
482 StringBuilder sb = new StringBuilder (message);
484 if ((args != null) && (args.Length > 0)) {
485 sb.Append (": ");
487 bool first = true;
488 foreach (object arg in args) {
489 if (first)
490 first = false;
491 else
492 sb.Append (", ");
493 if (arg == null)
494 sb.Append ("null");
495 else if (arg is ICollection)
496 sb.Append (PrintCollection ((ICollection) arg));
497 else
498 sb.Append (arg);
502 Console.WriteLine (sb.ToString ());
505 static public string PrintCollection (ICollection collection)
507 StringBuilder sb = new StringBuilder ();
509 sb.Append (collection.GetType ());
510 sb.Append ("(");
512 bool first = true;
513 foreach (object o in collection) {
514 if (first)
515 first = false;
516 else
517 sb.Append (", ");
518 sb.Append (o);
521 sb.Append (")");
522 return sb.ToString ();
526 public abstract class AbstractMessage
528 readonly string[] extra_info;
529 protected readonly int code;
530 protected readonly Location location;
531 readonly string message;
533 protected AbstractMessage (int code, Location loc, string msg, ArrayList extraInfo)
535 this.code = code;
536 if (code < 0)
537 this.code = 8000 - code;
539 this.location = loc;
540 this.message = msg;
541 if (extraInfo.Count != 0) {
542 this.extra_info = (string[])extraInfo.ToArray (typeof (string));
546 protected AbstractMessage (AbstractMessage aMsg)
548 this.code = aMsg.code;
549 this.location = aMsg.location;
550 this.message = aMsg.message;
551 this.extra_info = aMsg.extra_info;
554 public int Code {
555 get { return code; }
558 public override bool Equals (object obj)
560 AbstractMessage msg = obj as AbstractMessage;
561 if (msg == null)
562 return false;
564 return code == msg.code && location.Equals (msg.location) && message == msg.message;
567 public override int GetHashCode ()
569 return code.GetHashCode ();
572 public abstract bool IsWarning { get; }
574 public Location Location {
575 get { return location; }
578 public abstract string MessageType { get; }
580 public string[] RelatedSymbols {
581 get { return extra_info; }
584 public string Text {
585 get { return message; }
589 sealed class WarningMessage : AbstractMessage
591 public WarningMessage (int code, Location loc, string message, ArrayList extra_info)
592 : base (code, loc, message, extra_info)
596 public override bool IsWarning {
597 get { return true; }
600 public override string MessageType {
601 get {
602 return "warning";
607 sealed class ErrorMessage : AbstractMessage
609 public ErrorMessage (int code, Location loc, string message, ArrayList extraInfo)
610 : base (code, loc, message, extraInfo)
614 public ErrorMessage (AbstractMessage aMsg)
615 : base (aMsg)
619 public override bool IsWarning {
620 get { return false; }
623 public override string MessageType {
624 get {
625 return "error";
631 // Generic base for any message writer
633 public abstract class ReportPrinter
635 /// <summary>
636 /// Whether to dump a stack trace on errors.
637 /// </summary>
638 public bool Stacktrace;
640 int warnings, errors;
642 public int WarningsCount {
643 get { return warnings; }
646 public int ErrorsCount {
647 get { return errors; }
650 protected virtual string FormatText (string txt)
652 return txt;
656 // When (symbols related to previous ...) can be used
658 public virtual bool HasRelatedSymbolSupport {
659 get { return true; }
662 public virtual void Print (AbstractMessage msg)
664 if (msg.IsWarning)
665 ++warnings;
666 else
667 ++errors;
670 protected void Print (AbstractMessage msg, TextWriter output)
672 StringBuilder txt = new StringBuilder ();
673 if (!msg.Location.IsNull) {
674 txt.Append (msg.Location.ToString ());
675 txt.Append (" ");
678 txt.AppendFormat ("{0} CS{1:0000}: {2}", msg.MessageType, msg.Code, msg.Text);
680 if (!msg.IsWarning)
681 output.WriteLine (FormatText (txt.ToString ()));
682 else
683 output.WriteLine (txt.ToString ());
685 if (msg.RelatedSymbols != null) {
686 foreach (string s in msg.RelatedSymbols)
687 output.WriteLine (s + msg.MessageType + ")");
693 // Default message recorder, it uses two types of message groups.
694 // Common messages: messages reported in all sessions.
695 // Merged messages: union of all messages in all sessions.
697 // Used by the Lambda expressions to compile the code with various
698 // parameter values, or by attribute resolver
700 class SessionReportPrinter : ReportPrinter
702 ArrayList session_messages;
704 // A collection of exactly same messages reported in all sessions
706 ArrayList common_messages;
709 // A collection of unique messages reported in all sessions
711 ArrayList merged_messages;
713 public override void Print (AbstractMessage msg)
716 // This line is useful when debugging recorded messages
718 // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
720 if (session_messages == null)
721 session_messages = new ArrayList ();
723 session_messages.Add (msg);
725 base.Print (msg);
728 public void EndSession ()
730 if (session_messages == null)
731 return;
734 // Handles the first session
736 if (common_messages == null) {
737 common_messages = new ArrayList (session_messages);
738 merged_messages = session_messages;
739 session_messages = null;
740 return;
744 // Store common messages if any
746 for (int i = 0; i < common_messages.Count; ++i) {
747 AbstractMessage cmsg = (AbstractMessage) common_messages[i];
748 bool common_msg_found = false;
749 foreach (AbstractMessage msg in session_messages) {
750 if (cmsg.Equals (msg)) {
751 common_msg_found = true;
752 break;
756 if (!common_msg_found)
757 common_messages.RemoveAt (i);
761 // Merge session and previous messages
763 for (int i = 0; i < session_messages.Count; ++i) {
764 AbstractMessage msg = (AbstractMessage) session_messages[i];
765 bool msg_found = false;
766 for (int ii = 0; ii < merged_messages.Count; ++ii) {
767 if (msg.Equals (merged_messages[ii])) {
768 msg_found = true;
769 break;
773 if (!msg_found)
774 merged_messages.Add (msg);
778 public bool IsEmpty {
779 get {
780 return merged_messages == null && common_messages == null;
785 // Prints collected messages, common messages have a priority
787 public bool Merge (ReportPrinter dest)
789 ArrayList messages_to_print = merged_messages;
790 if (common_messages != null && common_messages.Count > 0) {
791 messages_to_print = common_messages;
794 if (messages_to_print == null)
795 return false;
797 foreach (AbstractMessage msg in messages_to_print)
798 dest.Print (msg);
800 return true;
804 class StreamReportPrinter : ReportPrinter
806 readonly TextWriter writer;
808 public StreamReportPrinter (TextWriter writer)
810 this.writer = writer;
813 public override void Print (AbstractMessage msg)
815 Print (msg, writer);
816 base.Print (msg);
820 class ConsoleReportPrinter : StreamReportPrinter
822 static readonly string prefix, postfix;
824 static ConsoleReportPrinter ()
826 string term = Environment.GetEnvironmentVariable ("TERM");
827 bool xterm_colors = false;
829 switch (term){
830 case "xterm":
831 case "rxvt":
832 case "rxvt-unicode":
833 if (Environment.GetEnvironmentVariable ("COLORTERM") != null){
834 xterm_colors = true;
836 break;
838 case "xterm-color":
839 xterm_colors = true;
840 break;
842 if (!xterm_colors)
843 return;
845 if (!(UnixUtils.isatty (1) && UnixUtils.isatty (2)))
846 return;
848 string config = Environment.GetEnvironmentVariable ("MCS_COLORS");
849 if (config == null){
850 config = "errors=red";
851 //config = "brightwhite,red";
854 if (config == "disable")
855 return;
857 if (!config.StartsWith ("errors="))
858 return;
860 config = config.Substring (7);
862 int p = config.IndexOf (",");
863 if (p == -1)
864 prefix = GetForeground (config);
865 else
866 prefix = GetBackground (config.Substring (p+1)) + GetForeground (config.Substring (0, p));
867 postfix = "\x001b[0m";
870 public ConsoleReportPrinter ()
871 : base (Console.Error)
875 public ConsoleReportPrinter (TextWriter writer)
876 : base (writer)
880 static int NameToCode (string s)
882 switch (s) {
883 case "black":
884 return 0;
885 case "red":
886 return 1;
887 case "green":
888 return 2;
889 case "yellow":
890 return 3;
891 case "blue":
892 return 4;
893 case "magenta":
894 return 5;
895 case "cyan":
896 return 6;
897 case "grey":
898 case "white":
899 return 7;
901 return 7;
905 // maps a color name to its xterm color code
907 static string GetForeground (string s)
909 string highcode;
911 if (s.StartsWith ("bright")) {
912 highcode = "1;";
913 s = s.Substring (6);
914 } else
915 highcode = "";
917 return "\x001b[" + highcode + (30 + NameToCode (s)).ToString () + "m";
920 static string GetBackground (string s)
922 return "\x001b[" + (40 + NameToCode (s)).ToString () + "m";
925 protected override string FormatText (string txt)
927 if (prefix != null)
928 return prefix + txt + postfix;
930 return txt;
933 static string FriendlyStackTrace (StackTrace t)
935 StringBuilder sb = new StringBuilder ();
937 bool foundUserCode = false;
939 for (int i = 0; i < t.FrameCount; i++) {
940 StackFrame f = t.GetFrame (i);
941 MethodBase mb = f.GetMethod ();
943 if (!foundUserCode && mb.ReflectedType == typeof (Report))
944 continue;
946 foundUserCode = true;
948 sb.Append ("\tin ");
950 if (f.GetFileLineNumber () > 0)
951 sb.AppendFormat ("(at {0}:{1}) ", f.GetFileName (), f.GetFileLineNumber ());
953 sb.AppendFormat ("{0}.{1} (", mb.ReflectedType.Name, mb.Name);
955 bool first = true;
956 foreach (ParameterInfo pi in mb.GetParameters ()) {
957 if (!first)
958 sb.Append (", ");
959 first = false;
961 sb.Append (TypeManager.CSharpName (pi.ParameterType));
963 sb.Append (")\n");
966 return sb.ToString ();
969 public override void Print (AbstractMessage msg)
971 base.Print (msg);
973 if (Stacktrace)
974 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
977 public static string FriendlyStackTrace (Exception e)
979 return FriendlyStackTrace (new StackTrace (e, true));
982 public static void StackTrace ()
984 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
988 public enum TimerType {
989 FindMembers = 0,
990 TcFindMembers = 1,
991 MemberLookup = 2,
992 CachedLookup = 3,
993 CacheInit = 4,
994 MiscTimer = 5,
995 CountTimers = 6
998 public enum CounterType {
999 FindMembers = 0,
1000 MemberCache = 1,
1001 MiscCounter = 2,
1002 CountCounters = 3
1005 public class Timer
1007 static DateTime[] timer_start;
1008 static TimeSpan[] timers;
1009 static long[] timer_counters;
1010 static long[] counters;
1012 static Timer ()
1014 timer_start = new DateTime [(int) TimerType.CountTimers];
1015 timers = new TimeSpan [(int) TimerType.CountTimers];
1016 timer_counters = new long [(int) TimerType.CountTimers];
1017 counters = new long [(int) CounterType.CountCounters];
1019 for (int i = 0; i < (int) TimerType.CountTimers; i++) {
1020 timer_start [i] = DateTime.Now;
1021 timers [i] = TimeSpan.Zero;
1025 [Conditional("TIMER")]
1026 static public void IncrementCounter (CounterType which)
1028 ++counters [(int) which];
1031 [Conditional("TIMER")]
1032 static public void StartTimer (TimerType which)
1034 timer_start [(int) which] = DateTime.Now;
1037 [Conditional("TIMER")]
1038 static public void StopTimer (TimerType which)
1040 timers [(int) which] += DateTime.Now - timer_start [(int) which];
1041 ++timer_counters [(int) which];
1044 [Conditional("TIMER")]
1045 static public void ShowTimers ()
1047 ShowTimer (TimerType.FindMembers, "- FindMembers timer");
1048 ShowTimer (TimerType.TcFindMembers, "- TypeContainer.FindMembers timer");
1049 ShowTimer (TimerType.MemberLookup, "- MemberLookup timer");
1050 ShowTimer (TimerType.CachedLookup, "- CachedLookup timer");
1051 ShowTimer (TimerType.CacheInit, "- Cache init");
1052 ShowTimer (TimerType.MiscTimer, "- Misc timer");
1054 ShowCounter (CounterType.FindMembers, "- Find members");
1055 ShowCounter (CounterType.MemberCache, "- Member cache");
1056 ShowCounter (CounterType.MiscCounter, "- Misc counter");
1059 static public void ShowCounter (CounterType which, string msg)
1061 Console.WriteLine ("{0} {1}", counters [(int) which], msg);
1064 static public void ShowTimer (TimerType which, string msg)
1066 Console.WriteLine (
1067 "[{0:00}:{1:000}] {2} (used {3} times)",
1068 (int) timers [(int) which].TotalSeconds,
1069 timers [(int) which].Milliseconds, msg,
1070 timer_counters [(int) which]);
1074 public class InternalErrorException : Exception {
1075 public InternalErrorException (MemberCore mc, Exception e)
1076 : base (mc.Location + " " + mc.GetSignatureForError (), e)
1080 public InternalErrorException ()
1081 : base ("Internal error")
1085 public InternalErrorException (string message)
1086 : base (message)
1090 public InternalErrorException (string message, params object[] args)
1091 : base (String.Format (message, args))
1094 public InternalErrorException (Exception e, Location loc)
1095 : base (loc.ToString (), e)
1100 /// <summary>
1101 /// Handles #pragma warning
1102 /// </summary>
1103 public class WarningRegions {
1105 abstract class PragmaCmd
1107 public int Line;
1109 protected PragmaCmd (int line)
1111 Line = line;
1114 public abstract bool IsEnabled (int code, bool previous);
1117 class Disable : PragmaCmd
1119 int code;
1120 public Disable (int line, int code)
1121 : base (line)
1123 this.code = code;
1126 public override bool IsEnabled (int code, bool previous)
1128 return this.code == code ? false : previous;
1132 class DisableAll : PragmaCmd
1134 public DisableAll (int line)
1135 : base (line) {}
1137 public override bool IsEnabled(int code, bool previous)
1139 return false;
1143 class Enable : PragmaCmd
1145 int code;
1146 public Enable (int line, int code)
1147 : base (line)
1149 this.code = code;
1152 public override bool IsEnabled(int code, bool previous)
1154 return this.code == code ? true : previous;
1158 class EnableAll : PragmaCmd
1160 public EnableAll (int line)
1161 : base (line) {}
1163 public override bool IsEnabled(int code, bool previous)
1165 return true;
1170 ArrayList regions = new ArrayList ();
1172 public void WarningDisable (int line)
1174 regions.Add (new DisableAll (line));
1177 public void WarningDisable (Location location, int code, Report Report)
1179 if (Report.CheckWarningCode (code, location))
1180 regions.Add (new Disable (location.Row, code));
1183 public void WarningEnable (int line)
1185 regions.Add (new EnableAll (line));
1188 public void WarningEnable (Location location, int code, Report Report)
1190 if (Report.CheckWarningCode (code, location))
1191 regions.Add (new Enable (location.Row, code));
1194 public bool IsWarningEnabled (int code, int src_line)
1196 bool result = true;
1197 foreach (PragmaCmd pragma in regions) {
1198 if (src_line < pragma.Line)
1199 break;
1201 result = pragma.IsEnabled (code, result);
1203 return result;