Removed remaining ConstructorBuilder usages.

This commit is contained in:
jfrijters 2012-09-13 13:21:35 +00:00
Родитель 3994622a36
Коммит 898696629a
12 изменённых файлов: 63 добавлений и 216 удалений

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

@ -117,7 +117,7 @@ namespace IKVM.Internal
private readonly AotTypeWrapper wrapper;
private readonly TypeBuilder typeBuilder;
private readonly MethodWrapper[] methods;
private ConstructorInfo baseSerializationCtor;
private MethodBuilder baseSerializationCtor;
internal WorkaroundBaseClass(AotTypeWrapper wrapper, TypeBuilder typeBuilder, MethodWrapper[] methods)
{
@ -126,7 +126,7 @@ namespace IKVM.Internal
this.methods = methods;
}
internal ConstructorInfo GetSerializationConstructor()
internal MethodBuilder GetSerializationConstructor()
{
if (baseSerializationCtor == null)
{
@ -229,7 +229,7 @@ namespace IKVM.Internal
}
}
internal void AddXmlMapParameterAttributes(MethodBase method, string className, string methodName, string methodSig, ref ParameterBuilder[] pbs)
internal void AddXmlMapParameterAttributes(MethodBuilder method, string className, string methodName, string methodSig, ref ParameterBuilder[] pbs)
{
IKVM.Internal.MapXml.Param[] parameters = classLoader.GetXmlMapParameters(className, methodName, methodSig);
if(parameters != null)
@ -1283,7 +1283,7 @@ namespace IKVM.Internal
return mw;
}
internal override ConstructorInfo GetBaseSerializationConstructor()
internal override MethodBase GetBaseSerializationConstructor()
{
if (workaroundBaseClass != null)
{

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

@ -2165,7 +2165,7 @@ namespace IKVM.Internal
}
}
internal static void AddDeclaredExceptions(MethodBase mb, IKVM.Internal.MapXml.Throws[] throws)
internal static void AddDeclaredExceptions(MethodBuilder mb, IKVM.Internal.MapXml.Throws[] throws)
{
if (throws != null)
{

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

@ -81,7 +81,7 @@ namespace IKVM.Internal
TypeWrapper enumTypeWrapper = loader.LoadClassByDottedName("java.lang.Enum");
enumTypeWrapper.Finish();
tb.SetParent(enumTypeWrapper.TypeAsBaseType);
CodeEmitter ilgen = CodeEmitter.Create(tb.DefineConstructor(MethodAttributes.Private, CallingConventions.Standard, new Type[] { Types.String, Types.Int32 }));
CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineConstructor(tb, MethodAttributes.Private, new Type[] { Types.String, Types.Int32 }));
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldarg_1);
ilgen.Emit(OpCodes.Ldarg_2);

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

@ -237,8 +237,7 @@ namespace IKVM.Internal
private static void CreateConstructor(TypeBuilder tb)
{
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { invocationHandlerClass.TypeAsSignatureType });
CodeEmitter ilgen = CodeEmitter.Create(cb);
CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineConstructor(tb, MethodAttributes.Public, new Type[] { invocationHandlerClass.TypeAsSignatureType }));
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldarg_1);
proxyConstructor.EmitCall(ilgen);
@ -344,8 +343,7 @@ namespace IKVM.Internal
private static void CreateStaticInitializer(TypeBuilder tb, List<ProxyMethod> methods)
{
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes);
CodeEmitter ilgen = CodeEmitter.Create(cb);
CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineTypeInitializer(tb));
CodeEmitterLocal callerID = ilgen.DeclareLocal(CoreClasses.ikvm.@internal.CallerID.Wrapper.TypeAsSignatureType);
TypeBuilder tbCallerID = DynamicTypeWrapper.FinishContext.EmitCreateCallerID(tb, ilgen);
ilgen.Emit(OpCodes.Stloc, callerID);

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

