Search in sources :

Example 1 with ThisExp

use of abs.frontend.ast.ThisExp in project abstools by abstools.

the class JavaGeneratorHelper method generateAsyncCall.

private static void generateAsyncCall(PrintStream stream, final String calleeString, final PureExp callee, final Type calleeType, final List<PureExp> args, final List<ParamDecl> params, final MethodSig sig, final List<Annotation> annotations) {
    final java.util.List<Type> paramTypes = sig.getTypes();
    stream.print(ABSRuntime.class.getName() + ".getCurrentRuntime().asyncCall(");
    String targetType = JavaBackend.getQualifiedString(calleeType);
    stream.println("new " + AbstractAsyncCallRT.class.getName() + "<" + targetType + ">(");
    stream.println("this,");
    if (callee instanceof ThisExp) {
        if (calleeString != null)
            stream.print(calleeString);
        else
            callee.generateJava(stream);
    } else {
        stream.print(ABSRuntime.class.getName() + ".checkForNull(");
        if (calleeString != null)
            stream.print(calleeString);
        else
            callee.generateJava(stream);
        stream.print(")");
    }
    stream.println(",");
    PureExp rtAttr;
    rtAttr = CompilerUtils.getAnnotationValueFromSimpleName(annotations, "Deadline");
    if (rtAttr == null)
        stream.print("new ABS.StdLib.Duration_InfDuration()");
    else
        rtAttr.generateJava(stream);
    stream.println(",");
    rtAttr = CompilerUtils.getAnnotationValueFromSimpleName(annotations, "Cost");
    if (rtAttr == null)
        stream.print("new ABS.StdLib.Duration_InfDuration()");
    else
        rtAttr.generateJava(stream);
    stream.println(",");
    rtAttr = CompilerUtils.getAnnotationValueFromSimpleName(annotations, "Critical");
    if (rtAttr == null)
        stream.print(ABSBool.class.getName() + ".FALSE");
    else
        rtAttr.generateJava(stream);
    stream.println(") {");
    int i = 0;
    for (Type t : paramTypes) {
        stream.println(JavaBackend.getQualifiedString(t) + " arg" + i + ";");
        i++;
    }
    generateTaskGetArgsMethod(stream, paramTypes.size());
    generateTaskInitMethod(stream, paramTypes);
    stream.println("public java.lang.String methodName() {");
    stream.println("return \"" + sig.getName() + "\";");
    stream.println("}");
    stream.println("public Object execute() {");
    stream.print("return target." + JavaBackend.getMethodName(sig.getName()) + "(");
    for (i = 0; i < paramTypes.size(); i++) {
        if (i > 0)
            stream.print(",");
        stream.println("arg" + i);
        if (paramTypes.get(i).isIntType())
            stream.print(".truncate()");
    }
    stream.println(");");
    stream.println("}");
    stream.print("}.init");
    if (args != null)
        JavaGeneratorHelper.generateArgs(stream, args, paramTypes);
    else
        JavaGeneratorHelper.generateParamArgs(stream, params);
    stream.println(")");
}
Also used : AbstractAsyncCallRT(abs.backend.java.lib.runtime.AbstractAsyncCallRT) Type(abs.frontend.typechecker.Type) ABSBool(abs.backend.java.lib.types.ABSBool) PureExp(abs.frontend.ast.PureExp) ThisExp(abs.frontend.ast.ThisExp)

Aggregations

AbstractAsyncCallRT (abs.backend.java.lib.runtime.AbstractAsyncCallRT)1 ABSBool (abs.backend.java.lib.types.ABSBool)1 PureExp (abs.frontend.ast.PureExp)1 ThisExp (abs.frontend.ast.ThisExp)1 Type (abs.frontend.typechecker.Type)1