2009-12-02 Jb Evain <jbevain@novell.com>
[mcs.git] / mcs / report.cs
blob66e9446e998c7d462858cabda8114053dfc572a0
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.Diagnostics;
15 using System.Reflection;
16 using System.Reflection.Emit;
18 namespace Mono.CSharp {
21 // Errors and warnings manager
23 public class Report {
24 /// <summary>
25 /// Whether errors should be throw an exception
26 /// </summary>
27 public bool Fatal;
29 /// <summary>
30 /// Whether warnings should be considered errors
31 /// </summary>
32 public bool WarningsAreErrors;
33 ArrayList warnings_as_error;
34 ArrayList warnings_only;
36 public static int DebugFlags = 0;
39 // Keeps track of the warnings that we are ignoring
41 public Hashtable warning_ignore_table;
43 Hashtable warning_regions_table;
45 int warning_level;
47 ReportPrinter printer;
49 int reporting_disabled;
51 /// <summary>
52 /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
53 /// </summary>
54 ArrayList extra_information = new ArrayList ();
56 //
57 // IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
59 public static readonly int[] AllWarnings = new int[] {
60 28, 67, 78,
61 105, 108, 109, 114, 162, 164, 168, 169, 183, 184, 197,
62 219, 251, 252, 253, 278, 282,
63 402, 414, 419, 420, 429, 436, 440, 458, 464, 465, 467, 469, 472,
64 612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675, 693,
65 809,
66 1030, 1058, 1066,
67 1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592,
68 1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692,
69 1700, 1717, 1718, 1720,
70 1901,
71 2002, 2023, 2029,
72 3000, 3001, 3002, 3003, 3005, 3006, 3007, 3008, 3009,
73 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019,
74 3021, 3022, 3023, 3024, 3026, 3027
77 static Report ()
79 // Just to be sure that binary search is working
80 Array.Sort (AllWarnings);
83 public Report (ReportPrinter printer)
85 if (printer == null)
86 throw new ArgumentNullException ("printer");
88 this.printer = printer;
89 warning_level = 4;
92 public void DisableReporting ()
94 ++reporting_disabled;
97 public void EnableReporting ()
99 --reporting_disabled;
102 public void FeatureIsNotAvailable (Location loc, string feature)
104 string version;
105 switch (RootContext.Version) {
106 case LanguageVersion.ISO_1:
107 version = "1.0";
108 break;
109 case LanguageVersion.ISO_2:
110 version = "2.0";
111 break;
112 case LanguageVersion.V_3:
113 version = "3.0";
114 break;
115 default:
116 throw new InternalErrorException ("Invalid feature version", RootContext.Version);
119 Error (1644, loc,
120 "Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
121 feature, version);
124 public void FeatureIsNotSupported (Location loc, string feature)
126 Error (1644, loc,
127 "Feature `{0}' is not supported in Mono mcs1 compiler. Consider using the `gmcs' compiler instead",
128 feature);
131 static bool IsValidWarning (int code)
133 return Array.BinarySearch (AllWarnings, code) >= 0;
136 bool IsWarningEnabled (int code, int level, Location loc)
138 if (WarningLevel < level)
139 return false;
141 if (warning_ignore_table != null) {
142 if (warning_ignore_table.Contains (code)) {
143 return false;
147 if (warning_regions_table == null || loc.IsNull)
148 return true;
150 WarningRegions regions = (WarningRegions) warning_regions_table [loc.Name];
151 if (regions == null)
152 return true;
154 return regions.IsWarningEnabled (code, loc.Row);
157 bool IsWarningAsError (int code)
159 bool is_error = WarningsAreErrors;
161 // Check specific list
162 if (warnings_as_error != null)
163 is_error |= warnings_as_error.Contains (code);
165 // Ignore excluded warnings
166 if (warnings_only != null && warnings_only.Contains (code))
167 is_error = false;
169 return is_error;
172 public void RuntimeMissingSupport (Location loc, string feature)
174 Error (-88, loc, "Your .NET Runtime does not support `{0}'. Please use the latest Mono runtime instead.", feature);
177 /// <summary>
178 /// In most error cases is very useful to have information about symbol that caused the error.
179 /// Call this method before you call Report.Error when it makes sense.
180 /// </summary>
181 public void SymbolRelatedToPreviousError (Location loc, string symbol)
183 SymbolRelatedToPreviousError (loc.ToString (), symbol);
186 public void SymbolRelatedToPreviousError (MemberInfo mi)
188 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
189 return;
191 Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
192 if (TypeManager.IsDelegateType (dt)) {
193 SymbolRelatedToPreviousError (dt);
194 return;
197 DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
198 if (temp_ds == null) {
199 SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
200 } else {
201 MethodBase mb = mi as MethodBase;
202 if (mb != null) {
203 mb = TypeManager.DropGenericMethodArguments (mb);
204 IMethodData md = TypeManager.GetMethod (mb);
205 if (md != null)
206 SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
208 return;
211 // FIXME: Completely wrong, it has to use FindMembers
212 MemberCore mc = temp_ds.GetDefinition (mi.Name);
213 if (mc != null)
214 SymbolRelatedToPreviousError (mc);
218 public void SymbolRelatedToPreviousError (MemberCore mc)
220 SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
223 public void SymbolRelatedToPreviousError (Type type)
225 if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
226 return;
228 type = TypeManager.DropGenericTypeArguments (type);
230 if (TypeManager.IsGenericParameter (type)) {
231 TypeParameter tp = TypeManager.LookupTypeParameter (type);
232 if (tp != null) {
233 SymbolRelatedToPreviousError (tp.Location, "");
234 return;
238 if (type is TypeBuilder) {
239 DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
240 SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
241 } else if (TypeManager.HasElementType (type)) {
242 SymbolRelatedToPreviousError (TypeManager.GetElementType (type));
243 } else {
244 SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
248 void SymbolRelatedToPreviousError (string loc, string symbol)
250 string msg = String.Format ("{0} (Location of the symbol related to previous ", loc);
251 if (extra_information.Contains (msg))
252 return;
254 extra_information.Add (msg);
257 public void AddWarningAsError (string warningId)
259 int id;
260 try {
261 id = int.Parse (warningId);
262 } catch {
263 id = -1;
266 if (!CheckWarningCode (id, warningId, Location.Null))
267 return;
269 if (warnings_as_error == null)
270 warnings_as_error = new ArrayList ();
272 warnings_as_error.Add (id);
275 public void RemoveWarningAsError (string warningId)
277 int id;
278 try {
279 id = int.Parse (warningId);
280 } catch {
281 id = -1;
284 if (!CheckWarningCode (id, warningId, Location.Null))
285 return;
287 if (warnings_only == null)
288 warnings_only = new ArrayList ();
290 warnings_only.Add (id);
293 public bool CheckWarningCode (int code, Location loc)
295 return CheckWarningCode (code, code.ToString (), loc);
298 public bool CheckWarningCode (int code, string scode, Location loc)
300 if (IsValidWarning (code))
301 return true;
303 Warning (1691, 1, loc, "`{0}' is not a valid warning number", scode);
304 return false;
307 public void ExtraInformation (Location loc, string msg)
309 extra_information.Add (String.Format ("{0} {1}", loc, msg));
312 public WarningRegions RegisterWarningRegion (Location location)
314 if (warning_regions_table == null)
315 warning_regions_table = new Hashtable ();
317 WarningRegions regions = (WarningRegions)warning_regions_table [location.Name];
318 if (regions == null) {
319 regions = new WarningRegions ();
320 warning_regions_table.Add (location.Name, regions);
322 return regions;
325 public void Warning (int code, int level, Location loc, string message)
327 if (reporting_disabled > 0)
328 return;
330 if (!IsWarningEnabled (code, level, loc))
331 return;
333 AbstractMessage msg;
334 if (IsWarningAsError (code))
335 msg = new ErrorMessage (code, loc, message, extra_information);
336 else
337 msg = new WarningMessage (code, loc, message, extra_information);
339 extra_information.Clear ();
340 printer.Print (msg);
343 public void Warning (int code, int level, Location loc, string format, string arg)
345 Warning (code, level, loc, String.Format (format, arg));
348 public void Warning (int code, int level, Location loc, string format, string arg1, string arg2)
350 Warning (code, level, loc, String.Format (format, arg1, arg2));
353 public void Warning (int code, int level, Location loc, string format, params object[] args)
355 Warning (code, level, loc, String.Format (format, args));
358 public void Warning (int code, int level, string message)
360 Warning (code, level, Location.Null, message);
363 public void Warning (int code, int level, string format, string arg)
365 Warning (code, level, Location.Null, format, arg);
368 public void Warning (int code, int level, string format, string arg1, string arg2)
370 Warning (code, level, Location.Null, format, arg1, arg2);
373 public void Warning (int code, int level, string format, params string[] args)
375 Warning (code, level, Location.Null, String.Format (format, args));
379 // Warnings encountered so far
381 public int Warnings {
382 get { return printer.WarningsCount; }
385 public void Error (int code, Location loc, string error)
387 if (reporting_disabled > 0)
388 return;
390 ErrorMessage msg = new ErrorMessage (code, loc, error, extra_information);
391 extra_information.Clear ();
393 printer.Print (msg);
395 if (Fatal)
396 throw new Exception (msg.Text);
399 public void Error (int code, Location loc, string format, string arg)
401 Error (code, loc, String.Format (format, arg));
404 public void Error (int code, Location loc, string format, string arg1, string arg2)
406 Error (code, loc, String.Format (format, arg1, arg2));
409 public void Error (int code, Location loc, string format, params object[] args)
411 Error (code, loc, String.Format (format, args));
414 public void Error (int code, string error)
416 Error (code, Location.Null, error);
419 public void Error (int code, string format, string arg)
421 Error (code, Location.Null, format, arg);
424 public void Error (int code, string format, string arg1, string arg2)
426 Error (code, Location.Null, format, arg1, arg2);
429 public void Error (int code, string format, params string[] args)
431 Error (code, Location.Null, String.Format (format, args));
435 // Errors encountered so far
437 public int Errors {
438 get { return printer.ErrorsCount; }
441 public ReportPrinter Printer {
442 get { return printer; }
445 public void SetIgnoreWarning (int code)
447 if (warning_ignore_table == null)
448 warning_ignore_table = new Hashtable ();
450 warning_ignore_table [code] = true;
453 public ReportPrinter SetPrinter (ReportPrinter printer)
455 ReportPrinter old = this.printer;
456 this.printer = printer;
457 return old;
460 public int WarningLevel {
461 get {
462 return warning_level;
464 set {
465 warning_level = value;
469 [Conditional ("MCS_DEBUG")]
470 static public void Debug (string message, params object[] args)
472 Debug (4, message, args);
475 [Conditional ("MCS_DEBUG")]
476 static public void Debug (int category, string message, params object[] args)
478 if ((category & DebugFlags) == 0)
479 return;
481 StringBuilder sb = new StringBuilder (message);
483 if ((args != null) && (args.Length > 0)) {
484 sb.Append (": ");
486 bool first = true;
487 foreach (object arg in args) {
488 if (first)
489 first = false;
490 else
491 sb.Append (", ");
492 if (arg == null)
493 sb.Append ("null");
494 else if (arg is ICollection)
495 sb.Append (PrintCollection ((ICollection) arg));
496 else
497 sb.Append (arg);
501 Console.WriteLine (sb.ToString ());
504 static public string PrintCollection (ICollection collection)
506 StringBuilder sb = new StringBuilder ();
508 sb.Append (collection.GetType ());
509 sb.Append ("(");
511 bool first = true;
512 foreach (object o in collection) {
513 if (first)
514 first = false;
515 else
516 sb.Append (", ");
517 sb.Append (o);
520 sb.Append (")");
521 return sb.ToString ();
525 public abstract class AbstractMessage
527 readonly string[] extra_info;
528 protected readonly int code;
529 protected readonly Location location;
530 readonly string message;
532 protected AbstractMessage (int code, Location loc, string msg, ArrayList extraInfo)
534 this.code = code;
535 if (code < 0)
536 this.code = 8000 - code;
538 this.location = loc;
539 this.message = msg;
540 if (extraInfo.Count != 0) {
541 this.extra_info = (string[])extraInfo.ToArray (typeof (string));
545 protected AbstractMessage (AbstractMessage aMsg)
547 this.code = aMsg.code;
548 this.location = aMsg.location;
549 this.message = aMsg.message;
550 this.extra_info = aMsg.extra_info;
553 public int Code {
554 get { return code; }
557 public override bool Equals (object obj)
559 AbstractMessage msg = obj as AbstractMessage;
560 if (msg == null)
561 return false;
563 return code == msg.code && location.Equals (msg.location) && message == msg.message;
566 public override int GetHashCode ()
568 return code.GetHashCode ();
571 public abstract bool IsWarning { get; }
573 public Location Location {
574 get { return location; }
577 public abstract string MessageType { get; }
579 public string[] RelatedSymbols {
580 get { return extra_info; }
583 public string Text {
584 get { return message; }
588 sealed class WarningMessage : AbstractMessage
590 public WarningMessage (int code, Location loc, string message, ArrayList extra_info)
591 : base (code, loc, message, extra_info)
595 public override bool IsWarning {
596 get { return true; }
599 public override string MessageType {
600 get {
601 return "warning";
606 sealed class ErrorMessage : AbstractMessage
608 public ErrorMessage (int code, Location loc, string message, ArrayList extraInfo)
609 : base (code, loc, message, extraInfo)
613 public ErrorMessage (AbstractMessage aMsg)
614 : base (aMsg)
618 public override bool IsWarning {
619 get { return false; }
622 public override string MessageType {
623 get {
624 return "error";
630 // Generic base for any message writer
632 public abstract class ReportPrinter
634 /// <summary>
635 /// Whether to dump a stack trace on errors.
636 /// </summary>
637 public bool Stacktrace;
639 int warnings, errors;
641 public int WarningsCount {
642 get { return warnings; }
645 public int ErrorsCount {
646 get { return errors; }
649 protected virtual string FormatText (string txt)
651 return txt;
655 // When (symbols related to previous ...) can be used
657 public virtual bool HasRelatedSymbolSupport {
658 get { return true; }
661 public virtual void Print (AbstractMessage msg)
663 if (msg.IsWarning)
664 ++warnings;
665 else
666 ++errors;
669 protected void Print (AbstractMessage msg, TextWriter output)
671 StringBuilder txt = new StringBuilder ();
672 if (!msg.Location.IsNull) {
673 txt.Append (msg.Location.ToString ());
674 txt.Append (" ");
677 txt.AppendFormat ("{0} CS{1:0000}: {2}", msg.MessageType, msg.Code, msg.Text);
679 if (!msg.IsWarning)
680 output.WriteLine (FormatText (txt.ToString ()));
681 else
682 output.WriteLine (txt.ToString ());
684 if (msg.RelatedSymbols != null) {
685 foreach (string s in msg.RelatedSymbols)
686 output.WriteLine (s + msg.MessageType + ")");
692 // Default message recorder, it uses two types of message groups.
693 // Common messages: messages reported in all sessions.
694 // Merged messages: union of all messages in all sessions.
696 // Used by the Lambda expressions to compile the code with various
697 // parameter values, or by attribute resolver
699 class SessionReportPrinter : ReportPrinter
701 ArrayList session_messages;
703 // A collection of exactly same messages reported in all sessions
705 ArrayList common_messages;
708 // A collection of unique messages reported in all sessions
710 ArrayList merged_messages;
712 public override void Print (AbstractMessage msg)
715 // This line is useful when debugging recorded messages
717 // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
719 if (session_messages == null)
720 session_messages = new ArrayList ();
722 session_messages.Add (msg);
724 base.Print (msg);
727 public void EndSession ()
729 if (session_messages == null)
730 return;
733 // Handles the first session
735 if (common_messages == null) {
736 common_messages = new ArrayList (session_messages);
737 merged_messages = session_messages;
738 session_messages = null;
739 return;
743 // Store common messages if any
745 for (int i = 0; i < common_messages.Count; ++i) {
746 AbstractMessage cmsg = (AbstractMessage) common_messages[i];
747 bool common_msg_found = false;
748 foreach (AbstractMessage msg in session_messages) {
749 if (cmsg.Equals (msg)) {
750 common_msg_found = true;
751 break;
755 if (!common_msg_found)
756 common_messages.RemoveAt (i);
760 // Merge session and previous messages
762 for (int i = 0; i < session_messages.Count; ++i) {
763 AbstractMessage msg = (AbstractMessage) session_messages[i];
764 bool msg_found = false;
765 for (int ii = 0; ii < merged_messages.Count; ++ii) {
766 if (msg.Equals (merged_messages[ii])) {
767 msg_found = true;
768 break;
772 if (!msg_found)
773 merged_messages.Add (msg);
777 public bool IsEmpty {
778 get {
779 return merged_messages == null && common_messages == null;
784 // Prints collected messages, common messages have a priority
786 public bool Merge (ReportPrinter dest)
788 ArrayList messages_to_print = merged_messages;
789 if (common_messages != null && common_messages.Count > 0) {
790 messages_to_print = common_messages;
793 if (messages_to_print == null)
794 return false;
796 foreach (AbstractMessage msg in messages_to_print)
797 dest.Print (msg);
799 return true;
803 class StreamReportPrinter : ReportPrinter
805 readonly TextWriter writer;
807 public StreamReportPrinter (TextWriter writer)
809 this.writer = writer;
812 public override void Print (AbstractMessage msg)
814 Print (msg, writer);
815 base.Print (msg);
819 class ConsoleReportPrinter : StreamReportPrinter
821 static readonly string prefix, postfix;
823 static ConsoleReportPrinter ()
825 string term = Environment.GetEnvironmentVariable ("TERM");
826 bool xterm_colors = false;
828 switch (term){
829 case "xterm":
830 case "rxvt":
831 case "rxvt-unicode":
832 if (Environment.GetEnvironmentVariable ("COLORTERM") != null){
833 xterm_colors = true;
835 break;
837 case "xterm-color":
838 xterm_colors = true;
839 break;
841 if (!xterm_colors)
842 return;
844 if (!(UnixUtils.isatty (1) && UnixUtils.isatty (2)))
845 return;
847 string config = Environment.GetEnvironmentVariable ("MCS_COLORS");
848 if (config == null){
849 config = "errors=red";
850 //config = "brightwhite,red";
853 if (config == "disable")
854 return;
856 if (!config.StartsWith ("errors="))
857 return;
859 config = config.Substring (7);
861 int p = config.IndexOf (",");
862 if (p == -1)
863 prefix = GetForeground (config);
864 else
865 prefix = GetBackground (config.Substring (p+1)) + GetForeground (config.Substring (0, p));
866 postfix = "\x001b[0m";
869 public ConsoleReportPrinter ()
870 : base (Console.Error)
874 public ConsoleReportPrinter (TextWriter writer)
875 : base (writer)
879 static int NameToCode (string s)
881 switch (s) {
882 case "black":
883 return 0;
884 case "red":
885 return 1;
886 case "green":
887 return 2;
888 case "yellow":
889 return 3;
890 case "blue":
891 return 4;
892 case "magenta":
893 return 5;
894 case "cyan":
895 return 6;
896 case "grey":
897 case "white":
898 return 7;
900 return 7;
904 // maps a color name to its xterm color code
906 static string GetForeground (string s)
908 string highcode;
910 if (s.StartsWith ("bright")) {
911 highcode = "1;";
912 s = s.Substring (6);
913 } else
914 highcode = "";
916 return "\x001b[" + highcode + (30 + NameToCode (s)).ToString () + "m";
919 static string GetBackground (string s)
921 return "\x001b[" + (40 + NameToCode (s)).ToString () + "m";
924 protected override string FormatText (string txt)
926 if (prefix != null)
927 return prefix + txt + postfix;
929 return txt;
932 static string FriendlyStackTrace (StackTrace t)
934 StringBuilder sb = new StringBuilder ();
936 bool foundUserCode = false;
938 for (int i = 0; i < t.FrameCount; i++) {
939 StackFrame f = t.GetFrame (i);
940 MethodBase mb = f.GetMethod ();
942 if (!foundUserCode && mb.ReflectedType == typeof (Report))
943 continue;
945 foundUserCode = true;
947 sb.Append ("\tin ");
949 if (f.GetFileLineNumber () > 0)
950 sb.AppendFormat ("(at {0}:{1}) ", f.GetFileName (), f.GetFileLineNumber ());
952 sb.AppendFormat ("{0}.{1} (", mb.ReflectedType.Name, mb.Name);
954 bool first = true;
955 foreach (ParameterInfo pi in mb.GetParameters ()) {
956 if (!first)
957 sb.Append (", ");
958 first = false;
960 sb.Append (TypeManager.CSharpName (pi.ParameterType));
962 sb.Append (")\n");
965 return sb.ToString ();
968 public override void Print (AbstractMessage msg)
970 base.Print (msg);
972 if (Stacktrace)
973 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
976 public static string FriendlyStackTrace (Exception e)
978 return FriendlyStackTrace (new StackTrace (e, true));
981 public static void StackTrace ()
983 Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
987 public enum TimerType {
988 FindMembers = 0,
989 TcFindMembers = 1,
990 MemberLookup = 2,
991 CachedLookup = 3,
992 CacheInit = 4,
993 MiscTimer = 5,
994 CountTimers = 6
997 public enum CounterType {
998 FindMembers = 0,
999 MemberCache = 1,
1000 MiscCounter = 2,
1001 CountCounters = 3
1004 public class Timer
1006 static DateTime[] timer_start;
1007 static TimeSpan[] timers;
1008 static long[] timer_counters;
1009 static long[] counters;
1011 static Timer ()
1013 timer_start = new DateTime [(int) TimerType.CountTimers];
1014 timers = new TimeSpan [(int) TimerType.CountTimers];
1015 timer_counters = new long [(int) TimerType.CountTimers];
1016 counters = new long [(int) CounterType.CountCounters];
1018 for (int i = 0; i < (int) TimerType.CountTimers; i++) {
1019 timer_start [i] = DateTime.Now;
1020 timers [i] = TimeSpan.Zero;
1024 [Conditional("TIMER")]
1025 static public void IncrementCounter (CounterType which)
1027 ++counters [(int) which];
1030 [Conditional("TIMER")]
1031 static public void StartTimer (TimerType which)
1033 timer_start [(int) which] = DateTime.Now;
1036 [Conditional("TIMER")]
1037 static public void StopTimer (TimerType which)
1039 timers [(int) which] += DateTime.Now - timer_start [(int) which];
1040 ++timer_counters [(int) which];
1043 [Conditional("TIMER")]
1044 static public void ShowTimers ()
1046 ShowTimer (TimerType.FindMembers, "- FindMembers timer");
1047 ShowTimer (TimerType.TcFindMembers, "- TypeContainer.FindMembers timer");
1048 ShowTimer (TimerType.MemberLookup, "- MemberLookup timer");
1049 ShowTimer (TimerType.CachedLookup, "- CachedLookup timer");
1050 ShowTimer (TimerType.CacheInit, "- Cache init");
1051 ShowTimer (TimerType.MiscTimer, "- Misc timer");
1053 ShowCounter (CounterType.FindMembers, "- Find members");
1054 ShowCounter (CounterType.MemberCache, "- Member cache");
1055 ShowCounter (CounterType.MiscCounter, "- Misc counter");
1058 static public void ShowCounter (CounterType which, string msg)
1060 Console.WriteLine ("{0} {1}", counters [(int) which], msg);
1063 static public void ShowTimer (TimerType which, string msg)
1065 Console.WriteLine (
1066 "[{0:00}:{1:000}] {2} (used {3} times)",
1067 (int) timers [(int) which].TotalSeconds,
1068 timers [(int) which].Milliseconds, msg,
1069 timer_counters [(int) which]);
1073 public class InternalErrorException : Exception {
1074 public InternalErrorException (MemberCore mc, Exception e)
1075 : base (mc.Location + " " + mc.GetSignatureForError (), e)
1079 public InternalErrorException ()
1080 : base ("Internal error")
1084 public InternalErrorException (string message)
1085 : base (message)
1089 public InternalErrorException (string message, params object[] args)
1090 : base (String.Format (message, args))
1093 public InternalErrorException (Exception e, Location loc)
1094 : base (loc.ToString (), e)
1099 /// <summary>
1100 /// Handles #pragma warning
1101 /// </summary>
1102 public class WarningRegions {
1104 abstract class PragmaCmd
1106 public int Line;
1108 protected PragmaCmd (int line)
1110 Line = line;
1113 public abstract bool IsEnabled (int code, bool previous);
1116 class Disable : PragmaCmd
1118 int code;
1119 public Disable (int line, int code)
1120 : base (line)
1122 this.code = code;
1125 public override bool IsEnabled (int code, bool previous)
1127 return this.code == code ? false : previous;
1131 class DisableAll : PragmaCmd
1133 public DisableAll (int line)
1134 : base (line) {}
1136 public override bool IsEnabled(int code, bool previous)
1138 return false;
1142 class Enable : PragmaCmd
1144 int code;
1145 public Enable (int line, int code)
1146 : base (line)
1148 this.code = code;
1151 public override bool IsEnabled(int code, bool previous)
1153 return this.code == code ? true : previous;
1157 class EnableAll : PragmaCmd
1159 public EnableAll (int line)
1160 : base (line) {}
1162 public override bool IsEnabled(int code, bool previous)
1164 return true;
1169 ArrayList regions = new ArrayList ();
1171 public void WarningDisable (int line)
1173 regions.Add (new DisableAll (line));
1176 public void WarningDisable (Location location, int code, Report Report)
1178 if (Report.CheckWarningCode (code, location))
1179 regions.Add (new Disable (location.Row, code));
1182 public void WarningEnable (int line)
1184 regions.Add (new EnableAll (line));
1187 public void WarningEnable (Location location, int code, Report Report)
1189 if (Report.CheckWarningCode (code, location))
1190 regions.Add (new Enable (location.Row, code));
1193 public bool IsWarningEnabled (int code, int src_line)
1195 bool result = true;
1196 foreach (PragmaCmd pragma in regions) {
1197 if (src_line < pragma.Line)
1198 break;
1200 result = pragma.IsEnabled (code, result);
1202 return result;