Fixme fixme fixme.
[mono.git] / mcs / gmcs / report.cs
index 8f5c0c7d9fc13d9cb4af215dd12e5573e0abcf68..b07fe6aea0ffa0f709ba3957d153ffc623321cbd 100644 (file)
@@ -12,6 +12,7 @@
 using System;
 using System.Text;
 using System.Collections;
+using System.Collections.Specialized;
 using System.Diagnostics;
 using System.Reflection;
 
@@ -58,6 +59,11 @@ namespace Mono.CSharp {
                // Keeps track of the warnings that we are ignoring
                //
                static Hashtable warning_ignore_table;
+
+               /// <summary>
+               /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
+               /// </summary>
+               static StringCollection related_symbols = new StringCollection ();
                
                struct WarningData {
                        public WarningData (int level, string text) {
@@ -82,6 +88,34 @@ namespace Mono.CSharp {
                static string GetErrorMsg (int error_no)
                {
                        switch (error_no) {
+                               case 0122: return "'{0}' is inaccessible due to its protection level";
+                               case 0134: return "Cannot use qualified namespace names in nested namespace declarations";
+                               case 0145: return "A const field requires a value to be provided";
+                               case 0160: return "A previous catch clause already catches all exceptions of this or a super type '{0}'";
+                               case 0210: return "You must provide an initializer in a fixed or using statement declaration";
+                               case 0243: return "Conditional not valid on '{0}' because it is an override method";
+                               case 0247: return "Cannot use a negative size with stackalloc";
+                               case 0415: return "The 'IndexerName' attribute is valid only on an indexer that is not an explicit interface member declaration";
+                               case 0553: return "'{0}' : user defined conversion to/from base class";
+                               case 0554: return "'{0}' : user defined conversion to/from derived class";
+                               case 0577: return "Conditional not valid on '{0}' because it is a destructor, operator, or explicit interface implementation";
+                               case 0578: return "Conditional not valid on '{0}' because its return type is not void";
+                               case 0582: return "Conditional not valid on interface members";
+                               case 0592: return "Attribute '{0}' is not valid on this declaration type. It is valid on {1} declarations only.";
+                               case 0601: return "The DllImport attribute must be specified on a method marked `static' and `extern'";
+                               case 0609: return "Cannot set the 'IndexerName' attribute on an indexer marked override";
+                               case 0610: return "Field or property cannot be of type '{0}'";
+                               case 0619: return "'{0}' is obsolete: '{1}'";
+                               case 0626: return "Method, operator, or accessor '{0}' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation";
+                               case 0629: return "Conditional member '{0}' cannot implement interface member";
+                               case 0633: return "The argument to the 'IndexerName' attribute must be a valid identifier";
+                               case 0657: return "'{0}' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are '{1}'";
+                               case 1555: return "Could not find '{0}' specified for Main method";
+                               case 1556: return "'{0}' specified for Main method must be a valid class or struct";                                    
+                               case 1618: return "Cannot create delegate with '{0}' because it has a Conditional attribute";
+                               case 1667: return "'{0}' is not valid on property or event accessors. It is valid on '{1}' declarations only";
+                               case 1669: return "__arglist is not valid in this context";                                    
+                               case 3000: return "Methods with variable arguments are not CLS-compliant";
                                case 3001: return "Argument type '{0}' is not CLS-compliant";
                                case 3002: return "Return type of '{0}' is not CLS-compliant";
                                case 3003: return "Type of '{0}' is not CLS-compliant";
@@ -102,7 +136,13 @@ namespace Mono.CSharp {
                static WarningData GetWarningMsg (int warn_no)
                {
                        switch (warn_no) {
+                               case -24: return new WarningData (1, "The Microsoft Runtime cannot set this marshal info. Please use the Mono runtime instead.");
+                               case -28: return new WarningData (1, "The Microsoft .NET Runtime 1.x does not permit setting custom attributes on the return type");
+                               case 0612: return new WarningData (1, "'{0}' is obsolete");
+                               case 0618: return new WarningData (2, "'{0}' is obsolete: '{1}'");
+                               case 0672: return new WarningData (1, "Member '{0}' overrides obsolete member. Add the Obsolete attribute to '{0}'");
                                case 3012: return new WarningData (1, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+                               case 3019: return new WarningData (2, "CLS compliance checking will not be performed on '{0}' because it is private or internal");
                        }
 
                        throw new InternalErrorException (String.Format ("Wrong warning number '{0}'", warn_no));
@@ -159,8 +199,40 @@ namespace Mono.CSharp {
                        return sb.ToString ();
                }
                
-               static public void LocationOfPreviousError (Location loc) {
+               static public void LocationOfPreviousError (Location loc)
+               {
                        Console.WriteLine (String.Format ("{0}({1}) (Location of symbol related to previous error)", loc.Name, loc.Row));
+               }                
+
+               /// <summary>
+                /// In most error cases is very useful to have information about symbol that caused the error.
+                /// Call this method before you call Report.Error when it makes sense.
+               /// </summary>
+               static public void SymbolRelatedToPreviousError (Location loc, string symbol)
+               {
+                       SymbolRelatedToPreviousError (String.Format ("{0}({1})", loc.Name, loc.Row), symbol);
+               }
+
+               static public void SymbolRelatedToPreviousError (MemberInfo mi)
+               {
+                       DeclSpace temp_ds = TypeManager.LookupDeclSpace (mi.DeclaringType);
+                       if (temp_ds == null) {
+                               SymbolRelatedToPreviousError (mi.DeclaringType.Assembly.Location, TypeManager.GetFullNameSignature (mi));
+                       } else {
+                               string name = String.Concat (temp_ds.Name, ".", mi.Name);
+                               MemberCore mc = temp_ds.GetDefinition (name) as MemberCore;
+                               SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
+                       }
+               }
+
+               static public void SymbolRelatedToPreviousError (Type type)
+               {
+                       SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
+               }
+
+               static void SymbolRelatedToPreviousError (string loc, string symbol)
+               {
+                       related_symbols.Add (String.Format ("{0}: ('{1}' name of symbol related to previous error)", loc, symbol));
                }
 
                static public void RealError (string msg)
@@ -168,6 +240,10 @@ namespace Mono.CSharp {
                        Errors++;
                        Console.WriteLine (msg);
 
+                       foreach (string s in related_symbols)
+                               Console.WriteLine (s);
+                       related_symbols.Clear ();
+
                        if (Stacktrace)
                                Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
                        
@@ -179,13 +255,13 @@ namespace Mono.CSharp {
                /// <summary>
                /// Method reports warning message. Only one reason why exist Warning and Report methods is beter code readability.
                /// </summary>
-               static public void Warning (int code, Location loc, params object[] args)
+               static public void Warning_T (int code, Location loc, params object[] args)
                {
                        WarningData warning = GetWarningMsg (code);
-                       if (!warning.IsEnabled ())
-                               return;
+                       if (warning.IsEnabled ())
+                               Warning (code, loc, warning.Format (args));
 
-                       Warning (code, loc, warning.Format (args));
+                       related_symbols.Clear ();
                }
 
                /// <summary>
@@ -231,8 +307,10 @@ namespace Mono.CSharp {
                                code = 8000-code;
                        
                        if (warning_ignore_table != null){
-                               if (warning_ignore_table.Contains (code))
+                               if (warning_ignore_table.Contains (code)) {
+                                       related_symbols.Clear ();
                                        return;
+                               }
                        }
                        
                        if (WarningsAreErrors)
@@ -250,6 +328,11 @@ namespace Mono.CSharp {
 //                                     "{0}({1}) warning CS{2}: {3}",
                                        l.Name,  row, code, text));
                                Warnings++;
+
+                               foreach (string s in related_symbols)
+                                       Console.WriteLine (s);
+                               related_symbols.Clear ();
+
                                Check (code);
 
                                if (Stacktrace)