Search in sources :

Example 11 with VarUse

use of org.abs_models.frontend.ast.VarUse 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 12 with VarUse

use of org.abs_models.frontend.ast.VarUse 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 13 with VarUse

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

the class JavaGeneratorHelper method isLocalVarUse.

/**
 * checks if astNode is a use of a local variable or parameter
 */
private static boolean isLocalVarUse(ASTNode<?> astNode) {
    if (astNode instanceof VarUse) {
        VarUse v = (VarUse) astNode;
        VarOrFieldDecl decl = v.getDecl();
        if (decl instanceof VarDecl || decl instanceof ParamDecl) {
            return !(decl.getParent() instanceof LetExp);
        }
    }
    return false;
}
Also used : TypedVarOrFieldDecl(org.abs_models.frontend.ast.TypedVarOrFieldDecl) VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) VarDecl(org.abs_models.frontend.ast.VarDecl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) LetExp(org.abs_models.frontend.ast.LetExp) VarUse(org.abs_models.frontend.ast.VarUse)

Example 14 with VarUse

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

the class JavaGeneratorHelper method replaceLocalVariables.

/**
 * replace all uses of local variables and parameters by a use of a newly introduced
 * temporary final local variable
 */
private static void replaceLocalVariables(ASTNode<?> astNode, PrintStream beforeAwaitStream) {
    if (isLocalVarUse(astNode)) {
        VarUse v = (VarUse) astNode;
        replaceVarUse(beforeAwaitStream, v, (TypedVarOrFieldDecl) v.getDecl());
    } else {
        // process children:
        for (int i = 0; i < astNode.getNumChild(); i++) {
            ASTNode<?> child = astNode.getChild(i);
            replaceLocalVariables(child, beforeAwaitStream);
        }
    }
}
Also used : VarUse(org.abs_models.frontend.ast.VarUse)

Example 15 with VarUse

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

the class VarResolutionTest method testNestedLetExp4.

@Test
public void testNestedLetExp4() {
    Model m = assertParse(" def Bool f(Bool b) = let (Bool x) = b in let (Bool x) = b in x;");
    LetExp e = (LetExp) getFirstFunctionExpr(m);
    LetExp e2 = (LetExp) e.getExp();
    VarOrFieldDecl decl = e2.getVar();
    VarUse u = (VarUse) e2.getExp();
    assertEquals(decl, u.getDecl());
}
Also used : VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) LetExp(org.abs_models.frontend.ast.LetExp) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

VarUse (org.abs_models.frontend.ast.VarUse)18 FrontendTest (org.abs_models.frontend.FrontendTest)9 Test (org.junit.Test)9 LetExp (org.abs_models.frontend.ast.LetExp)8 Model (org.abs_models.frontend.ast.Model)8 VarOrFieldDecl (org.abs_models.frontend.ast.VarOrFieldDecl)7 DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)3 MainBlock (org.abs_models.frontend.ast.MainBlock)3 ParamDecl (org.abs_models.frontend.ast.ParamDecl)3 ParametricDataTypeUse (org.abs_models.frontend.ast.ParametricDataTypeUse)3 Block (org.abs_models.frontend.ast.Block)2 FnApp (org.abs_models.frontend.ast.FnApp)2 GetExp (org.abs_models.frontend.ast.GetExp)2 List (org.abs_models.frontend.ast.List)2 MethodSig (org.abs_models.frontend.ast.MethodSig)2 NegExp (org.abs_models.frontend.ast.NegExp)2 PatternVarDecl (org.abs_models.frontend.ast.PatternVarDecl)2 PureExp (org.abs_models.frontend.ast.PureExp)2 TypeUse (org.abs_models.frontend.ast.TypeUse)2 VarDecl (org.abs_models.frontend.ast.VarDecl)2