Search in sources :

Example 16 with PureExp

use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.

the class MaudeCompilerHelper method emitParameterValueList.

public static void emitParameterValueList(PrintStream stream, List<PureExp> params, java.util.List<Type> paramTypes) {
    if (params.getNumChild() == 0) {
        stream.print("emp ");
    } else {
        boolean inlist = false;
        stream.print("(");
        for (int i = 0; i < params.getNumChild(); i++) {
            PureExp param = params.getChild(i);
            Type t = paramTypes.get(i);
            boolean needConversion = t.isIntType() && param.getType().isRatType();
            if (inlist)
                stream.print(":: ");
            else
                inlist = true;
            if (needConversion)
                stream.print("\"ABS.StdLib.truncate\"(");
            param.generateMaude(stream);
            if (needConversion)
                stream.print(")");
        }
        stream.print(") ");
    }
}
Also used : Type(org.abs_models.frontend.typechecker.Type) PureExp(org.abs_models.frontend.ast.PureExp)

Example 17 with PureExp

use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateAsyncTestCallAST.

private void generateAsyncTestCallAST(Block block, String objectRef, MethodSig method) {
    List<PureExp> args = new List<>();
    if (method.getNumParam() > 0) {
        args.add(new VarUse(dataValue));
    }
    block.addStmtNoTransform(getVAssign(fut, new AsyncCall(new VarUse(objectRef), method.getName(), args)));
    block.addStmtNoTransform(getVAssign(futs, getFnApp("Insert", new VarUse(fut), new VarUse(futs))));
}
Also used : List(org.abs_models.frontend.ast.List) PureExp(org.abs_models.frontend.ast.PureExp) AsyncCall(org.abs_models.frontend.ast.AsyncCall) VarUse(org.abs_models.frontend.ast.VarUse)

Example 18 with PureExp

use of org.abs_models.frontend.ast.PureExp 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)

Example 19 with PureExp

use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.

the class JavaGeneratorHelper method generateAsyncCall.

public static void generateAsyncCall(PrintStream stream, AsyncCall call) {
    final PureExp callee = call.getCallee();
    final List<PureExp> params = call.getParams();
    final MethodSig sig = call.getMethodSig();
    final List<Annotation> annotations = call.getAnnotations();
    generateAsyncCall(stream, null, callee, callee.getType(), params, null, sig, annotations);
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) PureExp(org.abs_models.frontend.ast.PureExp) Annotation(org.abs_models.frontend.ast.Annotation)

Example 20 with PureExp

use of org.abs_models.frontend.ast.PureExp in project abstools by abstools.

the class DeployInformationClass method addAnn.

public void addAnn(PureExp exp) {
    // A specification is a list (hence a FnApp with first argument being a list)
    DeployInformationClassSpecification info = new DeployInformationClassSpecification(_paramList, _paramType);
    PureExp list = ((FnApp) exp).getParam(0);
    while (((DataConstructorExp) list).hasParam() && (((DataConstructorExp) list).getParam(0) != null)) {
        // means we have a cons
        PureExp el = ((DataConstructorExp) list).getParam(0);
        list = ((DataConstructorExp) list).getParam(1);
        if (((DataConstructorExp) el).getDataConstructor().getName().equals("Cost")) {
            String name = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
            int cost = Integer.parseInt(((IntLiteral) ((DataConstructorExp) el).getParam(1)).getContent());
            info.addCost(name, cost);
            System.out.println("  Annotation is Cost(\"" + name + "\", " + cost + ")");
        } else if (((DataConstructorExp) el).getDataConstructor().getName().equals("MaxUse")) {
            int arity = Integer.parseInt(((IntLiteral) ((DataConstructorExp) el).getParam(0)).getContent());
            info.setProvide(arity);
            System.out.println("  Annotation is MaxUse(" + arity + ")");
        } else if (((DataConstructorExp) el).getDataConstructor().getName().equals("Name")) {
            String name = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
            info.addScenarioName(name);
            System.out.println("  Annotation is Name(" + name + ")");
        } else if (((DataConstructorExp) el).getDataConstructor().getName().equals("Param")) {
            String param = ((StringLiteral) ((DataConstructorExp) el).getParam(0)).getContent();
            String port = _paramType.get(param);
            PureExp spec = ((DataConstructorExp) el).getParam(1);
            if (((DataConstructorExp) spec).getDataConstructor().getName().equals("Req")) {
                System.out.print("Req");
                info.addRequirement(param);
                System.out.println("  Annotation is Req(\"" + param + "\")");
            } else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("List")) {
                int arity = Integer.parseInt(((IntLiteral) ((DataConstructorExp) spec).getParam(0)).getContent());
                info.addList(param, arity);
                System.out.println("  Annotation is List(\"" + port + "\", " + arity + ")");
            } else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("OptList")) {
                String value = ((StringLiteral) ((DataConstructorExp) spec).getParam(0)).getContent();
                info.addOptList(param, value);
                System.out.println("  Annotation is OptList(\"" + port + "\", " + value + ")");
            } else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("Default")) {
                System.out.print("Default");
                String value = ((StringLiteral) ((DataConstructorExp) spec).getParam(0)).getContent();
                if (port != null)
                    System.out.print("(\"" + port + "\", " + value + ")");
                info.addDefault(param, value);
                System.out.println("  Annotation is Default(\"" + port + "\", " + value + ")");
            } else if (((DataConstructorExp) spec).getDataConstructor().getName().equals("User")) {
                System.out.print("User");
                if (port != null)
                    System.out.print("(\"" + port + "\")");
                info.addUser(param, port);
                System.out.println("  Annotation is User(\"" + port + "\", " + param + ")");
            }
        }
    }
    _spec.add(info);
}
Also used : DataConstructorExp(org.abs_models.frontend.ast.DataConstructorExp) FnApp(org.abs_models.frontend.ast.FnApp) StringLiteral(org.abs_models.frontend.ast.StringLiteral) IntLiteral(org.abs_models.frontend.ast.IntLiteral) PureExp(org.abs_models.frontend.ast.PureExp)

Aggregations

PureExp (org.abs_models.frontend.ast.PureExp)22 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)8 FrontendTest (org.abs_models.frontend.FrontendTest)7 Model (org.abs_models.frontend.ast.Model)7 Test (org.junit.Test)7 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)5 FnApp (org.abs_models.frontend.ast.FnApp)5 IntLiteral (org.abs_models.frontend.ast.IntLiteral)5 Annotation (org.abs_models.frontend.ast.Annotation)4 Type (org.abs_models.frontend.typechecker.Type)3 ABSBool (org.abs_models.backend.java.lib.types.ABSBool)2 TypeError (org.abs_models.frontend.analyser.TypeError)2 FunctionDef (org.abs_models.frontend.ast.FunctionDef)2 List (org.abs_models.frontend.ast.List)2 MethodSig (org.abs_models.frontend.ast.MethodSig)2 TypedAnnotation (org.abs_models.frontend.ast.TypedAnnotation)2 VarUse (org.abs_models.frontend.ast.VarUse)2 AddExp (org.abs_models.frontend.ast.AddExp)1 AsyncCall (org.abs_models.frontend.ast.AsyncCall)1 ClassDecl (org.abs_models.frontend.ast.ClassDecl)1