2005-07-08 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / tools / corcompare / mono-api-info.cs
index c247ae35604c63e4ca7adf28a0168c1387b75d42..3094f68e5f9a643245988ef59494b57f2750acc8 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
-// (C) 2003 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2003-2005 Novell, Inc (http://www.novell.com)
 //
 
 using System;
@@ -12,6 +12,7 @@ using System.Collections;
 using System.Globalization;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Security.Permissions;
 using System.Text;
 using System.Xml;
 
@@ -264,7 +265,7 @@ namespace Mono.AssemblyInfo
                        AddAttribute (nclass, "type", classType);
 
                        if (type.BaseType != null)
-                               AddAttribute (nclass, "base", type.BaseType.FullName);
+                               AddAttribute (nclass, "base", type.BaseType.ToString ());
 
                        if (type.IsSealed)
                                AddAttribute (nclass, "sealed", "true");
@@ -296,7 +297,7 @@ namespace Mono.AssemblyInfo
                                                continue;
                                        }
                                        XmlNode iface = document.CreateElement ("interface", null);
-                                       AddAttribute (iface, "name", t.FullName);
+                                       AddAttribute (iface, "name", t.ToString ());
                                        ifaces.AppendChild (iface);
                                }
                        }
@@ -309,7 +310,7 @@ namespace Mono.AssemblyInfo
                                FieldData fd = new FieldData (document, nclass, fields);
                                // Special case for enum fields
                                if (classType == "enum") {
-                                       string etype = fields [0].GetType ().FullName;
+                                       string etype = fields [0].GetType ().ToString ();
                                        AddAttribute (nclass, "enumtype", etype);
                                }
                                members.Add (fd);
@@ -431,7 +432,7 @@ namespace Mono.AssemblyInfo
                        return (FieldInfo[]) list.ToArray (typeof (FieldInfo));
                }
 
