Integrated new IKVM.Reflection implementation.

This commit is contained in:
jfrijters 2010-01-25 07:52:27 +00:00
Родитель 0b30be9d2c
Коммит dbd6df02ae
27 изменённых файлов: 219 добавлений и 262 удалений

Просмотреть файл

@ -10,7 +10,7 @@
<nant buildfile="tools/tools.build" />
<nant buildfile="runtime/runtime.build" target="first-pass" />
<nant buildfile="native/native.build" />
<nant buildfile="refemit/refemit.build" />
<nant buildfile="reflect/reflect.build" />
<nant buildfile="ikvmc/ikvmc.build" />
<nant buildfile="openjdk/openjdk.build" />
<nant buildfile="runtime/runtime.build" />
@ -26,9 +26,7 @@
<delete failonerror="false">
<fileset>
<include name="bin/IKVM.AWT.WinForms.dll" />
<include name="bin/IKVM.Reflection.Emit.dll" />
<include name="bin/IKVM.Reflection.Emit.MdbWriter.dll" />
<include name="bin/IKVM.Reflection.Emit.PdbWriter.dll" />
<include name="bin/IKVM.Reflection.dll" />
<include name="bin/IKVM.Runtime.dll" />
<include name="bin/IKVM.Runtime.JNI.dll" />
<include name="bin/IKVM.OpenJDK.*.dll" />

Просмотреть файл

