Search in sources :

Example 1 with ThisExp

use of org.abs_models.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 = AnnotationHelper.getAnnotationValueFromSimpleName(annotations, "Deadline");
    if (rtAttr == null)
        stream.print("new ABS.StdLib.Duration_InfDuration()");
    else
        rtAttr.generateJava(stream);
    stream.println(",");
    rtAttr = AnnotationHelper.getAnnotationValueFromSimpleName(annotations, "Cost");
    if (rtAttr == null)
        stream.print("new ABS.StdLib.Duration_InfDuration()");
    else
        rtAttr.generateJava(stream);
    stream.println(",");
    rtAttr = AnnotationHelper.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 : Type(org.abs_models.frontend.typechecker.Type) ABSBool(org.abs_models.backend.java.lib.types.ABSBool) PureExp(org.abs_models.frontend.ast.PureExp) ThisExp(org.abs_models.frontend.ast.ThisExp)

Aggregations

ABSBool (org.abs_models.backend.java.lib.types.ABSBool)1 PureExp (org.abs_models.frontend.ast.PureExp)1 ThisExp (org.abs_models.frontend.ast.ThisExp)1 Type (org.abs_models.frontend.typechecker.Type)1