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;
//
// Errors and warnings manager
//
- public class Report {
- /// <summary>
- /// Whether errors should be throw an exception
- /// </summary>
- public bool Fatal;
-
+ public class Report
+ {
/// <summary>
/// Whether warnings should be considered errors
/// </summary>
public bool WarningsAreErrors;
- ArrayList warnings_as_error;
- ArrayList warnings_only;
+ List<int> warnings_as_error;
+ List<int> warnings_only;
public static int DebugFlags = 0;
//
// Keeps track of the warnings that we are ignoring
//
- public Hashtable warning_ignore_table;
+ public Dictionary<int, bool> warning_ignore_table;
- Hashtable warning_regions_table;
+ Dictionary<string, WarningRegions> warning_regions_table;
int warning_level;
/// <summary>
/// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
/// </summary>
- ArrayList extra_information = new ArrayList ();
+ List<string> extra_information = new List<string> ();
//
// IF YOU ADD A NEW WARNING YOU HAVE TO ADD ITS ID HERE
return false;
if (warning_ignore_table != null) {
- if (warning_ignore_table.Contains (code)) {
+ if (warning_ignore_table.ContainsKey (code)) {
return false;
}
}
if (warning_regions_table == null || loc.IsNull)
return true;
- WarningRegions regions = (WarningRegions) warning_regions_table [loc.Name];
- if (regions == null)
+ WarningRegions regions;
+ if (!warning_regions_table.TryGetValue (loc.Name, out regions))
return true;
return regions.IsWarningEnabled (code, loc.Row);
SymbolRelatedToPreviousError (loc.ToString (), symbol);
}
- public void SymbolRelatedToPreviousError (MemberInfo mi)
+ public void SymbolRelatedToPreviousError (MemberSpec ms)
{
if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
return;
- Type dt = TypeManager.DropGenericTypeArguments (mi.DeclaringType);
- if (TypeManager.IsDelegateType (dt)) {
- SymbolRelatedToPreviousError (dt);
- return;
- }
-
- DeclSpace temp_ds = TypeManager.LookupDeclSpace (dt);
- if (temp_ds == null) {
- SymbolRelatedToPreviousError (dt.Assembly.Location, TypeManager.GetFullNameSignature (mi));
+ var mc = ms.MemberDefinition as MemberCore;
+ if (mc != null) {
+ SymbolRelatedToPreviousError (mc);
} else {
- MethodBase mb = mi as MethodBase;
- if (mb != null) {
- mb = TypeManager.DropGenericMethodArguments (mb);
- IMethodData md = TypeManager.GetMethod (mb);
- if (md != null)
- SymbolRelatedToPreviousError (md.Location, md.GetSignatureForError ());
-
- return;
- }
-
- // FIXME: Completely wrong, it has to use FindMembers
- MemberCore mc = temp_ds.GetDefinition (mi.Name);
- if (mc != null)
- SymbolRelatedToPreviousError (mc);
+ var im = ms.MemberDefinition as ImportedMemberDefinition;
+ SymbolRelatedToPreviousError (im.Assembly.Location, "");
}
}
SymbolRelatedToPreviousError (mc.Location, mc.GetSignatureForError ());
}
- public void SymbolRelatedToPreviousError (Type type)
- {
- if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
- return;
-
- 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));
- } else if (TypeManager.HasElementType (type)) {
- SymbolRelatedToPreviousError (TypeManager.GetElementType (type));
- } else {
- SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
- }
- }
-
void SymbolRelatedToPreviousError (string loc, string symbol)
{
string msg = String.Format ("{0} (Location of the symbol related to previous ", loc);
return;
if (warnings_as_error == null)
- warnings_as_error = new ArrayList ();
+ warnings_as_error = new List<int> ();
warnings_as_error.Add (id);
}
return;
if (warnings_only == null)
- warnings_only = new ArrayList ();
+ warnings_only = new List<int> ();
warnings_only.Add (id);
}
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<string, WarningRegions> ();
+ } 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;
}
extra_information.Clear ();
printer.Print (msg);
-
- if (Fatal)
- throw new Exception (msg.Text);
}
public void Error (int code, Location loc, string format, string arg)
Error (code, loc, String.Format (format, arg1, arg2));
}
- public void Error (int code, Location loc, string format, params object[] args)
+ public void Error (int code, Location loc, string format, params string[] args)
{
Error (code, loc, String.Format (format, args));
}
public void SetIgnoreWarning (int code)
{
if (warning_ignore_table == null)
- warning_ignore_table = new Hashtable ();
+ warning_ignore_table = new Dictionary<int, bool> ();
warning_ignore_table [code] = true;
}
this.printer = printer;
return old;
}
-
+
public int WarningLevel {
get {
return warning_level;
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);
}
Console.WriteLine (sb.ToString ());
}
-
+/*
static public string PrintCollection (ICollection collection)
{
StringBuilder sb = new StringBuilder ();
sb.Append (")");
return sb.ToString ();
}
+*/
}
public abstract class AbstractMessage
protected readonly Location location;
readonly string message;
- protected AbstractMessage (int code, Location loc, string msg, ArrayList extraInfo)
+ protected AbstractMessage (int code, Location loc, string msg, List<string> extraInfo)
{
this.code = code;
if (code < 0)
this.location = loc;
this.message = msg;
if (extraInfo.Count != 0) {
- this.extra_info = (string[])extraInfo.ToArray (typeof (string));
+ this.extra_info = extraInfo.ToArray ();
}
}
sealed class WarningMessage : AbstractMessage
{
- public WarningMessage (int code, Location loc, string message, ArrayList extra_info)
+ public WarningMessage (int code, Location loc, string message, List<string> extra_info)
: base (code, loc, message, extra_info)
{
}
sealed class ErrorMessage : AbstractMessage
{
- public ErrorMessage (int code, Location loc, string message, ArrayList extraInfo)
+ public ErrorMessage (int code, Location loc, string message, List<string> extraInfo)
: base (code, loc, message, extraInfo)
{
}
//
// Generic base for any message writer
//
- public abstract class ReportPrinter
- {
+ public abstract class ReportPrinter {
/// <summary>
/// Whether to dump a stack trace on errors.
/// </summary>
//
class SessionReportPrinter : ReportPrinter
{
- ArrayList session_messages;
+ List<AbstractMessage> session_messages;
//
// A collection of exactly same messages reported in all sessions
//
- ArrayList common_messages;
+ List<AbstractMessage> common_messages;
//
// A collection of unique messages reported in all sessions
//
- ArrayList merged_messages;
+ List<AbstractMessage> merged_messages;
public override void Print (AbstractMessage msg)
{
// Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message);
if (session_messages == null)
- session_messages = new ArrayList ();
+ session_messages = new List<AbstractMessage> ();
session_messages.Add (msg);
// Handles the first session
//
if (common_messages == null) {
- common_messages = new ArrayList (session_messages);
+ common_messages = new List<AbstractMessage> (session_messages);
merged_messages = session_messages;
session_messages = null;
return;
//
public bool Merge (ReportPrinter dest)
{
- ArrayList messages_to_print = merged_messages;
+ var messages_to_print = merged_messages;
if (common_messages != null && common_messages.Count > 0) {
messages_to_print = common_messages;
}
{
}
+ public int Fatal { get; set; }
+
static int NameToCode (string s)
{
switch (s) {
if (!first)
sb.Append (", ");
first = false;
-
- sb.Append (TypeManager.CSharpName (pi.ParameterType));
+
+ 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)
}
- ArrayList regions = new ArrayList ();
+ List<PragmaCmd> regions = new List<PragmaCmd> ();
public void WarningDisable (int line)
{