Search in sources :

Example 1 with Parameter

use of es.bsc.compss.types.annotations.Parameter in project compss by bsc-wdc.

the class ITAppEditor method processParameters.

/**
 * Process the parameters, the target object and the return value of a given method
 *
 * @param declaredMethod
 * @param paramAnnot
 * @param paramTypes
 * @param isVoid
 * @param isStatic
 * @param isMethod
 * @param numParams
 * @param retType
 * @return
 */
private CallInformation processParameters(Method declaredMethod, Annotation[][] paramAnnot, Class<?>[] paramTypes, boolean isVoid, boolean isStatic, boolean isMethod, int numParams, Class<?> retType) throws CannotCompileException {
    StringBuilder toAppend = new StringBuilder("");
    StringBuilder toPrepend = new StringBuilder("");
    toAppend.append(",new Object[]{");
    // Add the actual parameters of the method
    for (int i = 0; i < paramAnnot.length; i++) {
        Class<?> formalType = paramTypes[i];
        Parameter par = ((Parameter) paramAnnot[i][0]);
        /*
             * Append the value of the current parameter according to the type. Basic types must be wrapped by an object
             * first
             */
        ParameterInformation infoParam = processParameterValue(i, par, formalType);
        toAppend.append(infoParam.getToAppend());
        toPrepend.insert(0, infoParam.getToPrepend());
        toAppend.append(infoParam.getType()).append(",");
        toAppend.append(infoParam.getDirection()).append(",");
        toAppend.append(infoParam.getStream()).append(",");
        toAppend.append(infoParam.getPrefix());
        if (i < paramAnnot.length - 1) {
            toAppend.append(",");
        }
    }
    // Add the target object of the call as an IN/INOUT parameter, for class methods
    String targetObject = processTargetObject(declaredMethod, isStatic, numParams, isVoid, isMethod);
    toAppend.append(targetObject);
    // Add the return value as an OUT parameter, if any
    ReturnInformation returnInfo = processReturnParameter(isVoid, numParams, retType);
    toAppend.append(returnInfo.getToAppend());
    toPrepend.insert(0, returnInfo.getToPrepend());
    toAppend.append("});");
    toAppend.append(returnInfo.getAfterExecution());
    CallInformation callInformation = new CallInformation(toAppend.toString(), toPrepend.toString());
    return callInformation;
}
Also used : Parameter(es.bsc.compss.types.annotations.Parameter)

Example 2 with Parameter

use of es.bsc.compss.types.annotations.Parameter in project compss by bsc-wdc.

the class ITFParser method constructSignatureAndCheckParameters.

/**
 * Constructs the signature of method @m and leaves the result in calleeMethodSignature. It also returns if the
 * method has stream parameters or not
 *
 * @param m
 * @param hasNonNative
 * @param calleeMethodSignature
 * @return
 */
private static boolean[] constructSignatureAndCheckParameters(java.lang.reflect.Method m, boolean hasNonNative, StringBuilder calleeMethodSignature) {
    boolean hasStreams = false;
    boolean hasPrefixes = false;
    String methodName = m.getName();
    boolean hasSTDIN = false;
    boolean hasSTDOUT = false;
    boolean hasSTDERR = false;
    int numPars = m.getParameterAnnotations().length;
    if (numPars > 0) {
        for (int i = 0; i < numPars; i++) {
            Parameter par = (Parameter) m.getParameterAnnotations()[i][0];
            Class<?> parType = m.getParameterTypes()[i];
            Type annotType = par.type();
            String type = inferType(parType, annotType);
            // Add to callee
            if (i >= 1) {
                calleeMethodSignature.append(",");
            }
            calleeMethodSignature.append(type);
            // Check parameter stream annotation
            switch(par.stream()) {
                case STDIN:
                    if (hasSTDIN) {
                        ErrorManager.error("Method " + methodName + " has more than one parameter annotated has Stream.STDIN");
                    }
                    hasSTDIN = true;
                    break;
                case STDOUT:
                    if (hasSTDOUT) {
                        ErrorManager.error("Method " + methodName + " has more than one parameter annotated has Stream.STDOUT");
                    }
                    hasSTDOUT = true;
                    break;
                case STDERR:
                    if (hasSTDERR) {
                        ErrorManager.error("Method " + methodName + " has more than one parameter annotated has Stream.STDERR");
                    }
                    hasSTDERR = true;
                    break;
                case UNSPECIFIED:
                    break;
            }
            hasStreams = hasStreams || !par.stream().equals(Stream.UNSPECIFIED);
            hasPrefixes = hasPrefixes || !par.prefix().equals(Constants.PREFIX_EMTPY);
            // Check parameter annotation (warnings and errors)
            checkParameterAnnotation(m, par, i, hasNonNative);
        }
    }
    calleeMethodSignature.append(")");
    boolean[] hasAnnotation = { hasStreams, hasPrefixes };
    return hasAnnotation;
}
Also used : Type(es.bsc.compss.types.annotations.parameter.Type) Parameter(es.bsc.compss.types.annotations.Parameter)

Aggregations

Parameter (es.bsc.compss.types.annotations.Parameter)2 Type (es.bsc.compss.types.annotations.parameter.Type)1