X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Freport.cs;h=3ca7fd681ea6c8f72c30415f38fc3327156da84d;hb=732841a4f171062563a831fb8cd3165be1ddfd6e;hp=76a52058a353a0499b4404c3878ce83028f1f229;hpb=19392be8b6ffdb0d8661e03fa95350f8f0b21215;p=mono.git
diff --git a/mcs/mcs/report.cs b/mcs/mcs/report.cs
index 76a52058a35..3ca7fd681ea 100644
--- a/mcs/mcs/report.cs
+++ b/mcs/mcs/report.cs
@@ -4,70 +4,50 @@
// Author: Miguel de Icaza (miguel@ximian.com)
// Marek Safar (marek.safar@seznam.cz)
//
-// (C) 2001 Ximian, Inc. (http://www.ximian.com)
+// Copyright 2001 Ximian, Inc. (http://www.ximian.com)
//
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;
namespace Mono.CSharp {
- ///
- /// This class is used to report errors and warnings t te user.
- ///
- public class Report {
- ///
- /// Errors encountered so far
- ///
- static public int Errors;
-
- ///
- /// Warnings encountered so far
- ///
- static public int Warnings;
-
- ///
- /// Whether errors should be throw an exception
- ///
- static public bool Fatal;
-
+ //
+ // Errors and warnings manager
+ //
+ public class Report
+ {
///
/// Whether warnings should be considered errors
///
- static public bool WarningsAreErrors;
-
- ///
- /// Whether to dump a stack trace on errors.
- ///
- static public bool Stacktrace;
+ public bool WarningsAreErrors;
+ List warnings_as_error;
+ List warnings_only;
- static public TextWriter Stderr = Console.Error;
-
- //
- // If the 'expected' error code is reported then the
- // compilation succeeds.
- //
- // Used for the test suite to excercise the error codes
- //
- static int expected_error = 0;
+ public static int DebugFlags = 0;
//
// Keeps track of the warnings that we are ignoring
//
- public static Hashtable warning_ignore_table;
+ public Dictionary warning_ignore_table;
- static Hashtable warning_regions_table;
+ Dictionary warning_regions_table;
+ int warning_level;
+
+ ReportPrinter printer;
+
+ int reporting_disabled;
+
///
/// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
///
- static StringCollection extra_information = new StringCollection ();
+ List extra_information = new List ();
//
// IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
@@ -75,19 +55,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,
- 419, 420, 429, 436, 440, 465, 467, 469,
- 612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675,
- 1030, 1058,
+ 219, 251, 252, 253, 278, 282,
+ 402, 414, 419, 420, 429, 436, 440, 458, 464, 465, 467, 469, 472,
+ 612, 618, 626, 628, 642, 649, 652, 658, 659, 660, 661, 665, 672, 675, 693,
+ 809,
+ 1030, 1058, 1066,
1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592,
- 1616, 1633, 1634, 1635, 1690, 1691, 1692,
- 1717, 1718, 1720,
+ 1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692,
+ 1700, 1717, 1718, 1720,
1901,
- 2002, 2023,
- 3005, 3012, 3019, 3021, 3022, 3023, 3026, 3027,
-#if GMCS_SOURCE
- 402, 414, 693, 1700, 3024
-#endif
+ 2002, 2023, 2029,
+ 3000, 3001, 3002, 3003, 3005, 3006, 3007, 3008, 3009,
+ 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019,
+ 3021, 3022, 3023, 3024, 3026, 3027
};
static Report ()
@@ -96,388 +76,351 @@ namespace Mono.CSharp {
Array.Sort (AllWarnings);
}
- public static void Reset ()
+ public Report (ReportPrinter printer)
{
- Errors = Warnings = 0;
- WarningsAreErrors = false;
- warning_ignore_table = null;
- warning_regions_table = null;
- }
+ if (printer == null)
+ throw new ArgumentNullException ("printer");
- abstract class AbstractMessage {
-
- static void Check (int code)
- {
- if (code == expected_error) {
- Environment.Exit (0);
- }
- }
-
- public abstract bool IsWarning { get; }
-
- public abstract string MessageType { get; }
-
- public virtual void Print (int code, string location, string text)
- {
- if (code < 0)
- code = 8000-code;
-
- StringBuilder msg = new StringBuilder ();
- if (location.Length != 0) {
- msg.Append (location);
- msg.Append (' ');
- }
- msg.AppendFormat ("{0} CS{1:0000}: {2}", MessageType, code, text);
- Stderr.WriteLine (msg.ToString ());
-
- foreach (string s in extra_information)
- Stderr.WriteLine (s + MessageType + ")");
-
- extra_information.Clear ();
+ this.printer = printer;
+ warning_level = 4;
+ }
- if (Stacktrace)
- Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
+ public void DisableReporting ()
+ {
+ ++reporting_disabled;
+ }
- if (Fatal) {
- if (!IsWarning || WarningsAreErrors)
- throw new Exception (text);
- }
+ public void EnableReporting ()
+ {
+ --reporting_disabled;
+ }
- Check (code);
+ public void FeatureIsNotAvailable (Location loc, string feature)
+ {
+ string version;
+ switch (RootContext.Version) {
+ case LanguageVersion.ISO_1:
+ version = "1.0";
+ break;
+ case LanguageVersion.ISO_2:
+ version = "2.0";
+ break;
+ case LanguageVersion.V_3:
+ version = "3.0";
+ break;
+ default:
+ throw new InternalErrorException ("Invalid feature version", RootContext.Version);
}
- public virtual void Print (int code, Location location, string text)
- {
- Print (code, location.IsNull ? "" : location.ToString (), text);
- }
+ Error (1644, loc,
+ "Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
+ feature, version);
}
- sealed class WarningMessage : AbstractMessage {
- Location loc = Location.Null;
- readonly int Level;
-
- public WarningMessage (int level)
- {
- Level = level;
- }
+ public void FeatureIsNotSupported (Location loc, string feature)
+ {
+ Error (1644, loc,
+ "Feature `{0}' is not supported in Mono mcs1 compiler. Consider using the `gmcs' compiler instead",
+ feature);
+ }
+
+ static bool IsValidWarning (int code)
+ {
+ return Array.BinarySearch (AllWarnings, code) >= 0;
+ }
- public override bool IsWarning {
- get { return true; }
- }
+ bool IsWarningEnabled (int code, int level, Location loc)
+ {
+ if (WarningLevel < level)
+ return false;
- bool IsEnabled (int code)
- {
- if (RootContext.WarningLevel < Level)
+ if (warning_ignore_table != null) {
+ if (warning_ignore_table.ContainsKey (code)) {
return false;
-
- if (warning_ignore_table != null) {
- if (warning_ignore_table.Contains (code)) {
- return false;
- }
- }
-
- if (warning_regions_table == null || loc.Equals (Location.Null))
- return true;
-
- WarningRegions regions = (WarningRegions)warning_regions_table [loc.Name];
- if (regions == null)
- return true;
-
- return regions.IsWarningEnabled (code, loc.Row);
- }
-
- public override void Print(int code, string location, string text)
- {
- if (!IsEnabled (code)) {
- extra_information.Clear ();
- return;
}
-
- if (WarningsAreErrors) {
- new ErrorMessage ().Print (code, location, text);
- return;
- }
-
- Warnings++;
- base.Print (code, location, text);
- }
-
- public override void Print(int code, Location location, string text)
- {
- loc = location;
- base.Print (code, location, text);
- }
-
- public override string MessageType {
- get {
- return "warning";
- }
- }
- }
-
- sealed class ErrorMessage : AbstractMessage {
-
- public override void Print(int code, string location, string text)
- {
- Errors++;
- base.Print (code, location, text);
}
- public override bool IsWarning {
- get { return false; }
- }
+ if (warning_regions_table == null || loc.IsNull)
+ return true;
- public override string MessageType {
- get {
- return "error";
- }
- }
+ WarningRegions regions;
+ if (!warning_regions_table.TryGetValue (loc.Name, out regions))
+ return true;
+ return regions.IsWarningEnabled (code, loc.Row);
}
- public static void FeatureIsNotStandardized (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);
- }
-
- public static string FriendlyStackTrace (Exception e)
+ bool IsWarningAsError (int code)
{
- return FriendlyStackTrace (new StackTrace (e, true));
- }
-
- static string FriendlyStackTrace (StackTrace t)
- {
- StringBuilder sb = new StringBuilder ();
-
- bool foundUserCode = false;
-
- for (int i = 0; i < t.FrameCount; i++) {
- StackFrame f = t.GetFrame (i);
- MethodBase mb = f.GetMethod ();
-
- if (!foundUserCode && mb.ReflectedType == typeof (Report))
- continue;
-
- foundUserCode = true;
-
- sb.Append ("\tin ");
-
- if (f.GetFileLineNumber () > 0)
- sb.AppendFormat ("(at {0}:{1}) ", f.GetFileName (), f.GetFileLineNumber ());
-
- sb.AppendFormat ("{0}.{1} (", mb.ReflectedType.Name, mb.Name);
-
- bool first = true;
- foreach (ParameterInfo pi in mb.GetParameters ()) {
- if (!first)
- sb.Append (", ");
- first = false;
-
- sb.Append (TypeManager.CSharpName (pi.ParameterType));
- }
- sb.Append (")\n");
- }
-
- return sb.ToString ();
- }
+ bool is_error = WarningsAreErrors;
- public static void StackTrace ()
- {
- Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
- }
+ // Check specific list
+ if (warnings_as_error != null)
+ is_error |= warnings_as_error.Contains (code);
- public static bool IsValidWarning (int code)
- {
- return Array.BinarySearch (AllWarnings, code) >= 0;
+ // Ignore excluded warnings
+ if (warnings_only != null && warnings_only.Contains (code))
+ is_error = false;
+
+ return is_error;
}
- static public void RuntimeMissingSupport (Location loc, string feature)
+ 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);
+ Error (-88, loc, "Your .NET Runtime does not support `{0}'. Please use the latest Mono runtime instead.", feature);
}
///
/// 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.
///
- static public void SymbolRelatedToPreviousError (Location loc, string symbol)
+ public void SymbolRelatedToPreviousError (Location loc, string symbol)
{
SymbolRelatedToPreviousError (loc.ToString (), symbol);
}
- static public void SymbolRelatedToPreviousError (MemberInfo mi)
+ public void SymbolRelatedToPreviousError (MemberSpec ms)
{
- Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
- TypeContainer temp_ds = TypeManager.LookupTypeContainer (dt);
- if (temp_ds == null) {
- SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
- } else {
- MethodBase mb = mi as MethodBase;
- if (mb != null) {
- mb = TypeManager.DropGenericMethodArguments (mb);
- IMethodData md = TypeManager.GetMethod (mb);
- SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
- return;
- }
+ if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
+ return;
- MemberCore mc = temp_ds.GetDefinition (mi.Name);
+ var mc = ms.MemberDefinition as MemberCore;
+ if (mc != null) {
SymbolRelatedToPreviousError (mc);
+ } else {
+ var im = ms.MemberDefinition as ImportedMemberDefinition;
+ SymbolRelatedToPreviousError (im.Assembly.Location, "");
}
}
- static public void SymbolRelatedToPreviousError (MemberCore mc)
+ public void SymbolRelatedToPreviousError (MemberCore mc)
{
SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
}
- static public void SymbolRelatedToPreviousError (Type type)
+ void SymbolRelatedToPreviousError (string loc, string symbol)
{
- type = TypeManager.DropGenericTypeArguments (type);
+ string msg = String.Format ("{0} (Location of the symbol related to previous ", loc);
+ if (extra_information.Contains (msg))
+ return;
- if (TypeManager.IsGenericParameter (type)) {
- TypeParameter tp = TypeManager.LookupTypeParameter (type);
- if (tp != null) {
- SymbolRelatedToPreviousError (tp.Location, "");
- return;
- }
+ extra_information.Add (msg);
+ }
+
+ public void AddWarningAsError (string warningId)
+ {
+ int id;
+ try {
+ id = int.Parse (warningId);
+ } catch {
+ id = -1;
}
- if (type is TypeBuilder) {
- DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
- SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
- } else if (type.HasElementType) {
- SymbolRelatedToPreviousError (type.GetElementType ());
- } else {
- SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
+ if (!CheckWarningCode (id, warningId, Location.Null))
+ return;
+
+ if (warnings_as_error == null)
+ warnings_as_error = new List ();
+
+ warnings_as_error.Add (id);
+ }
+
+ public void RemoveWarningAsError (string warningId)
+ {
+ int id;
+ try {
+ id = int.Parse (warningId);
+ } catch {
+ id = -1;
}
+
+ if (!CheckWarningCode (id, warningId, Location.Null))
+ return;
+
+ if (warnings_only == null)
+ warnings_only = new List ();
+
+ warnings_only.Add (id);
}
- static void SymbolRelatedToPreviousError (string loc, string symbol)
+ public bool CheckWarningCode (int code, Location loc)
{
- extra_information.Add (String.Format ("{0} (Location of the symbol related to previous ", loc));
+ return CheckWarningCode (code, code.ToString (), loc);
}
- public static void ExtraInformation (Location loc, string msg)
+ public bool CheckWarningCode (int code, string scode, Location loc)
+ {
+ if (IsValidWarning (code))
+ return true;
+
+ Warning (1691, 1, loc, "`{0}' is not a valid warning number", scode);
+ return false;
+ }
+
+ public void ExtraInformation (Location loc, string msg)
{
extra_information.Add (String.Format ("{0} {1}", loc, msg));
}
- public static WarningRegions RegisterWarningRegion (Location location)
+ 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 ();
+ } 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;
}
- static public void Warning (int code, int level, Location loc, string message)
+ public void Warning (int code, int level, Location loc, string message)
{
- WarningMessage w = new WarningMessage (level);
- w.Print (code, loc, message);
+ if (reporting_disabled > 0)
+ return;
+
+ if (!IsWarningEnabled (code, level, loc))
+ return;
+
+ AbstractMessage msg;
+ if (IsWarningAsError (code))
+ msg = new ErrorMessage (code, loc, message, extra_information);
+ else
+ msg = new WarningMessage (code, loc, message, extra_information);
+
+ extra_information.Clear ();
+ printer.Print (msg);
}
- static public void Warning (int code, int level, Location loc, string format, string arg)
+ 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));
+ Warning (code, level, loc, String.Format (format, arg));
}
- static public void Warning (int code, int level, Location loc, string format, string arg1, string arg2)
+ 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));
+ Warning (code, level, loc, String.Format (format, arg1, arg2));
}
- static public void Warning (int code, int level, Location loc, string format, params string[] args)
+ 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));
+ Warning (code, level, loc, String.Format (format, args));
}
- static public void Warning (int code, int level, string message)
+ public void Warning (int code, int level, string message)
{
Warning (code, level, Location.Null, message);
}
- static public void Warning (int code, int level, string format, string arg)
+ public void Warning (int code, int level, string format, string arg)
{
Warning (code, level, Location.Null, format, arg);
}
- static public void Warning (int code, int level, string format, string arg1, string arg2)
+ public void Warning (int code, int level, string format, string arg1, string arg2)
{
Warning (code, level, Location.Null, format, arg1, arg2);
}
- static public void Warning (int code, int level, string format, params string[] args)
+ public void Warning (int code, int level, string format, params string[] args)
{
Warning (code, level, Location.Null, String.Format (format, args));
}
- static public void Error (int code, Location loc, string error)
+ //
+ // Warnings encountered so far
+ //
+ public int Warnings {
+ get { return printer.WarningsCount; }
+ }
+
+ public void Error (int code, Location loc, string error)
{
- new ErrorMessage ().Print (code, loc, error);
+ if (reporting_disabled > 0)
+ return;
+
+ ErrorMessage msg = new ErrorMessage (code, loc, error, extra_information);
+ extra_information.Clear ();
+
+ printer.Print (msg);
}
- static public void Error (int code, Location loc, string format, string arg)
+ public void Error (int code, Location loc, string format, string arg)
{
- new ErrorMessage ().Print (code, loc, String.Format (format, arg));
+ Error (code, loc, String.Format (format, arg));
}
- static public void Error (int code, Location loc, string format, string arg1, string arg2)
+ public void Error (int code, Location loc, string format, string arg1, string arg2)
{
- new ErrorMessage ().Print (code, loc, String.Format (format, arg1, arg2));
+ Error (code, loc, String.Format (format, arg1, arg2));
}
- static public void Error (int code, Location loc, string format, params string[] args)
+ 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)
+ public void Error (int code, string error)
{
Error (code, Location.Null, error);
}
- static public void Error (int code, string format, string arg)
+ 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)
+ 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)
+ public void Error (int code, string format, params string[] args)
{
Error (code, Location.Null, String.Format (format, args));
}
- static public void SetIgnoreWarning (int code)
+ //
+ // Errors encountered so far
+ //
+ public int Errors {
+ get { return printer.ErrorsCount; }
+ }
+
+ public ReportPrinter Printer {
+ get { return printer; }
+ }
+
+ public void SetIgnoreWarning (int code)
{
if (warning_ignore_table == null)
- warning_ignore_table = new Hashtable ();
+ warning_ignore_table = new Dictionary ();
warning_ignore_table [code] = true;
}
-
- static public int ExpectedError {
- set {
- expected_error = value;
- }
+
+ public ReportPrinter SetPrinter (ReportPrinter printer)
+ {
+ ReportPrinter old = this.printer;
+ this.printer = printer;
+ return old;
+ }
+
+ public int WarningLevel {
get {
- return expected_error;
+ return warning_level;
+ }
+ set {
+ warning_level = value;
}
}
- public static int DebugFlags = 0;
-
[Conditional ("MCS_DEBUG")]
static public void Debug (string message, params object[] args)
{
@@ -503,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);
}
@@ -512,7 +455,7 @@ namespace Mono.CSharp {
Console.WriteLine (sb.ToString ());
}
-
+/*
static public string PrintCollection (ICollection collection)
{
StringBuilder sb = new StringBuilder ();
@@ -532,6 +475,474 @@ namespace Mono.CSharp {
sb.Append (")");
return sb.ToString ();
}
+*/
+ }
+
+ 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, List extraInfo)
+ {
+ this.code = code;
+ if (code < 0)
+ this.code = 8000 - code;
+
+ this.location = loc;
+ this.message = msg;
+ if (extraInfo.Count != 0) {
+ this.extra_info = extraInfo.ToArray ();
+ }
+ }
+
+ protected AbstractMessage (AbstractMessage aMsg)
+ {
+ this.code = aMsg.code;
+ this.location = aMsg.location;
+ this.message = aMsg.message;
+ this.extra_info = aMsg.extra_info;
+ }
+
+ public int Code {
+ get { return 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 Location Location {
+ get { return location; }
+ }
+
+ public abstract string MessageType { get; }
+
+ public string[] RelatedSymbols {
+ get { return extra_info; }
+ }
+
+ public string Text {
+ get { return message; }
+ }
+ }
+
+ sealed class WarningMessage : AbstractMessage
+ {
+ public WarningMessage (int code, Location loc, string message, List extra_info)
+ : base (code, loc, message, extra_info)
+ {
+ }
+
+ public override bool IsWarning {
+ get { return true; }
+ }
+
+ public override string MessageType {
+ get {
+ return "warning";
+ }
+ }
+ }
+
+ sealed class ErrorMessage : AbstractMessage
+ {
+ public ErrorMessage (int code, Location loc, string message, List extraInfo)
+ : base (code, loc, message, extraInfo)
+ {
+ }
+
+ public ErrorMessage (AbstractMessage aMsg)
+ : base (aMsg)
+ {
+ }
+
+ public override bool IsWarning {
+ get { return false; }
+ }
+
+ public override string MessageType {
+ get {
+ return "error";
+ }
+ }
+ }
+
+ //
+ // Generic base for any message writer
+ //
+ public abstract class ReportPrinter {
+ ///
+ /// Whether to dump a stack trace on errors.
+ ///
+ public bool Stacktrace;
+
+ int warnings, errors;
+
+ public int WarningsCount {
+ get { return warnings; }
+ }
+
+ public int ErrorsCount {
+ get { return errors; }
+ }
+
+ protected virtual string FormatText (string txt)
+ {
+ return txt;
+ }
+
+ //
+ // When (symbols related to previous ...) can be used
+ //
+ public virtual bool HasRelatedSymbolSupport {
+ get { return true; }
+ }
+
+ public virtual void Print (AbstractMessage msg)
+ {
+ if (msg.IsWarning)
+ ++warnings;
+ else
+ ++errors;
+ }
+
+ protected void Print (AbstractMessage msg, TextWriter output)
+ {
+ StringBuilder txt = new StringBuilder ();
+ if (!msg.Location.IsNull) {
+ txt.Append (msg.Location.ToString ());
+ txt.Append (" ");
+ }
+
+ txt.AppendFormat ("{0} CS{1:0000}: {2}", msg.MessageType, msg.Code, msg.Text);
+
+ if (!msg.IsWarning)
+ output.WriteLine (FormatText (txt.ToString ()));
+ else
+ output.WriteLine (txt.ToString ());
+
+ if (msg.RelatedSymbols != null) {
+ foreach (string s in msg.RelatedSymbols)
+ output.WriteLine (s + msg.MessageType + ")");
+ }
+ }
+ }
+
+ //
+ // 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.
+ //
+ // Used by the Lambda expressions to compile the code with various
+ // parameter values, or by attribute resolver
+ //
+ class SessionReportPrinter : ReportPrinter
+ {
+ List session_messages;
+ //
+ // A collection of exactly same messages reported in all sessions
+ //
+ List common_messages;
+
+ //
+ // A collection of unique messages reported in all sessions
+ //
+ List merged_messages;
+
+ public override void Print (AbstractMessage msg)
+ {
+ //
+ // This line is useful when debugging recorded messages
+ //
+ // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
+
+ if (session_messages == null)
+ session_messages = new List ();
+
+ session_messages.Add (msg);
+
+ base.Print (msg);
+ }
+
+ public void EndSession ()
+ {
+ if (session_messages == null)
+ return;
+
+ //
+ // Handles the first session
+ //
+ if (common_messages == null) {
+ common_messages = new List (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 bool IsEmpty {
+ get {
+ return merged_messages == null && common_messages == null;
+ }
+ }
+
+ //
+ // Prints collected messages, common messages have a priority
+ //
+ public bool Merge (ReportPrinter dest)
+ {
+ var 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)
+ dest.Print (msg);
+
+ return true;
+ }
+ }
+
+ class StreamReportPrinter : ReportPrinter
+ {
+ readonly TextWriter writer;
+
+ public StreamReportPrinter (TextWriter writer)
+ {
+ this.writer = writer;
+ }
+
+ public override void Print (AbstractMessage msg)
+ {
+ Print (msg, writer);
+ base.Print (msg);
+ }
+ }
+
+ class ConsoleReportPrinter : StreamReportPrinter
+ {
+ static readonly string prefix, postfix;
+
+ static ConsoleReportPrinter ()
+ {
+ string term = Environment.GetEnvironmentVariable ("TERM");
+ bool xterm_colors = false;
+
+ switch (term){
+ case "xterm":
+ case "rxvt":
+ case "rxvt-unicode":
+ if (Environment.GetEnvironmentVariable ("COLORTERM") != null){
+ xterm_colors = true;
+ }
+ break;
+
+ case "xterm-color":
+ xterm_colors = true;
+ break;
+ }
+ if (!xterm_colors)
+ return;
+
+ if (!(UnixUtils.isatty (1) && UnixUtils.isatty (2)))
+ return;
+
+ string config = Environment.GetEnvironmentVariable ("MCS_COLORS");
+ if (config == null){
+ config = "errors=red";
+ //config = "brightwhite,red";
+ }
+
+ if (config == "disable")
+ return;
+
+ if (!config.StartsWith ("errors="))
+ return;
+
+ config = config.Substring (7);
+
+ int p = config.IndexOf (",");
+ if (p == -1)
+ prefix = GetForeground (config);
+ else
+ prefix = GetBackground (config.Substring (p+1)) + GetForeground (config.Substring (0, p));
+ postfix = "\x001b[0m";
+ }
+
+ public ConsoleReportPrinter ()
+ : base (Console.Error)
+ {
+ }
+
+ public ConsoleReportPrinter (TextWriter writer)
+ : base (writer)
+ {
+ }
+
+ public int Fatal { get; set; }
+
+ static int NameToCode (string s)
+ {
+ switch (s) {
+ case "black":
+ return 0;
+ case "red":
+ return 1;
+ case "green":
+ return 2;
+ case "yellow":
+ return 3;
+ case "blue":
+ return 4;
+ case "magenta":
+ return 5;
+ case "cyan":
+ return 6;
+ case "grey":
+ case "white":
+ return 7;
+ }
+ return 7;
+ }
+
+ //
+ // maps a color name to its xterm color code
+ //
+ static string GetForeground (string s)
+ {
+ string highcode;
+
+ if (s.StartsWith ("bright")) {
+ highcode = "1;";
+ s = s.Substring (6);
+ } else
+ highcode = "";
+
+ return "\x001b[" + highcode + (30 + NameToCode (s)).ToString () + "m";
+ }
+
+ static string GetBackground (string s)
+ {
+ return "\x001b[" + (40 + NameToCode (s)).ToString () + "m";
+ }
+
+ protected override string FormatText (string txt)
+ {
+ if (prefix != null)
+ return prefix + txt + postfix;
+
+ return txt;
+ }
+
+ static string FriendlyStackTrace (StackTrace t)
+ {
+ StringBuilder sb = new StringBuilder ();
+
+ bool foundUserCode = false;
+
+ for (int i = 0; i < t.FrameCount; i++) {
+ StackFrame f = t.GetFrame (i);
+ MethodBase mb = f.GetMethod ();
+
+ if (!foundUserCode && mb.ReflectedType == typeof (Report))
+ continue;
+
+ foundUserCode = true;
+
+ sb.Append ("\tin ");
+
+ if (f.GetFileLineNumber () > 0)
+ sb.AppendFormat ("(at {0}:{1}) ", f.GetFileName (), f.GetFileLineNumber ());
+
+ sb.AppendFormat ("{0}.{1} (", mb.ReflectedType.Name, mb.Name);
+
+ bool first = true;
+ foreach (ParameterInfo pi in mb.GetParameters ()) {
+ if (!first)
+ sb.Append (", ");
+ first = false;
+
+ sb.Append (pi.ParameterType.FullName);
+ }
+ sb.Append (")\n");
+ }
+
+ 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)
+ {
+ return FriendlyStackTrace (new StackTrace (e, true));
+ }
+
+ public static void StackTrace ()
+ {
+ Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
+ }
}
public enum TimerType {
@@ -621,8 +1032,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)
{
}
@@ -639,6 +1050,11 @@ namespace Mono.CSharp {
public InternalErrorException (string message, params object[] args)
: base (String.Format (message, args))
{ }
+
+ public InternalErrorException (Exception e, Location loc)
+ : base (loc.ToString (), e)
+ {
+ }
}
///
@@ -711,16 +1127,16 @@ namespace Mono.CSharp {
}
- ArrayList regions = new ArrayList ();
+ List regions = new List ();
public void WarningDisable (int line)
{
regions.Add (new DisableAll (line));
}
- public void WarningDisable (Location location, int code)
+ public void WarningDisable (Location location, int code, Report Report)
{
- if (CheckWarningCode (code, location))
+ if (Report.CheckWarningCode (code, location))
regions.Add (new Disable (location.Row, code));
}
@@ -729,9 +1145,9 @@ namespace Mono.CSharp {
regions.Add (new EnableAll (line));
}
- public void WarningEnable (Location location, int code)
+ public void WarningEnable (Location location, int code, Report Report)
{
- if (CheckWarningCode (code, location))
+ if (Report.CheckWarningCode (code, location))
regions.Add (new Enable (location.Row, code));
}
@@ -746,14 +1162,5 @@ namespace Mono.CSharp {
}
return result;
}
-
- 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.ToString ());
- return false;
- }
}
}