private getComponentType ( ) : global::java.lang.Class | ||
return | global::java.lang.Class |
void emitNewArray(Name name) { Class rtype = name.function.methodType().returnType(); if (name.arguments.Length == 0) { // The array will be a constant. object emptyArray; try { emptyArray = name.function._resolvedHandle().invoke(); } catch (Exception ex) { throw new java.lang.InternalError(ex); } //assert(java.lang.reflect.Array.getLength(emptyArray) == 0); //assert(emptyArray.getClass() == rtype); // exact typing //mv.visitLdcInsn(constantPlaceholder(emptyArray)); EmitConstant(emptyArray); emitReferenceCast(rtype, emptyArray); return; } Class arrayElementType = rtype.getComponentType(); //assert(arrayElementType != null); emitIconstInsn(name.arguments.Length); OpCode xas = OpCodes.Stelem_Ref; if (!arrayElementType.isPrimitive()) { TypeWrapper tw = TypeWrapper.FromClass(arrayElementType); if (tw.IsUnloadable || tw.IsGhost || tw.IsGhostArray || tw.IsNonPrimitiveValueType) { throw new BailoutException(Bailout.UnsupportedArrayType, tw); } ilgen.Emit(OpCodes.Newarr, tw.TypeAsArrayType); } else { byte tc = arrayTypeCode(Wrapper.forPrimitiveType(arrayElementType)); xas = arrayInsnOpcode(tc); //mv.visitIntInsn(Opcodes.NEWARRAY, tc); ilgen.Emit(OpCodes.Newarr, TypeWrapper.FromClass(arrayElementType).TypeAsArrayType); } // store arguments for (int i = 0; i < name.arguments.Length; i++) { //mv.visitInsn(Opcodes.DUP); ilgen.Emit(OpCodes.Dup); emitIconstInsn(i); emitPushArgument(name, i); //mv.visitInsn(xas); ilgen.Emit(xas); } // the array is left on the stack assertStaticType(rtype, name); }
public static object invoke(MethodHandle mh, object[] args) { #if FIRST_PASS return(null); #else MethodType type = mh.type(); if (mh.isVarargsCollector()) { java.lang.Class varargType = type.parameterType(type.parameterCount() - 1); if (type.parameterCount() == args.Length) { if (!varargType.isInstance(args[args.Length - 1])) { Array arr = (Array)java.lang.reflect.Array.newInstance(varargType.getComponentType(), 1); arr.SetValue(args[args.Length - 1], 0); args[args.Length - 1] = arr; } } else if (type.parameterCount() - 1 > args.Length) { throw new WrongMethodTypeException(); } else { object[] newArgs = new object[type.parameterCount()]; Array.Copy(args, newArgs, newArgs.Length - 1); Array varargs = (Array)java.lang.reflect.Array.newInstance(varargType.getComponentType(), args.Length - (newArgs.Length - 1)); Array.Copy(args, newArgs.Length - 1, varargs, 0, varargs.Length); newArgs[newArgs.Length - 1] = varargs; args = newArgs; } } if (mh.type().parameterCount() != args.Length) { throw new WrongMethodTypeException(); } mh = mh.asSpreader(typeof(object[]), args.Length); return(IKVM.Runtime.ByteCodeHelper.GetDelegateForInvoke <IKVM.Runtime.MH <MethodHandle, object[], object> >(mh, ref cache)(mh, args)); #endif }
internal static GType RegisterClass(Class clazz, TypeRegistration registration) { if (knownClasses.ContainsKey(clazz)) { GType known = knownClasses[clazz]; if (registration != null) { known.Registration = registration; } return known; } var res = new GType(); if (clazz.isArray()) { res.ArrayElement = RegisterClass(clazz.getComponentType(), null); res.IsArray = true; string array = "[]"; Class comp = clazz.getComponentType(); while (comp.isArray()) { array += "[]"; comp = comp.getComponentType(); } res.LowerName = ((string) comp.getName()).ToLowerInvariant() + array; } else { res.LowerName = ((string) clazz.getName()).ToLowerInvariant(); } res.Attributes = 0; var classModifiers = (ModifierFlags) clazz.getModifiers(); if ((classModifiers & ModifierFlags.Abstract) != 0) { res.IsAbstract = true; res.Attributes |= TypeAttributes.Abstract; } if ((classModifiers & ModifierFlags.Final) != 0) { res.IsFinal = true; } if ((classModifiers & ModifierFlags.Public) != 0) { res.Attributes |= TypeAttributes.Public; } else if ((classModifiers & ModifierFlags.Private) != 0) { res.Attributes |= TypeAttributes.NotPublic; } //TODO internal ? if (knownNames.ContainsKey(res.LowerName)) { res = knownNames[res.LowerName]; } if (res.Registration == null && registration != null) { res.Registration = registration; } res.JVMType = clazz; res.JVMFullName = clazz.getName(); if (res.IsArray) { string array = "[]"; Class comp = clazz.getComponentType(); while (comp.isArray()) { array += "[]"; comp = comp.getComponentType(); } res.JVMFullName = comp.getName() + array; } else { res.JVMFullName = clazz.getName(); } res.IsJVMType = true; res.IsPrimitive = clazz.isPrimitive(); res.IsException = Throwable._class.isAssignableFrom(clazz); res.IsInterface = clazz.isInterface(); res.IsCLRProxy = clrProxyClass != null && clrProxyClass.isAssignableFrom(clazz); if (!res.IsCLRProxy) { res.IsJVMRealType = true; } Class superclass = clazz.getSuperclass(); var isBaseClassPublic = superclass == null || ((ModifierFlags)superclass.getModifiers() & ModifierFlags.Public) != 0; if (superclass != null && res.Base == null && clazz != Object._class && clazz != Throwable._class && res.JVMFullName != "system.Object" && res.JVMFullName != "system.Exception" && isBaseClassPublic) { res.Base = RegisterClass(superclass); } List<Class> interfaces = new List<Class>(clazz.getInterfaces()); if (!isBaseClassPublic) { interfaces.AddRange(superclass.getInterfaces()); res.Base = RegisterClass(superclass.getSuperclass()); } foreach (Class ifc in interfaces) { GType gifc = RegisterClass(ifc); if (!res.Interfaces.Contains(gifc)) { if (res.IsInterface && res.Base == null) { res.Base = gifc; } res.Interfaces.Add(gifc); res.AllInterfaces.Add(gifc); } } Register(res); return res; }
public virtual bool canAcceptArrayType(Class type) { return type.isArray() && this.canAcceptType(type.getComponentType()); }