Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -3,6 +3,7 @@ SUBDIRS =
include ../../build/rules.make
PROGRAM = monop.exe
LOCAL_MCS_FLAGS += -d:NO_AUTHENTICODE,STATIC,NO_SYMBOL_WRITER
CLEAN_FILES = monop.exe monop2.exe *.mdb

View File

@@ -26,6 +26,9 @@
using System;
using System.Collections;
#if STATIC
using Type=IKVM.Reflection.Type;
#endif
class TypeSorter : IComparer
{

View File

@@ -1,6 +1,9 @@
//
// monop -- a semi-clone of javap
//
// TODO:
// Dump all attributes.
//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
// John Luke (john.luke@gmail.com)
@@ -36,11 +39,15 @@ using System.CodeDom.Compiler;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using IKVM.Reflection;
using System.Text;
using Mono.CSharp;
using Type=IKVM.Reflection.Type;
class MonoP {
static Universe universe = new Universe(UniverseOptions.EnableFunctionPointers | UniverseOptions.ResolveMissingMembers | UniverseOptions.DisablePseudoCustomAttributeRetrieval);
static Assembly mscorlib;
static Type obsolete_attribute;
static string assembly;
// very common namespaces, all in corlib
@@ -49,7 +56,7 @@ class MonoP {
"System.Collections",
"System.Reflection",
"System.Text",
"System.IO"
"System.IO",
};
static readonly string [] common_assemblies = {
@@ -62,8 +69,12 @@ class MonoP {
static readonly string [] common_ns = {
"System.Xml",
"System.Web",
"Foundation",
"CoreFoundation",
"CoreGraphics",
"UIKit",
"Gtk",
"GLib"
"GLib",
};
static Type GetType (string tname, bool ignoreCase)
@@ -72,9 +83,9 @@ class MonoP {
if (assembly != null) {
Assembly a = GetAssembly (assembly, true);
t = a.GetType (tname, false, ignoreCase);
} else
t = Type.GetType (tname, false, ignoreCase);
} else {
t = mscorlib.GetType (tname, false, ignoreCase);
}
return t;
}
@@ -86,6 +97,7 @@ class MonoP {
string [] assemblies = GetKnownAssemblyNames ();
for (int i = 0; i < assemblies.Length; i++) {
Console.WriteLine ("Loading {0}", assemblies[i]);
Assembly a = GetAssembly (assemblies [i], false);
if (a == null)
continue;
@@ -117,6 +129,11 @@ class MonoP {
static string [] GetKnownAssemblyNames ()
{
Console.WriteLine (options.PublicDir);
if (options.Style == "xios" || options.Style == "xand"){
return Directory.GetFiles (options.PublicDir, "*.dll");
}
Process p = new Process ();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
@@ -157,22 +174,13 @@ class MonoP {
try {
// if it exists try to use LoadFrom
if (File.Exists (assembly))
a = Assembly.LoadFrom (assembly);
// if it looks like a fullname try that
else if (assembly.Split (',').Length == 4)
a = Assembly.Load (assembly);
// see if MONO_PATH has it
a = universe.LoadFile (assembly);
else
a = LoadFromMonoPath (assembly);
} catch {
// ignore exception it gets handled below
}
// last try partial name
// this (apparently) is exception safe
if (a == null)
a = Assembly.LoadWithPartialName (assembly);
if (a == null && exit) {
Console.WriteLine ("Could not load {0}", MonoP.assembly);
Environment.Exit (1);
@@ -189,7 +197,7 @@ class MonoP {
foreach (string path in paths) {
string apath = Path.Combine (path, assembly);
if (File.Exists (apath))
return Assembly.LoadFrom (apath);
return universe.LoadFile (apath);
}
return null;
}
@@ -213,13 +221,6 @@ class MonoP {
Console.WriteLine ();
Console.WriteLine ("Assembly Information:");
object[] cls = a.GetCustomAttributes (typeof (CLSCompliantAttribute), false);
if (cls.Length > 0) {
CLSCompliantAttribute cca = cls[0] as CLSCompliantAttribute;
if (cca.IsCompliant)
Console.WriteLine ("[CLSCompliant]");
}
foreach (string ai in a.ToString ().Split (','))
Console.WriteLine (ai.Trim ());
@@ -229,9 +230,9 @@ class MonoP {
int obsolete_count = 0;
foreach (Type t in types) {
if (filter_obsolete && t.IsDefined (typeof (ObsoleteAttribute), false))
obsolete_count ++;
else
if (filter_obsolete && t.IsDefined (obsolete_attribute, false))
obsolete_count++;
else
Console.WriteLine (t.FullName);
}
@@ -240,7 +241,7 @@ class MonoP {
internal static void Completion (string prefix)
{
foreach (Type t in typeof (object).Assembly.GetExportedTypes ()) {
foreach (Type t in mscorlib.GetExportedTypes ()) {
if (t.Name.StartsWith (prefix)) {
if (Array.IndexOf (v_common_ns, t.Namespace) != -1) {
Console.WriteLine (t.Name);
@@ -281,13 +282,6 @@ class MonoP {
{
Assembly a = GetAssembly (assembly, true);
object[] cls = a.GetCustomAttributes (typeof (CLSCompliantAttribute), false);
if (cls.Length > 0) {
CLSCompliantAttribute cca = cls[0] as CLSCompliantAttribute;
if (cca.IsCompliant)
Console.WriteLine ("[CLSCompliant]");
}
foreach (string ai in a.ToString ().Split (','))
Console.WriteLine (ai.Trim ());
@@ -297,20 +291,28 @@ class MonoP {
var sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
foreach (Type t in types) {
if (filter_obsolete && t.IsDefined (typeof (ObsoleteAttribute), false))
if (filter_obsolete && t.IsDefined (obsolete_attribute, false))
continue;
new Outline (t, sw, true, show_private, filter_obsolete).OutlineType ();
new Outline (universe, mscorlib, t, sw, true, show_private, filter_obsolete).OutlineType ();
}
sw.Flush ();
}
static Options options = new Options ();
static void Main (string [] args)
{
Options options = new Options ();
if (!options.ProcessArgs (args))
return;
if (options.Style == null)
mscorlib = universe.LoadFile (typeof (int).Assembly.Location);
else
mscorlib = universe.LoadFile (Path.Combine (options.PublicDir, "mscorlib.dll"));
obsolete_attribute = mscorlib.GetType ("System.ObsoleteAttribute");
if (options.AssemblyReference != null) {
assembly = options.AssemblyReference;
@@ -327,12 +329,13 @@ class MonoP {
}
}
}
string message = null;
string tname = options.Type;
Type t = null;
int count;
if (options.Search) {
string matches = SearchTypes (tname, ref t, out count);
@@ -364,6 +367,8 @@ class MonoP {
foreach (string assm in GetKnownAssemblyNames ()) {
try {
Assembly a = GetAssembly (assm, false);
if (a == null)
continue;
t = a.GetType (tname, false, true);
if (t != null) {
message = String.Format ("{0} is included in the {1} assembly.",
@@ -380,7 +385,8 @@ class MonoP {
goto found;
}
}
} catch {
} catch (Exception e){
Console.WriteLine ("Failure: " + e);
}
}
}
@@ -395,7 +401,7 @@ class MonoP {
// This gets us nice buffering
//
StreamWriter sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
new Outline (t, sw, options.DeclaredOnly, options.ShowPrivate, options.FilterObsolete).OutlineType ();
new Outline (universe, mscorlib, t, sw, options.DeclaredOnly, options.ShowPrivate, options.FilterObsolete).OutlineType ();
sw.Flush ();
if (message != null)

View File

@@ -2,3 +2,15 @@ monop.cs
options.cs
outline.cs
TypeSorter.cs
../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs
../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs
../../class/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs
../../class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs
../../../external/ikvm/reflect/*.cs
../../../external/ikvm/reflect/Emit/*.cs
../../../external/ikvm/reflect/Metadata/*.cs
../../../external/ikvm/reflect/Reader/*.cs
../../../external/ikvm/reflect/Writer/*.cs
../../../external/ikvm/reflect/Impl/ITypeOwner.cs
../../../external/ikvm/reflect/Impl/SymbolSupport.cs

View File

@@ -36,6 +36,8 @@ public class Options
public bool ShowPrivate = false;
public string AssemblyReference = null;
public string Type = null;
public string PublicDir = null;
public string Style = null;
public Options ()
{
@@ -52,62 +54,70 @@ public class Options
for (int i = 0; i < args.Length; i++) {
switch (args[i]) {
case "-h":
case "--help":
PrintHelp ();
return false;
case "--runtime-version":
PrintRuntimeVersion ();
return false;
case "-d":
case "--declared-only":
DeclaredOnly = true;
case "-h":
case "--help":
PrintHelp ();
return false;
case "--runtime-version":
PrintRuntimeVersion ();
return false;
case "-d":
case "--declared-only":
DeclaredOnly = true;
break;
case "--filter-obsolete":
case "-f":
FilterObsolete = true;
break;
case "-p":
case "--private":
ShowPrivate = true;
break;
case "--refs":
PrintRefs = true;
break;
case "-xi":
PublicDir = "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS";
Style = "xios";
break;
case "-xa":
PublicDir = "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/2.1";
Style = "xand";
break;
case "-s":
case "-k":
case "--search":
Search = true;
break;
case "-c":
i++;
if (i < args.Length)
MonoP.Completion (args[i]);
return false;
case "-r":
i++;
if (i < args.Length)
AssemblyReference = args[i];
break;
case "-a":
ShowAll = true;
break;
default:
if (args[i].StartsWith ("-r:") || args[i].StartsWith ("/r:")) {
AssemblyReference = args [i].Substring (3);
break;
case "--filter-obsolete":
case "-f":
FilterObsolete = true;
break;
case "-p":
case "--private":
ShowPrivate = true;
break;
case "--refs":
PrintRefs = true;
break;
case "-s":
case "-k":
case "--search":
Search = true;
break;
case "-c":
i++;
if (i < args.Length)
MonoP.Completion (args[i]);
return false;
case "-r":
i++;
if (i < args.Length)
AssemblyReference = args[i];
break;
case "-a":
ShowAll = true;
break;
default:
if (args[i].StartsWith ("-r:") || args[i].StartsWith ("/r:")) {
AssemblyReference = args [i].Substring (3);
break;
}
// The first unrecognizable option becomes
// the type to look up
if (Type == null) {
Type = args[i];
break;
}
// others are ignored
Console.WriteLine ("ignored: {0}", args[i]);
}
// The first unrecognizable option becomes
// the type to look up
if (Type == null) {
Type = args[i];
break;
}
// others are ignored
Console.WriteLine ("ignored: {0}", args[i]);
break;
}
}
@@ -135,6 +145,8 @@ public class Options
Console.WriteLine ("\t--refs\t\t\tPrint a list of the referenced assemblies for an assembly");
Console.WriteLine ("\t--runtime-version\tPrint runtime version");
Console.WriteLine ("\t--search,-s,-k\t\tSearch through all known namespaces");
Console.WriteLine ("\t--xi\t\tSet search style to Xamarin.iOS");
Console.WriteLine ("\t--xa\t\tSet search style to Xamarin.Android");
Console.WriteLine ("\t--a\t\tShows all the types declare in the specified assembly");
}
}

View File

@@ -30,22 +30,59 @@
//
using System;
using System.Reflection;
using System.Collections;
using System.CodeDom.Compiler;
using System.IO;
using System.Text;
#if STATIC
using IKVM.Reflection;
using Type=IKVM.Reflection.Type;
#else
using System.Reflection;
#endif
namespace Mono.CSharp {
public class Outline {
bool declared_only;
bool show_private;
bool filter_obsolete;
IndentedTextWriter o;
Type t;
Type type_multicast_delegate, type_object, type_value_type, type_int, type_flags_attribute, type_obsolete_attribute, type_param_array_attribute;
#if STATIC
Universe universe;
Assembly mscorlib;
public Outline (System.Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
{
throw new NotImplementedException ();
}
public Outline (Universe universe, Assembly mscorlib, Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
{
if (universe == null)
throw new ArgumentNullException ("universe");
if (mscorlib == null)
throw new ArgumentNullException ("mscorlib");
this.universe = universe;
this.mscorlib = mscorlib;
this.t = t;
this.o = new IndentedTextWriter (output, "\t");
this.declared_only = declared_only;
this.show_private = show_private;
this.filter_obsolete = filter_obsolete;
type_multicast_delegate = mscorlib.GetType("System.MulticastDelegate");
type_object = mscorlib.GetType ("System.Object");
type_value_type = mscorlib.GetType ("System.ValueType");
type_int = mscorlib.GetType ("System.Int32");
type_flags_attribute = mscorlib.GetType ("System.FlagsAttribute");
type_obsolete_attribute = mscorlib.GetType ("System.ObsoleteAttribute");
type_param_array_attribute = mscorlib.GetType ("System.ParamArrayAttribute");
}
#else
public Outline (Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
{
this.t = t;
@@ -53,7 +90,16 @@ public class Outline {
this.declared_only = declared_only;
this.show_private = show_private;
this.filter_obsolete = filter_obsolete;
type_multicast_delegate = typeof (System.MulticastDelegate);
type_object = typeof (object);
type_value_type = typeof (ValueType);
type_int = typeof (int);
type_flags_attribute = typeof (FlagsAttribute);
type_obsolete_attribute = typeof (ObsoleteAttribute);
type_param_array_attribute = typeof (ParamArrayAttribute);
}
#endif
public void OutlineType ()
{
@@ -62,7 +108,7 @@ public class Outline {
OutlineAttributes ();
o.Write (GetTypeVisibility (t));
if (t.IsClass && !t.IsSubclassOf (typeof (System.MulticastDelegate))) {
if (t.IsClass && !t.IsSubclassOf (type_multicast_delegate)) {
if (t.IsSealed)
o.Write (t.IsAbstract ? " static" : " sealed");
else if (t.IsAbstract)
@@ -76,7 +122,7 @@ public class Outline {
Type [] interfaces = (Type []) Comparer.Sort (TypeGetInterfaces (t, declared_only));
Type parent = t.BaseType;
if (t.IsSubclassOf (typeof (System.MulticastDelegate))) {
if (t.IsSubclassOf (type_multicast_delegate)) {
MethodInfo method;
method = t.GetMethod ("Invoke");
@@ -88,20 +134,18 @@ public class Outline {
OutlineParams (method.GetParameters ());
o.Write (")");
#if NET_2_0
WriteGenericConstraints (t.GetGenericArguments ());
#endif
o.WriteLine (";");
return;
}
o.Write (GetTypeName (t));
if (((parent != null && parent != typeof (object) && parent != typeof (ValueType)) || interfaces.Length != 0) && ! t.IsEnum) {
if (((parent != null && parent != type_object && parent != type_value_type) || interfaces.Length != 0) && ! t.IsEnum) {
first = true;
o.Write (" : ");
if (parent != null && parent != typeof (object) && parent != typeof (ValueType)) {
if (parent != null && parent != type_object && parent != type_value_type) {
o.Write (FormatType (parent));
first = false;
}
@@ -115,13 +159,11 @@ public class Outline {
}
if (t.IsEnum) {
Type underlyingType = System.Enum.GetUnderlyingType (t);
if (underlyingType != typeof (int))
Type underlyingType = t.GetEnumUnderlyingType ();
if (underlyingType != type_int)
o.Write (" : {0}", FormatType (underlyingType));
}
#if NET_2_0
WriteGenericConstraints (t.GetGenericArguments ());
#endif
o.WriteLine (" {");
o.Indent++;
@@ -260,8 +302,12 @@ public class Outline {
if (first)
o.WriteLine ();
first = false;
#if STATIC
new Outline (universe, mscorlib, ntype, o, declared_only, show_private, filter_obsolete).OutlineType ();
#else
new Outline (ntype, o, declared_only, show_private, filter_obsolete).OutlineType ();
#endif
}
o.Indent--; o.WriteLine ("}");
@@ -284,20 +330,21 @@ public class Outline {
if (t.IsSerializable)
o.WriteLine ("[Serializable]");
if (t.IsDefined (typeof (System.FlagsAttribute), true))
if (t.IsDefined (type_flags_attribute, true))
o.WriteLine ("[Flags]");
if (t.IsDefined (typeof (System.ObsoleteAttribute), true))
if (t.IsDefined (type_obsolete_attribute, true))
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));
var attrs = mi.GetCustomAttributesData ();
if (attrs.Count > 0)
o.WriteLine ("");
foreach (var attr in attrs)
o.WriteLine (attr);
}
void OutlineEvent (EventInfo ei)
@@ -396,15 +443,11 @@ public class Outline {
}
o.Write (mi.Name);
#if NET_2_0
o.Write (FormatGenericParams (mi.GetGenericArguments ()));
#endif
o.Write (" (");
OutlineParams (mi.GetParameters ());
o.Write (")");
#if NET_2_0
WriteGenericConstraints (mi.GetGenericArguments ());
#endif
o.Write (";");
}
@@ -433,7 +476,7 @@ public class Outline {
if (p.ParameterType.IsByRef) {
o.Write (p.IsOut ? "out " : "ref ");
o.Write (FormatType (p.ParameterType.GetElementType ()));
} else if (p.IsDefined (typeof (ParamArrayAttribute), false)) {
} else if (p.IsDefined (type_param_array_attribute, false)) {
o.Write ("params ");
o.Write (FormatType (p.ParameterType));
} else {
@@ -462,7 +505,7 @@ public class Outline {
o.Write (" ");
o.Write (fi.Name);
if (fi.IsLiteral) {
object v = fi.GetValue (this);
object v = fi.GetRawConstantValue ();
// TODO: Escape values here
o.Write (" = ");
@@ -471,7 +514,7 @@ public class Outline {
else if (v is string)
o.Write ("\"{0}\"", v);
else
o.Write (fi.GetValue (this));
o.Write (fi.GetRawConstantValue ());
}
o.Write (";");
}
@@ -529,12 +572,12 @@ public class Outline {
return null;
}
static string GetTypeKind (Type t)
string GetTypeKind (Type t)
{
if (t.IsEnum)
return "enum";
if (t.IsClass) {
if (t.IsSubclassOf (typeof (System.MulticastDelegate)))
if (t.IsSubclassOf (type_multicast_delegate))
return "delegate";
else
return "class";
@@ -563,7 +606,6 @@ public class Outline {
}
}
#if NET_2_0
string FormatGenericParams (Type [] args)
{
StringBuilder sb = new StringBuilder ();
@@ -579,7 +621,6 @@ 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.
@@ -593,6 +634,8 @@ public class Outline {
return t.ToString ();
if (!type.StartsWith ("System.")) {
if (type.IndexOf (".") == -1)
return type;
if (t.Namespace == this.t.Namespace)
return t.Name;
return type;
@@ -679,9 +722,7 @@ public class Outline {
void GetTypeName (StringBuilder sb, Type t)
{
sb.Append (RemoveGenericArity (t.Name));
#if NET_2_0
sb.Append (FormatGenericParams (t.GetGenericArguments ()));
#endif
}
string GetFullName (Type t)
@@ -693,12 +734,10 @@ public class Outline {
void GetFullName_recursed (StringBuilder sb, Type t, bool recursed)
{
#if NET_2_0
if (t.IsGenericParameter) {
sb.Append (t.Name);
return;
}
#endif
if (t.DeclaringType != null) {
GetFullName_recursed (sb, t.DeclaringType, true);
@@ -716,7 +755,6 @@ public class Outline {
GetTypeName (sb, t);
}
#if NET_2_0
void WriteGenericConstraints (Type [] args)
{
@@ -731,13 +769,13 @@ public class Outline {
GenericParameterAttributes.DefaultConstructorConstraint
};
if (t.BaseType != typeof (object) || ifaces.Length != 0 || attrs != 0) {
if (t.BaseType != type_object || ifaces.Length != 0 || attrs != 0) {
o.Write (" where ");
o.Write (FormatType (t));
o.Write (" : ");
}
if (t.BaseType != typeof (object)) {
if (t.BaseType != type_object) {
o.Write (FormatType (t.BaseType));
first = false;
}
@@ -772,7 +810,6 @@ public class Outline {
}
}
}
#endif
string OperatorFromName (string name)
{
@@ -833,7 +870,7 @@ public class Outline {
if (show_private)
return true;
if (filter_obsolete && mi.IsDefined (typeof (ObsoleteAttribute), false))
if (filter_obsolete && mi.IsDefined (type_obsolete_attribute, false))
return false;
switch (mi.MemberType) {
@@ -921,8 +958,6 @@ public class Comparer : IComparer {
Type type1 = (Type) a;
Type type2 = (Type) b;
if (type1.IsSubclassOf (typeof (System.MulticastDelegate)) != type2.IsSubclassOf (typeof (System.MulticastDelegate)))
return (type1.IsSubclassOf (typeof (System.MulticastDelegate)))? -1:1;
return string.Compare (type1.Name, type2.Name);
}