/// </summary>
static public bool WarningsAreErrors;
+
/// <summary>
/// Whether to dump a stack trace on errors.
/// </summary>
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.
+ // A stack because of `Report.Errors == errors;'
+ //
+ static Stack error_stack;
+ static Stack warning_stack;
+ static bool reporting_disabled;
+
+ static int warning_level;
+
/// <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 ();
+ static ArrayList extra_information = new ArrayList ();
//
// IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
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,
+ 419, 420, 429, 436, 440, 465, 467, 469, 472,
612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675,
- 1030, 1058,
+ 809,
+ 1030,
1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592,
- 1616, 1633, 1634, 1635, 1690, 1691, 1692,
+ 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, 3024
+ 402, 414, 693, 1058, 1700, 3024
#endif
};
WarningsAreErrors = false;
warning_ignore_table = null;
warning_regions_table = null;
+ reporting_disabled = false;
+ }
+
+ public static void DisableReporting ()
+ {
+ if (error_stack == null)
+ error_stack = new Stack ();
+ error_stack.Push (Errors);
+
+ if (Warnings > 0) {
+ if (warning_stack == null)
+ warning_stack = new Stack ();
+ warning_stack.Push (Warnings);
+ }
+
+ reporting_disabled = true;
+ }
+
+ public static void EnableReporting ()
+ {
+ if (warning_stack != null)
+ Warnings = (int) warning_stack.Pop ();
+
+ Errors = (int) error_stack.Pop ();
+ if (error_stack.Count == 0) {
+ reporting_disabled = false;
+ }
+ }
+
+ public static IMessageRecorder msg_recorder;
+
+ public static IMessageRecorder SetMessageRecorder (IMessageRecorder recorder)
+ {
+ IMessageRecorder previous = msg_recorder;
+ msg_recorder = recorder;
+ return previous;
+ }
+
+ public interface IMessageRecorder
+ {
+ void EndSession ();
+ void AddMessage (AbstractMessage msg);
+ bool PrintMessages ();
+ }
+
+ //
+ // Default message recorder, it uses two types of message groups.
+ // Common messages: messages reported in all sessions.
+ // Merged messages: union of all messages in all sessions.
+ //
+ public struct MessageRecorder : IMessageRecorder
+ {
+ ArrayList session_messages;
+ //
+ // A collection of exactly same messages reported in all sessions
+ //
+ ArrayList common_messages;
+
+ //
+ // A collection of unique messages reported in all sessions
+ //
+ ArrayList merged_messages;
+
+ public void EndSession ()
+ {
+ if (session_messages == null)
+ return;
+
+ //
+ // Handles the first session
+ //
+ if (common_messages == null) {
+ common_messages = new ArrayList (session_messages);
+ merged_messages = session_messages;
+ session_messages = null;
+ return;
+ }
+
+ //
+ // Store common messages if any
+ //
+ for (int i = 0; i < common_messages.Count; ++i) {
+ AbstractMessage cmsg = (AbstractMessage) common_messages [i];
+ bool common_msg_found = false;
+ foreach (AbstractMessage msg in session_messages) {
+ if (cmsg.Equals (msg)) {
+ common_msg_found = true;
+ break;
+ }
+ }
+
+ if (!common_msg_found)
+ common_messages.RemoveAt (i);
+ }
+
+ //
+ // Merge session and previous messages
+ //
+ for (int i = 0; i < session_messages.Count; ++i) {
+ AbstractMessage msg = (AbstractMessage) session_messages [i];
+ bool msg_found = false;
+ for (int ii = 0; ii < merged_messages.Count; ++ii) {
+ if (msg.Equals (merged_messages [ii])) {
+ msg_found = true;
+ break;
+ }
+ }
+
+ if (!msg_found)
+ merged_messages.Add (msg);
+ }
+ }
+
+ public void AddMessage (AbstractMessage msg)
+ {
+ if (session_messages == null)
+ session_messages = new ArrayList ();
+
+ session_messages.Add (msg);
+ }
+
+ //
+ // Prints collected messages, common messages have a priority
+ //
+ public bool PrintMessages ()
+ {
+ ArrayList messages_to_print = merged_messages;
+ if (common_messages != null && common_messages.Count > 0) {
+ messages_to_print = common_messages;
+ }
+
+ if (messages_to_print == null)
+ return false;
+
+ foreach (AbstractMessage msg in messages_to_print)
+ msg.Print ();
+
+ return true;
+ }
}
+
+ public abstract class AbstractMessage
+ {
+ readonly string[] extra_info;
+ protected readonly int code;
+ protected readonly Location location;
+ readonly string message;
+
+ protected AbstractMessage (int code, Location loc, string msg, ArrayList extraInfo)
+ {
+ this.code = code;
+ if (code < 0)
+ this.code = 8000 - code;
+
+ this.location = loc;
+ this.message = msg;
+ if (extraInfo.Count != 0) {
+ this.extra_info = (string[])extraInfo.ToArray (typeof (string));
+ }
+ }
- abstract class AbstractMessage {
+ protected AbstractMessage (AbstractMessage aMsg)
+ {
+ this.code = aMsg.code;
+ this.location = aMsg.location;
+ this.message = aMsg.message;
+ this.extra_info = aMsg.extra_info;
+ }
static void Check (int code)
{
}
}
+ public override bool Equals (object obj)
+ {
+ AbstractMessage msg = obj as AbstractMessage;
+ if (msg == null)
+ return false;
+
+ return code == msg.code && location.Equals (msg.location) && message == msg.message;
+ }
+
+ public override int GetHashCode ()
+ {
+ return code.GetHashCode ();
+ }
+
public abstract bool IsWarning { get; }
public abstract string MessageType { get; }
- public virtual void Print (int code, string location, string text)
+ public virtual void Print ()
{
- if (code < 0)
- code = 8000-code;
+ if (msg_recorder != null) {
+ //
+ // This line is useful when debugging messages recorder
+ //
+ // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
+ msg_recorder.AddMessage (this);
+ return;
+ }
+
+ if (reporting_disabled)
+ return;
StringBuilder msg = new StringBuilder ();
- if (location.Length != 0) {
- msg.Append (location);
- msg.Append (' ');
+ if (!location.IsNull) {
+ msg.Append (location.ToString ());
+ msg.Append (" ");
}
- msg.AppendFormat ("{0} CS{1:0000}: {2}", MessageType, code, text);
+ msg.AppendFormat ("{0} CS{1:0000}: {2}", MessageType, code, message);
Stderr.WriteLine (msg.ToString ());
- foreach (string s in extra_information)
- Stderr.WriteLine (s + MessageType + ")");
-
- extra_information.Clear ();
+ if (extra_info != null) {
+ foreach (string s in extra_info)
+ Stderr.WriteLine (s + MessageType + ")");
+ }
if (Stacktrace)
Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
if (Fatal) {
if (!IsWarning || WarningsAreErrors)
- throw new Exception (text);
+ throw new Exception (message);
}
Check (code);
}
-
- public virtual void Print (int code, Location location, string text)
- {
- Print (code, location.IsNull ? "" : location.ToString (), text);
- }
}
- sealed class WarningMessage : AbstractMessage {
- Location loc = Location.Null;
+ sealed class WarningMessage : AbstractMessage
+ {
readonly int Level;
- public WarningMessage (int level)
+ public WarningMessage (int code, int level, Location loc, string message, ArrayList extra_info)
+ : base (code, loc, message, extra_info)
{
Level = level;
}
get { return true; }
}
- bool IsEnabled (int code)
+ bool IsEnabled ()
{
- if (RootContext.WarningLevel < Level)
+ if (WarningLevel < Level)
return false;
if (warning_ignore_table != null) {
}
}
- if (warning_regions_table == null || loc.Equals (Location.Null))
+ if (warning_regions_table == null || location.IsNull)
return true;
- WarningRegions regions = (WarningRegions)warning_regions_table [loc.Name];
+ WarningRegions regions = (WarningRegions)warning_regions_table [location.Name];
if (regions == null)
return true;
- return regions.IsWarningEnabled (code, loc.Row);
+ return regions.IsWarningEnabled (code, location.Row);
}
- public override void Print(int code, string location, string text)
+ public override void Print ()
{
- if (!IsEnabled (code)) {
- extra_information.Clear ();
+ if (!IsEnabled ())
return;
- }
if (WarningsAreErrors) {
- new ErrorMessage ().Print (code, location, text);
+ new ErrorMessage (this).Print ();
return;
}
Warnings++;
- base.Print (code, location, text);
- }
-
- public override void Print(int code, Location location, string text)
- {
- loc = location;
- base.Print (code, location, text);
+ base.Print ();
}
public override string MessageType {
}
}
- sealed class ErrorMessage : AbstractMessage {
+ sealed class ErrorMessage : AbstractMessage
+ {
+ public ErrorMessage (int code, Location loc, string message, ArrayList extraInfo)
+ : base (code, loc, message, extraInfo)
+ {
+ }
+
+ public ErrorMessage (AbstractMessage aMsg)
+ : base (aMsg)
+ {
+ }
- public override void Print(int code, string location, string text)
+ public override void Print()
{
Errors++;
- base.Print (code, location, text);
+ base.Print ();
}
public override bool IsWarning {
return "error";
}
}
-
}
- 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);
+ string version;
+ if (RootContext.Version == LanguageVersion.ISO_1)
+ version = "1.0";
+ else if (RootContext.Version == LanguageVersion.ISO_2)
+ version = "2.0";
+ else
+ throw new InternalErrorException ("Invalid feature version", RootContext.Version);
+
+ Report.Error (1644, loc,
+ "Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
+ feature, version);
}
public static string FriendlyStackTrace (Exception e)
static public void SymbolRelatedToPreviousError (MemberInfo mi)
{
+ if (reporting_disabled)
+ return;
+
Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
if (temp_ds == null) {
static public void SymbolRelatedToPreviousError (Type type)
{
+ if (reporting_disabled)
+ return;
+
type = TypeManager.DropGenericTypeArguments (type);
if (TypeManager.IsGenericParameter (type)) {
static public void Warning (int code, int level, Location loc, string message)
{
- WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, message);
+ WarningMessage w = new WarningMessage (code, level, loc, message, extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
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));
+ WarningMessage w = new WarningMessage (code, level, loc, String.Format (format, arg), extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
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));
+ WarningMessage w = new WarningMessage (code, level, loc, String.Format (format, arg1, arg2), extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
- static public void Warning (int code, int level, Location loc, string format, params string[] args)
+ static public void Warning (int code, int level, Location loc, string format, params object[] args)
{
- WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, String.Format (format, args));
+ WarningMessage w = new WarningMessage (code, level, loc, String.Format (format, args), extra_information);
+ extra_information.Clear ();
+ w.Print ();
}
static public void Warning (int code, int level, string message)
static public void Error (int code, Location loc, string error)
{
- new ErrorMessage ().Print (code, loc, error);
+ new ErrorMessage (code, loc, error, extra_information).Print ();
+ extra_information.Clear ();
}
static public void Error (int code, Location loc, string format, string arg)
{
- new ErrorMessage ().Print (code, loc, String.Format (format, arg));
+ new ErrorMessage (code, loc, String.Format (format, arg), extra_information).Print ();
+ extra_information.Clear ();
}
static public void Error (int code, Location loc, string format, string arg1, string arg2)
{
- new ErrorMessage ().Print (code, loc, String.Format (format, arg1, arg2));
+ new ErrorMessage (code, loc, String.Format (format, arg1, arg2), extra_information).Print ();
+ extra_information.Clear ();
}
- static public void Error (int code, Location loc, string format, params string[] args)
+ static public void Error (int code, Location loc, string format, params object[] args)
{
Error (code, loc, String.Format (format, args));
}
return expected_error;
}
}
+
+ public static int WarningLevel {
+ get {
+ return warning_level;
+ }
+ set {
+ warning_level = value;
+ }
+ }
public static int DebugFlags = 0;
}
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)
{
}
public InternalErrorException (string message, params object[] args)
: base (String.Format (message, args))
{ }
+
+ public InternalErrorException (Exception e, Location loc)
+ : base (loc.ToString (), e)
+ {
+ }
}
/// <summary>