2010-01-12 Zoltan Varga <vargaz@gmail.com>
[mcs.git] / mcs / report.cs
blobaf4724bdd6c33f686455846c93eb1c2c58116b6a
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 419, 420, 429, 436, 440, 465, 467, 469, 472,
65 612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675,
66 809,
67 1030, 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 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, 3026, 3027,
77 414, // Non ISO-1 warnings
78 #if GMCS_SOURCE
79 402, 458, 464, 693, 1058, 1700, 3024
80 #endif
83 static Report ()
85 // Just to be sure that binary search is working
86 Array.Sort (AllWarnings);
89 public Report (ReportPrinter printer)
91 if (printer == null)
92 throw new ArgumentNullException ("printer");
94 this.printer = printer;
95 warning_level = 4;
98 public void DisableReporting ()
100 ++reporting_disabled;
103 public void EnableReporting ()
105 --reporting_disabled;
108 public void FeatureIsNotAvailable (Location loc, string feature)
110 string version;
111 switch (RootContext.Version) {
112 case LanguageVersion.ISO_1:
113 version = "1.0";
114 break;
115 case LanguageVersion.ISO_2:
116 version = "2.0";
117 break;
118 case LanguageVersion.V_3:
119 version = "3.0";
120 break;
121 default:
122 throw new InternalErrorException ("Invalid feature version", RootContext.Version);
125 Error (1644, loc,
126 "Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
127 feature, version);
130 public void FeatureIsNotSupported (Location loc, string feature)
132 Error (1644, loc,
133 "Feature `{0}' is not supported in Mono mcs1 compiler. Consider using the `gmcs' compiler instead",
134 feature);
137 static bool IsValidWarning (int code)
139 return Array.BinarySearch (AllWarnings, code) >= 0;
142 bool IsWarningEnabled (int code, int level, Location loc)
144 if (WarningLevel < level)
145 return false;
147 if (warning_ignore_table != null) {
148 if (warning_ignore_table.Contains (code)) {
149 return false;
153 if (warning_regions_table == null || loc.IsNull)
154 return true;
156 WarningRegions regions = (WarningRegions) warning_regions_table [loc.Name];
157 if (regions == null)
158 return true;
160 return regions.IsWarningEnabled (code, loc.Row);
163 bool IsWarningAsError (int code)
165 bool is_error = WarningsAreErrors;
167 // Check specific list
168 if (warnings_as_error != null)
169 is_error |= warnings_as_error.Contains (code);
171 // Ignore excluded warnings
172 if (warnings_only != null && warnings_only.Contains (code))
173 is_error = false;
175 return is_error;
178 public void RuntimeMissingSupport (Location loc, string feature)
180 Error (-88, loc, "Your .NET Runtime does not support `{0}'. Please use the latest Mono runtime instead.", feature);
183 /// <summary>
184 /// In most error cases is very useful to have information about symbol that caused the error.
185 /// Call this method before you call Report.Error when it makes sense.
186 /// </summary>
187 public void SymbolRelatedToPreviousError (Location loc, string symbol)
189 SymbolRelatedToPreviousError (loc.ToString (), symbol);
192 public void SymbolRelatedToPreviousError (MemberInfo mi)
194 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
195 return;
197 Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
198 if (TypeManager.IsDelegateType (dt)) {
199 SymbolRelatedToPreviousError (dt);
200 return;
203 DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
204 if (temp_ds == null) {
205 SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
206 } else {
207 MethodBase mb = mi as MethodBase;
208 if (mb != null) {
209 mb = TypeManager.DropGenericMethodArguments (mb);
210 IMethodData md = TypeManager.GetMethod (mb);
211 if (md != null)
212 SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
214 return;
217 // FIXME: Completely wrong, it has to use FindMembers
218 MemberCore mc = temp_ds.GetDefinition (mi.Name);
219 if (mc != null)
220 SymbolRelatedToPreviousError (mc);
224 public void SymbolRelatedToPreviousError (MemberCore mc)
226 SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
229 public void SymbolRelatedToPreviousError (Type type)
231 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
232 return;
234 type = TypeManager.DropGenericTypeArguments (type);
236 if (TypeManager.IsGenericParameter (type)) {
237 TypeParameter tp = TypeManager.LookupTypeParameter (type);
238 if (tp != null) {
239 SymbolRelatedToPreviousError (tp.Location, "");
240 return;
244 if (type is TypeBuilder) {
245 DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
246 SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
247 } else if (TypeManager.HasElementType (type)) {
248 SymbolRelatedToPreviousError (TypeManager.GetElementType (type));
249 } else {
250 SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
254 void SymbolRelatedToPreviousError (string loc, string symbol)
256 string msg = String.Format ("{0} (Location of the symbol related to previous ", loc);
257 if (extra_information.Contains (msg))
258 return;
260 extra_information.Add (msg);
263 public void AddWarningAsError (string warningId)
265 int id;
266 try {
267 id = int.Parse (warningId);
268 } catch {
269 id = -1;
272 if (!CheckWarningCode (id, warningId, Location.Null))
273 return;
275 if (warnings_as_error == null)
276 warnings_as_error = new ArrayList ();
278 warnings_as_error.Add (id);
281 public void RemoveWarningAsError (string warningId)
283 int id;
284 try {
285 id = int.Parse (warningId);
286 } catch {
287 id = -1;
290 if (!CheckWarningCode (id, warningId, Location.Null))
291 return;
293 if (warnings_only == null)
294 warnings_only = new ArrayList ();
296 warnings_only.Add (id);
299 public bool CheckWarningCode (int code, Location loc)
301 return CheckWarningCode (code, code.ToString (), loc);
304 public bool CheckWarningCode (int code, string scode, Location loc)
306 if (IsValidWarning (code))
307 return true;
309 Warning (1691, 1, loc, "`{0}' is not a valid warning number", scode);
310 return false;
313 public void ExtraInformation (Location loc, string msg)
315 extra_information.Add (String.Format ("{0} {1}", loc, msg));
318 public WarningRegions RegisterWarningRegion (Location location)
320 if (warning_regions_table == null)
321 warning_regions_table = new Hashtable ();
323 WarningRegions regions = (WarningRegions)warning_regions_table [location.Name];
324 if (regions == null) {
325 regions = new WarningRegions ();
326 warning_regions_table.Add (location.Name, regions);
328 return regions;
331 public void Warning (int code, int level, Location loc, string message)
333 if (reporting_disabled > 0)
334 return;
336 if (!IsWarningEnabled (code, level, loc))
337 return;
339 AbstractMessage msg;
340 if (IsWarningAsError (code))
341 msg = new ErrorMessage (code, loc, message, extra_information);
342 else
343 msg = new WarningMessage (code, loc, message, extra_information);
345 extra_information.Clear ();
346 printer.Print (msg);
349 public void Warning (int code, int level, Location loc, string format, string arg)
351 Warning (code, level, loc, String.Format (format, arg));
354 public void Warning (int code, int level, Location loc, string format, string arg1, string arg2)
356 Warning (code, level, loc, String.Format (format, arg1, arg2));
359 public void Warning (int code, int level, Location loc, string format, params object[] args)
361 Warning (code, level, loc, String.Format (format, args));
364 public void Warning (int code, int level, string message)
366 Warning (code, level, Location.Null, message);
369 public void Warning (int code, int level, string format, string arg)
371 Warning (code, level, Location.Null, format, arg);
374 public void Warning (int code, int level, string format, string arg1, string arg2)
376 Warning (code, level, Location.Null, format, arg1, arg2);
379 public void Warning (int code, int level, string format, params string[] args)
381 Warning (code, level, Location.Null, String.Format (format, args));
385 // Warnings encountered so far
387 public int Warnings {
388 get { return printer.WarningsCount; }
391 public void Error (int code, Location loc, string error)
393 if (reporting_disabled > 0)
394 return;
396 ErrorMessage msg = new ErrorMessage (code, loc, error, extra_information);
397 extra_information.Clear ();
399 printer.Print (msg);
401 if (Fatal)
402 throw new Exception (msg.Text);
405 public void Error (int code, Location loc, string format, string arg)
407 Error (code, loc, String.Format (format, arg));
410 public void Error (int code, Location loc, string format, string arg1, string arg2)
412 Error (code, loc, String.Format (format, arg1, arg2));
415 public void Error (int code, Location loc, string format, params object[] args)
417 Error (code, loc, String.Format (format, args));
420 public void Error (int code, string error)
422 Error (code, Location.Null, error);
425 public void Error (int code, string format, string arg)
427 Error (code, Location.Null, format, arg);
430 public void Error (int code, string format, string arg1, string arg2)
432 Error (code, Location.Null, format, arg1, arg2);
435 public void Error (int code, string format, params string[] args)
437 Error (code, Location.Null, String.Format (format, args));
441 // Errors encountered so far
443 public int Errors {
444 get { return printer.ErrorsCount; }
447 public ReportPrinter Printer {
448 get { return printer; }
451 public void SetIgnoreWarning (int code)
453 if (warning_ignore_table == null)
454 warning_ignore_table = new Hashtable ();
456 warning_ignore_table [code] = true;
459 public ReportPrinter SetPrinter (ReportPrinter printer)
461 ReportPrinter old = this.printer;
462 this.printer = printer;
463 return old;
466 public int WarningLevel {
467 get {
468 return warning_level;
470 set {
471 warning_level = value;
475 [Conditional ("MCS_DEBUG")]
476 static public void Debug (string message, params object[] args)
478 Debug (4, message, args);
481 [Conditional ("MCS_DEBUG")]
482 static public void Debug (int category, string message, params object[] args)
484 if ((category & DebugFlags) == 0)
485 return;
487 StringBuilder sb = new StringBuilder (message);
489 if ((args != null) && (args.Length > 0)) {
490 sb.Append (": ");
492 bool first = true;
493 foreach (object arg in args) {
494 if (first)
495 first = false;
496 else
497 sb.Append (", ");
498 if (arg == null)
499 sb.Append ("null");
500 else if (arg is ICollection)
501 sb.Append (PrintCollection ((ICollection) arg));
502 else
503 sb.Append (arg);
507 Console.WriteLine (sb.ToString ());
510 static public string PrintCollection (ICollection collection)
512 StringBuilder sb = new StringBuilder ();
514 sb.Append (collection.GetType ());
515 sb.Append ("(");
517 bool first = true;
518 foreach (object o in collection) {
519 if (first)
520 first = false;
521 else
522 sb.Append (", ");
523 sb.Append (o);
526 sb.Append (")");
527 return sb.ToString ();
531 public abstract class AbstractMessage
533 readonly string[] extra_info;
534 protected readonly int code;
535 protected readonly Location location;
536 readonly string message;
538 protected AbstractMessage (int code, Location loc, string msg, ArrayList extraInfo)
540 this.code = code;
541 if (code < 0)
542 this.code = 8000 - code;
544 this.location = loc;
545 this.message = msg;
546 if (extraInfo.Count != 0) {
547 this.extra_info = (string[])extraInfo.ToArray (typeof (string));
551 protected AbstractMessage (AbstractMessage aMsg)
553 this.code = aMsg.code;
554 this.location = aMsg.location;
555 this.message = aMsg.message;
556 this.extra_info = aMsg.extra_info;
559 public int Code {
560 get { return code; }
563 public override bool Equals (object obj)
565 AbstractMessage msg = obj as AbstractMessage;
566 if (msg == null)
567 return false;
569 return code == msg.code && location.Equals (msg.location) && message == msg.message;
572 public override int GetHashCode ()
574 return code.GetHashCode ();
577 public abstract bool IsWarning { get; }
579 public Location Location {
580 get { return location; }
583 public abstract string MessageType { get; }
585 public string[] RelatedSymbols {
586 get { return extra_info; }
589 public string Text {
590 get { return message; }
594 sealed class WarningMessage : AbstractMessage
596 public WarningMessage (int code, Location loc, string message, ArrayList extra_info)
597 : base (code, loc, message, extra_info)
601 public override bool IsWarning {
602 get { return true; }
605 public override string MessageType {
606 get {
607 return "warning";
612 sealed class ErrorMessage : AbstractMessage
614 public ErrorMessage (int code, Location loc, string message, ArrayList extraInfo)
615 : base (code, loc, message, extraInfo)
619 public ErrorMessage (AbstractMessage aMsg)
620 : base (aMsg)
624 public override bool IsWarning {
625 get { return false; }
628 public override string MessageType {
629 get {
630 return "error";
636 // Generic base for any message writer
638 public abstract class ReportPrinter
640 /// <summary>
641 /// Whether to dump a stack trace on errors.
642 /// </summary>
643 public bool Stacktrace;
645 int warnings, errors;
647 public int WarningsCount {
648 get { return warnings; }
651 public int ErrorsCount {
652 get { return errors; }
655 protected virtual string FormatText (string txt)
657 return txt;
661 // When (symbols related to previous ...) can be used
663 public virtual bool HasRelatedSymbolSupport {
664 get { return true; }
667 public virtual void Print (AbstractMessage msg)
669 if (msg.IsWarning)
670 ++warnings;
671 else
672 ++errors;
675 protected void Print (AbstractMessage msg, TextWriter output)
677 StringBuilder txt = new StringBuilder ();
678 if (!msg.Location.IsNull) {
679 txt.Append (msg.Location.ToString ());
680 txt.Append (" ");
683 txt.AppendFormat ("{0} CS{1:0000}: {2}", msg.MessageType, msg.Code, msg.Text);
685 if (!msg.IsWarning)
686 output.WriteLine (FormatText (txt.ToString ()));
687 else
688 output.WriteLine (txt.ToString ());
690 if (msg.RelatedSymbols != null) {
691 foreach (string s in msg.RelatedSymbols)
692 output.WriteLine (s + msg.MessageType + ")");
698 // Default message recorder, it uses two types of message groups.
699 // Common messages: messages reported in all sessions.
700 // Merged messages: union of all messages in all sessions.
702 // Used by the Lambda expressions to compile the code with various
703 // parameter values, or by attribute resolver
705 class SessionReportPrinter : ReportPrinter
707 ArrayList session_messages;
709 // A collection of exactly same messages reported in all sessions
711 ArrayList common_messages;
714 // A collection of unique messages reported in all sessions
716 ArrayList merged_messages;
718 public override void Print (AbstractMessage msg)
721 // This line is useful when debugging recorded messages
723 // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
725 if (session_messages == null)
726 session_messages = new ArrayList ();
728 session_messages.Add (msg);
730 base.Print (msg);
733 public void EndSession ()
735 if (session_messages == null)
736 return;
739 // Handles the first session
741 if (common_messages == null) {
742 common_messages = new ArrayList (session_messages);
743 merged_messages = session_messages;
744 session_messages = null;
745 return;
749 // Store common messages if any
751 for (int i = 0; i < common_messages.Count; ++i) {
752 AbstractMessage cmsg = (AbstractMessage) common_messages[i];
753 bool common_msg_found = false;
754 foreach (AbstractMessage msg in session_messages) {
755 if (cmsg.Equals (msg)) {
756 common_msg_found = true;
757 break;
761 if (!common_msg_found)
762 common_messages.RemoveAt (i);
766 // Merge session and previous messages
768 for (int i = 0; i < session_messages.Count; ++i) {
769 AbstractMessage msg = (AbstractMessage) session_messages[i];
770 bool msg_found = false;
771 for (int ii = 0; ii < merged_messages.Count; ++ii) {
772 if (msg.Equals (merged_messages[ii])) {
773 msg_found = true;
774 break;
778 if (!msg_found)
779 merged_messages.Add (msg);
783 public bool IsEmpty {
784 get {
785 return merged_messages == null && common_messages == null;
790 // Prints collected messages, common messages have a priority
792 public bool Merge (ReportPrinter dest)
794 ArrayList messages_to_print = merged_messages;
795 if (common_messages != null && common_messages.Count > 0) {
796 messages_to_print = common_messages;
799 if (messages_to_print == null)
800 return false;
802 foreach (AbstractMessage msg in messages_to_print)
803 dest.Print (msg);
805 return true;
809 class StreamReportPrinter : ReportPrinter
811 readonly TextWriter writer;
813 public StreamReportPrinter (TextWriter writer)
815 this.writer = writer;
818 public override void Print (AbstractMessage msg)
820 Print (msg, writer);
821 base.Print (msg);
825 class ConsoleReportPrinter : StreamReportPrinter
827 static readonly string prefix, postfix;
829 static ConsoleReportPrinter ()
831 string term = Environment.GetEnvironmentVariable ("TERM");
832 bool xterm_colors = false;
834 switch (term){
835 case "xterm":
836 case "rxvt":
837 case "rxvt-unicode":
838 if (Environment.GetEnvironmentVariable ("COLORTERM") != null){
839 xterm_colors = true;
841 break;
843 case "xterm-color":
844 xterm_colors = true;
845 break;
847 if (!xterm_colors)
848 return;
850 if (!(UnixUtils.isatty (1) && UnixUtils.isatty (2)))
851 return;
853 string config = Environment.GetEnvironmentVariable ("MCS_COLORS");
854 if (config == null){
855 config = "errors=red";
856 //config = "brightwhite,red";
859 if (config == "disable")
860 return;
862 if (!config.StartsWith ("errors="))
863 return;
865 config = config.Substring (7);
867 int p = config.IndexOf (",");
868 if (p == -1)
869 prefix = GetForeground (config);
870 else
871 prefix = GetBackground (config.Substring (p+1)) + GetForeground (config.Substring (0, p));
872 postfix = "\x001b[0m";
875 public ConsoleReportPrinter ()
876 : base (Console.Error)
880 public ConsoleReportPrinter (TextWriter writer)
881 : base (writer)
885 static int NameToCode (string s)
887 switch (s) {
888 case "black":
889 return 0;
890 case "red":
891 return 1;
892 case "green":
893 return 2;
894 case "yellow":
895 return 3;
896 case "blue":
897 return 4;
898 case "magenta":
899 return 5;
900 case "cyan":
901 return 6;
902 case "grey":
903 case "white":
904 return 7;
906 return 7;
910 // maps a color name to its xterm color code
912 static string GetForeground (string s)
914 string highcode;
916 if (s.StartsWith ("bright")) {
917 highcode = "1;";
918 s = s.Substring (6);
919 } else
920 highcode = "";
922 return "\x001b[" + highcode + (30 + NameToCode (s)).ToString () + "m";
925 static string GetBackground (string s)
927 return "\x001b[" + (40 + NameToCode (s)).ToString () + "m";
930 protected override string FormatText (string txt)
932 if (prefix != null)
933 return prefix + txt + postfix;
935 return txt;
938 static string FriendlyStackTrace (StackTrace t)
940 StringBuilder sb = new StringBuilder ();
942 bool foundUserCode = false;
944 for (int i = 0; i < t.FrameCount; i++) {
945 StackFrame f = t.GetFrame (i);
946 MethodBase mb = f.GetMethod ();
948 if (!foundUserCode && mb.ReflectedType == typeof (Report))
949 continue;
951 foundUserCode = true;
953 sb.Append ("\tin ");
955 if (f.GetFileLineNumber () > 0)
956 sb.AppendFormat ("(at {0}:{1}) ", f.GetFileName (), f.GetFileLineNumber ());
958 sb.AppendFormat ("{0}.{1} (", mb.ReflectedType.Name, mb.Name);
960 bool first = true;
961 foreach (ParameterInfo pi in mb.GetParameters ()) {
962 if (!first)
963 sb.Append (", ");
964 first = false;
966 sb.Append (TypeManager.CSharpName (pi.ParameterType));
968 sb.Append (")\n");
971 return sb.ToString ();
974 public override void Print (AbstractMessage msg)
976 base.Print (msg);
978 if (Stacktrace)
979 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
982 public static string FriendlyStackTrace (Exception e)
984 return FriendlyStackTrace (new StackTrace (e, true));
987 public static void StackTrace ()
989 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
993 public enum TimerType {
994 FindMembers = 0,
995 TcFindMembers = 1,
996 MemberLookup = 2,
997 CachedLookup = 3,
998 CacheInit = 4,
999 MiscTimer = 5,
1000 CountTimers = 6
1003 public enum CounterType {
1004 FindMembers = 0,
1005 MemberCache = 1,
1006 MiscCounter = 2,
1007 CountCounters = 3
1010 public class Timer
1012 static DateTime[] timer_start;
1013 static TimeSpan[] timers;
1014 static long[] timer_counters;
1015 static long[] counters;
1017 static Timer ()
1019 timer_start = new DateTime [(int) TimerType.CountTimers];
1020 timers = new TimeSpan [(int) TimerType.CountTimers];
1021 timer_counters = new long [(int) TimerType.CountTimers];
1022 counters = new long [(int) CounterType.CountCounters];
1024 for (int i = 0; i < (int) TimerType.CountTimers; i++) {
1025 timer_start [i] = DateTime.Now;
1026 timers [i] = TimeSpan.Zero;
1030 [Conditional("TIMER")]
1031 static public void IncrementCounter (CounterType which)
1033 ++counters [(int) which];
1036 [Conditional("TIMER")]
1037 static public void StartTimer (TimerType which)
1039 timer_start [(int) which] = DateTime.Now;
1042 [Conditional("TIMER")]
1043 static public void StopTimer (TimerType which)
1045 timers [(int) which] += DateTime.Now - timer_start [(int) which];
1046 ++timer_counters [(int) which];
1049 [Conditional("TIMER")]
1050 static public void ShowTimers ()
1052 ShowTimer (TimerType.FindMembers, "- FindMembers timer");
1053 ShowTimer (TimerType.TcFindMembers, "- TypeContainer.FindMembers timer");
1054 ShowTimer (TimerType.MemberLookup, "- MemberLookup timer");
1055 ShowTimer (TimerType.CachedLookup, "- CachedLookup timer");
1056 ShowTimer (TimerType.CacheInit, "- Cache init");
1057 ShowTimer (TimerType.MiscTimer, "- Misc timer");
1059 ShowCounter (CounterType.FindMembers, "- Find members");
1060 ShowCounter (CounterType.MemberCache, "- Member cache");
1061 ShowCounter (CounterType.MiscCounter, "- Misc counter");
1064 static public void ShowCounter (CounterType which, string msg)
1066 Console.WriteLine ("{0} {1}", counters [(int) which], msg);
1069 static public void ShowTimer (TimerType which, string msg)
1071 Console.WriteLine (
1072 "[{0:00}:{1:000}] {2} (used {3} times)",
1073 (int) timers [(int) which].TotalSeconds,
1074 timers [(int) which].Milliseconds, msg,
1075 timer_counters [(int) which]);
1079 public class InternalErrorException : Exception {
1080 public InternalErrorException (MemberCore mc, Exception e)
1081 : base (mc.Location + " " + mc.GetSignatureForError (), e)
1085 public InternalErrorException ()
1086 : base ("Internal error")
1090 public InternalErrorException (string message)
1091 : base (message)
1095 public InternalErrorException (string message, params object[] args)
1096 : base (String.Format (message, args))
1099 public InternalErrorException (Exception e, Location loc)
1100 : base (loc.ToString (), e)
1105 /// <summary>
1106 /// Handles #pragma warning
1107 /// </summary>
1108 public class WarningRegions {
1110 abstract class PragmaCmd
1112 public int Line;
1114 protected PragmaCmd (int line)
1116 Line = line;
1119 public abstract bool IsEnabled (int code, bool previous);
1122 class Disable : PragmaCmd
1124 int code;
1125 public Disable (int line, int code)
1126 : base (line)
1128 this.code = code;
1131 public override bool IsEnabled (int code, bool previous)
1133 return this.code == code ? false : previous;
1137 class DisableAll : PragmaCmd
1139 public DisableAll (int line)
1140 : base (line) {}
1142 public override bool IsEnabled(int code, bool previous)
1144 return false;
1148 class Enable : PragmaCmd
1150 int code;
1151 public Enable (int line, int code)
1152 : base (line)
1154 this.code = code;
1157 public override bool IsEnabled(int code, bool previous)
1159 return this.code == code ? true : previous;
1163 class EnableAll : PragmaCmd
1165 public EnableAll (int line)
1166 : base (line) {}
1168 public override bool IsEnabled(int code, bool previous)
1170 return true;
1175 ArrayList regions = new ArrayList ();
1177 public void WarningDisable (int line)
1179 regions.Add (new DisableAll (line));
1182 public void WarningDisable (Location location, int code, Report Report)
1184 if (Report.CheckWarningCode (code, location))
1185 regions.Add (new Disable (location.Row, code));
1188 public void WarningEnable (int line)
1190 regions.Add (new EnableAll (line));
1193 public void WarningEnable (Location location, int code, Report Report)
1195 if (Report.CheckWarningCode (code, location))
1196 regions.Add (new Enable (location.Row, code));
1199 public bool IsWarningEnabled (int code, int src_line)
1201 bool result = true;
1202 foreach (PragmaCmd pragma in regions) {
1203 if (src_line < pragma.Line)
1204 break;
1206 result = pragma.IsEnabled (code, result);
1208 return result;