Skip to content

Commit

Permalink
Split some nested classes out so we can see them.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Jul 13, 2023
1 parent 68a4f58 commit 5a52624
Show file tree
Hide file tree
Showing 9 changed files with 6,515 additions and 6,169 deletions.
109 changes: 109 additions & 0 deletions src/IKVM.Runtime/DefineMethodHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright (C) 2002-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 IMPORTER
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using IKVM.Tools.Importer;

using Type = IKVM.Reflection.Type;
using DynamicOrAotTypeWrapper = IKVM.Tools.Importer.AotTypeWrapper;
using ProtectionDomain = System.Object;
#else
using System.Reflection;
using System.Reflection.Emit;
#endif

namespace IKVM.Internal
{

sealed class DefineMethodHelper
{

private readonly MethodWrapper mw;

internal DefineMethodHelper(MethodWrapper mw)
{
this.mw = mw;
}

internal int ParameterCount
{
get { return mw.GetParameters().Length + (mw.HasCallerID ? 1 : 0); }
}

internal MethodBuilder DefineMethod(DynamicTypeWrapper context, TypeBuilder tb, string name, MethodAttributes attribs)
{
return DefineMethod(context.GetClassLoader().GetTypeWrapperFactory(), tb, name, attribs, null, false);
}

internal MethodBuilder DefineMethod(TypeWrapperFactory context, TypeBuilder tb, string name, MethodAttributes attribs)
{
return DefineMethod(context, tb, name, attribs, null, false);
}

internal MethodBuilder DefineMethod(TypeWrapperFactory context, TypeBuilder tb, string name, MethodAttributes attribs, Type firstParameter, bool mustBePublic)
{
// we add optional modifiers to make the signature unique
int firstParam = firstParameter == null ? 0 : 1;
TypeWrapper[] parameters = mw.GetParameters();
Type[] parameterTypes = new Type[parameters.Length + (mw.HasCallerID ? 1 : 0) + firstParam];
Type[][] modopt = new Type[parameterTypes.Length][];
if (firstParameter != null)
{
parameterTypes[0] = firstParameter;
modopt[0] = Type.EmptyTypes;
}
for (int i = 0; i < parameters.Length; i++)
{
parameterTypes[i + firstParam] = mustBePublic
? parameters[i].TypeAsPublicSignatureType
: parameters[i].TypeAsSignatureType;
modopt[i + firstParam] = DynamicTypeWrapper.GetModOpt(context, parameters[i], mustBePublic);
}
if (mw.HasCallerID)
{
parameterTypes[parameterTypes.Length - 1] = CoreClasses.ikvm.@internal.CallerID.Wrapper.TypeAsSignatureType;
}
Type returnType = mustBePublic
? mw.ReturnType.TypeAsPublicSignatureType
: mw.ReturnType.TypeAsSignatureType;
Type[] modoptReturnType = DynamicTypeWrapper.GetModOpt(context, mw.ReturnType, mustBePublic);
return tb.DefineMethod(name, attribs, CallingConventions.Standard, returnType, null, modoptReturnType, parameterTypes, null, modopt);
}

internal MethodBuilder DefineConstructor(DynamicTypeWrapper context, TypeBuilder tb, MethodAttributes attribs)
{
return DefineConstructor(context.GetClassLoader().GetTypeWrapperFactory(), tb, attribs);
}

internal MethodBuilder DefineConstructor(TypeWrapperFactory context, TypeBuilder tb, MethodAttributes attribs)
{
return DefineMethod(context, tb, ConstructorInfo.ConstructorName, attribs | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
}

}

}
84 changes: 84 additions & 0 deletions src/IKVM.Runtime/DynamicCallerIDProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright (C) 2002-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.Diagnostics;

#if IMPORTER
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using IKVM.Tools.Importer;

using Type = IKVM.Reflection.Type;
using DynamicOrAotTypeWrapper = IKVM.Tools.Importer.AotTypeWrapper;
using ProtectionDomain = System.Object;
#else
using System.Reflection;
#endif

namespace IKVM.Internal
{
#if !IMPORTER

sealed class DynamicCallerIDProvider
{

// this object acts as a capability that is passed to trusted code to allow the DynamicCallerID()
// method to be public without giving untrusted code the ability to forge a CallerID token
internal static readonly DynamicCallerIDProvider Instance = new DynamicCallerIDProvider();

private DynamicCallerIDProvider() { }

internal ikvm.@internal.CallerID GetCallerID()
{
for (int i = 0; ;)
{
MethodBase method = new StackFrame(i++, false).GetMethod();
if (method == null)
{
#if !FIRST_PASS
return ikvm.@internal.CallerID.create(null, null);
#endif
}
if (IKVM.Java.Externs.sun.reflect.Reflection.IsHideFromStackWalk(method))
{
continue;
}
TypeWrapper caller = ClassLoaderWrapper.GetWrapperFromType(method.DeclaringType);
return CreateCallerID(caller.Host ?? caller);
}
}

internal static ikvm.@internal.CallerID CreateCallerID(TypeWrapper tw)
{
#if FIRST_PASS
return null;
#else
return ikvm.@internal.CallerID.create(tw.ClassObject, tw.GetClassLoader().GetJavaClassLoader());
#endif
}

}

#endif

}
79 changes: 79 additions & 0 deletions src/IKVM.Runtime/DynamicTypeWrapper.DynamicImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright (C) 2002-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;

using IKVM.Attributes;

#if IMPORTER
using IKVM.Reflection;
using IKVM.Reflection.Emit;
using IKVM.Tools.Importer;

using Type = IKVM.Reflection.Type;
using DynamicOrAotTypeWrapper = IKVM.Tools.Importer.AotTypeWrapper;
using ProtectionDomain = System.Object;
#else
using System.Reflection;
#endif

namespace IKVM.Internal
{

#if IMPORTER
abstract partial class DynamicTypeWrapper : TypeWrapper
#else
#pragma warning disable 628 // don't complain about protected members in sealed type
sealed partial class DynamicTypeWrapper
#endif
{
private abstract class DynamicImpl
{
internal abstract Type Type { get; }
internal abstract TypeWrapper[] InnerClasses { get; }
internal abstract TypeWrapper DeclaringTypeWrapper { get; }
internal abstract Modifiers ReflectiveModifiers { get; }
internal abstract DynamicImpl Finish();
internal abstract MethodBase LinkMethod(MethodWrapper mw);
internal abstract FieldInfo LinkField(FieldWrapper fw);
internal abstract void EmitRunClassConstructor(CodeEmitter ilgen);
internal abstract string GetGenericSignature();
internal abstract string[] GetEnclosingMethod();
internal abstract string GetGenericMethodSignature(int index);
internal abstract string GetGenericFieldSignature(int index);
internal abstract object[] GetDeclaredAnnotations();
internal abstract object GetMethodDefaultValue(int index);
internal abstract object[] GetMethodAnnotations(int index);
internal abstract object[][] GetParameterAnnotations(int index);
internal abstract MethodParametersEntry[] GetMethodParameters(int index);
internal abstract object[] GetFieldAnnotations(int index);
internal abstract MethodInfo GetFinalizeMethod();
internal abstract object[] GetConstantPool();
internal abstract byte[] GetRawTypeAnnotations();
internal abstract byte[] GetMethodRawTypeAnnotations(int index);
internal abstract byte[] GetFieldRawTypeAnnotations(int index);
internal abstract TypeWrapper Host { get; }
}
}

}
Loading

0 comments on commit 5a52624

Please sign in to comment.