Search in sources :

Example 6 with TypeUse

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

Example 7 with TypeUse

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

the class AbsASTBuilderUtil method generateImportAST.

public static final Set<Import> generateImportAST(TypeUse t) {
    Set<Import> imports = new HashSet<>();
    imports.add(generateImportAST(t.getName(), t.getModuleDecl().getName()));
    if (t instanceof ParametricDataTypeUse) {
        for (TypeUse st : ((ParametricDataTypeUse) t).getParams()) {
            imports.addAll(generateImportAST(st));
        }
    }
    return imports;
}
Also used : DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) Import(org.abs_models.frontend.ast.Import) FromImport(org.abs_models.frontend.ast.FromImport) HashSet(java.util.HashSet) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse)

Aggregations

DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)7 ParametricDataTypeUse (org.abs_models.frontend.ast.ParametricDataTypeUse)7 TypeUse (org.abs_models.frontend.ast.TypeUse)7 InterfaceTypeUse (org.abs_models.frontend.ast.InterfaceTypeUse)4 HashSet (java.util.HashSet)3 Block (org.abs_models.frontend.ast.Block)3 VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)3 ABSTest (org.abs_models.ABSTest)2 FrontendTest (org.abs_models.frontend.FrontendTest)2 InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)2 MainBlock (org.abs_models.frontend.ast.MainBlock)2 MethodSig (org.abs_models.frontend.ast.MethodSig)2 Model (org.abs_models.frontend.ast.Model)2 VarUse (org.abs_models.frontend.ast.VarUse)2 Test (org.junit.Test)2 ClassDecl (org.abs_models.frontend.ast.ClassDecl)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 FromImport (org.abs_models.frontend.ast.FromImport)1 Import (org.abs_models.frontend.ast.Import)1 SyncCall (org.abs_models.frontend.ast.SyncCall)1