// report.cs: report errors and warnings.
//
// Author: Miguel de Icaza (miguel@ximian.com)
+// Marek Safar (marek.safar@seznam.cz)
//
// (C) 2001 Ximian, Inc. (http://www.ximian.com)
//
-//
-// FIXME: currently our class library does not support custom number format strings
-//
using System;
using System.IO;
using System.Text;
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>
static StringCollection extra_information = new StringCollection ();
+ //
+ // IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
+ //
+ 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, 278, 282,
+ 419, 420, 429, 436, 440, 465, 467, 469,
+ 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, 1685, 1690, 1691, 1692,
+ 1717, 1718, 1720,
+ 1901,
+ 2002, 2023, 2029,
+ 3005, 3012, 3018, 3019, 3021, 3022, 3023, 3026, 3027,
+#if GMCS_SOURCE
+ 402, 414, 693, 1058, 1700, 3024
+#endif
+ };
+
+ static Report ()
+ {
+ // Just to be sure that binary search is working
+ Array.Sort (AllWarnings);
+ }
+
public static void Reset ()
{
Errors = Warnings = 0;
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)
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;
Stderr.WriteLine (msg.ToString ());
foreach (string s in extra_information)
- Stderr.WriteLine (s + MessageType);
+ Stderr.WriteLine (s + MessageType + ")");
extra_information.Clear ();
public virtual void Print (int code, Location location, string text)
{
- if (location.IsNull) {
- Print (code, "", text);
- return;
- }
- Print (code, location.ToString (), text);
+ Print (code, location.IsNull ? "" : location.ToString (), text);
}
}
- sealed class WarningMessage: AbstractMessage {
+ sealed class WarningMessage : AbstractMessage {
Location loc = Location.Null;
readonly int Level;
- public WarningMessage ():
- this (-1) {}
-
public WarningMessage (int level)
{
Level = level;
}
}
- sealed class ErrorMessage: AbstractMessage {
+ sealed class ErrorMessage : AbstractMessage {
public override void Print(int code, string location, string text)
{
}
- 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)
Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
}
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- // IF YOU ADD A NEW WARNING YOU HAVE TO DUPLICATE ITS ID HERE
- //
public static bool IsValidWarning (int code)
- {
- int[] all_warnings = new int[] {
- 28, 67, 78, 105, 108, 109, 114, 192, 168, 169, 183, 184, 219, 251, 612, 618, 626, 628, 642, 649,
- 659, 660, 661, 672, 1030, 1522, 1616, 1691, 1692, 1901, 2002, 2023, 3012, 3019, 8024, 8028
- };
-
- foreach (int i in all_warnings) {
- if (i == code)
- return true;
- }
- return false;
+ {
+ return Array.BinarySearch (AllWarnings, code) >= 0;
}
-
- static public void LocationOfPreviousError (Location loc)
- {
- Stderr.WriteLine (String.Format ("{0} (Location of symbol related to previous error)", loc));
- }
-
+
static public void RuntimeMissingSupport (Location loc, string feature)
{
Report.Error (-88, loc, "Your .NET Runtime does not support `{0}'. Please use the latest Mono runtime instead.", feature);
static public void SymbolRelatedToPreviousError (MemberInfo mi)
{
- TypeContainer temp_ds = TypeManager.LookupTypeContainer (mi.DeclaringType);
+ Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
+ DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
if (temp_ds == null) {
- SymbolRelatedToPreviousError (mi.DeclaringType.Assembly.Location, TypeManager.GetFullNameSignature (mi));
+ SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
} else {
- if (mi is MethodBase) {
- IMethodData md = TypeManager.GetMethod ((MethodBase)mi);
+ MethodBase mb = mi as MethodBase;
+ if (mb != null) {
+ mb = TypeManager.DropGenericMethodArguments (mb);
+ IMethodData md = TypeManager.GetMethod (mb);
SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
return;
}
static public void SymbolRelatedToPreviousError (Type type)
{
+ 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));
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)
return regions;
}
- static public void Warning (int code, int level, Location loc, string format, params object[] args)
+ static public void Warning (int code, int level, Location loc, string message)
{
WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, String.Format (format, args));
+ w.Print (code, loc, message);
+ }
+
+ static public void Warning (int code, int level, Location loc, string format, string arg)
+ {
+ WarningMessage w = new WarningMessage (level);
+ w.Print (code, loc, String.Format (format, arg));
+ }
+
+ static public void Warning (int code, int level, Location loc, string format, string arg1, string arg2)
+ {
+ WarningMessage w = new WarningMessage (level);
+ w.Print (code, loc, String.Format (format, arg1, arg2));
}
- static public void Warning (int code, Location loc, string format, params object[] args)
+ static public void Warning (int code, int level, Location loc, string format, params string[] args)
{
- WarningMessage w = new WarningMessage ();
+ WarningMessage w = new WarningMessage (level);
w.Print (code, loc, String.Format (format, args));
}
- static public void Warning (int code, string format, params object[] args)
+ static public void Warning (int code, int level, string message)
{
- Warning (code, Location.Null, String.Format (format, args));
+ Warning (code, level, Location.Null, message);
}
- /// <summary>
- /// Did you test your WarningLevel, that you use this method
- /// </summary>
- static public void Warning (int code, string text)
+ static public void Warning (int code, int level, string format, string arg)
{
- Warning (code, Location.Null, text);
+ Warning (code, level, Location.Null, format, arg);
}
- static public void Error (int code, string format, params object[] args)
+ static public void Warning (int code, int level, string format, string arg1, string arg2)
{
- Error (code, Location.Null, String.Format (format, args));
+ Warning (code, level, Location.Null, format, arg1, arg2);
}
- static public void Error (int code, Location loc, string format, params object[] args)
+ static public void Warning (int code, int level, string format, params string[] args)
{
- Error (code, loc, String.Format (format, args));
+ Warning (code, level, Location.Null, String.Format (format, args));
}
static public void Error (int code, Location loc, string error)
new ErrorMessage ().Print (code, loc, error);
}
+ static public void Error (int code, Location loc, string format, string arg)
+ {
+ new ErrorMessage ().Print (code, loc, String.Format (format, arg));
+ }
+
+ static public void Error (int code, Location loc, string format, string arg1, string arg2)
+ {
+ new ErrorMessage ().Print (code, loc, String.Format (format, arg1, arg2));
+ }
+
+ static public void Error (int code, Location loc, string format, params string[] args)
+ {
+ Error (code, loc, String.Format (format, args));
+ }
+
+ static public void Error (int code, string error)
+ {
+ Error (code, Location.Null, error);
+ }
+
+ static public void Error (int code, string format, string arg)
+ {
+ Error (code, Location.Null, format, arg);
+ }
+
+ static public void Error (int code, string format, string arg1, string arg2)
+ {
+ Error (code, Location.Null, format, arg1, arg2);
+ }
+
+ static public void Error (int code, string format, params string[] args)
+ {
+ Error (code, Location.Null, String.Format (format, args));
+ }
+
static public void SetIgnoreWarning (int code)
{
if (warning_ignore_table == null)
}
public class InternalErrorException : Exception {
+ public InternalErrorException (MemberCore mc, Exception e)
+ : base (mc.Location + " " + mc.GetSignatureForError (), e)
+ {
+ }
+
public InternalErrorException ()
: base ("Internal error")
{
: base (message)
{
}
+
+ public InternalErrorException (string message, params object[] args)
+ : base (String.Format (message, args))
+ { }
}
/// <summary>
public abstract bool IsEnabled (int code, bool previous);
}
- class Disable: PragmaCmd
+ class Disable : PragmaCmd
{
int code;
public Disable (int line, int code)
}
}
- class DisableAll: PragmaCmd
+ class DisableAll : PragmaCmd
{
public DisableAll (int line)
: base (line) {}
}
}
- class Enable: PragmaCmd
+ class Enable : PragmaCmd
{
int code;
public Enable (int line, int code)
}
}
- class EnableAll: PragmaCmd
+ class EnableAll : PragmaCmd
{
public EnableAll (int line)
: base (line) {}
return result;
}
- bool CheckWarningCode (int code, Location loc)
+ static bool CheckWarningCode (int code, Location loc)
{
if (Report.IsValidWarning (code))
return true;
- Report.Warning (1691, 1, loc, "`{0}' is not a valid warning number", code);
+ Report.Warning (1691, 1, loc, "`{0}' is not a valid warning number", code.ToString ());
return false;
}
}