* xbuild/Microsoft.Common.targets (_RecordCleanFile): Append list of
[mcs.git] / mcs / report.cs
blobcfbff594df33df4b76179c9f28fef3bc008e1a98
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.Generic;
14 using System.Diagnostics;
15 using System.Reflection;
16 using System.Reflection.Emit;
18 namespace Mono.CSharp {
21 // Errors and warnings manager
23 public class Report
25 /// <summary>
26 /// Whether warnings should be considered errors
27 /// </summary>
28 public bool WarningsAreErrors;
29 List<int> warnings_as_error;
30 List<int> warnings_only;
32 public static int DebugFlags = 0;
35 // Keeps track of the warnings that we are ignoring
37 public Dictionary<int, bool> warning_ignore_table;
39 Dictionary<string, WarningRegions> warning_regions_table;
41 int warning_level;
43 ReportPrinter printer;
45 int reporting_disabled;
47 /// <summary>
48 /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
49 /// </summary>
50 List<string> extra_information = new List<string> ();
52 //
53 // IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
55 public static readonly int[] AllWarnings = new int[] {
56 28, 67, 78,
57 105, 108, 109, 114, 162, 164, 168, 169, 183, 184, 197,
58 219, 251, 252, 253, 278, 282,
59 402, 414, 419, 420, 429, 436, 440, 458, 464, 465, 467, 469, 472,
60 612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675, 693,
61 809,
62 1030, 1058, 1066,
63 1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592,
64 1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692,
65 1700, 1717, 1718, 1720,
66 1901,
67 2002, 2023, 2029,
68 3000, 3001, 3002, 3003, 3005, 3006, 3007, 3008, 3009,
69 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019,
70 3021, 3022, 3023, 3024, 3026, 3027
73 static Report ()
75 // Just to be sure that binary search is working
76 Array.Sort (AllWarnings);
79 public Report (ReportPrinter printer)
81 if (printer == null)
82 throw new ArgumentNullException ("printer");
84 this.printer = printer;
85 warning_level = 4;
88 public void DisableReporting ()
90 ++reporting_disabled;
93 public void EnableReporting ()
95 --reporting_disabled;
98 public void FeatureIsNotAvailable (Location loc, string feature)
100 string version;
101 switch (RootContext.Version) {
102 case LanguageVersion.ISO_1:
103 version = "1.0";
104 break;
105 case LanguageVersion.ISO_2:
106 version = "2.0";
107 break;
108 case LanguageVersion.V_3:
109 version = "3.0";
110 break;
111 default:
112 throw new InternalErrorException ("Invalid feature version", RootContext.Version);
115 Error (1644, loc,
116 "Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
117 feature, version);
120 public void FeatureIsNotSupported (Location loc, string feature)
122 Error (1644, loc,
123 "Feature `{0}' is not supported in Mono mcs1 compiler. Consider using the `gmcs' compiler instead",
124 feature);
127 static bool IsValidWarning (int code)
129 return Array.BinarySearch (AllWarnings, code) >= 0;
132 bool IsWarningEnabled (int code, int level, Location loc)
134 if (WarningLevel < level)
135 return false;
137 if (warning_ignore_table != null) {
138 if (warning_ignore_table.ContainsKey (code)) {
139 return false;
143 if (warning_regions_table == null || loc.IsNull)
144 return true;
146 WarningRegions regions;
147 if (!warning_regions_table.TryGetValue (loc.Name, out regions))
148 return true;
150 return regions.IsWarningEnabled (code, loc.Row);
153 bool IsWarningAsError (int code)
155 bool is_error = WarningsAreErrors;
157 // Check specific list
158 if (warnings_as_error != null)
159 is_error |= warnings_as_error.Contains (code);
161 // Ignore excluded warnings
162 if (warnings_only != null && warnings_only.Contains (code))
163 is_error = false;
165 return is_error;
168 public void RuntimeMissingSupport (Location loc, string feature)
170 Error (-88, loc, "Your .NET Runtime does not support `{0}'. Please use the latest Mono runtime instead.", feature);
173 /// <summary>
174 /// In most error cases is very useful to have information about symbol that caused the error.
175 /// Call this method before you call Report.Error when it makes sense.
176 /// </summary>
177 public void SymbolRelatedToPreviousError (Location loc, string symbol)
179 SymbolRelatedToPreviousError (loc.ToString (), symbol);
182 public void SymbolRelatedToPreviousError (MemberInfo mi)
184 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
185 return;
187 Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
188 if (TypeManager.IsDelegateType (dt)) {
189 SymbolRelatedToPreviousError (dt);
190 return;
193 DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
194 if (temp_ds == null) {
195 SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
196 } else {
197 MethodBase mb = mi as MethodBase;
198 if (mb != null) {
199 mb = TypeManager.DropGenericMethodArguments (mb);
200 IMethodData md = TypeManager.GetMethod (mb);
201 if (md != null)
202 SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
204 return;
207 // FIXME: Completely wrong, it has to use FindMembers
208 MemberCore mc = temp_ds.GetDefinition (mi.Name);
209 if (mc != null)
210 SymbolRelatedToPreviousError (mc);
214 public void SymbolRelatedToPreviousError (MemberCore mc)
216 SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
219 public void SymbolRelatedToPreviousError (Type type)
221 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
222 return;
224 type = TypeManager.DropGenericTypeArguments (type);
226 if (TypeManager.IsGenericParameter (type)) {
227 TypeParameter tp = TypeManager.LookupTypeParameter (type);
228 if (tp != null) {
229 SymbolRelatedToPreviousError (tp.Location, "");
230 return;
234 if (type is TypeBuilder) {
235 DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
236 SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
237 } else if (TypeManager.HasElementType (type)) {
238 SymbolRelatedToPreviousError (TypeManager.GetElementType (type));
239 } else {
240 SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
244 void SymbolRelatedToPreviousError (string loc, string symbol)
246 string msg = String.Format ("{0} (Location of the symbol related to previous ", loc);
247 if (extra_information.Contains (msg))
248 return;
250 extra_information.Add (msg);
253 public void AddWarningAsError (string warningId)
255 int id;
256 try {
257 id = int.Parse (warningId);
258 } catch {
259 id = -1;
262 if (!CheckWarningCode (id, warningId, Location.Null))
263 return;
265 if (warnings_as_error == null)
266 warnings_as_error = new List<int> ();
268 warnings_as_error.Add (id);
271 public void RemoveWarningAsError (string warningId)
273 int id;
274 try {
275 id = int.Parse (warningId);
276 } catch {
277 id = -1;
280 if (!CheckWarningCode (id, warningId, Location.Null))
281 return;
283 if (warnings_only == null)
284 warnings_only = new List<int> ();
286 warnings_only.Add (id);
289 public bool CheckWarningCode (int code, Location loc)
291 return CheckWarningCode (code, code.ToString (), loc);
294 public bool CheckWarningCode (int code, string scode, Location loc)
296 if (IsValidWarning (code))
297 return true;
299 Warning (1691, 1, loc, "`{0}' is not a valid warning number", scode);
300 return false;
303 public void ExtraInformation (Location loc, string msg)
305 extra_information.Add (String.Format ("{0} {1}", loc, msg));
308 public WarningRegions RegisterWarningRegion (Location location)
310 WarningRegions regions;
311 if (warning_regions_table == null) {
312 regions = null;
313 warning_regions_table = new Dictionary<string, WarningRegions> ();
314 } else {
315 warning_regions_table.TryGetValue (location.Name, out regions);
318 if (regions == null) {
319 regions = new WarningRegions ();
320 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);
397 public void Error (int code, Location loc, string format, string arg)
399 Error (code, loc, String.Format (format, arg));
402 public void Error (int code, Location loc, string format, string arg1, string arg2)
404 Error (code, loc, String.Format (format, arg1, arg2));
407 public void Error (int code, Location loc, string format, params object[] args)
409 Error (code, loc, String.Format (format, args));
412 public void Error (int code, string error)
414 Error (code, Location.Null, error);
417 public void Error (int code, string format, string arg)
419 Error (code, Location.Null, format, arg);
422 public void Error (int code, string format, string arg1, string arg2)
424 Error (code, Location.Null, format, arg1, arg2);
427 public void Error (int code, string format, params string[] args)
429 Error (code, Location.Null, String.Format (format, args));
433 // Errors encountered so far
435 public int Errors {
436 get { return printer.ErrorsCount; }
439 public ReportPrinter Printer {
440 get { return printer; }
443 public void SetIgnoreWarning (int code)
445 if (warning_ignore_table == null)
446 warning_ignore_table = new Dictionary<int, bool> ();
448 warning_ignore_table [code] = true;
451 public ReportPrinter SetPrinter (ReportPrinter printer)
453 ReportPrinter old = this.printer;
454 this.printer = printer;
455 return old;
458 public int WarningLevel {
459 get {
460 return warning_level;
462 set {
463 warning_level = value;
467 [Conditional ("MCS_DEBUG")]
468 static public void Debug (string message, params object[] args)
470 Debug (4, message, args);
473 [Conditional ("MCS_DEBUG")]
474 static public void Debug (int category, string message, params object[] args)
476 if ((category & DebugFlags) == 0)
477 return;
479 StringBuilder sb = new StringBuilder (message);
481 if ((args != null) && (args.Length > 0)) {
482 sb.Append (": ");
484 bool first = true;
485 foreach (object arg in args) {
486 if (first)
487 first = false;
488 else
489 sb.Append (", ");
490 if (arg == null)
491 sb.Append ("null");
492 // else if (arg is ICollection)
493 // sb.Append (PrintCollection ((ICollection) arg));
494 else
495 sb.Append (arg);
499 Console.WriteLine (sb.ToString ());
502 static public string PrintCollection (ICollection collection)
504 StringBuilder sb = new StringBuilder ();
506 sb.Append (collection.GetType ());
507 sb.Append ("(");
509 bool first = true;
510 foreach (object o in collection) {
511 if (first)
512 first = false;
513 else
514 sb.Append (", ");
515 sb.Append (o);
518 sb.Append (")");
519 return sb.ToString ();
524 public abstract class AbstractMessage
526 readonly string[] extra_info;
527 protected readonly int code;
528 protected readonly Location location;
529 readonly string message;
531 protected AbstractMessage (int code, Location loc, string msg, List<string> extraInfo)
533 this.code = code;
534 if (code < 0)
535 this.code = 8000 - code;
537 this.location = loc;
538 this.message = msg;
539 if (extraInfo.Count != 0) {
540 this.extra_info = extraInfo.ToArray ();
544 protected AbstractMessage (AbstractMessage aMsg)
546 this.code = aMsg.code;
547 this.location = aMsg.location;
548 this.message = aMsg.message;
549 this.extra_info = aMsg.extra_info;
552 public int Code {
553 get { return code; }
556 public override bool Equals (object obj)
558 AbstractMessage msg = obj as AbstractMessage;
559 if (msg == null)
560 return false;
562 return code == msg.code && location.Equals (msg.location) && message == msg.message;
565 public override int GetHashCode ()
567 return code.GetHashCode ();
570 public abstract bool IsWarning { get; }
572 public Location Location {
573 get { return location; }
576 public abstract string MessageType { get; }
578 public string[] RelatedSymbols {
579 get { return extra_info; }
582 public string Text {
583 get { return message; }
587 sealed class WarningMessage : AbstractMessage
589 public WarningMessage (int code, Location loc, string message, List<string> extra_info)
590 : base (code, loc, message, extra_info)
594 public override bool IsWarning {
595 get { return true; }
598 public override string MessageType {
599 get {
600 return "warning";
605 sealed class ErrorMessage : AbstractMessage
607 public ErrorMessage (int code, Location loc, string message, List<string> extraInfo)
608 : base (code, loc, message, extraInfo)
612 public ErrorMessage (AbstractMessage aMsg)
613 : base (aMsg)
617 public override bool IsWarning {
618 get { return false; }
621 public override string MessageType {
622 get {
623 return "error";
629 // Generic base for any message writer
631 public abstract class ReportPrinter
633 /// <summary>
634 /// Whether to dump a stack trace on errors.
635 /// </summary>
636 public bool Stacktrace;
638 int warnings, errors;
640 public int WarningsCount {
641 get { return warnings; }
644 public int ErrorsCount {
645 get { return errors; }
648 protected virtual string FormatText (string txt)
650 return txt;
654 // When (symbols related to previous ...) can be used
656 public virtual bool HasRelatedSymbolSupport {
657 get { return true; }
660 public virtual void Print (AbstractMessage msg)
662 if (msg.IsWarning)
663 ++warnings;
664 else
665 ++errors;
668 protected void Print (AbstractMessage msg, TextWriter output)
670 StringBuilder txt = new StringBuilder ();
671 if (!msg.Location.IsNull) {
672 txt.Append (msg.Location.ToString ());
673 txt.Append (" ");
676 txt.AppendFormat ("{0} CS{1:0000}: {2}", msg.MessageType, msg.Code, msg.Text);
678 if (!msg.IsWarning)
679 output.WriteLine (FormatText (txt.ToString ()));
680 else
681 output.WriteLine (txt.ToString ());
683 if (msg.RelatedSymbols != null) {
684 foreach (string s in msg.RelatedSymbols)
685 output.WriteLine (s + msg.MessageType + ")");
691 // Default message recorder, it uses two types of message groups.
692 // Common messages: messages reported in all sessions.
693 // Merged messages: union of all messages in all sessions.
695 // Used by the Lambda expressions to compile the code with various
696 // parameter values, or by attribute resolver
698 class SessionReportPrinter : ReportPrinter
700 List<AbstractMessage> session_messages;
702 // A collection of exactly same messages reported in all sessions
704 List<AbstractMessage> common_messages;
707 // A collection of unique messages reported in all sessions
709 List<AbstractMessage> merged_messages;
711 public override void Print (AbstractMessage msg)
714 // This line is useful when debugging recorded messages
716 // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
718 if (session_messages == null)
719 session_messages = new List<AbstractMessage> ();
721 session_messages.Add (msg);
723 base.Print (msg);
726 public void EndSession ()
728 if (session_messages == null)
729 return;
732 // Handles the first session
734 if (common_messages == null) {
735 common_messages = new List<AbstractMessage> (session_messages);
736 merged_messages = session_messages;
737 session_messages = null;
738 return;
742 // Store common messages if any
744 for (int i = 0; i < common_messages.Count; ++i) {
745 AbstractMessage cmsg = (AbstractMessage) common_messages[i];
746 bool common_msg_found = false;
747 foreach (AbstractMessage msg in session_messages) {
748 if (cmsg.Equals (msg)) {
749 common_msg_found = true;
750 break;
754 if (!common_msg_found)
755 common_messages.RemoveAt (i);
759 // Merge session and previous messages
761 for (int i = 0; i < session_messages.Count; ++i) {
762 AbstractMessage msg = (AbstractMessage) session_messages[i];
763 bool msg_found = false;
764 for (int ii = 0; ii < merged_messages.Count; ++ii) {
765 if (msg.Equals (merged_messages[ii])) {
766 msg_found = true;
767 break;
771 if (!msg_found)
772 merged_messages.Add (msg);
776 public bool IsEmpty {
777 get {
778 return merged_messages == null && common_messages == null;
783 // Prints collected messages, common messages have a priority
785 public bool Merge (ReportPrinter dest)
787 var messages_to_print = merged_messages;
788 if (common_messages != null && common_messages.Count > 0) {
789 messages_to_print = common_messages;
792 if (messages_to_print == null)
793 return false;
795 foreach (AbstractMessage msg in messages_to_print)
796 dest.Print (msg);
798 return true;
802 class StreamReportPrinter : ReportPrinter
804 readonly TextWriter writer;
806 public StreamReportPrinter (TextWriter writer)
808 this.writer = writer;
811 public override void Print (AbstractMessage msg)
813 Print (msg, writer);
814 base.Print (msg);
818 class ConsoleReportPrinter : StreamReportPrinter
820 static readonly string prefix, postfix;
822 static ConsoleReportPrinter ()
824 string term = Environment.GetEnvironmentVariable ("TERM");
825 bool xterm_colors = false;
827 switch (term){
828 case "xterm":
829 case "rxvt":
830 case "rxvt-unicode":
831 if (Environment.GetEnvironmentVariable ("COLORTERM") != null){
832 xterm_colors = true;
834 break;
836 case "xterm-color":
837 xterm_colors = true;
838 break;
840 if (!xterm_colors)
841 return;
843 if (!(UnixUtils.isatty (1) && UnixUtils.isatty (2)))
844 return;
846 string config = Environment.GetEnvironmentVariable ("MCS_COLORS");
847 if (config == null){
848 config = "errors=red";
849 //config = "brightwhite,red";
852 if (config == "disable")
853 return;
855 if (!config.StartsWith ("errors="))
856 return;
858 config = config.Substring (7);
860 int p = config.IndexOf (",");
861 if (p == -1)
862 prefix = GetForeground (config);
863 else
864 prefix = GetBackground (config.Substring (p+1)) + GetForeground (config.Substring (0, p));
865 postfix = "\x001b[0m";
868 public ConsoleReportPrinter ()
869 : base (Console.Error)
873 public ConsoleReportPrinter (TextWriter writer)
874 : base (writer)
878 public int Fatal { get; set; }
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 int print_count;
970 public override void Print (AbstractMessage msg)
972 base.Print (msg);
974 if (Stacktrace)
975 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
977 if (++print_count == Fatal)
978 throw new Exception (msg.Text);
981 public static string FriendlyStackTrace (Exception e)
983 return FriendlyStackTrace (new StackTrace (e, true));
986 public static void StackTrace ()
988 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
992 public enum TimerType {
993 FindMembers = 0,
994 TcFindMembers = 1,
995 MemberLookup = 2,
996 CachedLookup = 3,
997 CacheInit = 4,
998 MiscTimer = 5,
999 CountTimers = 6
1002 public enum CounterType {
1003 FindMembers = 0,
1004 MemberCache = 1,
1005 MiscCounter = 2,
1006 CountCounters = 3
1009 public class Timer
1011 static DateTime[] timer_start;
1012 static TimeSpan[] timers;
1013 static long[] timer_counters;
1014 static long[] counters;
1016 static Timer ()
1018 timer_start = new DateTime [(int) TimerType.CountTimers];
1019 timers = new TimeSpan [(int) TimerType.CountTimers];
1020 timer_counters = new long [(int) TimerType.CountTimers];
1021 counters = new long [(int) CounterType.CountCounters];
1023 for (int i = 0; i < (int) TimerType.CountTimers; i++) {
1024 timer_start [i] = DateTime.Now;
1025 timers [i] = TimeSpan.Zero;
1029 [Conditional("TIMER")]
1030 static public void IncrementCounter (CounterType which)
1032 ++counters [(int) which];
1035 [Conditional("TIMER")]
1036 static public void StartTimer (TimerType which)
1038 timer_start [(int) which] = DateTime.Now;
1041 [Conditional("TIMER")]
1042 static public void StopTimer (TimerType which)
1044 timers [(int) which] += DateTime.Now - timer_start [(int) which];
1045 ++timer_counters [(int) which];
1048 [Conditional("TIMER")]
1049 static public void ShowTimers ()
1051 ShowTimer (TimerType.FindMembers, "- FindMembers timer");
1052 ShowTimer (TimerType.TcFindMembers, "- TypeContainer.FindMembers timer");
1053 ShowTimer (TimerType.MemberLookup, "- MemberLookup timer");
1054 ShowTimer (TimerType.CachedLookup, "- CachedLookup timer");
1055 ShowTimer (TimerType.CacheInit, "- Cache init");
1056 ShowTimer (TimerType.MiscTimer, "- Misc timer");
1058 ShowCounter (CounterType.FindMembers, "- Find members");
1059 ShowCounter (CounterType.MemberCache, "- Member cache");
1060 ShowCounter (CounterType.MiscCounter, "- Misc counter");
1063 static public void ShowCounter (CounterType which, string msg)
1065 Console.WriteLine ("{0} {1}", counters [(int) which], msg);
1068 static public void ShowTimer (TimerType which, string msg)
1070 Console.WriteLine (
1071 "[{0:00}:{1:000}] {2} (used {3} times)",
1072 (int) timers [(int) which].TotalSeconds,
1073 timers [(int) which].Milliseconds, msg,
1074 timer_counters [(int) which]);
1078 public class InternalErrorException : Exception {
1079 public InternalErrorException (MemberCore mc, Exception e)
1080 : base (mc.Location + " " + mc.GetSignatureForError (), e)
1084 public InternalErrorException ()
1085 : base ("Internal error")
1089 public InternalErrorException (string message)
1090 : base (message)
1094 public InternalErrorException (string message, params object[] args)
1095 : base (String.Format (message, args))
1098 public InternalErrorException (Exception e, Location loc)
1099 : base (loc.ToString (), e)
1104 /// <summary>
1105 /// Handles #pragma warning
1106 /// </summary>
1107 public class WarningRegions {
1109 abstract class PragmaCmd
1111 public int Line;
1113 protected PragmaCmd (int line)
1115 Line = line;
1118 public abstract bool IsEnabled (int code, bool previous);
1121 class Disable : PragmaCmd
1123 int code;
1124 public Disable (int line, int code)
1125 : base (line)
1127 this.code = code;
1130 public override bool IsEnabled (int code, bool previous)
1132 return this.code == code ? false : previous;
1136 class DisableAll : PragmaCmd
1138 public DisableAll (int line)
1139 : base (line) {}
1141 public override bool IsEnabled(int code, bool previous)
1143 return false;
1147 class Enable : PragmaCmd
1149 int code;
1150 public Enable (int line, int code)
1151 : base (line)
1153 this.code = code;
1156 public override bool IsEnabled(int code, bool previous)
1158 return this.code == code ? true : previous;
1162 class EnableAll : PragmaCmd
1164 public EnableAll (int line)
1165 : base (line) {}
1167 public override bool IsEnabled(int code, bool previous)
1169 return true;
1174 List<PragmaCmd> regions = new List<PragmaCmd> ();
1176 public void WarningDisable (int line)
1178 regions.Add (new DisableAll (line));
1181 public void WarningDisable (Location location, int code, Report Report)
1183 if (Report.CheckWarningCode (code, location))
1184 regions.Add (new Disable (location.Row, code));
1187 public void WarningEnable (int line)
1189 regions.Add (new EnableAll (line));
1192 public void WarningEnable (Location location, int code, Report Report)
1194 if (Report.CheckWarningCode (code, location))
1195 regions.Add (new Enable (location.Row, code));
1198 public bool IsWarningEnabled (int code, int src_line)
1200 bool result = true;
1201 foreach (PragmaCmd pragma in regions) {
1202 if (src_line < pragma.Line)
1203 break;
1205 result = pragma.IsEnabled (code, result);
1207 return result;