Search in sources :

Example 1 with MainBlock

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

the class TimeoutThread method genCode.

/**
 * Generates Erlang code in target directory, adding a last statement that
 * prints the value of the `testresult' variable.
 *
 * @return a Module Name containing a Main Block
 * @throws InternalBackendException
 */
public String genCode(Model model, File targetDir, boolean appendResultprinter) throws IOException, InterruptedException, InternalBackendException {
    if (model.hasErrors()) {
        Assert.fail(model.getErrors().getFirstError().getHelpMessage());
    }
    if (model.hasTypeErrors()) {
        Assert.fail(model.getTypeErrors().getFirstError().getHelpMessage());
    }
    MainBlock mb = model.getMainBlock();
    if (mb != null && appendResultprinter) {
        // We search for this output in the `run' method below
        mb.addStmt(new ExpressionStmt(new List<>(), new FnApp("ABS.StdLib.println", new List<>(new AddAddExp(new StringLiteral("RES="), new FnApp("ABS.StdLib.toString", new List<>(new VarUse("testresult"))))))));
    }
    new ErlangBackend().compile(model, targetDir, // use the following argument for silent compiler:
    EnumSet.noneOf(ErlangBackend.CompileOptions.class));
    if (mb == null)
        return null;
    else
        return mb.getModuleDecl().getName();
}
Also used : AddAddExp(org.abs_models.frontend.ast.AddAddExp) FnApp(org.abs_models.frontend.ast.FnApp) StringLiteral(org.abs_models.frontend.ast.StringLiteral) ArrayList(java.util.ArrayList) List(org.abs_models.frontend.ast.List) LinkedList(java.util.LinkedList) MainBlock(org.abs_models.frontend.ast.MainBlock) VarUse(org.abs_models.frontend.ast.VarUse) ExpressionStmt(org.abs_models.frontend.ast.ExpressionStmt)

Example 2 with MainBlock

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

the class ASTBasedABSTestRunnerGenerator method generateMainBlockAST.

private MainBlock generateMainBlockAST(List<Import> list) {
    final MainBlock block = new MainBlock();
    DataConstructorExp empty = new DataConstructorExp("EmptySet", new List<>());
    VarDeclStmt futsStatement = getVarDecl(futs, getType("Set", getFutUnitType()), empty);
    block.addStmtNoTransform(futsStatement);
    VarDeclStmt futStatement = getVarDecl(fut, getFutUnitType(), null);
    block.addStmtNoTransform(futStatement);
    Set<TypeUse> use = new HashSet<>();
    for (InterfaceDecl key : tests.keySet()) {
        for (ClassDecl clazz : tests.get(key)) {
            use.addAll(generateTestClassImplAST(key, clazz, block));
        }
    }
    block.addStmtNoTransform(generateWaitSyncAST());
    return block;
}
Also used : DataConstructorExp(org.abs_models.frontend.ast.DataConstructorExp) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) ClassDecl(org.abs_models.frontend.ast.ClassDecl) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) MainBlock(org.abs_models.frontend.ast.MainBlock) HashSet(java.util.HashSet)

Example 3 with MainBlock

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

the class ASTBasedABSTestRunnerGenerator method generateTestClassImplAST.

private Set<TypeUse> generateTestClassImplAST(InterfaceDecl inf, ClassDecl clazz, MainBlock block) {
    Set<TypeUse> accesses = new HashSet<>();
    TypeUse dataType = generateDataPointsAST(inf, clazz, accesses, block);
    String namePrefix = clazz.getName();
    int instance = 0;
    for (MethodSig method : getTestMethods(inf)) {
        Block thisBlock = block;
        WhileStmt ws = null;
        if (method.getNumParam() > 0) {
            if (dataType == null) {
                throw new IllegalStateException("Test method requires arguments but test class defines no data point");
            }
            /*
                 * a while loop over all data points
                 */
            String dataPointSet = dataPointSetName(clazz);
            ws = new WhileStmt();
            ws.setCondition(getFnApp("hasNext", new VarUse(dataPointSet)));
            Block body = new Block();
            thisBlock = body;
            DataTypeUse u = getType("Pair", getType("Set", (TypeUse) dataType.copy()), (TypeUse) dataType.copy());
            thisBlock.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(dataPointSet))));
            thisBlock.addStmtNoTransform(getVarDecl(dataValue, (TypeUse) dataType.copy(), getFnApp("snd", new VarUse("nt"))));
            thisBlock.addStmtNoTransform(getVAssign(dataPointSet, getFnApp("fst", new VarUse("nt"))));
            ws.setBody(body);
        }
        /*
             * Add those methods that are not ignored
             */
        if (!isIgnored(clazz, method)) {
            String objectRef = uncap(namePrefix) + instance;
            thisBlock.addStmtNoTransform(newObj(inf, clazz, objectRef, false));
            generateAsyncTestCallAST(thisBlock, objectRef, method);
        }
        if (ws != null) {
            block.addStmtNoTransform(ws);
        }
        instance++;
    }
    return accesses;
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) WhileStmt(org.abs_models.frontend.ast.WhileStmt) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) Block(org.abs_models.frontend.ast.Block) MainBlock(org.abs_models.frontend.ast.MainBlock) VarUse(org.abs_models.frontend.ast.VarUse) HashSet(java.util.HashSet)

Aggregations

MainBlock (org.abs_models.frontend.ast.MainBlock)3 HashSet (java.util.HashSet)2 DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)2 ParametricDataTypeUse (org.abs_models.frontend.ast.ParametricDataTypeUse)2 TypeUse (org.abs_models.frontend.ast.TypeUse)2 VarUse (org.abs_models.frontend.ast.VarUse)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 AddAddExp (org.abs_models.frontend.ast.AddAddExp)1 Block (org.abs_models.frontend.ast.Block)1 ClassDecl (org.abs_models.frontend.ast.ClassDecl)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 ExpressionStmt (org.abs_models.frontend.ast.ExpressionStmt)1 FnApp (org.abs_models.frontend.ast.FnApp)1 InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)1 List (org.abs_models.frontend.ast.List)1 MethodSig (org.abs_models.frontend.ast.MethodSig)1 StringLiteral (org.abs_models.frontend.ast.StringLiteral)1 VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)1 WhileStmt (org.abs_models.frontend.ast.WhileStmt)1