-               private PropertyInfo[] GetProperties (Type type)
+               internal static PropertyInfo[] GetProperties (Type type)
                {
                        ArrayList list = new ArrayList ();
 
@@ -540,7 +541,7 @@ namespace Mono.AssemblyInfo
                {
                        base.AddExtraData (p, member);
                        FieldInfo field = (FieldInfo) member;
-                       AddAttribute (p, "fieldtype", field.FieldType.FullName);
+                       AddAttribute (p, "fieldtype", field.FieldType.ToString ());
 
                        if (field.IsLiteral) {
                                object value = field.GetValue (null);
@@ -585,7 +586,8 @@ namespace Mono.AssemblyInfo
                {
                        base.AddExtraData (p, member);
                        PropertyInfo prop = (PropertyInfo) member;
-                       AddAttribute (p, "ptype", prop.PropertyType.FullName);
+                       Type t = prop.PropertyType;
+                       AddAttribute (p, "ptype", prop.PropertyType.ToString ());
                        MethodInfo _get = prop.GetGetMethod (true);
                        MethodInfo _set = prop.GetSetMethod (true);
                        bool haveGet = (_get != null && TypeData.MustDocumentMethod(_get));
@@ -649,7 +651,7 @@ namespace Mono.AssemblyInfo
                {
                        base.AddExtraData (p, member);
                        EventInfo evt = (EventInfo) member;
-                       AddAttribute (p, "eventtype", evt.EventHandlerType.FullName);
+                       AddAttribute (p, "eventtype", evt.EventHandlerType.ToString ());
                }
 
                public override string ParentTag {
@@ -681,7 +683,7 @@ namespace Mono.AssemblyInfo
                protected override string GetMemberAttributes (MemberInfo member)
                {
                        MethodBase method = (MethodBase) member;
-                       return ((int) method.Attributes).ToString (CultureInfo.InvariantCulture);
+                       return ((int)( method.Attributes & ~MethodAttributes.ReservedMask)).ToString (CultureInfo.InvariantCulture);
                }
 
                protected override void AddExtraData (XmlNode p, MemberInfo member)
@@ -696,7 +698,7 @@ namespace Mono.AssemblyInfo
                                return;
 
                        MethodInfo method = (MethodInfo) member;
-                       AddAttribute (p, "returntype", method.ReturnType.FullName);
+                       AddAttribute (p, "returntype", method.ReturnType.ToString ());
 
                        AttributeData.OutputAttributes (document, p,
                                method.ReturnTypeCustomAttributes.GetCustomAttributes (false));
@@ -761,12 +763,12 @@ namespace Mono.AssemblyInfo
                                }
 
                                Type t = parameter.ParameterType;
-                               AddAttribute (paramNode, "type", t.FullName);
+                               AddAttribute (paramNode, "type", t.ToString ());
 
                                if (parameter.IsOptional) {
                                        AddAttribute (paramNode, "optional", "true");
-                                       if (parameter.DefaultValue != null)
-                                               AddAttribute (paramNode, "defaultValue", parameter.DefaultValue.ToString ());
+                                       if (parameter.DefaultValue != System.DBNull.Value)
+                                               AddAttribute (paramNode, "defaultValue", (parameter.DefaultValue == null) ? "NULL" : parameter.DefaultValue.ToString ());
                                }
 
                                if (direction != "in")
@@ -808,30 +810,55 @@ namespace Mono.AssemblyInfo
                                parent.AppendChild (natts);
                        }
 
-                       ArrayList typeList = new ArrayList (atts.Length);
-                       string comment = null;
-                       for (int i = atts.Length - 1; i >= 0; i--) {
-                               Type attType = atts [i].GetType ();
-                               if (!MustDocumentAttribute (attType))
+                       for (int i = 0; i < atts.Length; ++i) {
+                               Type t = atts [i].GetType ();
+                               if (!t.IsPublic && !t.Name.EndsWith ("TODOAttribute"))
+                                       continue;
+
+                               // we ignore attributes that inherit from SecurityAttribute on purpose as they:
+                               // * aren't part of GetCustomAttributes in Fx 1.0/1.1;
+                               // * are encoded differently and in a different metadata table; and
+                               // * won't ever exactly match MS implementation (from a syntax pov)
+                               if (t.IsSubclassOf (typeof (SecurityAttribute)))
                                        continue;
-                               typeList.Add (attType);
-                               if (attType.Name.EndsWith ("TODOAttribute")) {
-                                       PropertyInfo prop = attType.GetProperty ("Comment");
-                                       if (prop != null)
-                                               comment = (string) prop.GetValue (atts [i], null);
-                               }
-                       }
 
-                       Type[] types = (Type[]) typeList.ToArray (typeof (Type));
-                       Array.Sort (types, TypeComparer.Default);
-                       foreach (Type t in types) {
                                XmlNode node = document.CreateElement ("attribute");
-                               AddAttribute (node, "name", t.FullName);
+                               AddAttribute (node, "name", t.ToString ());
+
+                               XmlNode properties = null;
+                               foreach (PropertyInfo pi in TypeData.GetProperties (t)) {
+                                       if (pi.Name == "TypeId")
+                                               continue;
+
+                                       if (properties == null) {
+                                               properties = node.AppendChild (document.CreateElement ("properties"));
+                                       }
+
+                                       try {
+                                               object o = pi.GetValue (atts [i], null);
+
+                                               XmlNode n = properties.AppendChild (document.CreateElement ("property"));
+                                               AddAttribute (n, "name", pi.Name);
+
+                                               if (o == null) {
+                                                       AddAttribute (n, "null", "true");
+                                                       continue;
+                                               }
+
+                                               string value = o.ToString ();
+                                               if (t == typeof (GuidAttribute))
+                                                       value = value.ToUpper ();
+
+                                               AddAttribute (n, "value", value);
+                                       }
+                                       catch (TargetInvocationException) {
+                                               continue;
+                                       }
+                               }
+
                                if (target != null) {
                                        AddAttribute (node, "target", target);
                                }
-                               if (comment != null && t.Name.EndsWith ("TODOAttribute"))
-                                       AddAttribute (node, "comment", comment);
 
                                natts.AppendChild (node);
                        }
@@ -877,7 +904,7 @@ namespace Mono.AssemblyInfo
                                else
                                        modifier = "";
 
-                               string type_name = info.ParameterType.ToString ();
+                               string type_name = info.ParameterType.ToString ().Replace ('<', '[').Replace ('>', ']');
                                sb.AppendFormat ("{0}{1}, ", modifier, type_name);
                        }