@ -14,11 +14,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ikvm-native", "native\nativ
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.Runtime.JNI.8", "runtime\IKVM.Runtime.JNI.8.csproj", "{CEA4FEC4-1D24-4004-908E-F86C8D7AC772}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.Reflection.Emit", "refemit\IKVM.Reflection.Emit.csproj", "{3949055D-38DF-4A8F-A632-0F0E62337428}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.Reflection.Emit.PdbWriter", "refemit\IKVM.PdbWriter\IKVM.Reflection.Emit.PdbWriter.csproj", "{54037FA3-3F3F-4806-938B-A76C4B4B78B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.Reflection.Emit.MdbWriter", "refemit\IKVM.MdbWriter\IKVM.Reflection.Emit.MdbWriter.csproj", "{30D0FC5E-31D2-4BC0-B4F0-51D01C0A89B5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.Reflection", "reflect\IKVM.Reflection.csproj", "{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -62,21 +58,11 @@ Global
{CEA4FEC4-1D24-4004-908E-F86C8D7AC772}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CEA4FEC4-1D24-4004-908E-F86C8D7AC772}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CEA4FEC4-1D24-4004-908E-F86C8D7AC772}.Debug|Win32.ActiveCfg = Debug|Any CPU
{3949055D-38DF-4A8F-A632-0F0E62337428}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3949055D-38DF-4A8F-A632-0F0E62337428}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3949055D-38DF-4A8F-A632-0F0E62337428}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{3949055D-38DF-4A8F-A632-0F0E62337428}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{3949055D-38DF-4A8F-A632-0F0E62337428}.Debug|Win32.ActiveCfg = Debug|Any CPU
{54037FA3-3F3F-4806-938B-A76C4B4B78B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54037FA3-3F3F-4806-938B-A76C4B4B78B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54037FA3-3F3F-4806-938B-A76C4B4B78B9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{54037FA3-3F3F-4806-938B-A76C4B4B78B9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{54037FA3-3F3F-4806-938B-A76C4B4B78B9}.Debug|Win32.ActiveCfg = Debug|Any CPU
{30D0FC5E-31D2-4BC0-B4F0-51D01C0A89B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30D0FC5E-31D2-4BC0-B4F0-51D01C0A89B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30D0FC5E-31D2-4BC0-B4F0-51D01C0A89B5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{30D0FC5E-31D2-4BC0-B4F0-51D01C0A89B5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{30D0FC5E-31D2-4BC0-B4F0-51D01C0A89B5}.Debug|Win32.ActiveCfg = Debug|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Debug|Win32.ActiveCfg = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -140,9 +140,9 @@
<Compile Include="CommonAssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="refemit\IKVM.Reflection.Emit.csproj">
<Project>{3949055D-38DF-4A8F-A632-0F0E62337428}</Project>
<Name>IKVM.Reflection.Emit</Name>
<ProjectReference Include="reflect\IKVM.Reflection.csproj">
<Project>{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}</Project>
<Name>IKVM.Reflection</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

Просмотреть файл

@ -24,10 +24,12 @@
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;

Просмотреть файл

@ -29,10 +29,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
using ResolveEventHandler = IKVM.Reflection.ResolveEventHandler;
using ResolveEventArgs = IKVM.Reflection.ResolveEventArgs;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Threading;
@ -84,7 +88,11 @@ class IkvmcCompiler
static int Main(string[] args)
{
DateTime start = DateTime.Now;
#if IKVM_REF_EMIT
StaticCompiler.Universe.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
#else
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
#endif
System.Threading.Thread.CurrentThread.Name = "compiler";
Tracer.EnableTraceConsoleListener();
Tracer.EnableTraceForDebug();
@ -137,18 +145,18 @@ class IkvmcCompiler
static string GetVersionAndCopyrightInfo()
{
Assembly asm = Assembly.GetEntryAssembly();
object[] desc = asm.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly();
object[] desc = asm.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), false);
if (desc.Length == 1)
{
object[] copyright = asm.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
object[] copyright = asm.GetCustomAttributes(typeof(System.Reflection.AssemblyCopyrightAttribute), false);
if (copyright.Length == 1)
{
return string.Format("{0} version {1}{2}{3}{2}http://www.ikvm.net/",
((AssemblyTitleAttribute)desc[0]).Title,
((System.Reflection.AssemblyTitleAttribute)desc[0]).Title,
asm.GetName().Version,
Environment.NewLine,
((AssemblyCopyrightAttribute)copyright[0]).Copyright);
((System.Reflection.AssemblyCopyrightAttribute)copyright[0]).Copyright);
}
}
return "";
@ -788,7 +796,7 @@ class IkvmcCompiler
{
#pragma warning disable 618
// Assembly.LoadWithPartialName is obsolete
Assembly found = Assembly.LoadWithPartialName(r);
System.Reflection.Assembly found = System.Reflection.Assembly.LoadWithPartialName(r);
#pragma warning restore
if (found != null)
{
@ -1065,8 +1073,66 @@ class IkvmcCompiler
}
}
// this method checks if the assembly was loaded from a CLR probe location
// (in that case we can also resolve its dependencies via the CLR)
private static bool IsLoadedFromCurrentClrProbeLocation(Assembly asm)
{
try
{
return System.Reflection.Assembly.ReflectionOnlyLoad(asm.FullName).Location == asm.Location;
}
catch
{
return false;
}
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
#if IKVM_REF_EMIT
if (args.RequestingAssembly == null || IsLoadedFromCurrentClrProbeLocation(args.RequestingAssembly))
{
System.Reflection.Assembly asm = null;
try
{
asm = System.Reflection.Assembly.ReflectionOnlyLoad(args.Name);
}
catch
{
}
if (asm != null)
{
return StaticCompiler.LoadFile(asm.Location);
}
}
else
{
Assembly asm = null;
// apply unification and policy
try
{
string name = System.Reflection.Assembly.ReflectionOnlyLoad(args.Name).FullName;
if (name != args.Name)
{
asm = StaticCompiler.Load(name);
}
}
catch
{
}
if (asm != null)
{
return asm;
}
}
Console.Error.WriteLine("Error: unable to find assembly '{0}'", args.Name);
if (args.RequestingAssembly != null)
{
Console.Error.WriteLine(" (a dependency of '{0}')", args.RequestingAssembly.FullName);
}
Environment.Exit(1);
return null;
#else
// make sure all the referenced assemblies are visible (they are loaded with LoadFrom, so
// they end up in the LoadFrom context [unless they happen to be available in one of the probe paths])
foreach(Assembly a in AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies())
@ -1077,5 +1143,6 @@ class IkvmcCompiler
}
}
return Assembly.ReflectionOnlyLoad(args.Name);
#endif
}
}

