diff options
author | jfrijters <jfrijters> | 2015-02-16 15:24:28 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2015-02-18 13:43:24 +0300 |
commit | 2f8960be22819f0c0e9af65de0e0c93fc60425e3 (patch) | |
tree | 30899e57379c6147fe223595768c3e63d62b34c6 | |
parent | 6dbc79826d11f63151f050fc2c63e5e73b4da8b8 (diff) |
Added CoreCLR target for IKVM.Reflection.
-rw-r--r-- | reflect/AmbiguousMatchException.cs | 7 | ||||
-rw-r--r-- | reflect/AssemblyName.cs | 9 | ||||
-rw-r--r-- | reflect/BadImageFormatException.cs | 7 | ||||
-rw-r--r-- | reflect/Emit/AssemblyBuilder.cs | 6 | ||||
-rw-r--r-- | reflect/Emit/ConstructorBuilder.cs | 2 | ||||
-rw-r--r-- | reflect/Emit/ILGenerator.cs | 12 | ||||
-rw-r--r-- | reflect/Emit/MethodBuilder.cs | 11 | ||||
-rw-r--r-- | reflect/Emit/ModuleBuilder.cs | 34 | ||||
-rw-r--r-- | reflect/Emit/TypeBuilder.cs | 2 | ||||
-rw-r--r-- | reflect/Fusion.cs | 2 | ||||
-rw-r--r-- | reflect/IKVM.Reflection.csproj | 5 | ||||
-rw-r--r-- | reflect/Impl/SymbolSupport.cs | 17 | ||||
-rw-r--r-- | reflect/Missing.cs | 18 | ||||
-rw-r--r-- | reflect/Reader/ModuleReader.cs | 8 | ||||
-rw-r--r-- | reflect/StrongNameKeyPair.cs | 4 | ||||
-rw-r--r-- | reflect/Type.cs | 99 | ||||
-rw-r--r-- | reflect/Universe.cs | 22 | ||||
-rw-r--r-- | reflect/Util.cs | 20 | ||||
-rw-r--r-- | reflect/Writer/ModuleWriter.cs | 2 | ||||
-rw-r--r-- | reflect/Writer/VersionInfo.cs | 4 | ||||
-rw-r--r-- | reflect/coreclr.cs | 70 | ||||
-rw-r--r-- | reflect/reflect.build | 23 |
22 files changed, 338 insertions, 46 deletions
diff --git a/reflect/AmbiguousMatchException.cs b/reflect/AmbiguousMatchException.cs index 121d69fb..6a43621b 100644 --- a/reflect/AmbiguousMatchException.cs +++ b/reflect/AmbiguousMatchException.cs @@ -22,11 +22,12 @@ */ using System; -using System.Runtime.Serialization; namespace IKVM.Reflection { +#if !CORECLR [Serializable] +#endif public sealed class AmbiguousMatchException : Exception { public AmbiguousMatchException() @@ -43,9 +44,11 @@ namespace IKVM.Reflection { } - private AmbiguousMatchException(SerializationInfo info, StreamingContext context) +#if !CORECLR + private AmbiguousMatchException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif } } diff --git a/reflect/AssemblyName.cs b/reflect/AssemblyName.cs index f383d2b9..43c25e8d 100644 --- a/reflect/AssemblyName.cs +++ b/reflect/AssemblyName.cs @@ -31,7 +31,10 @@ using IKVM.Reflection.Reader; namespace IKVM.Reflection { - public sealed class AssemblyName : ICloneable + public sealed class AssemblyName +#if !CORECLR + : ICloneable +#endif { private string name; private string culture; @@ -199,6 +202,7 @@ namespace IKVM.Reflection set { codeBase = value; } } +#if !CORECLR public string EscapedCodeBase { get @@ -209,6 +213,7 @@ namespace IKVM.Reflection return tmp.EscapedCodeBase; } } +#endif public ProcessorArchitecture ProcessorArchitecture { @@ -446,11 +451,13 @@ namespace IKVM.Reflection return b == null || b.Length == 0 ? b : (byte[])b.Clone(); } +#if !CORECLR public static bool ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition) { // HACK use the real AssemblyName to implement the (broken) ReferenceMatchesDefinition method return System.Reflection.AssemblyName.ReferenceMatchesDefinition(new System.Reflection.AssemblyName(reference.FullName), new System.Reflection.AssemblyName(definition.FullName)); } +#endif public static AssemblyName GetAssemblyName(string path) { diff --git a/reflect/BadImageFormatException.cs b/reflect/BadImageFormatException.cs index 330f9839..57044349 100644 --- a/reflect/BadImageFormatException.cs +++ b/reflect/BadImageFormatException.cs @@ -22,11 +22,12 @@ */ using System; -using System.Runtime.Serialization; namespace IKVM.Reflection { +#if !CORECLR [Serializable] +#endif public sealed class BadImageFormatException : Exception { public BadImageFormatException() @@ -43,9 +44,11 @@ namespace IKVM.Reflection { } - private BadImageFormatException(SerializationInfo info, StreamingContext context) +#if !CORECLR + private BadImageFormatException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif } } diff --git a/reflect/Emit/AssemblyBuilder.cs b/reflect/Emit/AssemblyBuilder.cs index 81987031..a1ba7177 100644 --- a/reflect/Emit/AssemblyBuilder.cs +++ b/reflect/Emit/AssemblyBuilder.cs @@ -82,7 +82,9 @@ namespace IKVM.Reflection.Emit internal string Name; internal string FileName; internal ResourceAttributes Attributes; +#if !CORECLR internal ResourceWriter Writer; +#endif } internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, IEnumerable<CustomAttributeBuilder> customAttributes) @@ -413,11 +415,13 @@ namespace IKVM.Reflection.Emit foreach (ResourceFile resfile in resourceFiles) { +#if !CORECLR if (resfile.Writer != null) { resfile.Writer.Generate(); resfile.Writer.Close(); } +#endif int fileToken = AddFile(manifestModule, resfile.FileName, 1 /*ContainsNoMetaData*/); ManifestResourceTable.Record rec = new ManifestResourceTable.Record(); rec.Offset = 0; @@ -499,6 +503,7 @@ namespace IKVM.Reflection.Emit resourceFiles.Add(resfile); } +#if !CORECLR public IResourceWriter DefineResource(string name, string description, string fileName) { return DefineResource(name, description, fileName, ResourceAttributes.Public); @@ -522,6 +527,7 @@ namespace IKVM.Reflection.Emit resourceFiles.Add(resfile); return rw; } +#endif public void DefineVersionInfoResource() { diff --git a/reflect/Emit/ConstructorBuilder.cs b/reflect/Emit/ConstructorBuilder.cs index 02ccca1f..d54041f1 100644 --- a/reflect/Emit/ConstructorBuilder.cs +++ b/reflect/Emit/ConstructorBuilder.cs @@ -77,10 +77,12 @@ namespace IKVM.Reflection.Emit methodBuilder.__AddDeclarativeSecurity(customBuilder); } +#if !CORECLR public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet) { methodBuilder.AddDeclarativeSecurity(securityAction, permissionSet); } +#endif public void SetImplementationFlags(MethodImplAttributes attributes) { diff --git a/reflect/Emit/ILGenerator.cs b/reflect/Emit/ILGenerator.cs index d7bb6904..18db09be 100644 --- a/reflect/Emit/ILGenerator.cs +++ b/reflect/Emit/ILGenerator.cs @@ -24,7 +24,9 @@ using System; using System.Runtime.InteropServices; using System.Collections.Generic; +#if !NO_SYMBOL_WRITER using System.Diagnostics.SymbolStore; +#endif using System.Diagnostics; using IKVM.Reflection.Writer; @@ -183,12 +185,14 @@ namespace IKVM.Reflection.Emit private struct SequencePoint { +#if !NO_SYMBOL_WRITER internal ISymbolDocumentWriter document; internal int offset; internal int startLine; internal int startColumn; internal int endLine; internal int endColumn; +#endif } private sealed class Scope @@ -402,10 +406,12 @@ namespace IKVM.Reflection.Emit public void UsingNamespace(string usingNamespace) { +#if !NO_SYMBOL_WRITER if (moduleBuilder.symbolWriter != null) { moduleBuilder.symbolWriter.UsingNamespace(usingNamespace); } +#endif } public LocalBuilder DeclareLocal(Type localType) @@ -882,6 +888,7 @@ namespace IKVM.Reflection.Emit } } +#if !NO_SYMBOL_WRITER public void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int startColumn, int endLine, int endColumn) { SequencePoint sp = new SequencePoint(); @@ -893,6 +900,7 @@ namespace IKVM.Reflection.Emit sp.endColumn = endColumn; sequencePoints.Add(sp); } +#endif public void ThrowException(Type excType) { @@ -928,6 +936,7 @@ namespace IKVM.Reflection.Emit rva = WriteFatHeaderAndCode(bb, localVarSigTok, initLocals); } +#if !NO_SYMBOL_WRITER if (moduleBuilder.symbolWriter != null) { if (sequencePoints.Count != 0) @@ -955,6 +964,7 @@ namespace IKVM.Reflection.Emit WriteScope(scope, localVarSigTok); } +#endif return rva; } @@ -1111,6 +1121,7 @@ namespace IKVM.Reflection.Emit } } +#if !NO_SYMBOL_WRITER private void WriteScope(Scope scope, int localVarSigTok) { moduleBuilder.symbolWriter.OpenScope(scope.startOffset); @@ -1134,5 +1145,6 @@ namespace IKVM.Reflection.Emit } moduleBuilder.symbolWriter.CloseScope(scope.endOffset); } +#endif } } diff --git a/reflect/Emit/MethodBuilder.cs b/reflect/Emit/MethodBuilder.cs index 8d46cdde..b3602d7b 100644 --- a/reflect/Emit/MethodBuilder.cs +++ b/reflect/Emit/MethodBuilder.cs @@ -27,7 +27,9 @@ using System.Diagnostics; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; +#if !NO_SYMBOL_WRITER using System.Diagnostics.SymbolStore; +#endif using IKVM.Reflection.Metadata; using IKVM.Reflection.Writer; @@ -89,15 +91,19 @@ namespace IKVM.Reflection.Emit { if (ilgen != null) { +#if !NO_SYMBOL_WRITER if (this.ModuleBuilder.symbolWriter != null) { this.ModuleBuilder.symbolWriter.OpenMethod(new SymbolToken(-pseudoToken | 0x06000000), this); } +#endif rva = ilgen.WriteBody(initLocals); +#if !NO_SYMBOL_WRITER if (this.ModuleBuilder.symbolWriter != null) { this.ModuleBuilder.symbolWriter.CloseMethod(); } +#endif ilgen = null; } } @@ -288,11 +294,13 @@ namespace IKVM.Reflection.Emit declarativeSecurity.Add(customBuilder); } +#if !CORECLR public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet) { this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, securityAction, permissionSet); this.attributes |= MethodAttributes.HasSecurity; } +#endif public void SetImplementationFlags(MethodImplAttributes attributes) { @@ -742,7 +750,8 @@ namespace IKVM.Reflection.Emit { if (methodSignature == null) { - methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length); + methodSignature = MethodSignature.MakeFromBuilder(returnType ?? typeBuilder.Universe.System_Void, parameterTypes ?? Type.EmptyTypes, + customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length); } return methodSignature; } diff --git a/reflect/Emit/ModuleBuilder.cs b/reflect/Emit/ModuleBuilder.cs index 9e946510..cef01345 100644 --- a/reflect/Emit/ModuleBuilder.cs +++ b/reflect/Emit/ModuleBuilder.cs @@ -25,7 +25,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Diagnostics; +#if !NO_SYMBOL_WRITER using System.Diagnostics.SymbolStore; +#endif using System.Security.Cryptography; using System.Resources; using System.Runtime.CompilerServices; @@ -76,10 +78,25 @@ namespace IKVM.Reflection.Emit private struct ResourceWriterRecord { private readonly string name; +#if !CORECLR private readonly ResourceWriter rw; +#endif private readonly Stream stream; private readonly ResourceAttributes attributes; +#if CORECLR + internal ResourceWriterRecord(string name, Stream stream, ResourceAttributes attributes) + { + this.name = name; + this.stream = stream; + this.attributes = attributes; + } +#else + internal ResourceWriterRecord(string name, Stream stream, ResourceAttributes attributes) + : this(name, null, stream, attributes) + { + } + internal ResourceWriterRecord(string name, ResourceWriter rw, Stream stream, ResourceAttributes attributes) { this.name = name; @@ -87,13 +104,16 @@ namespace IKVM.Reflection.Emit this.stream = stream; this.attributes = attributes; } +#endif internal void Emit(ModuleBuilder mb, int offset) { +#if !CORECLR if (rw != null) { rw.Generate(); } +#endif ManifestResourceTable.Record rec = new ManifestResourceTable.Record(); rec.Offset = offset; rec.Flags = (int)attributes; @@ -121,10 +141,12 @@ namespace IKVM.Reflection.Emit internal void Close() { +#if !CORECLR if (rw != null) { rw.Close(); } +#endif } } @@ -480,11 +502,13 @@ namespace IKVM.Reflection.Emit this.DeclSecurity.AddRecord(rec); } +#if !CORECLR internal void AddDeclarativeSecurity(int token, System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet) { // like Ref.Emit, we're using the .NET 1.x xml format AddDeclSecurityRecord(token, (int)securityAction, this.Blobs.Add(ByteBuffer.Wrap(System.Text.Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString())))); } +#endif internal void AddDeclarativeSecurity(int token, List<CustomAttributeBuilder> declarativeSecurity) { @@ -539,9 +563,10 @@ namespace IKVM.Reflection.Emit public void DefineManifestResource(string name, Stream stream, ResourceAttributes attribute) { - resourceWriters.Add(new ResourceWriterRecord(name, null, stream, attribute)); + resourceWriters.Add(new ResourceWriterRecord(name, stream, attribute)); } +#if !CORECLR public IResourceWriter DefineResource(string name, string description) { return DefineResource(name, description, ResourceAttributes.Public); @@ -556,6 +581,7 @@ namespace IKVM.Reflection.Emit resourceWriters.Add(new ResourceWriterRecord(name, rw, mem, attribute)); return rw; } +#endif internal void EmitResources() { @@ -645,10 +671,12 @@ namespace IKVM.Reflection.Emit } } +#if !NO_SYMBOL_WRITER public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType) { return symbolWriter.DefineDocument(url, language, languageVendor, documentType); } +#endif public int __GetAssemblyToken(Assembly assembly) { @@ -1387,10 +1415,12 @@ namespace IKVM.Reflection.Emit get { return moduleName; } } +#if !NO_SYMBOL_WRITER public ISymbolWriter GetSymWriter() { return symbolWriter; } +#endif public void DefineUnmanagedResource(string resourceFileName) { @@ -1412,10 +1442,12 @@ namespace IKVM.Reflection.Emit { token = -token | 0x06000000; } +#if !NO_SYMBOL_WRITER if (symbolWriter != null) { symbolWriter.SetUserEntryPoint(new SymbolToken(token)); } +#endif } public StringToken GetStringConstant(string str) diff --git a/reflect/Emit/TypeBuilder.cs b/reflect/Emit/TypeBuilder.cs index 30cde68c..41d14a24 100644 --- a/reflect/Emit/TypeBuilder.cs +++ b/reflect/Emit/TypeBuilder.cs @@ -649,11 +649,13 @@ namespace IKVM.Reflection.Emit declarativeSecurity.Add(customBuilder); } +#if !CORECLR public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet) { this.ModuleBuilder.AddDeclarativeSecurity(token, securityAction, permissionSet); this.attribs |= TypeAttributes.HasSecurity; } +#endif public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { diff --git a/reflect/Fusion.cs b/reflect/Fusion.cs index ec9c252d..bc083239 100644 --- a/reflect/Fusion.cs +++ b/reflect/Fusion.cs @@ -60,6 +60,7 @@ namespace IKVM.Reflection const string PublicKeyTokenSilverlight = "7cec85d7bea7798e"; const string PublicKeyTokenWinFX = "31bf3856ad364e35"; +#if !CORECLR internal static bool CompareAssemblyIdentityNative(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result) { bool equivalent; @@ -69,6 +70,7 @@ namespace IKVM.Reflection [DllImport("fusion", CharSet = CharSet.Unicode)] private static extern int CompareAssemblyIdentity(string pwzAssemblyIdentity1, bool fUnified1, string pwzAssemblyIdentity2, bool fUnified2, out bool pfEquivalent, out AssemblyComparisonResult pResult); +#endif // internal for use by mcs internal static bool CompareAssemblyIdentityPure(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result) diff --git a/reflect/IKVM.Reflection.csproj b/reflect/IKVM.Reflection.csproj index 5023d9c4..8de23b7f 100644 --- a/reflect/IKVM.Reflection.csproj +++ b/reflect/IKVM.Reflection.csproj @@ -3,7 +3,7 @@ <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>9.0.21022</ProductVersion> + <ProductVersion>9.0.30729</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}</ProjectGuid> <OutputType>Library</OutputType> @@ -22,8 +22,6 @@ </SccAuxPath> <SccProvider> </SccProvider> - <SignAssembly>true</SignAssembly> - <AssemblyOriginatorKeyFile>..\ikvm-fork.snk</AssemblyOriginatorKeyFile> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -49,6 +47,7 @@ <Compile Include="BadImageFormatException.cs" /> <Compile Include="Binder.cs" /> <Compile Include="ConstructorInfo.cs" /> + <Compile Include="coreclr.cs" /> <Compile Include="CustomAttributeData.cs" /> <Compile Include="CustomAttributeNamedArgument.cs" /> <Compile Include="CustomAttributeTypedArgument.cs" /> diff --git a/reflect/Impl/SymbolSupport.cs b/reflect/Impl/SymbolSupport.cs index 64547ebe..c573b2b5 100644 --- a/reflect/Impl/SymbolSupport.cs +++ b/reflect/Impl/SymbolSupport.cs @@ -23,7 +23,9 @@ */ using System; using System.Runtime.InteropServices; +#if !NO_SYMBOL_WRITER using System.Diagnostics.SymbolStore; +#endif using IKVM.Reflection.Emit; namespace IKVM.Reflection.Impl @@ -41,6 +43,20 @@ namespace IKVM.Reflection.Impl public uint PointerToRawData; } +#if NO_SYMBOL_WRITER + struct SymbolToken + { + internal SymbolToken(int value) { } + } + + interface ISymbolWriterImpl + { + byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd); + void RemapToken(int oldToken, int newToken); + void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, int addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset); + void OpenMethod(SymbolToken symbolToken, MethodBase mb); + } +#else interface ISymbolWriterImpl : ISymbolWriter { byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd); @@ -48,6 +64,7 @@ namespace IKVM.Reflection.Impl void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset); void OpenMethod(SymbolToken symbolToken, MethodBase mb); } +#endif static class SymbolSupport { diff --git a/reflect/Missing.cs b/reflect/Missing.cs index ff9c5c06..1754c66d 100644 --- a/reflect/Missing.cs +++ b/reflect/Missing.cs @@ -27,10 +27,14 @@ using System.Runtime.InteropServices; namespace IKVM.Reflection { +#if !CORECLR [Serializable] +#endif public sealed class MissingAssemblyException : InvalidOperationException { +#if !CORECLR [NonSerialized] +#endif private readonly MissingAssembly assembly; internal MissingAssemblyException(MissingAssembly assembly) @@ -39,10 +43,12 @@ namespace IKVM.Reflection this.assembly = assembly; } +#if !CORECLR private MissingAssemblyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif public Assembly Assembly { @@ -50,10 +56,14 @@ namespace IKVM.Reflection } } +#if !CORECLR [Serializable] +#endif public sealed class MissingModuleException : InvalidOperationException { +#if !CORECLR [NonSerialized] +#endif private readonly MissingModule module; internal MissingModuleException(MissingModule module) @@ -62,10 +72,12 @@ namespace IKVM.Reflection this.module = module; } +#if !CORECLR private MissingModuleException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif public Module Module { @@ -73,10 +85,14 @@ namespace IKVM.Reflection } } +#if !CORECLR [Serializable] +#endif public sealed class MissingMemberException : InvalidOperationException { +#if !CORECLR [NonSerialized] +#endif private readonly MemberInfo member; internal MissingMemberException(MemberInfo member) @@ -85,10 +101,12 @@ namespace IKVM.Reflection this.member = member; } +#if !CORECLR private MissingMemberException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif public MemberInfo MemberInfo { diff --git a/reflect/Reader/ModuleReader.cs b/reflect/Reader/ModuleReader.cs index 5f3f7a8f..111efd14 100644 --- a/reflect/Reader/ModuleReader.cs +++ b/reflect/Reader/ModuleReader.cs @@ -875,7 +875,11 @@ namespace IKVM.Reflection.Reader { return field; } +#if CORECLR + throw new MissingFieldException(org.ToString() + "." + name); +#else throw new MissingFieldException(org.ToString(), name); +#endif } else { @@ -894,7 +898,11 @@ namespace IKVM.Reflection.Reader { return method; } +#if CORECLR + throw new MissingMethodException(org.ToString() + "." + name); +#else throw new MissingMethodException(org.ToString(), name); +#endif } } diff --git a/reflect/StrongNameKeyPair.cs b/reflect/StrongNameKeyPair.cs index 7d354475..1e17bc4e 100644 --- a/reflect/StrongNameKeyPair.cs +++ b/reflect/StrongNameKeyPair.cs @@ -74,11 +74,13 @@ namespace IKVM.Reflection { get { +#if !CORECLR if (Universe.MonoRuntime) { // MONOBUG workaround for https://bugzilla.xamarin.com/show_bug.cgi?id=5299 return MonoGetPublicKey(); } +#endif using (RSACryptoServiceProvider rsa = CreateRSA()) { byte[] cspBlob = rsa.ExportCspBlob(false); @@ -125,6 +127,7 @@ namespace IKVM.Reflection } } +#if !CORECLR [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] private byte[] MonoGetPublicKey() { @@ -132,5 +135,6 @@ namespace IKVM.Reflection ? new System.Reflection.StrongNameKeyPair(keyPairArray).PublicKey : new System.Reflection.StrongNameKeyPair(keyPairContainer).PublicKey; } +#endif } } diff --git a/reflect/Type.cs b/reflect/Type.cs index de4f534f..0cb1ea05 100644 --- a/reflect/Type.cs +++ b/reflect/Type.cs @@ -504,6 +504,7 @@ namespace IKVM.Reflection return names.ToArray(); } +#if !CORECLR public string GetEnumName(object value) { if (!IsEnum) @@ -539,6 +540,7 @@ namespace IKVM.Reflection } return null; } +#endif public bool IsEnumDefined(object value) { @@ -1315,6 +1317,7 @@ namespace IKVM.Reflection get { return IsClass && IsImport; } } +#if !CORECLR public bool IsContextful { get { return IsSubclassOf(this.Module.universe.Import(typeof(ContextBoundObject))); } @@ -1324,6 +1327,7 @@ namespace IKVM.Reflection { get { return IsSubclassOf(this.Module.universe.Import(typeof(MarshalByRefObject))); } } +#endif public virtual bool IsVisible { @@ -1801,48 +1805,90 @@ namespace IKVM.Reflection public InterfaceMapping GetInterfaceMap(Type interfaceType) { CheckBaked(); - InterfaceMapping map = new InterfaceMapping(); - if (!IsDirectlyImplementedInterface(interfaceType)) + InterfaceMapping map; + map.InterfaceMethods = interfaceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); + map.InterfaceType = interfaceType; + map.TargetMethods = new MethodInfo[map.InterfaceMethods.Length]; + map.TargetType = this; + FillInInterfaceMethods(interfaceType, map.InterfaceMethods, map.TargetMethods); + return map; + } + + private void FillInInterfaceMethods(Type interfaceType, MethodInfo[] interfaceMethods, MethodInfo[] targetMethods) + { + FillInExplicitInterfaceMethods(interfaceMethods, targetMethods); + bool direct = IsDirectlyImplementedInterface(interfaceType); + if (direct) { - Type baseType = this.BaseType; - if (baseType == null) + FillInImplicitInterfaceMethods(interfaceMethods, targetMethods); + } + Type baseType = this.BaseType; + if (baseType != null) + { + baseType.FillInInterfaceMethods(interfaceType, interfaceMethods, targetMethods); + ReplaceOverriddenMethods(targetMethods); + } + if (direct) + { + for (Type type = this.BaseType; type != null && type.Module == Module; type = type.BaseType) { - throw new ArgumentException(); + type.FillInImplicitInterfaceMethods(interfaceMethods, targetMethods); } - else + } + } + + private void FillInImplicitInterfaceMethods(MethodInfo[] interfaceMethods, MethodInfo[] targetMethods) + { + MethodBase[] methods = null; + for (int i = 0; i < targetMethods.Length; i++) + { + if (targetMethods[i] == null) { - map = baseType.GetInterfaceMap(interfaceType); + if (methods == null) + { + methods = __GetDeclaredMethods(); + } + for (int j = 0; j < methods.Length; j++) + { + if (methods[j].IsVirtual + && methods[j].Name == interfaceMethods[i].Name + && methods[j].MethodSignature.Equals(interfaceMethods[i].MethodSignature)) + { + targetMethods[i] = (MethodInfo)methods[j]; + break; + } + } } } - else + } + + private void ReplaceOverriddenMethods(MethodInfo[] baseMethods) + { + __MethodImplMap impl = __GetMethodImplMap(); + for (int i = 0; i < baseMethods.Length; i++) { - map.InterfaceMethods = interfaceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); - map.InterfaceType = interfaceType; - map.TargetMethods = new MethodInfo[map.InterfaceMethods.Length]; - FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods); - MethodInfo[] methods = GetMethods(BindingFlags.Instance | BindingFlags.Public); - for (int i = 0; i < map.TargetMethods.Length; i++) + if (baseMethods[i] != null && !baseMethods[i].IsFinal) { - if (map.TargetMethods[i] == null) + MethodInfo def = baseMethods[i].GetBaseDefinition(); + for (int j = 0; j < impl.MethodDeclarations.Length; j++) { - // TODO use proper method resolution (also take into account that no implicit base class implementation is used across assembly boundaries) - for (int j = 0; j < methods.Length; j++) + for (int k = 0; k < impl.MethodDeclarations[j].Length; k++) { - if (methods[j].Name == map.InterfaceMethods[i].Name - && methods[j].MethodSignature.Equals(map.InterfaceMethods[i].MethodSignature)) + if (impl.MethodDeclarations[j][k].GetBaseDefinition() == def) { - map.TargetMethods[i] = methods[j]; + baseMethods[i] = impl.MethodBodies[j]; + goto next; } } } + MethodInfo candidate = FindMethod(def.Name, def.MethodSignature) as MethodInfo; + if (candidate != null && candidate.IsVirtual && !candidate.IsNewSlot) + { + baseMethods[i] = candidate; + } } - for (Type baseType = this.BaseType; baseType != null && interfaceType.IsAssignableFrom(baseType); baseType = baseType.BaseType) - { - baseType.FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods); - } + next: ; } - map.TargetType = this; - return map; } internal void FillInExplicitInterfaceMethods(MethodInfo[] interfaceMethods, MethodInfo[] targetMethods) @@ -2040,7 +2086,6 @@ namespace IKVM.Reflection { if (this.Assembly == this.Universe.Mscorlib || this.Assembly.GetName().Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase) - || this.Assembly.GetName().Name.Equals("System.Runtime", StringComparison.OrdinalIgnoreCase) // check if mscorlib forwards the type (.NETCore profile reference mscorlib forwards System.Enum and System.ValueType to System.Runtime.dll) || this.Universe.Mscorlib.FindType(new TypeName(__Namespace, __Name)) == this) { diff --git a/reflect/Universe.cs b/reflect/Universe.cs index 09f3655a..30ed1204 100644 --- a/reflect/Universe.cs +++ b/reflect/Universe.cs @@ -818,6 +818,9 @@ namespace IKVM.Reflection { return asm; } +#if CORECLR + return null; +#else string fileName; if (throwOnError) { @@ -848,6 +851,7 @@ namespace IKVM.Reflection } } return LoadFile(fileName); +#endif } public Type GetType(string assemblyQualifiedTypeName) @@ -920,9 +924,13 @@ namespace IKVM.Reflection // this is equivalent to the Fusion CompareAssemblyIdentity API public bool CompareAssemblyIdentity(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result) { +#if CORECLR + return Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result); +#else return useNativeFusion ? Fusion.CompareAssemblyIdentityNative(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result) : Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result); +#endif } public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) @@ -940,6 +948,7 @@ namespace IKVM.Reflection return new AssemblyBuilder(this, name, dir, null); } +#if !CORECLR #if NET_4_0 [Obsolete] #endif @@ -959,6 +968,7 @@ namespace IKVM.Reflection ab.__AddDeclarativeSecurity(CustomAttributeBuilder.__FromBlob(CustomAttributeBuilder.LegacyPermissionSet, (int)action, Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString()))); } } +#endif internal void RegisterDynamicAssembly(AssemblyBuilder asm) { @@ -1103,7 +1113,11 @@ namespace IKVM.Reflection } return method; } +#if CORECLR + throw new MissingMethodException(declaringType.ToString() + "." + name); +#else throw new MissingMethodException(declaringType.ToString(), name); +#endif } internal FieldInfo GetMissingFieldOrThrow(Module requester, Type declaringType, string name, FieldSignature signature) @@ -1117,7 +1131,11 @@ namespace IKVM.Reflection } return field; } +#if CORECLR + throw new MissingFieldException(declaringType.ToString() + "." + name); +#else throw new MissingFieldException(declaringType.ToString(), name); +#endif } internal PropertyInfo GetMissingPropertyOrThrow(Module requester, Type declaringType, string name, PropertySignature propertySignature) @@ -1133,7 +1151,11 @@ namespace IKVM.Reflection } return property; } +#if CORECLR + throw new System.MissingMemberException(declaringType.ToString() + "." + name); +#else throw new System.MissingMemberException(declaringType.ToString(), name); +#endif } internal Type CanonicalizeType(Type type) diff --git a/reflect/Util.cs b/reflect/Util.cs index e05b5dbe..7ca6a0f8 100644 --- a/reflect/Util.cs +++ b/reflect/Util.cs @@ -23,7 +23,6 @@ */ using System; using System.Collections.Generic; -using System.Runtime.Serialization; namespace IKVM.Reflection { @@ -33,7 +32,9 @@ namespace IKVM.Reflection IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit); } +#if !CORECLR [Serializable] +#endif public sealed class FileFormatLimitationExceededException : InvalidOperationException { public const int META_E_STRINGSPACE_FULL = unchecked((int)0x80131198); @@ -44,10 +45,12 @@ namespace IKVM.Reflection this.HResult = hresult; } +#if !CORECLR private FileFormatLimitationExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { } +#endif public int ErrorCode { @@ -55,26 +58,33 @@ namespace IKVM.Reflection } } +#if !CORECLR [Serializable] - public sealed class Missing : ISerializable +#endif + public sealed class Missing +#if !CORECLR + : System.Runtime.Serialization.ISerializable +#endif { public static readonly Missing Value = new Missing(); private Missing() { } - void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) +#if !CORECLR + void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { info.SetType(typeof(SingletonSerializationHelper)); } [Serializable] - private sealed class SingletonSerializationHelper : IObjectReference + private sealed class SingletonSerializationHelper : System.Runtime.Serialization.IObjectReference { - public object GetRealObject(StreamingContext context) + public object GetRealObject(System.Runtime.Serialization.StreamingContext context) { return Value; } } +#endif } static class Empty<T> diff --git a/reflect/Writer/ModuleWriter.cs b/reflect/Writer/ModuleWriter.cs index d074cee9..b81beadd 100644 --- a/reflect/Writer/ModuleWriter.cs +++ b/reflect/Writer/ModuleWriter.cs @@ -338,11 +338,13 @@ namespace IKVM.Reflection.Writer StrongName(stream, keyPair, writer.HeaderSize, text.PointerToRawData, code.StrongNameSignatureRVA - text.VirtualAddress + text.PointerToRawData, code.StrongNameSignatureLength); } +#if !NO_SYMBOL_WRITER if (moduleBuilder.symbolWriter != null) { moduleBuilder.WriteSymbolTokenMap(); moduleBuilder.symbolWriter.Close(); } +#endif } private static int ComputeStrongNameSignatureLength(byte[] publicKey) diff --git a/reflect/Writer/VersionInfo.cs b/reflect/Writer/VersionInfo.cs index 25eb193b..efb65ce2 100644 --- a/reflect/Writer/VersionInfo.cs +++ b/reflect/Writer/VersionInfo.cs @@ -108,7 +108,11 @@ namespace IKVM.Reflection.Writer { if (name.CultureInfo != null) { +#if CORECLR + throw new NotImplementedException(); +#else lcid = name.CultureInfo.LCID; +#endif } } catch (ArgumentException) diff --git a/reflect/coreclr.cs b/reflect/coreclr.cs new file mode 100644 index 00000000..999fd3ab --- /dev/null +++ b/reflect/coreclr.cs @@ -0,0 +1,70 @@ +/* + Copyright (C) 2015 Jeroen Frijters + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ +using System; + +#if CORECLR +namespace System.Diagnostics +{ + static class Debug + { + [Conditional("DEBUG")] + internal static void Assert(bool cond) + { + if (!cond) + { + Environment.FailFast("assertion failed"); + } + } + } +} + +namespace System.Collections.Generic +{ + sealed class Stack<T> + { + private readonly List<T> items = new List<T>(); + + internal void Push(T value) + { + items.Add(value); + } + + internal T Peek() + { + if (items.Count == 0) + { + throw new InvalidOperationException(); + } + return items[items.Count - 1]; + } + + internal T Pop() + { + T value = Peek(); + items.RemoveAt(items.Count - 1); + return value; + } + } +} +#endif diff --git a/reflect/reflect.build b/reflect/reflect.build index 3aeae305..53fed7f9 100644 --- a/reflect/reflect.build +++ b/reflect/reflect.build @@ -25,7 +25,7 @@ <project name="reflect" default="IKVM.Reflection"> <include buildfile="../ikvm.include" /> - <target name="IKVM.Reflection"> + <target name="properties"> <property name="defs" value="TRACE" /> <if test="${framework::exists('mono-2.0')}"> <property name="defs" value="${defs};MONO" /> @@ -41,6 +41,20 @@ <if test="${framework::exists('mono-2.0')}"> <property name="MonoSymbolWriter" value="${path::combine(framework::get-assembly-directory('mono-2.0'), 'Mono.CompilerServices.SymbolWriter.dll')}" /> </if> + </target> + + <target name="CoreCLR" depends="properties"> + <property name="CoreCLR" value="true" /> + <property name="defs" value="${defs};CORECLR;NO_SYMBOL_WRITER;NO_AUTHENTICODE" /> + <call target="compile" /> + </target> + + <target name="IKVM.Reflection" depends="properties"> + <property name="CoreCLR" value="false" /> + <call target="compile" /> + </target> + + <target name="compile"> <csc target="library" output="../bin/IKVM.Reflection.dll" optimize="true" define="${defs}" noconfig="true" nostdlib="true"> <sources> <include name="../CommonAssemblyInfo.cs" /> @@ -50,6 +64,7 @@ <include name="BadImageFormatException.cs" /> <include name="Binder.cs" /> <include name="ConstructorInfo.cs" /> + <include name="coreclr.cs" /> <include name="CustomAttributeData.cs" /> <include name="CustomAttributeNamedArgument.cs" /> <include name="CustomAttributeTypedArgument.cs" /> @@ -107,7 +122,7 @@ <include name="Emit\TypeBuilder.cs" /> <include name="Impl\ITypeOwner.cs" /> <include name="Impl\MdbWriter.cs" /> - <include name="Impl\PdbWriter.cs" /> + <include name="Impl\PdbWriter.cs" unless="${CoreCLR}" /> <include name="Impl\SymbolSupport.cs" /> <include name="Metadata\CliHeader.cs" /> <include name="Metadata\MetadataRW.cs" /> @@ -138,8 +153,8 @@ <references> <include if="${framework::exists('mono-2.0')}" name="${MonoSymbolWriter}" /> <include name="${ReferencePath}/mscorlib.dll" /> - <include name="${ReferencePath}/System.dll" /> - <include name="${ReferencePath}/System.Security.dll" /> + <include name="${ReferencePath}/System.dll" unless="${CoreCLR}" /> + <include name="${ReferencePath}/System.Security.dll" unless="${CoreCLR}" /> </references> </csc> </target> |