* function has different argument type.
*/
public static Type mapReturnType(Type functionType, Type arrayTokenType)
throws IllegalActionException {
if (functionType instanceof FunctionType) {
FunctionType castFunctionType = (FunctionType) functionType;
if (castFunctionType.getArgCount() == 1) {
Type argType = castFunctionType.getArgType(0);
int comparison = TypeLattice.compare(
((ArrayType) arrayTokenType).getElementType(), argType);
if ((comparison != CPO.LOWER) && (comparison != CPO.SAME)) {
throw new IllegalActionException(
"map(): specified array token is not compatible "
+ "with function argument type.");
}
} else if (castFunctionType.getArgCount() > 1) {
Type firstArgType = castFunctionType.getArgType(0);
boolean flag = true;
for (int i = 1; i < castFunctionType.getArgCount(); i++) {
Type argType = castFunctionType.getArgType(i);
if (argType != firstArgType) {
i = castFunctionType.getArgCount();
flag = false;
throw new IllegalActionException("map() can only work "
+ "for functions whose arguments are all of "
+ "the same type.");
}
}
if (flag) {
Type argType = castFunctionType.getArgType(0);
Type elementType = ((ArrayType) arrayTokenType)
.getElementType();
if (!(elementType instanceof ArrayType)) {
throw new IllegalActionException(
"map(): specified array token is not "
+ "compatible with function arity.");
} else {
int comparison = TypeLattice.compare(
((ArrayType) elementType).getElementType(),
argType);
if ((comparison != CPO.LOWER)
&& (comparison != CPO.SAME)) {
throw new IllegalActionException(
"map(): specified array token is not "
+ "compatible with function "
+ "argument type.");
}
}
}
}
Type resultType = castFunctionType.getReturnType();
return new ArrayType(resultType);
} else {
return BaseType.UNKNOWN;
}
}