Search in sources :

Example 1 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateWaitSyncAST.

private WhileStmt generateWaitSyncAST() {
    WhileStmt ws = new WhileStmt();
    ws.setCondition(getFnApp("hasNext", new VarUse(futs)));
    Block body = new Block();
    DataTypeUse u = getType("Pair", getType("Set", getType("Fut", getType("Unit"))), getType("Fut", getType("Unit")));
    body.addStmtNoTransform(getVarDecl("nt", u, getFnApp("next", new VarUse(futs))));
    body.addStmtNoTransform(getVAssign(fut, getFnApp("snd", new VarUse("nt"))));
    body.addStmtNoTransform(getVAssign(futs, getFnApp("fst", new VarUse("nt"))));
    body.addStmtNoTransform(getExpStmt(new GetExp(new VarUse("fut"))));
    // Attach body at the end, since JastAdd will avoid touching ASTs without parents.
    ws.setBody(body);
    return ws;
}
Also used : WhileStmt(abs.frontend.ast.WhileStmt) ParametricDataTypeUse(abs.frontend.ast.ParametricDataTypeUse) DataTypeUse(abs.frontend.ast.DataTypeUse) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) GetExp(abs.frontend.ast.GetExp) VarUse(abs.frontend.ast.VarUse)

Example 2 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class ABSUnitTestCaseBuilder method makeSetStatements.

void makeSetStatements(Map<String, String> typeHierarchy, Map<String, List<Stmt>> initialisations, List<String> initialisationsOrders, String testName, Set<String> heapNames, Map<ABSRef, ABSObject> initialHeap, Map<String, InterfaceTypeUse> objectsInHeap, ABSRef ref, ABSObject state, ClassDecl testClass) {
    String rn = heapRefBuilder.heapReferenceForTest(testName, getABSDataValue(ref));
    String concreteTypeName = getABSObjectType(state);
    ClassDecl concreteType = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(concreteTypeName));
    if (concreteType == null) {
        throw new IllegalStateException("Cannot find class: " + concreteTypeName);
    }
    List<Stmt> statements = new ArrayList<Stmt>();
    initialisations.put(rn, statements);
    if (!initialisationsOrders.contains(rn)) {
        initialisationsOrders.add(rn);
    }
    Map<String, ABSData> fields = getABSObjectFields(state);
    abs.frontend.ast.List<ParamDecl> params = concreteType.getParamList();
    PureExp[] constructorArgs = new PureExp[params.getNumChild()];
    for (int i = 0; i < params.getNumChild(); i++) {
        ParamDecl param = params.getChild(i);
        String name = param.getName();
        assert fields.containsKey(name);
        ABSData d = fields.remove(name);
        objectsInHeap.putAll(getTypesFromABSData(testName, d));
        PureExp exp = pureExpBuilder.createPureExpression(rn, initialisationsOrders, testName, heapNames, d);
        constructorArgs[i] = exp;
    }
    statements.add(getVAssign(rn, newObj(concreteType, false, constructorArgs)));
    for (String fn : fields.keySet()) {
        ABSData d = fields.get(fn);
        objectsInHeap.putAll(getTypesFromABSData(testName, d));
        PureExp exp = pureExpBuilder.createPureExpression(rn, initialisationsOrders, testName, heapNames, d);
        Call call = getCall(new VarUse(rn), testCaseNameBuilder.setterMethodName(fn), true, exp);
        statements.add(getExpStmt(call));
    }
    // ADD getter and setter
    deltaBuilder.updateDelta(typeHierarchy, objectsInHeap.get(rn), getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(concreteTypeName)));
}
Also used : Call(abs.frontend.ast.Call) AbsASTBuilderUtil.getCall(abs.backend.tests.AbsASTBuilderUtil.getCall) PreviousCall(apet.testCases.PreviousCall) DeclNamePredicate(abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate) ArrayList(java.util.ArrayList) PureExp(abs.frontend.ast.PureExp) VarUse(abs.frontend.ast.VarUse) AbsASTBuilderUtil.getExpStmt(abs.backend.tests.AbsASTBuilderUtil.getExpStmt) Stmt(abs.frontend.ast.Stmt) ClassDecl(abs.frontend.ast.ClassDecl) ParamDecl(abs.frontend.ast.ParamDecl) ABSData(apet.testCases.ABSData)

Example 3 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class ABSUnitTestCaseBuilder method makeGetAndAssertStatementsForHeapRef.