@ -455,11 +455,6 @@ namespace IKVM.Internal
return new CodeEmitter(mb.GetILGenerator(), mb.DeclaringType);
}
internal static CodeEmitter Create(ConstructorBuilder cb)
{
return new CodeEmitter(cb.GetILGenerator(), cb.DeclaringType);
}
#if !STATIC_COMPILER
internal static CodeEmitter Create(DynamicMethod dm)
{
@ -2740,7 +2735,7 @@ namespace IKVM.Internal
}
#if STATIC_COMPILER
internal void EmitLineNumberTable(MethodBase mb)
internal void EmitLineNumberTable(MethodBuilder mb)
{
if(linenums != null)
{

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

@ -1131,10 +1131,6 @@ namespace IKVM.Internal
{
}
internal override void Apply(ClassLoaderWrapper loader, ConstructorBuilder cb, object annotation)
{
}
internal override void Apply(ClassLoaderWrapper loader, FieldBuilder fb, object annotation)
{
}
@ -1269,15 +1265,6 @@ namespace IKVM.Internal
}
}
internal override void Apply(ClassLoaderWrapper loader, ConstructorBuilder cb, object annotation)
{
Annotation annot = type.Annotation;
foreach (object ann in UnwrapArray(annotation))
{
annot.Apply(loader, cb, ann);
}
}
internal override void Apply(ClassLoaderWrapper loader, FieldBuilder fb, object annotation)
{
Annotation annot = type.Annotation;
@ -1527,28 +1514,6 @@ namespace IKVM.Internal
}
}
internal override void Apply(ClassLoaderWrapper loader, ConstructorBuilder cb, object annotation)
{
if (type.IsSubclassOf(Types.SecurityAttribute))
{
#if STATIC_COMPILER
cb.__AddDeclarativeSecurity(MakeCustomAttributeBuilder(loader, annotation));
#elif STUB_GENERATOR
#else
SecurityAction action;
PermissionSet permSet;
if (MakeDeclSecurity(type, annotation, out action, out permSet))
{
cb.AddDeclarativeSecurity(action, permSet);
}
#endif
}
else
{
cb.SetCustomAttribute(MakeCustomAttributeBuilder(loader, annotation));
}
}
internal override void Apply(ClassLoaderWrapper loader, MethodBuilder mb, object annotation)
{
if (type.IsSubclassOf(Types.SecurityAttribute))

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

@ -58,7 +58,7 @@ namespace IKVM.Internal
#if !STATIC_COMPILER
private byte[][] lineNumberTables;
#endif
private ConstructorInfo automagicSerializationCtor;
private MethodBase automagicSerializationCtor;
private static TypeWrapper LoadTypeWrapper(ClassLoaderWrapper classLoader, string name)
{
@ -916,7 +916,7 @@ namespace IKVM.Internal
private sealed class DelegateConstructorMethodWrapper : MethodWrapper
{
private ConstructorBuilder constructor;
private MethodBuilder constructor;
private MethodInfo invoke;
internal DelegateConstructorMethodWrapper(DynamicTypeWrapper tw, ClassFile.Method m)
@ -927,7 +927,7 @@ namespace IKVM.Internal
internal void DoLink(TypeBuilder typeBuilder)
{
MethodAttributes attribs = MethodAttributes.HideBySig | MethodAttributes.Public;
constructor = typeBuilder.DefineConstructor(attribs, CallingConventions.Standard, new Type[] { Types.Object, Types.IntPtr }, null, null);
constructor = ReflectUtil.DefineConstructor(typeBuilder, attribs, new Type[] { Types.Object, Types.IntPtr });
constructor.SetImplementationFlags(MethodImplAttributes.Runtime);
MethodWrapper mw = GetParameters()[0].GetMethods()[0];
mw.Link();
@ -1707,7 +1707,7 @@ namespace IKVM.Internal
private TypeBuilder outer;
private TypeBuilder annotationTypeBuilder;
private TypeBuilder attributeTypeBuilder;
private ConstructorBuilder defineConstructor;
private MethodBuilder defineConstructor;
internal AnnotationBuilder(JavaTypeImpl o, TypeBuilder outer)
{
@ -1869,7 +1869,7 @@ namespace IKVM.Internal
}
}
defineConstructor = attributeTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { JVM.Import(typeof(object[])) });
defineConstructor = ReflectUtil.DefineConstructor(attributeTypeBuilder, MethodAttributes.Public, new Type[] { JVM.Import(typeof(object[])) });
AttributeHelper.SetEditorBrowsableNever(defineConstructor);
}
@ -1974,7 +1974,7 @@ namespace IKVM.Internal
}
}
ConstructorBuilder defaultConstructor = attributeTypeBuilder.DefineConstructor(unsupported || requiredArgCount > 0 ? MethodAttributes.Private : MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
MethodBuilder defaultConstructor = ReflectUtil.DefineConstructor(attributeTypeBuilder, unsupported || requiredArgCount > 0 ? MethodAttributes.Private : MethodAttributes.Public, Type.EmptyTypes);
CodeEmitter ilgen;
if (!unsupported)
@ -1992,7 +1992,7 @@ namespace IKVM.Internal
}
}
}
ConstructorBuilder reqArgConstructor = attributeTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, args);
MethodBuilder reqArgConstructor = ReflectUtil.DefineConstructor(attributeTypeBuilder, MethodAttributes.Public, args);
AttributeHelper.HideFromJava(reqArgConstructor);
ilgen = CodeEmitter.Create(reqArgConstructor);
ilgen.Emit(OpCodes.Ldarg_0);
@ -2019,7 +2019,7 @@ namespace IKVM.Internal
Type argType = TypeWrapperToAnnotationParameterType(o.methods[valueArg].ReturnType);
if (argType != null)
{
ConstructorBuilder cb = attributeTypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { argType });
MethodBuilder cb = ReflectUtil.DefineConstructor(attributeTypeBuilder, MethodAttributes.Public, new Type[] { argType });
AttributeHelper.HideFromJava(cb);
cb.DefineParameter(1, ParameterAttributes.None, "value");
ilgen = CodeEmitter.Create(cb);
@ -2150,7 +2150,7 @@ namespace IKVM.Internal
if (annotationTypeBuilder != null)
{
annotation = QualifyClassNames(loader, annotation);
tb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor, new object[] { annotation }));
tb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor.__AsConstructorInfo(), new object[] { annotation }));
}
}
@ -2160,17 +2160,7 @@ namespace IKVM.Internal
if (annotationTypeBuilder != null)
{
annotation = QualifyClassNames(loader, annotation);
mb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor, new object[] { annotation }));
}
}
internal override void Apply(ClassLoaderWrapper loader, ConstructorBuilder cb, object annotation)
{
Link();
if (annotationTypeBuilder != null)
{
annotation = QualifyClassNames(loader, annotation);
cb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor, new object[] { annotation }));
mb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor.__AsConstructorInfo(), new object[] { annotation }));
}
}
@ -2180,7 +2170,7 @@ namespace IKVM.Internal
if (annotationTypeBuilder != null)
{
annotation = QualifyClassNames(loader, annotation);
fb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor, new object[] { annotation }));
fb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor.__AsConstructorInfo(), new object[] { annotation }));
}
}
@ -2190,7 +2180,7 @@ namespace IKVM.Internal
if (annotationTypeBuilder != null)
{
annotation = QualifyClassNames(loader, annotation);
pb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor, new object[] { annotation }));
pb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor.__AsConstructorInfo(), new object[] { annotation }));
}
}
@ -2200,7 +2190,7 @@ namespace IKVM.Internal
if (annotationTypeBuilder != null)
{
annotation = QualifyClassNames(loader, annotation);
ab.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor, new object[] { annotation }));
ab.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor.__AsConstructorInfo(), new object[] { annotation }));
}
}
@ -2210,7 +2200,7 @@ namespace IKVM.Internal
if (annotationTypeBuilder != null)
{
annotation = QualifyClassNames(loader, annotation);
pb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor, new object[] { annotation }));
pb.SetCustomAttribute(new CustomAttributeBuilder(defineConstructor.__AsConstructorInfo(), new object[] { annotation }));
}
}
@ -2743,7 +2733,7 @@ namespace IKVM.Internal
}
}
ClassFile.Method m = classFile.Methods[index];
MethodBase method;
MethodBuilder method;
bool setModifiers = false;
if (methods[index].HasCallerID && (m.Modifiers & Modifiers.VarArgs) != 0)
{
@ -2774,28 +2764,14 @@ namespace IKVM.Internal
AttributeHelper.SetThrowsAttribute(method, exceptions);
if (setModifiers || m.IsInternal || (m.Modifiers & (Modifiers.Synthetic | Modifiers.Bridge)) != 0)
{
if (method is ConstructorBuilder)
{
AttributeHelper.SetModifiers((ConstructorBuilder)method, m.Modifiers, m.IsInternal);
}
else
{
AttributeHelper.SetModifiers((MethodBuilder)method, m.Modifiers, m.IsInternal);
}
AttributeHelper.SetModifiers(method, m.Modifiers, m.IsInternal);
}
if ((m.Modifiers & (Modifiers.Synthetic | Modifiers.Bridge)) != 0
&& (m.IsPublic || m.IsProtected)
&& wrapper.IsPublic
&& !IsAccessBridge(classFile, m))
{
if (method is ConstructorBuilder)
{
AttributeHelper.SetEditorBrowsableNever((ConstructorBuilder)method);
}
else
{
AttributeHelper.SetEditorBrowsableNever((MethodBuilder)method);
}
AttributeHelper.SetEditorBrowsableNever(method);
// TODO on WHIDBEY apply CompilerGeneratedAttribute
}
if (m.DeprecatedAttribute)
@ -2820,14 +2796,14 @@ namespace IKVM.Internal
}
}
private MethodBase GenerateConstructor(MethodWrapper mw)
private MethodBuilder GenerateConstructor(MethodWrapper mw)
{
MethodBuilder cb = mw.GetDefineMethodHelper().DefineConstructor(wrapper, typeBuilder, GetMethodAccess(mw) | MethodAttributes.HideBySig);
cb.SetImplementationFlags(MethodImplAttributes.NoInlining);
return cb;
}
private MethodBase GenerateMethod(int index, ClassFile.Method m, ref bool setModifiers)
private MethodBuilder GenerateMethod(int index, ClassFile.Method m, ref bool setModifiers)
{
MethodAttributes attribs = MethodAttributes.HideBySig;
if (m.IsNative)
@ -3546,7 +3522,7 @@ namespace IKVM.Internal
private List<TypeBuilder> nestedTypeBuilders;
private MethodInfo callerIDMethod;
private List<Item> items;
private Dictionary<FieldWrapper, ConstructorBuilder> arfuMap;
private Dictionary<FieldWrapper, MethodBuilder> arfuMap;
private struct Item
{
@ -3897,7 +3873,7 @@ namespace IKVM.Internal
mbld.SetImplementationFlags(mbld.GetMethodImplementationFlags() | MethodImplAttributes.NoInlining);
}
#if STATIC_COMPILER
ilGenerator.EmitLineNumberTable(methods[i].GetMethod());
ilGenerator.EmitLineNumberTable((MethodBuilder)methods[i].GetMethod());
#else // STATIC_COMPILER
byte[] linenumbers = ilGenerator.GetLineNumberTable();
if (linenumbers != null)
@ -3957,8 +3933,7 @@ namespace IKVM.Internal
// - we don't want the synthesized constructor to show up in Java
if (!hasConstructor)
{
ConstructorBuilder cb = typeBuilder.DefineConstructor(MethodAttributes.PrivateScope, CallingConventions.Standard, Type.EmptyTypes);
CodeEmitter ilgen = CodeEmitter.Create(cb);
CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineConstructor(typeBuilder, MethodAttributes.PrivateScope, Type.EmptyTypes));
ilgen.Emit(OpCodes.Ldnull);
ilgen.Emit(OpCodes.Throw);
ilgen.DoEmit();
@ -4026,7 +4001,7 @@ namespace IKVM.Internal
FieldBuilder fb = tbFields.DefineField(f.Name, ToPublicSignatureType(fields[i].FieldTypeWrapper), attribs);
if (ilgenClinit == null)
{
ilgenClinit = CodeEmitter.Create(tbFields.DefineTypeInitializer());
ilgenClinit = CodeEmitter.Create(ReflectUtil.DefineTypeInitializer(tbFields));
}
wrapper.GetFieldWrapper(f.Name, f.Signature).EmitGet(ilgenClinit);
ilgenClinit.Emit(OpCodes.Stsfld, fb);
@ -4052,7 +4027,7 @@ namespace IKVM.Internal
for (int i = 0; i < classFile.Methods.Length; i++)
{
ClassFile.Method m = classFile.Methods[i];
MethodBase mb = methods[i].GetMethod();
MethodBuilder mb = (MethodBuilder)methods[i].GetMethod();
if (mb == null)
{
continue;
@ -4088,7 +4063,6 @@ namespace IKVM.Internal
}
wrapper.AddXmlMapParameterAttributes(mb, classFile.Name, m.Name, m.Signature, ref parameterBuilders);
#endif
ConstructorBuilder cb = mb as ConstructorBuilder;
MethodBuilder mBuilder = mb as MethodBuilder;
if (m.Annotations != null)
{
@ -4097,10 +4071,6 @@ namespace IKVM.Internal
Annotation annotation = Annotation.Load(wrapper.GetClassLoader(), def);
if (annotation != null)
{
if (cb != null)
{
annotation.Apply(wrapper.GetClassLoader(), cb, def);
}
if (mBuilder != null)
{
annotation.Apply(wrapper.GetClassLoader(), mBuilder, def);
@ -5246,7 +5216,7 @@ namespace IKVM.Internal
Compiler.Compile(context, wrapper, methods[methodIndex], classFile, m, ilGenerator, ref nonLeaf, invokespecialstubcache);
ilGenerator.DoEmit();
#if STATIC_COMPILER
ilGenerator.EmitLineNumberTable(methods[methodIndex].GetMethod());
ilGenerator.EmitLineNumberTable((MethodBuilder)methods[methodIndex].GetMethod());
#else // STATIC_COMPILER
byte[] linenumbers = ilGenerator.GetLineNumberTable();
if (linenumbers != null)
@ -5303,7 +5273,7 @@ namespace IKVM.Internal
{
TypeWrapper tw = CoreClasses.ikvm.@internal.CallerID.Wrapper;
TypeBuilder typeCallerID = typeBuilder.DefineNestedType("__<CallerID>", TypeAttributes.Sealed | TypeAttributes.NestedPrivate, tw.TypeAsBaseType);
ConstructorBuilder cb = typeCallerID.DefineConstructor(MethodAttributes.Assembly, CallingConventions.Standard, null);
MethodBuilder cb = ReflectUtil.DefineConstructor(typeCallerID, MethodAttributes.Assembly, null);
CodeEmitter ctorIlgen = CodeEmitter.Create(cb);
ctorIlgen.Emit(OpCodes.Ldarg_0);
MethodWrapper mw = tw.GetMethodWrapper("<init>", "()V", false);
@ -5372,7 +5342,7 @@ namespace IKVM.Internal
}
}
internal ConstructorBuilder DefineThreadLocalType()
internal MethodBuilder DefineThreadLocalType()
{
TypeWrapper threadLocal = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.IntrinsicThreadLocal");
int id = nestedTypeBuilders == null ? 0 : nestedTypeBuilders.Count;
@ -5388,7 +5358,7 @@ namespace IKVM.Internal
ilgen.Emit(OpCodes.Ldarg_1);
ilgen.Emit(OpCodes.Stsfld, fb);
ilgen.Emit(OpCodes.Ret);
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Assembly, CallingConventions.Standard, Type.EmptyTypes);
MethodBuilder cb = ReflectUtil.DefineConstructor(tb, MethodAttributes.Assembly, Type.EmptyTypes);
CodeEmitter ctorilgen = CodeEmitter.Create(cb);
ctorilgen.Emit(OpCodes.Ldarg_0);
MethodWrapper basector = threadLocal.GetMethodWrapper("<init>", "()V", false);
@ -5400,19 +5370,19 @@ namespace IKVM.Internal
return cb;
}
internal ConstructorBuilder GetAtomicReferenceFieldUpdater(FieldWrapper field)
internal MethodBuilder GetAtomicReferenceFieldUpdater(FieldWrapper field)
{
if (arfuMap == null)
{
arfuMap = new Dictionary<FieldWrapper, ConstructorBuilder>();
arfuMap = new Dictionary<FieldWrapper, MethodBuilder>();
}
ConstructorBuilder cb;
MethodBuilder cb;
if (!arfuMap.TryGetValue(field, out cb))
{
TypeWrapper arfuTypeWrapper = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.IntrinsicAtomicReferenceFieldUpdater");
TypeBuilder tb = typeBuilder.DefineNestedType("__<ARFU>_" + arfuMap.Count, TypeAttributes.NestedPrivate | TypeAttributes.Sealed, arfuTypeWrapper.TypeAsBaseType);
AtomicReferenceFieldUpdaterEmitter.EmitImpl(tb, field.GetField());
cb = tb.DefineConstructor(MethodAttributes.Assembly, CallingConventions.Standard, Type.EmptyTypes);
cb = ReflectUtil.DefineConstructor(tb, MethodAttributes.Assembly, Type.EmptyTypes);
arfuMap.Add(field, cb);
CodeEmitter ctorilgen = CodeEmitter.Create(cb);
ctorilgen.Emit(OpCodes.Ldarg_0);
@ -5643,7 +5613,7 @@ namespace IKVM.Internal
}
}
protected static ParameterBuilder[] GetParameterBuilders(MethodBase mb, int parameterCount, string[] parameterNames)
protected static ParameterBuilder[] GetParameterBuilders(MethodBuilder mb, int parameterCount, string[] parameterNames)
{
ParameterBuilder[] parameterBuilders = new ParameterBuilder[parameterCount];
Dictionary<string, int> clashes = null;
@ -5668,15 +5638,7 @@ namespace IKVM.Internal
name += clash;
}
}
MethodBuilder mBuilder = mb as MethodBuilder;
if (mBuilder != null)
{
parameterBuilders[i] = mBuilder.DefineParameter(i + 1, ParameterAttributes.None, name);
}
else
{
parameterBuilders[i] = ((ConstructorBuilder)mb).DefineParameter(i + 1, ParameterAttributes.None, name);
}
parameterBuilders[i] = mb.DefineParameter(i + 1, ParameterAttributes.None, name);
}
return parameterBuilders;
}
@ -5955,7 +5917,7 @@ namespace IKVM.Internal
}
#endif // STATIC_COMPILER
internal override ConstructorInfo GetSerializationConstructor()
internal override MethodBase GetSerializationConstructor()
{
return automagicSerializationCtor;
}

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

