2007-03-21 Mike Kestner <mkestner@novell.com>
[mono.git] / mcs / mcs / report.cs
index 97aa9a083d05609d91cbf6d755faa1d4b5394ec1..61cd03f66f82b1ac5c09fd8f9f18da07614b731b 100644 (file)
@@ -64,6 +64,14 @@ namespace Mono.CSharp {
 
                static Hashtable warning_regions_table;
 
+               //
+               // This is used to save/restore the error state.  When the
+               // error stack contains elements, warnings and errors are not
+               // reported to the user.  This is used by the Lambda expression
+               // support to compile the code with various parameter values.
+               //
+               static Stack error_stack;
+               
                /// <summary>
                /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
                /// </summary>
@@ -75,18 +83,19 @@ namespace Mono.CSharp {
                public static readonly int[] AllWarnings = new int[] {
                        28, 67, 78,
                        105, 108, 109, 114, 162, 164, 168, 169, 183, 184, 197,
-                       219, 251, 252, 253, 282,
+                       219, 251, 252, 253, 278, 282,
                        419, 420, 429, 436, 440, 465, 467, 469,
-                       612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672,
-                       1030, 1058,
+                       612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675,
+                       809,
+                       1030,
                        1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592,
-                       1616, 1633, 1634, 1635, 1690, 1691, 1692,
-                       1717, 1718,
+                       1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692,
+                       1717, 1718, 1720,
                        1901,
-                       2002, 2023,
-                       3005, 3012, 3019, 3021, 3022, 3023, 3026, 3027,
+                       2002, 2023, 2029,
+                       3005, 3012, 3018, 3019, 3021, 3022, 3023, 3026, 3027,
 #if GMCS_SOURCE
-                       402, 414, 693, 1700
+                       402, 414, 693, 1058, 1700, 3024
 #endif
                };
 
@@ -104,6 +113,18 @@ namespace Mono.CSharp {
                        warning_regions_table = null;
                }
 
+               public static void DisableErrors ()
+               {
+                       if (error_stack == null)
+                               error_stack = new Stack ();
+                       error_stack.Push (Errors);
+               }
+
+               public static void EnableErrors ()
+               {
+                       Errors = (int) error_stack.Pop ();
+               }
+               
                abstract class AbstractMessage {
 
                        static void Check (int code)
@@ -119,6 +140,9 @@ namespace Mono.CSharp {
 
                        public virtual void Print (int code, string location, string text)
                        {
+                               if (error_stack != null && error_stack.Count != 0)
+                                       return;
+                               
                                if (code < 0)
                                        code = 8000-code;
 
@@ -131,7 +155,7 @@ namespace Mono.CSharp {
                                Stderr.WriteLine (msg.ToString ());
 
                                foreach (string s in extra_information) 
-                                       Stderr.WriteLine (s + MessageType);
+                                       Stderr.WriteLine (s + MessageType + ")");
 
                                extra_information.Clear ();
 
@@ -235,9 +259,17 @@ namespace Mono.CSharp {
 
                }
 
-               public static void FeatureIsNotStandardized (Location loc, string feature)
+               public static void FeatureIsNotISO1 (Location loc, string feature)
                {
-                       Report.Error (1644, loc, "Feature `{0}' cannot be used because it is not part of the standardized ISO C# language specification", feature);
+                       Report.Error (1644, loc,
+                               "Feature `{0}' cannot be used because it is not part of the C# 1.0 language specification",
+                                     feature);
+               }
+
+               public static void FeatureRequiresLINQ (Location loc, string feature)
+               {
+                       Report.Error (1644, loc,
+                                     "Feature `{0}' can only be used if the language level is LINQ", feature);
                }
                
                public static string FriendlyStackTrace (Exception e)
@@ -308,7 +340,7 @@ namespace Mono.CSharp {
                static public void SymbolRelatedToPreviousError (MemberInfo mi)
                {
                        Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
-                       TypeContainer temp_ds = TypeManager.LookupTypeContainer (dt);
+                       DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
                        if (temp_ds == null) {
                                SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
                        } else {
@@ -354,7 +386,7 @@ namespace Mono.CSharp {
 
                static void SymbolRelatedToPreviousError (string loc, string symbol)
                {
-                       extra_information.Add (String.Format ("{0}: `{1}', name of symbol related to previous ", loc, symbol));
+                       extra_information.Add (String.Format ("{0} (Location of the symbol related to previous ", loc));
                }
 
                public static void ExtraInformation (Location loc, string msg)
@@ -621,8 +653,8 @@ namespace Mono.CSharp {
        }
 
        public class InternalErrorException : Exception {
-               public InternalErrorException (Location loc, string text, Exception e)
-                       : base (loc + " " + text, e)
+               public InternalErrorException (MemberCore mc, Exception e)
+                       : base (mc.Location + " " + mc.GetSignatureForError (), e)
                {
                }
 
@@ -635,6 +667,10 @@ namespace Mono.CSharp {
                        : base (message)
                {
                }
+
+               public InternalErrorException (string message, params object[] args)
+                       : base (String.Format (message, args))
+               { }
        }
 
        /// <summary>