Merge branch 'BigIntegerParse'
[mono.git] / mcs / tools / monop / outline.cs
index 35f1e4fb99cd3079c853e593c2ab50486c7607e3..1104b1c1169c1f40da1c2cbc39d00e9424f5fa1b 100644 (file)
@@ -35,18 +35,24 @@ using System.Collections;
 using System.CodeDom.Compiler;
 using System.IO;
 using System.Text;
-       
+
+namespace Mono.CSharp {
 public class Outline {
+
+       bool declared_only;
+       bool show_private;
+       bool filter_obsolete;
        
-       Options options;
        IndentedTextWriter o;
        Type t;
        
-       public Outline (Type t, TextWriter output, Options options)
+       public Outline (Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
        {
                this.t = t;
                this.o = new IndentedTextWriter (output, "\t");
-               this.options = options;
+               this.declared_only = declared_only;
+               this.show_private = show_private;
+               this.filter_obsolete = filter_obsolete;
        }
 
        public void OutlineType ()
@@ -67,7 +73,7 @@ public class Outline {
                o.Write (GetTypeKind (t));
                o.Write (" ");
                
-               Type [] interfaces = (Type []) Comparer.Sort (TypeGetInterfaces (t, options.DeclaredOnly));
+               Type [] interfaces = (Type []) Comparer.Sort (TypeGetInterfaces (t, declared_only));
                Type parent = t.BaseType;
 
                if (t.IsSubclassOf (typeof (System.MulticastDelegate))) {
@@ -109,7 +115,7 @@ public class Outline {
                }
 
                if (t.IsEnum) {
-                       Type underlyingType = Enum.GetUnderlyingType (t);
+                       Type underlyingType = System.Enum.GetUnderlyingType (t);
                        if (underlyingType != typeof (int))
                                o.Write (" : {0}", FormatType (underlyingType));
                }
@@ -136,7 +142,6 @@ public class Outline {
                first = true;
                
                foreach (ConstructorInfo ci in t.GetConstructors (DefaultFlags)) {
-                       
                        if (! ShowMember (ci))
                                continue;
                        
@@ -144,6 +149,7 @@ public class Outline {
                                o.WriteLine ();
                        first = false;
                        
+                       OutlineMemberAttribute (ci);
                        OutlineConstructor (ci);
                        
                        o.WriteLine ();
@@ -163,7 +169,8 @@ public class Outline {
                        if (first)
                                o.WriteLine ();
                        first = false;
-                       
+
+                       OutlineMemberAttribute (m);
                        OutlineMethod (m);
                        
                        o.WriteLine ();
@@ -185,6 +192,7 @@ public class Outline {
                                o.WriteLine ();
                        first = false;
                        
+                       OutlineMemberAttribute (m);
                        OutlineOperator (m);
                        
                        o.WriteLine ();
@@ -202,6 +210,7 @@ public class Outline {
                                o.WriteLine ();
                        first = false;
                        
+                       OutlineMemberAttribute (pi);
                        OutlineProperty (pi);
                        
                        o.WriteLine ();
@@ -218,6 +227,7 @@ public class Outline {
                                o.WriteLine ();
                        first = false;
                        
+                       OutlineMemberAttribute (fi);
                        OutlineField (fi);
                        
                        o.WriteLine ();
@@ -234,6 +244,7 @@ public class Outline {
                                o.WriteLine ();
                        first = false;
                        
+                       OutlineMemberAttribute (ei);
                        OutlineEvent (ei);
                        
                        o.WriteLine ();
@@ -250,7 +261,7 @@ public class Outline {
                                o.WriteLine ();
                        first = false;
                        
-                       new Outline (ntype, o, options).OutlineType ();
+                       new Outline (ntype, o, declared_only, show_private, filter_obsolete).OutlineType ();
                }
                
                o.Indent--; o.WriteLine ("}");
@@ -260,7 +271,7 @@ public class Outline {
                get {
                        BindingFlags f = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
                        
-                       if (options.DeclaredOnly)
+                       if (declared_only)
                                f |= BindingFlags.DeclaredOnly;
                        
                        return f;
@@ -280,6 +291,15 @@ public class Outline {
                        o.WriteLine ("[Obsolete]");
        }
 
+       void OutlineMemberAttribute (MemberInfo mi)
+       {
+               if (!mi.IsDefined (typeof (System.ObsoleteAttribute), false))
+                       return;
+               var oa = mi.GetCustomAttributes (typeof (System.ObsoleteAttribute), false) [0] as ObsoleteAttribute;
+               var msg = oa.Message;
+               o.WriteLine ("[Obsolete{0}]", msg == null || msg == "" ? "" : string.Format ("(\"{0}\")", msg));
+       }
+       
        void OutlineEvent (EventInfo ei)
        {
                MethodBase accessor = ei.GetAddMethod (true);
@@ -543,6 +563,7 @@ public class Outline {
                 }
        }
 
+#if NET_2_0
        string FormatGenericParams (Type [] args)
        {
                StringBuilder sb = new StringBuilder ();
@@ -558,12 +579,18 @@ public class Outline {
                sb.Append (">");
                return sb.ToString ();
        }
-       
+#endif
+
        // TODO: fine tune this so that our output is less verbose. We need to figure
        // out a way to do this while not making things confusing.
        string FormatType (Type t)
        {
+               if (t == null)
+                       return "";
+
                string type = GetFullName (t);
+               if (type == null)
+                       return t.ToString ();
                
                if (!type.StartsWith ("System.")) {
                        if (t.Namespace == this.t.Namespace)
@@ -803,10 +830,10 @@ public class Outline {
                if (mi.MemberType == MemberTypes.Constructor && ((MethodBase) mi).IsStatic)
                        return false;
                
-               if (options.ShowPrivate)
+               if (show_private)
                        return true;
 
-               if (options.FilterObsolete && mi.IsDefined (typeof (ObsoleteAttribute), false))
+               if (filter_obsolete && mi.IsDefined (typeof (ObsoleteAttribute), false))
                        return false;
                
                switch (mi.MemberType) {
@@ -853,6 +880,9 @@ public class Outline {
 
        static Type [] TypeGetInterfaces (Type t, bool declonly)
        {
+               if (t.IsGenericParameter)
+                       return new Type [0];
+
                Type [] ifaces = t.GetInterfaces ();
                if (! declonly)
                        return ifaces;
@@ -897,13 +927,13 @@ public class Comparer : IComparer  {
                        
        }
 
-       static Comparer TypeComparer = new Comparer (new ComparerFunc (CompareType));
+//     static Comparer TypeComparer = new Comparer (new ComparerFunc (CompareType));
 
-       static Type [] Sort (Type [] types)
-       {
-               Array.Sort (types, TypeComparer);
-               return types;
-       }
+//     static Type [] Sort (Type [] types)
+//     {
+//             Array.Sort (types, TypeComparer);
+//             return types;
+//     }
        
        static int CompareMemberInfo (object a, object b)
        {
@@ -935,7 +965,7 @@ public class Comparer : IComparer  {
                        
                        ap = aa.GetParameters ();
                        bp = bb.GetParameters ();
-                       int n = Math.Min (ap.Length, bp.Length);
+                       int n = System.Math.Min (ap.Length, bp.Length);
 
                        for (int i = 0; i < n; i ++)
                                if ((c = CompareType (ap [i].ParameterType, bp [i].ParameterType)) != 0)
@@ -1005,3 +1035,4 @@ public class Comparer : IComparer  {
                return inf;
        }
 }
+}