X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Ftools%2Fcorcompare%2Fmono-api-info.cs;h=8b1ad945095c64d208ea0ce2d8626209b6c68709;hb=36a31a578e18da5f9efdab9e7bc373bd7cfd8775;hp=173c39f66049505806e77363040c52de77c8df78;hpb=f4f993f4bf4b9c413f61e6b7704dbbf6964d74bd;p=mono.git diff --git a/mcs/tools/corcompare/mono-api-info.cs b/mcs/tools/corcompare/mono-api-info.cs index 173c39f6604..8b1ad945095 100644 --- a/mcs/tools/corcompare/mono-api-info.cs +++ b/mcs/tools/corcompare/mono-api-info.cs @@ -1010,6 +1010,15 @@ namespace CorCompare AddAttribute ("sealed", "true"); if (mbase.IsStatic) AddAttribute ("static", "true"); + var baseMethod = TypeHelper.GetBaseMethodInTypeHierarchy (mbase); + if (baseMethod != null && baseMethod != mbase) { + // This indicates whether this method is an override of another method. + // This information is not necessarily available in the api info for any + // particular assembly, because a method is only overriding another if + // there is a base virtual function with the same signature, and that + // base method can come from another assembly. + AddAttribute ("is-override", "true"); + } string rettype = Utils.CleanupTypeName (mbase.MethodReturnType.ReturnType); if (rettype != "System.Void" || !mbase.IsConstructor) AddAttribute ("returntype", (rettype)); @@ -1106,17 +1115,9 @@ namespace CorCompare } } - class AttributeData : BaseData + class AttributeData { - IList providers; - - AttributeData (XmlWriter writer, IList providers) - : base (writer) - { - this.providers = providers; - } - - public override void DoOutput () + public static void DoOutput (XmlWriter writer, IList providers) { if (writer == null) throw new InvalidOperationException ("Document not set"); @@ -1149,31 +1150,34 @@ namespace CorCompare string attName = Utils.CleanupTypeName (att.Constructor.DeclaringType); writer.WriteStartElement ("attribute"); - AddAttribute ("name", attName); - - var attribute_mapping = CreateAttributeMapping (att).Where ((kvp) => kvp.Key != "TypeId"); - - if (attribute_mapping.Any ()) { - writer.WriteStartElement ("properties"); - foreach (var kvp in attribute_mapping) { - string name = kvp.Key; - object o = kvp.Value; - - writer.WriteStartElement ("property"); - AddAttribute ("name", name); - - if (o == null) { - AddAttribute ("value", "null"); - } else { - string value = o.ToString (); - if (attName.EndsWith ("GuidAttribute", StringComparison.Ordinal)) - value = value.ToUpper (); - AddAttribute ("value", value); + writer.WriteAttributeString ("name", attName); + + var attribute_mapping = CreateAttributeMapping (att); + + if (attribute_mapping != null) { + var mapping = attribute_mapping.Where ((attr) => attr.Key != "TypeId"); + if (mapping.Any ()) { + writer.WriteStartElement ("properties"); + foreach (var kvp in mapping) { + string name = kvp.Key; + object o = kvp.Value; + + writer.WriteStartElement ("property"); + writer.WriteAttributeString ("name", name); + + if (o == null) { + writer.WriteAttributeString ("value", "null"); + } else { + string value = o.ToString (); + if (attName.EndsWith ("GuidAttribute", StringComparison.Ordinal)) + value = value.ToUpper (); + writer.WriteAttributeString ("value", value); + } + + writer.WriteEndElement (); // property } - - writer.WriteEndElement (); // property + writer.WriteEndElement (); // properties } - writer.WriteEndElement (); // properties } writer.WriteEndElement (); // attribute } @@ -1184,20 +1188,20 @@ namespace CorCompare static Dictionary CreateAttributeMapping (CustomAttribute attribute) { - var mapping = new Dictionary (); + Dictionary mapping = null; - PopulateMapping (mapping, attribute); + PopulateMapping (ref mapping, attribute); var constructor = attribute.Constructor.Resolve (); if (constructor == null || !constructor.HasParameters) return mapping; - PopulateMapping (mapping, constructor, attribute); + PopulateMapping (ref mapping, constructor, attribute); return mapping; } - static void PopulateMapping (Dictionary mapping, CustomAttribute attribute) + static void PopulateMapping (ref Dictionary mapping, CustomAttribute attribute) { if (!attribute.HasProperties) return; @@ -1209,13 +1213,15 @@ namespace CorCompare if (arg.Value is CustomAttributeArgument) arg = (CustomAttributeArgument) arg.Value; + if (mapping == null) + mapping = new Dictionary (StringComparer.Ordinal); mapping.Add (name, GetArgumentValue (arg.Type, arg.Value)); } } static Dictionary CreateArgumentFieldMapping (MethodDefinition constructor) { - Dictionary field_mapping = new Dictionary (); + Dictionary field_mapping = null; int? argument = null; @@ -1243,6 +1249,9 @@ namespace CorCompare if (!argument.HasValue) break; + if (field_mapping == null) + field_mapping = new Dictionary (); + if (!field_mapping.ContainsKey (field)) field_mapping.Add (field, (int) argument - 1); @@ -1256,7 +1265,7 @@ namespace CorCompare static Dictionary CreatePropertyFieldMapping (TypeDefinition type) { - Dictionary property_mapping = new Dictionary (); + Dictionary property_mapping = null; foreach (PropertyDefinition property in type.Properties) { if (property.GetMethod == null) @@ -1272,6 +1281,8 @@ namespace CorCompare if (field.DeclaringType.FullName != type.FullName) continue; + if (property_mapping == null) + property_mapping = new Dictionary (); property_mapping.Add (property, field); break; } @@ -1280,7 +1291,7 @@ namespace CorCompare return property_mapping; } - static void PopulateMapping (Dictionary mapping, MethodDefinition constructor, CustomAttribute attribute) + static void PopulateMapping (ref Dictionary mapping, MethodDefinition constructor, CustomAttribute attribute) { if (!constructor.HasBody) return; @@ -1293,6 +1304,8 @@ namespace CorCompare new DecimalConstantAttribute ((byte) ca[0].Value, (byte) ca[1].Value, (int) ca[2].Value, (int) ca[3].Value, (int) ca[4].Value) : new DecimalConstantAttribute ((byte) ca[0].Value, (byte) ca[1].Value, (uint) ca[2].Value, (uint) ca[3].Value, (uint) ca[4].Value); + if (mapping == null) + mapping = new Dictionary (StringComparer.Ordinal); mapping.Add ("Value", dca.Value); return; case "System.ComponentModel.BindableAttribute": @@ -1300,6 +1313,8 @@ namespace CorCompare break; if (constructor.Parameters[0].ParameterType == constructor.Module.TypeSystem.Boolean) { + if (mapping == null) + mapping = new Dictionary (StringComparer.Ordinal); mapping.Add ("Bindable", ca[0].Value); } else { throw new NotImplementedException (); @@ -1309,18 +1324,24 @@ namespace CorCompare } var field_mapping = CreateArgumentFieldMapping (constructor); - var property_mapping = CreatePropertyFieldMapping ((TypeDefinition) constructor.DeclaringType); - - foreach (var pair in property_mapping) { - int argument; - if (!field_mapping.TryGetValue (pair.Value, out argument)) - continue; - - var ca_arg = ca [argument]; - if (ca_arg.Value is CustomAttributeArgument) - ca_arg = (CustomAttributeArgument) ca_arg.Value; - - mapping.Add (pair.Key.Name, GetArgumentValue (ca_arg.Type, ca_arg.Value)); + if (field_mapping != null) { + var property_mapping = CreatePropertyFieldMapping ((TypeDefinition) constructor.DeclaringType); + + if (property_mapping != null) { + foreach (var pair in property_mapping) { + int argument; + if (!field_mapping.TryGetValue (pair.Value, out argument)) + continue; + + var ca_arg = ca [argument]; + if (ca_arg.Value is CustomAttributeArgument) + ca_arg = (CustomAttributeArgument)ca_arg.Value; + + if (mapping == null) + mapping = new Dictionary (StringComparer.Ordinal); + mapping.Add (pair.Key.Name, GetArgumentValue (ca_arg.Type, ca_arg.Value)); + } + } } } @@ -1436,8 +1457,7 @@ namespace CorCompare public static void OutputAttributes (XmlWriter writer, params ICustomAttributeProvider[] providers) { - AttributeData ad = new AttributeData (writer, providers); - ad.DoOutput (); + AttributeData.DoOutput (writer, providers); } }