X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Freport.cs;h=9f989954da5485a1e4f028bf848ee3a936444d44;hb=92f60fbffa1187be7dedf6a9286b5c35b2082815;hp=77058a17208e6acf67e085ff7297d1028f83790c;hpb=9e1f34dd2d7be45b2a3a6b1c133a4a1de8c3d864;p=mono.git diff --git a/mcs/mcs/report.cs b/mcs/mcs/report.cs index 77058a17208..9f989954da5 100644 --- a/mcs/mcs/report.cs +++ b/mcs/mcs/report.cs @@ -13,7 +13,6 @@ using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; -using System.Reflection.Emit; namespace Mono.CSharp { @@ -31,12 +30,14 @@ namespace Mono.CSharp { public static int DebugFlags = 0; + public const int RuntimeErrorId = 10000; + // // Keeps track of the warnings that we are ignoring // - public Dictionary warning_ignore_table; + HashSet warning_ignore_table; - Dictionary warning_regions_table; + Dictionary warning_regions_table; int warning_level; @@ -61,20 +62,16 @@ namespace Mono.CSharp { 809, 1030, 1058, 1066, 1522, 1570, 1571, 1572, 1573, 1574, 1580, 1581, 1584, 1587, 1589, 1590, 1591, 1592, - 1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692, - 1700, 1717, 1718, 1720, - 1901, + 1616, 1633, 1634, 1635, 1685, 1690, 1691, 1692, 1695, 1696, 1699, + 1700, 1709, 1717, 1718, 1720, + 1901, 1981, 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 () - { - // Just to be sure that binary search is working - Array.Sort (AllWarnings); - } + static HashSet AllWarningsHashSet; public Report (ReportPrinter printer) { @@ -124,32 +121,29 @@ namespace Mono.CSharp { feature); } - static bool IsValidWarning (int code) - { - return Array.BinarySearch (AllWarnings, code) >= 0; - } - bool IsWarningEnabled (int code, int level, Location loc) { if (WarningLevel < level) return false; - if (warning_ignore_table != null) { - if (warning_ignore_table.ContainsKey (code)) { - return false; - } - } + if (IsWarningDisabledGlobally (code)) + return false; if (warning_regions_table == null || loc.IsNull) return true; WarningRegions regions; - if (!warning_regions_table.TryGetValue (loc.Name, out regions)) + if (!warning_regions_table.TryGetValue (loc.File, out regions)) return true; return regions.IsWarningEnabled (code, loc.Row); } + public bool IsWarningDisabledGlobally (int code) + { + return warning_ignore_table != null && warning_ignore_table.Contains (code); + } + bool IsWarningAsError (int code) { bool is_error = WarningsAreErrors; @@ -179,35 +173,21 @@ namespace Mono.CSharp { 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)); - } 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; - } + var mc = ms.MemberDefinition as MemberCore; + while (ms is ElementTypeSpec) { + ms = ((ElementTypeSpec) ms).Element; + mc = ms.MemberDefinition as MemberCore; + } - // FIXME: Completely wrong, it has to use FindMembers - MemberCore mc = temp_ds.GetDefinition (mi.Name); - if (mc != null) - SymbolRelatedToPreviousError (mc); + if (mc != null) { + SymbolRelatedToPreviousError (mc); + } else if (ms.MemberDefinition != null) { + SymbolRelatedToPreviousError (ms.MemberDefinition.Assembly.Location, ""); } } @@ -216,31 +196,6 @@ namespace Mono.CSharp { 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); @@ -256,10 +211,11 @@ namespace Mono.CSharp { try { id = int.Parse (warningId); } catch { - id = -1; + CheckWarningCode (warningId, Location.Null); + return; } - if (!CheckWarningCode (id, warningId, Location.Null)) + if (!CheckWarningCode (id, Location.Null)) return; if (warnings_as_error == null) @@ -274,10 +230,11 @@ namespace Mono.CSharp { try { id = int.Parse (warningId); } catch { - id = -1; + CheckWarningCode (warningId, Location.Null); + return; } - if (!CheckWarningCode (id, warningId, Location.Null)) + if (!CheckWarningCode (id, Location.Null)) return; if (warnings_only == null) @@ -286,18 +243,21 @@ namespace Mono.CSharp { warnings_only.Add (id); } - public bool CheckWarningCode (int code, Location loc) + public bool CheckWarningCode (string code, Location loc) { - return CheckWarningCode (code, code.ToString (), loc); + Warning (1691, 1, loc, "`{0}' is not a valid warning number", code); + return false; } - public bool CheckWarningCode (int code, string scode, Location loc) + public bool CheckWarningCode (int code, Location loc) { - if (IsValidWarning (code)) + if (AllWarningsHashSet == null) + AllWarningsHashSet = new HashSet (AllWarnings); + + if (AllWarningsHashSet.Contains (code)) return true; - Warning (1691, 1, loc, "`{0}' is not a valid warning number", scode); - return false; + return CheckWarningCode (code.ToString (), loc); } public void ExtraInformation (Location loc, string msg) @@ -310,14 +270,14 @@ namespace Mono.CSharp { WarningRegions regions; if (warning_regions_table == null) { regions = null; - warning_regions_table = new Dictionary (); + warning_regions_table = new Dictionary (); } else { - warning_regions_table.TryGetValue (location.Name, out regions); + warning_regions_table.TryGetValue (location.File, out regions); } if (regions == null) { regions = new WarningRegions (); - warning_regions_table.Add (location.Name, regions); + warning_regions_table.Add (location.File, regions); } return regions; @@ -404,7 +364,7 @@ namespace Mono.CSharp { 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)); } @@ -436,6 +396,12 @@ namespace Mono.CSharp { get { return printer.ErrorsCount; } } + public bool IsDisabled { + get { + return reporting_disabled > 0; + } + } + public ReportPrinter Printer { get { return printer; } } @@ -443,9 +409,9 @@ namespace Mono.CSharp { public void SetIgnoreWarning (int code) { if (warning_ignore_table == null) - warning_ignore_table = new Dictionary (); + warning_ignore_table = new HashSet (); - warning_ignore_table [code] = true; + warning_ignore_table.Add (code); } public ReportPrinter SetPrinter (ReportPrinter printer) @@ -712,7 +678,7 @@ namespace Mono.CSharp { // // This line is useful when debugging recorded messages // - // Console.WriteLine ("RECORDING: {0} {1} {2}", code, location, message); + // Console.WriteLine ("RECORDING: {0}", msg.ToString ()); if (session_messages == null) session_messages = new List (); @@ -741,7 +707,7 @@ namespace Mono.CSharp { // Store common messages if any // for (int i = 0; i < common_messages.Count; ++i) { - AbstractMessage cmsg = (AbstractMessage) common_messages[i]; + AbstractMessage cmsg = common_messages[i]; bool common_msg_found = false; foreach (AbstractMessage msg in session_messages) { if (cmsg.Equals (msg)) { @@ -758,7 +724,7 @@ namespace Mono.CSharp { // Merge session and previous messages // for (int i = 0; i < session_messages.Count; ++i) { - AbstractMessage msg = (AbstractMessage) session_messages[i]; + AbstractMessage msg = session_messages[i]; bool msg_found = false; for (int ii = 0; ii < merged_messages.Count; ++ii) { if (msg.Equals (merged_messages[ii])) { @@ -791,10 +757,13 @@ namespace Mono.CSharp { if (messages_to_print == null) return false; - foreach (AbstractMessage msg in messages_to_print) + bool error_msg = false; + foreach (AbstractMessage msg in messages_to_print) { dest.Print (msg); + error_msg |= !msg.IsWarning; + } - return true; + return error_msg; } } @@ -956,8 +925,8 @@ namespace Mono.CSharp { if (!first) sb.Append (", "); first = false; - - sb.Append (TypeManager.CSharpName (pi.ParameterType)); + + sb.Append (pi.ParameterType.FullName); } sb.Append (")\n"); } @@ -1092,7 +1061,13 @@ namespace Mono.CSharp { public InternalErrorException (string message, params object[] args) : base (String.Format (message, args)) - { } + { + } + + public InternalErrorException (Exception exception, string message, params object[] args) + : base (String.Format (message, args), exception) + { + } public InternalErrorException (Exception e, Location loc) : base (loc.ToString (), e) @@ -1190,8 +1165,13 @@ namespace Mono.CSharp { public void WarningEnable (Location location, int code, Report Report) { - if (Report.CheckWarningCode (code, location)) - regions.Add (new Enable (location.Row, code)); + if (!Report.CheckWarningCode (code, location)) + return; + + if (Report.IsWarningDisabledGlobally (code)) + Report.Warning (1635, 1, location, "Cannot restore warning `CS{0:0000}' because it was disabled globally", code); + + regions.Add (new Enable (location.Row, code)); } public bool IsWarningEnabled (int code, int src_line)