2010-04-29 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / report.cs
index b4fe05f8e1e16c99eaa5c7889fff1b326a645e06..3ca7fd681ea6c8f72c30415f38fc3327156da84d 100644 (file)
@@ -10,8 +10,7 @@
 using System;
 using System.IO;
 using System.Text;
-using System.Collections;
-using System.Collections.Specialized;
+using System.Collections.Generic;
 using System.Diagnostics;
 using System.Reflection;
 using System.Reflection.Emit;
@@ -21,27 +20,23 @@ namespace Mono.CSharp {
        //
        // Errors and warnings manager
        //
-       public class Report {
-               /// <summary>  
-               ///   Whether errors should be throw an exception
-               /// </summary>
-               public bool Fatal;
-               
+       public class Report
+       {
                /// <summary>  
                ///   Whether warnings should be considered errors
                /// </summary>
                public bool WarningsAreErrors;
-               ArrayList warnings_as_error;
-               ArrayList warnings_only;
+               List<int> warnings_as_error;
+               List<int> warnings_only;
 
                public static int DebugFlags = 0;
 
                //
                // Keeps track of the warnings that we are ignoring
                //
-               public Hashtable warning_ignore_table;
+               public Dictionary<int, bool> warning_ignore_table;
 
-               Hashtable warning_regions_table;
+               Dictionary<string, WarningRegions> warning_regions_table;
 
                int warning_level;
 
@@ -52,7 +47,7 @@ namespace Mono.CSharp {
                /// <summary>
                /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
                /// </summary>
-               ArrayList extra_information = new ArrayList ();
+               List<string> extra_information = new List<string> ();
 
                // 
                // IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
@@ -140,7 +135,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (warning_ignore_table != null) {
-                               if (warning_ignore_table.Contains (code)) {
+                               if (warning_ignore_table.ContainsKey (code)) {
                                        return false;
                                }
                        }
@@ -148,8 +143,8 @@ namespace Mono.CSharp {
                        if (warning_regions_table == null || loc.IsNull)
                                return true;
 
-                       WarningRegions regions = (WarningRegions) warning_regions_table [loc.Name];
-                       if (regions == null)
+                       WarningRegions regions;
+                       if (!warning_regions_table.TryGetValue (loc.Name, out regions))
                                return true;
 
                        return regions.IsWarningEnabled (code, loc.Row);
@@ -184,35 +179,17 @@ namespace Mono.CSharp {
                        SymbolRelatedToPreviousError (loc.ToString (), symbol);
                }
 
-               public void SymbolRelatedToPreviousError (MemberInfo mi)
+               public void SymbolRelatedToPreviousError (MemberSpec ms)
                {
                        if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
                                return;
 
-                       Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
-                       if (TypeManager.IsDelegateType (dt)) {
-                               SymbolRelatedToPreviousError (dt);
-                               return;
-                       }                       
-                       
-                       DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
-                       if (temp_ds == null) {
-                               SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
+                       var mc = ms.MemberDefinition as MemberCore;
+                       if (mc != null) {
+                               SymbolRelatedToPreviousError (mc);
                        } else {
-                               MethodBase mb = mi as MethodBase;
-                               if (mb != null) {
-                                       mb = TypeManager.DropGenericMethodArguments (mb);
-                                       IMethodData md = TypeManager.GetMethod (mb);
-                                       if (md != null)
-                                               SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
-
-                                       return;
-                               }
-
-                               // FIXME: Completely wrong, it has to use FindMembers
-                               MemberCore mc = temp_ds.GetDefinition (mi.Name);
-                               if (mc != null)
-                                       SymbolRelatedToPreviousError (mc);
+                               var im = ms.MemberDefinition as ImportedMemberDefinition;
+                               SymbolRelatedToPreviousError (im.Assembly.Location, "");
                        }
                }
 
@@ -221,31 +198,6 @@ namespace Mono.CSharp {
                        SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
                }
 
-               public void SymbolRelatedToPreviousError (Type type)
-               {
-                       if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
-                               return;
-
-                       type = TypeManager.DropGenericTypeArguments (type);
-
-                       if (TypeManager.IsGenericParameter (type)) {
-                               TypeParameter tp = TypeManager.LookupTypeParameter (type);
-                               if (tp != null) {
-                                       SymbolRelatedToPreviousError (tp.Location, "");
-                                       return;
-                               }
-                       }
-
-                       if (type is TypeBuilder) {
-                               DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
-                               SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
-                       } else if (TypeManager.HasElementType (type)) {
-                               SymbolRelatedToPreviousError (TypeManager.GetElementType (type));
-                       } else {
-                               SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
-                       }
-               }
-
                void SymbolRelatedToPreviousError (string loc, string symbol)
                {
                        string msg = String.Format ("{0} (Location of the symbol related to previous ", loc);
@@ -268,7 +220,7 @@ namespace Mono.CSharp {
                                return;
 
                        if (warnings_as_error == null)
-                               warnings_as_error = new ArrayList ();
+                               warnings_as_error = new List<int> ();
                        
                        warnings_as_error.Add (id);
                }
@@ -286,7 +238,7 @@ namespace Mono.CSharp {
                                return;
 
                        if (warnings_only == null)
-                               warnings_only = new ArrayList ();
+                               warnings_only = new List<int> ();
 
                        warnings_only.Add (id);
                }
@@ -312,14 +264,19 @@ namespace Mono.CSharp {
 
                public WarningRegions RegisterWarningRegion (Location location)
                {
-                       if (warning_regions_table == null)
-                               warning_regions_table = new Hashtable ();
+                       WarningRegions regions;
+                       if (warning_regions_table == null) {
+                               regions = null;
+                               warning_regions_table = new Dictionary<string, WarningRegions> ();
+                       } else {
+                               warning_regions_table.TryGetValue (location.Name, out regions);
+                       }
 
-                       WarningRegions regions = (WarningRegions)warning_regions_table [location.Name];
                        if (regions == null) {
                                regions = new WarningRegions ();
                                warning_regions_table.Add (location.Name, regions);
                        }
+
                        return regions;
                }
 
@@ -392,9 +349,6 @@ namespace Mono.CSharp {
                        extra_information.Clear ();
 
                        printer.Print (msg);
-
-                       if (Fatal)
-                               throw new Exception (msg.Text);
                }
 
                public void Error (int code, Location loc, string format, string arg)
@@ -407,7 +361,7 @@ namespace Mono.CSharp {
                        Error (code, loc, String.Format (format, arg1, arg2));
                }
 
-               public void Error (int code, Location loc, string format, params object[] args)
+               public void Error (int code, Location loc, string format, params string[] args)
                {
                        Error (code, loc, String.Format (format, args));
                }
@@ -446,7 +400,7 @@ namespace Mono.CSharp {
                public void SetIgnoreWarning (int code)
                {
                        if (warning_ignore_table == null)
-                               warning_ignore_table = new Hashtable ();
+                               warning_ignore_table = new Dictionary<int, bool> ();
 
                        warning_ignore_table [code] = true;
                }
@@ -457,7 +411,7 @@ namespace Mono.CSharp {
                        this.printer = printer;
                        return old;
                }
-               
+
                public int WarningLevel {
                        get {
                                return warning_level;
@@ -492,8 +446,8 @@ namespace Mono.CSharp {
                                                sb.Append (", ");
                                        if (arg == null)
                                                sb.Append ("null");
-                                       else if (arg is ICollection)
-                                               sb.Append (PrintCollection ((ICollection) arg));
+//                                     else if (arg is ICollection)
+//                                             sb.Append (PrintCollection ((ICollection) arg));
                                        else
                                                sb.Append (arg);
                                }
@@ -501,7 +455,7 @@ namespace Mono.CSharp {
 
                        Console.WriteLine (sb.ToString ());
                }
-
+/*
                static public string PrintCollection (ICollection collection)
                {
                        StringBuilder sb = new StringBuilder ();
@@ -521,6 +475,7 @@ namespace Mono.CSharp {
                        sb.Append (")");
                        return sb.ToString ();
                }
+*/ 
        }
 
        public abstract class AbstractMessage
@@ -530,7 +485,7 @@ namespace Mono.CSharp {
                protected readonly Location location;
                readonly string message;
 
-               protected AbstractMessage (int code, Location loc, string msg, ArrayList extraInfo)
+               protected AbstractMessage (int code, Location loc, string msg, List<string> extraInfo)
                {
                        this.code = code;
                        if (code < 0)
@@ -539,7 +494,7 @@ namespace Mono.CSharp {
                        this.location = loc;
                        this.message = msg;
                        if (extraInfo.Count != 0) {
-                               this.extra_info = (string[])extraInfo.ToArray (typeof (string));
+                               this.extra_info = extraInfo.ToArray ();
                        }
                }
 
@@ -588,7 +543,7 @@ namespace Mono.CSharp {
 
        sealed class WarningMessage : AbstractMessage
        {
-               public WarningMessage (int code, Location loc, string message, ArrayList extra_info)
+               public WarningMessage (int code, Location loc, string message, List<string> extra_info)
                        : base (code, loc, message, extra_info)
                {
                }
@@ -606,7 +561,7 @@ namespace Mono.CSharp {
 
        sealed class ErrorMessage : AbstractMessage
        {
-               public ErrorMessage (int code, Location loc, string message, ArrayList extraInfo)
+               public ErrorMessage (int code, Location loc, string message, List<string> extraInfo)
                        : base (code, loc, message, extraInfo)
                {
                }
@@ -630,8 +585,7 @@ namespace Mono.CSharp {
        //
        // Generic base for any message writer
        //
-       public abstract class ReportPrinter
-       {
+       public abstract class ReportPrinter {
                /// <summary>  
                ///   Whether to dump a stack trace on errors. 
                /// </summary>
@@ -699,16 +653,16 @@ namespace Mono.CSharp {
        //
        class SessionReportPrinter : ReportPrinter
        {
-               ArrayList session_messages;
+               List<AbstractMessage> session_messages;
                //
                // A collection of exactly same messages reported in all sessions
                //
-               ArrayList common_messages;
+               List<AbstractMessage> common_messages;
 
                //
                // A collection of unique messages reported in all sessions
                //
-               ArrayList merged_messages;
+               List<AbstractMessage> merged_messages;
 
                public override void Print (AbstractMessage msg)
                {
@@ -718,7 +672,7 @@ namespace Mono.CSharp {
                        // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
 
                        if (session_messages == null)
-                               session_messages = new ArrayList ();
+                               session_messages = new List<AbstractMessage> ();
 
                        session_messages.Add (msg);
 
@@ -734,7 +688,7 @@ namespace Mono.CSharp {
                        // Handles the first session
                        //
                        if (common_messages == null) {
-                               common_messages = new ArrayList (session_messages);
+                               common_messages = new List<AbstractMessage> (session_messages);
                                merged_messages = session_messages;
                                session_messages = null;
                                return;
@@ -786,7 +740,7 @@ namespace Mono.CSharp {
                //
                public bool Merge (ReportPrinter dest)
                {
-                       ArrayList messages_to_print = merged_messages;
+                       var messages_to_print = merged_messages;
                        if (common_messages != null && common_messages.Count > 0) {
                                messages_to_print = common_messages;
                        }
@@ -877,6 +831,8 @@ namespace Mono.CSharp {
                {
                }
 
+               public int Fatal { get; set; }
+
                static int NameToCode (string s)
                {
                        switch (s) {
@@ -957,8 +913,8 @@ namespace Mono.CSharp {
                                        if (!first)
                                                sb.Append (", ");
                                        first = false;
-                                       
-                                       sb.Append (TypeManager.CSharpName (pi.ParameterType));
+
+                                       sb.Append (pi.ParameterType.FullName);
                                }
                                sb.Append (")\n");
                        }
@@ -966,12 +922,16 @@ namespace Mono.CSharp {
                        return sb.ToString ();
                }
 
+               int print_count;
                public override void Print (AbstractMessage msg)
                {
                        base.Print (msg);
 
                        if (Stacktrace)
                                Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
+
+                       if (++print_count == Fatal)
+                               throw new Exception (msg.Text);
                }
 
                public static string FriendlyStackTrace (Exception e)
@@ -1167,7 +1127,7 @@ namespace Mono.CSharp {
                }
 
 
-               ArrayList regions = new ArrayList ();
+               List<PragmaCmd> regions = new List<PragmaCmd> ();
 
                public void WarningDisable (int line)
                {