@ -913,10 +913,6 @@ namespace IKVM.Internal
{
method = method.Module.ResolveMethod(((MethodBuilder)method).GetToken().Token);
}
if(method is ConstructorBuilder)
{
method = method.Module.ResolveMethod(((ConstructorBuilder)method).GetToken().Token);
}
}
[HideFromJava]

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

@ -80,8 +80,7 @@ namespace IKVM.Internal
GenericTypeParameterBuilder typeParam = tb.DefineGenericParameters("T")[0];
Type classType = CoreClasses.java.lang.Class.Wrapper.TypeAsSignatureType;
classLiteralField = tb.DefineField("Value", classType, FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.InitOnly);
ConstructorBuilder cctor = tb.DefineTypeInitializer();
CodeEmitter ilgen = CodeEmitter.Create(cctor);
CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineTypeInitializer(tb));
ilgen.Emit(OpCodes.Ldtoken, typeParam);
ilgen.Emit(OpCodes.Call, Types.Type.GetMethod("GetTypeFromHandle", new Type[] { Types.RuntimeTypeHandle }));
MethodWrapper mw = CoreClasses.java.lang.Class.Wrapper.GetMethodWrapper("<init>", "(Lcli.System.Type;)V", false);

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

@ -78,9 +78,9 @@ namespace IKVM.Internal
return true;
}
internal static ConstructorInfo AddAutomagicSerialization(DynamicTypeWrapper wrapper, TypeBuilder typeBuilder)
internal static MethodBuilder AddAutomagicSerialization(DynamicTypeWrapper wrapper, TypeBuilder typeBuilder)
{
ConstructorInfo serializationCtor = null;
MethodBuilder serializationCtor = null;
if ((wrapper.Modifiers & IKVM.Attributes.Modifiers.Enum) != 0)
{
MarkSerializable(typeBuilder);
@ -107,7 +107,7 @@ namespace IKVM.Internal
}
else if (wrapper.BaseTypeWrapper.IsSubTypeOf(serializable))
{
ConstructorInfo baseCtor = wrapper.GetBaseSerializationConstructor();
MethodBase baseCtor = wrapper.GetBaseSerializationConstructor();
if (baseCtor != null && (baseCtor.IsFamily || baseCtor.IsFamilyOrAssembly))
{
MarkSerializable(typeBuilder);
@ -135,7 +135,7 @@ namespace IKVM.Internal
return serializationCtor;
}
internal static ConstructorInfo AddAutomagicSerializationToWorkaroundBaseClass(TypeBuilder typeBuilderWorkaroundBaseClass, ConstructorInfo baseCtor)
internal static MethodBuilder AddAutomagicSerializationToWorkaroundBaseClass(TypeBuilder typeBuilderWorkaroundBaseClass, MethodBase baseCtor)
{
if (typeBuilderWorkaroundBaseClass.BaseType.IsSerializable)
{
@ -173,9 +173,9 @@ namespace IKVM.Internal
ilgen.DoEmit();
}
private static ConstructorInfo AddConstructor(TypeBuilder tb, MethodWrapper defaultConstructor, ConstructorInfo serializationConstructor, bool callReadObject)
private static MethodBuilder AddConstructor(TypeBuilder tb, MethodWrapper defaultConstructor, MethodBase serializationConstructor, bool callReadObject)
{
ConstructorBuilder ctor = tb.DefineConstructor(MethodAttributes.Family, CallingConventions.Standard, new Type[] { JVM.Import(typeof(SerializationInfo)), JVM.Import(typeof(StreamingContext)) });
MethodBuilder ctor = ReflectUtil.DefineConstructor(tb, MethodAttributes.Family, new Type[] { JVM.Import(typeof(SerializationInfo)), JVM.Import(typeof(StreamingContext)) });
AttributeHelper.HideFromJava(ctor);
ctor.AddDeclarativeSecurity(SecurityAction.Demand, psetSerializationFormatter);
CodeEmitter ilgen = CodeEmitter.Create(ctor);

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

@ -358,31 +358,18 @@ namespace IKVM.Internal
mb.SetCustomAttribute(GetEditorBrowsableNever());
}
internal static void SetEditorBrowsableNever(ConstructorBuilder cb)
{
cb.SetCustomAttribute(GetEditorBrowsableNever());
}
internal static void SetEditorBrowsableNever(PropertyBuilder pb)
{
pb.SetCustomAttribute(GetEditorBrowsableNever());
}
internal static void SetDeprecatedAttribute(MethodBase mb)
internal static void SetDeprecatedAttribute(MethodBuilder mb)
{
if(deprecatedAttribute == null)
{
deprecatedAttribute = new CustomAttributeBuilder(JVM.Import(typeof(ObsoleteAttribute)).GetConstructor(Type.EmptyTypes), new object[0]);
}
MethodBuilder method = mb as MethodBuilder;
if(method != null)
{
method.SetCustomAttribute(deprecatedAttribute);
}
else
{
((ConstructorBuilder)mb).SetCustomAttribute(deprecatedAttribute);
}
mb.SetCustomAttribute(deprecatedAttribute);
}
internal static void SetDeprecatedAttribute(TypeBuilder tb)
@ -412,7 +399,7 @@ namespace IKVM.Internal
pb.SetCustomAttribute(deprecatedAttribute);
}
internal static void SetThrowsAttribute(MethodBase mb, string[] exceptions)
internal static void SetThrowsAttribute(MethodBuilder mb, string[] exceptions)
{
if(exceptions != null && exceptions.Length != 0)
{
@ -420,16 +407,7 @@ namespace IKVM.Internal
{
throwsAttribute = typeofThrowsAttribute.GetConstructor(new Type[] { JVM.Import(typeof(string[])) });
}
if(mb is MethodBuilder)
{
MethodBuilder method = (MethodBuilder)mb;
method.SetCustomAttribute(new CustomAttributeBuilder(throwsAttribute, new object[] { exceptions }));
}
else
{
ConstructorBuilder constructor = (ConstructorBuilder)mb;
constructor.SetCustomAttribute(new CustomAttributeBuilder(throwsAttribute, new object[] { exceptions }));
}
mb.SetCustomAttribute(new CustomAttributeBuilder(throwsAttribute, new object[] { exceptions }));
}
}
@ -499,15 +477,6 @@ namespace IKVM.Internal
typeBuilder.SetCustomAttribute(hideFromJavaAttribute);
}
internal static void HideFromJava(ConstructorBuilder cb)
{
if(hideFromJavaAttribute == null)
{
hideFromJavaAttribute = new CustomAttributeBuilder(typeofHideFromJavaAttribute.GetConstructor(Type.EmptyTypes), new object[0]);
}
cb.SetCustomAttribute(hideFromJavaAttribute);
}
internal static void HideFromJava(MethodBuilder mb)
{
if(hideFromJavaAttribute == null)
@ -736,20 +705,6 @@ namespace IKVM.Internal
mb.SetCustomAttribute(customAttributeBuilder);
}
internal static void SetModifiers(ConstructorBuilder cb, Modifiers modifiers, bool isInternal)
{
CustomAttributeBuilder customAttributeBuilder;
if (isInternal)
{
customAttributeBuilder = new CustomAttributeBuilder(typeofModifiersAttribute.GetConstructor(new Type[] { typeofModifiers, Types.Boolean }), new object[] { modifiers, isInternal });
}
else
{
customAttributeBuilder = new CustomAttributeBuilder(typeofModifiersAttribute.GetConstructor(new Type[] { typeofModifiers }), new object[] { modifiers });
}
cb.SetCustomAttribute(customAttributeBuilder);
}
internal static void SetModifiers(FieldBuilder fb, Modifiers modifiers, bool isInternal)
{
CustomAttributeBuilder customAttributeBuilder;
@ -835,7 +790,7 @@ namespace IKVM.Internal
moduleBuilder.SetCustomAttribute(new CustomAttributeBuilder(sourceFileAttribute, new object[] { filename }));
}
internal static void SetLineNumberTable(MethodBase mb, IKVM.Attributes.LineNumberTableAttribute.LineNumberWriter writer)
internal static void SetLineNumberTable(MethodBuilder mb, IKVM.Attributes.LineNumberTableAttribute.LineNumberWriter writer)
{
object arg;
ConstructorInfo con;
@ -857,14 +812,7 @@ namespace IKVM.Internal
con = lineNumberTableAttribute1;
arg = writer.ToArray();
}
if(mb is ConstructorBuilder)
{
((ConstructorBuilder)mb).SetCustomAttribute(new CustomAttributeBuilder(con, new object[] { arg }));
}
else
{
((MethodBuilder)mb).SetCustomAttribute(new CustomAttributeBuilder(con, new object[] { arg }));
}
mb.SetCustomAttribute(new CustomAttributeBuilder(con, new object[] { arg }));
}
internal static void SetEnclosingMethodAttribute(TypeBuilder tb, string className, string methodName, string methodSig)
@ -894,20 +842,13 @@ namespace IKVM.Internal
fb.SetCustomAttribute(new CustomAttributeBuilder(signatureAttribute, new object[] { signature }));
}
internal static void SetSignatureAttribute(MethodBase mb, string signature)
internal static void SetSignatureAttribute(MethodBuilder mb, string signature)
{
if(signatureAttribute == null)
{
signatureAttribute = typeofSignatureAttribute.GetConstructor(new Type[] { Types.String });
}
if(mb is ConstructorBuilder)
{
((ConstructorBuilder)mb).SetCustomAttribute(new CustomAttributeBuilder(signatureAttribute, new object[] { signature }));
}
else
{
((MethodBuilder)mb).SetCustomAttribute(new CustomAttributeBuilder(signatureAttribute, new object[] { signature }));
}
mb.SetCustomAttribute(new CustomAttributeBuilder(signatureAttribute, new object[] { signature }));
}
internal static void SetParamArrayAttribute(ParameterBuilder pb)
@ -1702,7 +1643,6 @@ namespace IKVM.Internal
internal abstract void Apply(ClassLoaderWrapper loader, TypeBuilder tb, object annotation);
internal abstract void Apply(ClassLoaderWrapper loader, MethodBuilder mb, object annotation);
internal abstract void Apply(ClassLoaderWrapper loader, ConstructorBuilder cb, object annotation);
internal abstract void Apply(ClassLoaderWrapper loader, FieldBuilder fb, object annotation);
internal abstract void Apply(ClassLoaderWrapper loader, ParameterBuilder pb, object annotation);
internal abstract void Apply(ClassLoaderWrapper loader, AssemblyBuilder ab, object annotation);
@ -3175,14 +3115,14 @@ namespace IKVM.Internal
#if !STUB_GENERATOR
// return the constructor used for automagic .NET serialization
internal virtual ConstructorInfo GetSerializationConstructor()
internal virtual MethodBase GetSerializationConstructor()
{
Debug.Assert(!(this is DynamicTypeWrapper));
return this.TypeAsBaseType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] {
JVM.Import(typeof(System.Runtime.Serialization.SerializationInfo)), JVM.Import(typeof(System.Runtime.Serialization.StreamingContext)) }, null);
}
internal virtual ConstructorInfo GetBaseSerializationConstructor()
internal virtual MethodBase GetBaseSerializationConstructor()
{
return BaseTypeWrapper.GetSerializationConstructor();
}
@ -4674,12 +4614,6 @@ namespace IKVM.Internal
tb.SetCustomAttribute(MakeCustomAttributeBuilder(annotation));
}
internal override void Apply(ClassLoaderWrapper loader, ConstructorBuilder cb, object annotation)
{
annotation = QualifyClassNames(loader, annotation);
cb.SetCustomAttribute(MakeCustomAttributeBuilder(annotation));
}
internal override void Apply(ClassLoaderWrapper loader, MethodBuilder mb, object annotation)
{
annotation = QualifyClassNames(loader, annotation);

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

@ -3034,8 +3034,7 @@ sealed class Compiler
}
TypeBuilder tb = compiler.context.DefineIndyCallSiteType();
FieldBuilder fb = tb.DefineField("value", typeofIndyCallSite, FieldAttributes.Static | FieldAttributes.Assembly);
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes);
CodeEmitter ilgen = CodeEmitter.Create(cb);
CodeEmitter ilgen = CodeEmitter.Create(ReflectUtil.DefineTypeInitializer(tb));
ilgen.Emit(OpCodes.Ldnull);
ilgen.Emit(OpCodes.Ldftn, CreateBootstrapStub(compiler, cpi, delegateType, tb, fb, methodGetTarget));
ilgen.Emit(OpCodes.Newobj, MethodHandleUtil.GetDelegateConstructor(delegateType));
@ -3274,8 +3273,7 @@ sealed class Compiler
{
TypeBuilder tb = compiler.context.DefineMethodHandleConstantType(index);
FieldBuilder field = tb.DefineField("value", CoreClasses.java.lang.invoke.MethodHandle.Wrapper.TypeAsSignatureType, FieldAttributes.Assembly | FieldAttributes.Static | FieldAttributes.InitOnly);
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes);
ILGenerator ilgen = cb.GetILGenerator();
ILGenerator ilgen = ReflectUtil.DefineTypeInitializer(tb).GetILGenerator();
ClassFile.ConstantPoolItemMethodHandle mh = compiler.classFile.GetConstantPoolConstantMethodHandle(index);
Type delegateType;
switch (mh.Kind)