Просмотреть файл

@ -23,10 +23,12 @@
*/
using System;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Resources;
@ -198,7 +200,7 @@ namespace IKVM.Internal
#if NET_4_0 || IKVM_REF_EMIT
assemblyBuilder =
#if IKVM_REF_EMIT
AssemblyBuilder
StaticCompiler.Universe
#else
AppDomain.CurrentDomain
#endif
@ -1920,6 +1922,15 @@ namespace IKVM.Internal
private static void CopyLinkDemands(MethodBuilder mb, MethodInfo mi)
{
#if IKVM_REF_EMIT
foreach (CustomAttributeData cad in CustomAttributeData.__GetDeclarativeSecurity(mi))
{
if (cad.ConstructorArguments.Count == 0 || (int)cad.ConstructorArguments[0].Value == (int)SecurityAction.LinkDemand)
{
mb.__AddDeclarativeSecurity(cad.__ToBuilder());
}
}
#else
foreach (object attr in mi.GetCustomAttributes(false))
{
CodeAccessSecurityAttribute cas = attr as CodeAccessSecurityAttribute;
@ -1933,6 +1944,7 @@ namespace IKVM.Internal
}
}
}
#endif
}
private static string MakeMethodKey(MethodInfo method)
@ -2504,16 +2516,11 @@ namespace IKVM.Internal
{
if(runtimeAssembly == null)
{
// HACK based on our assembly name we create the default runtime assembly name
AssemblyName compilerAssembly = typeof(CompilerClassLoader).Assembly.GetName();
StaticCompiler.runtimeAssembly = StaticCompiler.Load(compilerAssembly.FullName.Replace(compilerAssembly.Name, "IKVM.Runtime"));
StaticCompiler.runtimeJniAssembly = StaticCompiler.Load(compilerAssembly.FullName.Replace(compilerAssembly.Name, "IKVM.Runtime.JNI"));
}
else
{
StaticCompiler.runtimeAssembly = StaticCompiler.LoadFile(runtimeAssembly);
StaticCompiler.runtimeJniAssembly = StaticCompiler.LoadFile(Path.Combine(StaticCompiler.runtimeAssembly.CodeBase, ".." + Path.DirectorySeparatorChar + "IKVM.Runtime.JNI.dll"));
// we assume that the runtime is in the same directory as the compiler
runtimeAssembly = Path.Combine(typeof(CompilerClassLoader).Assembly.Location, ".." + Path.DirectorySeparatorChar + "IKVM.Runtime.dll");
}
StaticCompiler.runtimeAssembly = StaticCompiler.LoadFile(runtimeAssembly);
StaticCompiler.runtimeJniAssembly = StaticCompiler.LoadFile(Path.Combine(StaticCompiler.runtimeAssembly.Location, ".." + Path.DirectorySeparatorChar + "IKVM.Runtime.JNI.dll"));
}
catch(FileNotFoundException)
{
@ -2643,6 +2650,7 @@ namespace IKVM.Internal
return 1;
}
}
#if !IKVM_REF_EMIT
bool err = false;
foreach(Assembly reference in references)
{
@ -2674,20 +2682,7 @@ namespace IKVM.Internal
{
return 1;
}
// If the "System" assembly wasn't explicitly referenced, load it automatically
bool systemIsLoaded = false;
foreach(Assembly asm in AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies())
{
if(asm.GetType("System.ComponentModel.EditorBrowsableAttribute") != null)
{
systemIsLoaded = true;
break;
}
}
if(!systemIsLoaded)
{
Assembly.ReflectionOnlyLoadFrom(JVM.Import(typeof(System.ComponentModel.EditorBrowsableAttribute)).Assembly.Location);
}
#endif
List<object> assemblyAnnotations = new List<object>();
Dictionary<string, string> baseClasses = new Dictionary<string, string>();
Tracer.Info(Tracer.Compiler, "Parsing class files");
@ -2861,17 +2856,10 @@ namespace IKVM.Internal
Assembly asm = null;
try
{
asm = StaticCompiler.Load(name.FullName);
asm = LoadReferencedAssembly(StaticCompiler.runtimeAssembly.Location + "/../" + name.Name + ".dll");
}
catch(FileNotFoundException)
{
try
{
asm = LoadReferencedAssembly(StaticCompiler.runtimeAssembly.CodeBase + "/../" + name.Name + ".dll");
}
catch(FileNotFoundException)
{
}
}
if(asm != null && IsCoreAssembly(asm))
{
@ -2915,6 +2903,7 @@ namespace IKVM.Internal
private static Assembly LoadReferencedAssembly(string r)
{
Assembly asm = StaticCompiler.LoadFile(r);
#if !IKVM_REF_EMIT
if (asm.GetManifestResourceInfo("ikvm.exports") != null)
{
// If this is the main assembly in a multi assembly group, try to pre-load all the assemblies.
@ -2944,6 +2933,7 @@ namespace IKVM.Internal
}
}
}
#endif
return asm;
}
@ -3329,17 +3319,18 @@ namespace IKVM.Internal
static class StaticCompiler
{
internal static readonly Universe Universe = new Universe();
internal static Assembly runtimeAssembly;
internal static Assembly runtimeJniAssembly;
internal static Assembly Load(string assemblyString)
{
return Assembly.ReflectionOnlyLoad(assemblyString);
return Universe.Load(assemblyString);
}
internal static Assembly LoadFile(string path)
{
return Assembly.ReflectionOnlyLoadFrom(path);
return Universe.LoadFile(path);
}
internal static Type GetRuntimeType(string name)
@ -3378,7 +3369,7 @@ namespace IKVM.Internal
{
return runtimeJniAssembly.GetType(name);
}
foreach(Assembly asm in AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies())
foreach(Assembly asm in Universe.GetAssemblies())
{
Type t = asm.GetType(name, false);
if(t != null)

Просмотреть файл

@ -24,10 +24,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif

Просмотреть файл

@ -46,7 +46,7 @@
</sources>
<references>
<include name="../bin/ICSharpCode.SharpZipLib.dll" asis="true" />
<include name="../bin/IKVM.Reflection.Emit.dll" asis="true" />
<include name="../bin/IKVM.Reflection.dll" asis="true" />
<!-- HACK mcs requires an explicit reference to System.Configuration -->
<include name="${framework::get-assembly-directory(framework::get-target-framework())}/System.Configuration.dll" />
</references>

Просмотреть файл

@ -25,10 +25,12 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;

Просмотреть файл

@ -22,7 +22,6 @@
*/
using System;
using System.Reflection;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
@ -30,6 +29,12 @@ using System.Threading;
using System.Runtime.CompilerServices;
using FormatterServices = System.Runtime.Serialization.FormatterServices;
using IKVM.Attributes;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
#endif
namespace IKVM.Internal
{
@ -456,7 +461,7 @@ namespace IKVM.Internal
return null;
}
private Assembly LoadAssemblyOrClearName(ref string name)
private Assembly LoadAssemblyOrClearName(ref string name, bool exported)
{
if (name == null)
{
@ -466,7 +471,14 @@ namespace IKVM.Internal
try
{
#if STATIC_COMPILER
return StaticCompiler.Load(name);
if (exported)
{
return StaticCompiler.LoadFile(this.MainAssembly.Location + "/../" + new AssemblyName(name).Name + ".dll");
}
else
{
return StaticCompiler.Load(name);
}
#else
if (isReflectionOnly)
{
@ -505,7 +517,7 @@ namespace IKVM.Internal
AssemblyLoader loader = exportedAssemblies[index];
if (loader == null)
{
Assembly asm = LoadAssemblyOrClearName(ref exportedAssemblyNames[index]);
Assembly asm = LoadAssemblyOrClearName(ref exportedAssemblyNames[index], true);
if (asm == null)
{
continue;
@ -610,7 +622,7 @@ namespace IKVM.Internal
{
if (delegates[i] == null)
{
Assembly asm = LoadAssemblyOrClearName(ref references[i]);
Assembly asm = LoadAssemblyOrClearName(ref references[i], false);
if (asm != null)
{
delegates[i] = AssemblyClassLoader.FromAssembly(asm);
@ -659,7 +671,7 @@ namespace IKVM.Internal
AssemblyLoader loader = exportedAssemblies[index];
if (loader == null)
{
Assembly asm = LoadAssemblyOrClearName(ref exportedAssemblyNames[index]);
Assembly asm = LoadAssemblyOrClearName(ref exportedAssemblyNames[index], true);
if (asm == null)
{
continue;
@ -698,7 +710,7 @@ namespace IKVM.Internal
{
if (delegates[i] == null)
{
Assembly asm = LoadAssemblyOrClearName(ref references[i]);
Assembly asm = LoadAssemblyOrClearName(ref references[i], false);
if (asm != null)
{
delegates[i] = AssemblyClassLoader.FromAssembly(asm);

Просмотреть файл

@ -22,10 +22,12 @@
*/
using System;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.IO;

Просмотреть файл

@ -23,10 +23,12 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Runtime.InteropServices;

Просмотреть файл

@ -23,10 +23,12 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;

Просмотреть файл

@ -24,10 +24,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif

Просмотреть файл

@ -23,10 +23,12 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;

Просмотреть файл

@ -23,10 +23,12 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;

Просмотреть файл

@ -22,10 +22,12 @@
*/
using System;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
@ -37,36 +39,18 @@ namespace IKVM.Internal
internal static bool IsSameAssembly(Type type1, Type type2)
{
#if IKVM_REF_EMIT && !NET_4_0
return IkvmAssembly.GetAssembly(type1) == IkvmAssembly.GetAssembly(type2);
#else
return type1.Assembly.Equals(type2.Assembly);
#endif
}
#if IKVM_REF_EMIT && !NET_4_0
internal static bool IsFromAssembly(Type type, IkvmAssembly assembly)
{
return IkvmAssembly.GetAssembly(type) == assembly;
}
#else
internal static bool IsFromAssembly(Type type, Assembly assembly)
{
return type.Assembly.Equals(assembly);
}
#endif
#if IKVM_REF_EMIT && !NET_4_0
internal static IkvmAssembly GetAssembly(Type type)
{
return IkvmAssembly.GetAssembly(type);
}
#else
internal static Assembly GetAssembly(Type type)
{
return type.Assembly;
}
#endif
internal static bool IsDynamicAssembly(Assembly asm)
{

Просмотреть файл

@ -22,10 +22,12 @@
*/
using System;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;
@ -58,12 +60,7 @@ namespace IKVM.Internal
{
classLiteralField = classLiteralType.GetField("Value", BindingFlags.Public | BindingFlags.Static);
}
#if IKVM_REF_EMIT
// MONOBUG https://bugzilla.novell.com/show_bug.cgi?id=486307
return TypeBuilder.GetField(MonoHackGenericType.Make(classLiteralType, type), classLiteralField);
#else
return TypeBuilder.GetField(classLiteralType.MakeGenericType(type), classLiteralField);
#endif
}
private static bool IsTypeBuilder(Type type)

Просмотреть файл

@ -22,13 +22,15 @@
*/
using System;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif

Просмотреть файл

@ -23,10 +23,12 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;
@ -319,7 +321,7 @@ namespace IKVM.Internal
}
if(tw.IsArray)
{
Array arr = Array.CreateInstance(tw.ElementTypeWrapper.TypeAsArrayType, attr.Params[i].Elements.Length);
Array arr = Array.CreateInstance(Type.__GetSystemType(Type.GetTypeCode(tw.ElementTypeWrapper.TypeAsArrayType)), attr.Params[i].Elements.Length);
for(int j = 0; j < arr.Length; j++)
{
arr.SetValue(ParseValue(loader, tw.ElementTypeWrapper, attr.Params[i].Elements[j].Value), j);
@ -1789,7 +1791,11 @@ namespace IKVM.Internal
{
internal static Type GetUnderlyingType(Type enumType)
{
#if IKVM_REF_EMIT
return enumType.GetEnumUnderlyingType();
#else
return Enum.GetUnderlyingType(enumType);
#endif
}
#if STATIC_COMPILER
@ -1931,7 +1937,7 @@ namespace IKVM.Internal
return field.GetRawConstantValue();
}
// both __unspecified and missing values end up here
return Activator.CreateInstance(EnumHelper.GetUnderlyingType(enumType));
return EnumHelper.GetPrimitiveValue(EnumHelper.GetUnderlyingType(enumType), 0);
}
protected static object ConvertValue(ClassLoaderWrapper loader, Type targetType, object obj)

Просмотреть файл

@ -22,6 +22,9 @@
*/
using System;
#if IKVM_REF_EMIT
using Type = IKVM.Reflection.Type;
#endif
namespace IKVM.Internal
{

Просмотреть файл

@ -24,10 +24,12 @@
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using IKVM.Internal;
@ -125,9 +127,6 @@ static class AtomicReferenceFieldUpdaterEmitter
private static MethodInfo MakeCompareExchange(Type type)
{
return new CompareExchangeMethodInfo(type);
// MONOBUG this doesn't work in Mono (because we're closing a generic method over our own Type implementation)
/*
MethodInfo interlockedCompareExchange = null;
foreach (MethodInfo m in JVM.Import(typeof(System.Threading.Interlocked)).GetMethods())
{
@ -138,142 +137,6 @@ static class AtomicReferenceFieldUpdaterEmitter
}
}
return interlockedCompareExchange.MakeGenericMethod(type);
*/
}
private sealed class CompareExchangeMethodInfo : MethodInfo
{
private readonly Type type;
internal CompareExchangeMethodInfo(Type type)
{
this.type = type;
}
public override MethodInfo GetBaseDefinition()
{
throw new NotImplementedException();
}
public override ICustomAttributeProvider ReturnTypeCustomAttributes
{
get { throw new NotImplementedException(); }
}
public override MethodAttributes Attributes
{
get { return MethodAttributes.Public; }
}
public override MethodImplAttributes GetMethodImplementationFlags()
{
throw new NotImplementedException();
}
private sealed class MyParameterInfo : ParameterInfo
{
private readonly Type type;
internal MyParameterInfo(Type type)
{
this.type = type;
}
public override Type ParameterType
{
get
{
return type;
}
}
}
public override ParameterInfo[] GetParameters()
{
return new ParameterInfo[] {
new MyParameterInfo(type.MakeByRefType()),
new MyParameterInfo(type),
new MyParameterInfo(type)
};
}
public override ParameterInfo ReturnParameter
{
get
{
return new MyParameterInfo(type);
}
}
public override Type ReturnType
{
get
{
return type;
}
}
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
public override RuntimeMethodHandle MethodHandle
{
get { throw new NotImplementedException(); }
}
public override Type DeclaringType
{
get { return typeof(System.Threading.Interlocked); }
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
throw new NotImplementedException();
}
public override object[] GetCustomAttributes(bool inherit)
{
throw new NotImplementedException();
}
public override bool IsDefined(Type attributeType, bool inherit)
{
throw new NotImplementedException();
}
public override string Name
{
get { return "CompareExchange"; }
}
public override Type ReflectedType
{
get { return DeclaringType; }
}
public override bool IsGenericMethod
{
get { return true; }
}
public override Type[] GetGenericArguments()
{
return new Type[] { type };
}
public override MethodInfo GetGenericMethodDefinition()
{
foreach (MethodInfo m in typeof(System.Threading.Interlocked).GetMethods())
{
if (m.Name == "CompareExchange" && m.IsGenericMethodDefinition)
{
return m;
}
}
throw new InvalidOperationException();
}
}
private static void EmitGet(TypeBuilder tb, FieldInfo field)

Просмотреть файл

@ -22,7 +22,12 @@
*/
using System;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
#endif
namespace IKVM.Attributes
{

Просмотреть файл

@ -23,10 +23,12 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;

Просмотреть файл

@ -24,10 +24,12 @@
using System;
using System.Collections.Generic;
using System.Reflection;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif
using System.Diagnostics;

Просмотреть файл

@ -27,6 +27,7 @@ using System.Collections.Generic;
using System.Diagnostics;
#if IKVM_REF_EMIT
using IKVM.Reflection.Emit;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection.Emit;
#endif

Просмотреть файл

@ -23,7 +23,12 @@
*/
using System;
using System.Threading;
#if IKVM_REF_EMIT
using IKVM.Reflection;
using Type = IKVM.Reflection.Type;
#else
using System.Reflection;
#endif
using System.IO;
using System.Diagnostics;
using System.Text;
@ -95,7 +100,7 @@ namespace IKVM.Internal
#endif // STATIC_COMPILER
private static Assembly coreAssembly;
internal static Version SafeGetAssemblyVersion(Assembly asm)
internal static Version SafeGetAssemblyVersion(System.Reflection.Assembly asm)
{
// Assembly.GetName().Version requires FileIOPermission,
// so we parse the FullName manually :-(
@ -245,7 +250,7 @@ namespace IKVM.Internal
try
{
Tracer.Error(Tracer.Runtime, "CRITICAL FAILURE: {0}", message);
Type messageBox = null;
System.Type messageBox = null;
#if !STATIC_COMPILER
// NOTE we use reflection to invoke MessageBox.Show, to make sure we run in environments where WinForms isn't available
Assembly winForms = IsUnix ? null : Assembly.Load("System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
@ -270,7 +275,7 @@ namespace IKVM.Internal
try
{
Version ver = SafeGetAssemblyVersion(typeof(JVM).Assembly);
messageBox.InvokeMember("Show", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, new object[] { message, "IKVM.NET " + ver + " Critical Failure" });
messageBox.InvokeMember("Show", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, null, new object[] { message, "IKVM.NET " + ver + " Critical Failure" });
}
catch
{
@ -292,13 +297,20 @@ namespace IKVM.Internal
}
}
#if IKVM_REF_EMIT
internal static Type LoadType(System.Type type)
{
return StaticCompiler.GetRuntimeType(type.FullName);
}
#endif
// this method resolves types in IKVM.Runtime.dll
// (the version of IKVM.Runtime.dll that we're running
// with can be different from the one we're compiling against.)
internal static Type LoadType(Type type)
{
#if STATIC_COMPILER
return StaticCompiler.GetType(type.FullName);
return StaticCompiler.GetRuntimeType(type.FullName);
#else
return type;
#endif
@ -444,12 +456,20 @@ namespace IKVM.Internal
internal static Type Import(System.Type type)
{
#if STATIC_COMPILER
return StaticCompiler.Universe.Import(type);
#else
return type;
#endif
}
internal static Type GetType(string typeName, bool throwOnError)
{
#if STATIC_COMPILER
return StaticCompiler.Universe.GetType(typeName, throwOnError);
#else
return Type.GetType(typeName, throwOnError);
#endif
}
}
}