void makeGetAndAssertStatementsForHeapRef(String testName, Set<String> heapNames, Map<ABSRef, ABSObject> finalHeap, ABSRef ref, ABSObject state, Set<String> visited, Block block) {
    String rn = heapRefBuilder.heapReferenceForTest(testName, getABSDataValue(ref));
    if (!visited.add(rn)) {
        return;
    }
    Map<String, ABSData> fields = getABSObjectFields(state);
    ClassDecl clazz = getDecl(model, ClassDecl.class, new DeclNamePredicate<ClassDecl>(getABSObjectType(state)));
    abs.frontend.ast.List<FieldDecl> fieldDecls = clazz.getFieldList();
    for (int i = 0; i < fieldDecls.getNumChild(); i++) {
        FieldDecl field = fieldDecls.getChild(i);
        String fn = field.getName();
        if (fields.containsKey(fn)) {
            ABSData d = fields.get(fn);
            block.addStmtNoTransform(getVarDecl(testCaseNameBuilder.resultOfGetterMethodName(fn), field.getAccess().treeCopyNoTransform(), getCall(new VarUse(rn), testCaseNameBuilder.getterMethodName(fn), true)));
            makeOracle(testName, heapNames, finalHeap, testCaseNameBuilder.resultOfGetterMethodName(fn), field.getAccess().treeCopyNoTransform(), d, visited, block);
        }
    }
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ClassDecl(abs.frontend.ast.ClassDecl) ABSData(apet.testCases.ABSData) VarUse(abs.frontend.ast.VarUse)

Example 4 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class DeltaForGetSetFieldsBuilder method addSetter.

/**
 * Add an add method modifier
 * @param fieldName
 * @param exp
 * @param decl
 * @return
 */
AddMethodModifier addSetter(String fieldName, Access type) {
    MethodSig sig = new MethodSig(testCaseNameBuilder.setterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), getUnit(), new abs.frontend.ast.List<ParamDecl>());
    sig.addParam(new ParamDecl("v", type, new abs.frontend.ast.List<Annotation>()));
    Block block = new Block();
    block.addStmtNoTransform(getVAssign(new FieldUse(fieldName), new VarUse("v")));
    MethodImpl method = new MethodImpl(sig, block, false);
    AddMethodModifier modifier = new AddMethodModifier(method);
    return modifier;
}
Also used : AddMethodModifier(abs.frontend.ast.AddMethodModifier) VarUse(abs.frontend.ast.VarUse) Annotation(abs.frontend.ast.Annotation) AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) FieldUse(abs.frontend.ast.FieldUse) Block(abs.frontend.ast.Block)

Example 5 with VarUse

use of abs.frontend.ast.VarUse in project abstools by abstools.

the class PureExpressionBuilder method createPureExpression.

/**
 * @param currentHeapReference
 * @param initialisationsOrders
 * @param heapNames
 * @param dataValue
 * @return
 */
PureExp createPureExpression(String currentHeapReference, List<String> initialisationsOrders, String testName, Set<String> heapNames, ABSData dataValue) {
    String type = getABSDataType(dataValue);
    String value = getABSDataValue(dataValue);
    if (type.contains("(") && dataValue instanceof ABSTerm) {
        ABSTerm term = (ABSTerm) dataValue;
        type = getABSTermTypeName(term);
    }
    // import type
    Decl decl = getDecl(model, Decl.class, namePred(type));
    importType(decl);
    if (dataValue instanceof ABSTerm) {
        ABSTerm term = (ABSTerm) dataValue;
        return makeDataTermValue(currentHeapReference, initialisationsOrders, testName, heapNames, term, decl);
    } else if (dataValue instanceof ABSRef) {
        if (heapNames.contains(value)) {
            String ref = heapRefBuilder.heapReferenceForTest(testName, value);
            if (currentHeapReference != null) {
                // we need to consider initialisation order!
                updateInitialisationOrder(initialisationsOrders, currentHeapReference, ref);
            }
            return new VarUse(ref);
        } else {
            return new NullExp();
        }
    } else {
        throw new IllegalStateException("Cannot handle ABSData that is not " + "either a ABSRef or a ABSTerm");
    }
}
Also used : ABSTerm(apet.testCases.ABSTerm) ABSRef(apet.testCases.ABSRef) NullExp(abs.frontend.ast.NullExp) AbsASTBuilderUtil.getDecl(abs.backend.tests.AbsASTBuilderUtil.getDecl) DataTypeDecl(abs.frontend.ast.DataTypeDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Decl(abs.frontend.ast.Decl) TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) VarUse(abs.frontend.ast.VarUse)

Aggregations

VarUse (abs.frontend.ast.VarUse)15 PureExp (abs.frontend.ast.PureExp)6 DataTypeUse (abs.frontend.ast.DataTypeUse)5 Block (abs.frontend.ast.Block)4 ParamDecl (abs.frontend.ast.ParamDecl)4 ABSData (apet.testCases.ABSData)4 ABSRef (apet.testCases.ABSRef)4 MethodSig (abs.frontend.ast.MethodSig)3 NullExp (abs.frontend.ast.NullExp)3 ParametricDataTypeUse (abs.frontend.ast.ParametricDataTypeUse)3 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)2 AbsASTBuilderUtil.getCall (abs.backend.tests.AbsASTBuilderUtil.getCall)2 Call (abs.frontend.ast.Call)2 ClassDecl (abs.frontend.ast.ClassDecl)2 EqExp (abs.frontend.ast.EqExp)2 FieldDecl (abs.frontend.ast.FieldDecl)2 GetExp (abs.frontend.ast.GetExp)2 InterfaceDecl (abs.frontend.ast.InterfaceDecl)2 MainBlock (abs.frontend.ast.MainBlock)2 TypeUse (abs.frontend.ast.TypeUse)2