use of org.robovm.compiler.MarshalerLookup.MarshalSite in project robovm by robovm.
the class BroMethodCompiler method getParameterType.
private Type getParameterType(String anno, SootMethod method, int i) {
soot.Type sootType = method.getParameterType(i);
if (hasPointerAnnotation(method, i)) {
if (!sootType.equals(LongType.v())) {
throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be of type long when annotated with @Pointer.");
}
return I8_PTR;
}
if (hasMachineSizedFloatAnnotation(method, i)) {
if (!sootType.equals(DoubleType.v()) && !sootType.equals(FloatType.v())) {
throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be of type float or double when annotated with @MachineSizedFloat.");
}
return config.getArch().is32Bit() ? FLOAT : DOUBLE;
}
if (hasMachineSizedSIntAnnotation(method, i) || hasMachineSizedUIntAnnotation(method, i)) {
if (!sootType.equals(LongType.v())) {
throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be of type long when annotated with " + "@MachineSizedSInt or @MachineSizedUInt");
}
return config.getArch().is32Bit() ? I32 : I64;
}
if (hasStructRetAnnotation(method, i)) {
if (i > 0) {
throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " cannot be annotated with @StructRet. Only the first" + " parameter may have this annotation.");
}
if (!isStruct(sootType)) {
throw new IllegalArgumentException("Parameter " + (i + 1) + " of " + anno + " annotated method " + method + " must be a sub class of Struct when annotated with @StructRet.");
}
// @StructRet implies pass by reference
return new PointerType(getStructType(sootType));
}
if (isStruct(sootType)) {
StructureType structType = getStructType(sootType);
if (hasByValAnnotation(method, i)) {
return getStructType(sootType);
}
return new PointerType(structType);
} else if (isNativeObject(sootType)) {
// NativeObjects are always passed by reference.
return I8_PTR;
} else if (sootType instanceof PrimType) {
return getType(sootType);
}
MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(new MarshalSite(method, i));
if (marshalerMethod instanceof ValueMarshalerMethod) {
return ((ValueMarshalerMethod) marshalerMethod).getNativeType(config.getArch());
} else {
return I8_PTR;
}
}
use of org.robovm.compiler.MarshalerLookup.MarshalSite in project robovm by robovm.
the class BroMethodCompiler method storeValueForSetter.
protected void storeValueForSetter(SootMethod method, Function function, Type memberType, Value memberPtr, Value env, Value value, long flags) {
soot.Type type = method.getParameterType(0);
if (needsMarshaler(type)) {
MarshalerMethod marshalerMethod = config.getMarshalerLookup().findMarshalerMethod(new MarshalSite(method, 0));
if (memberType instanceof PrimitiveType) {
value = marshalValueObjectToNative(function, marshalerMethod, memberType, env, value, flags);
} else {
if (memberType instanceof StructureType || memberType instanceof ArrayType) {
// The parameter must not be null. We assume that Structs
// never have a NULL handle so we just check that the Java
// Object isn't null.
call(function, CHECK_NULL, env, value);
}
if (memberType instanceof ArrayType) {
// Array
marshalArrayToNative(function, marshalerMethod, env, value, memberPtr, flags, getArrayDimensions(method, 0));
value = null;
} else {
value = marshalObjectToNative(function, marshalerMethod, null, memberType, env, value, flags);
}
}
} else {
value = marshalPrimitiveToNative(function, method, 0, value);
}
if (value != null) {
function.add(new Store(value, memberPtr));
}
}
Aggregations