Search in sources :

Example 1 with NullExp

use of abs.frontend.ast.NullExp 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)

Example 2 with NullExp

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

the class ABSUnitTestCaseBuilder method makeOracle.

void makeOracle(String testName, Set<String> heapNames, Map<ABSRef, ABSObject> finalHeap, String actual, Access access, ABSData data, Set<String> visited, Block block) {
    InterfaceDecl inf = null;
    if (access instanceof DataTypeUse) {
        inf = getDecl(model, InterfaceDecl.class, new DeclNamePredicate<InterfaceDecl>(((DataTypeUse) access).getName()));
    }
    PureExp exp = pureExpBuilder.createPureExpression(testName, heapNames, data);
    block.addStmtNoTransform(getExpStmt(getCall(new VarUse(ASSERT_HELPER), "assertTrue", true, new EqExp(new VarUse(actual), exp))));
    if (inf != null && !(exp instanceof NullExp)) {
        String ref = getABSDataValue(data);
        for (ABSRef r : finalHeap.keySet()) {
            if (getABSDataValue(r).equals(ref)) {
                makeGetAndAssertStatementsForHeapRef(testName, heapNames, finalHeap, r, finalHeap.get(r), visited, block);
                break;
            }
        }
    }
}
Also used : EqExp(abs.frontend.ast.EqExp) DataTypeUse(abs.frontend.ast.DataTypeUse) ABSRef(apet.testCases.ABSRef) DeclNamePredicate(abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate) NullExp(abs.frontend.ast.NullExp) InterfaceDecl(abs.frontend.ast.InterfaceDecl) PureExp(abs.frontend.ast.PureExp) VarUse(abs.frontend.ast.VarUse)

Aggregations

InterfaceDecl (abs.frontend.ast.InterfaceDecl)2 NullExp (abs.frontend.ast.NullExp)2 VarUse (abs.frontend.ast.VarUse)2 ABSRef (apet.testCases.ABSRef)2 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)1 AbsASTBuilderUtil.getDecl (abs.backend.tests.AbsASTBuilderUtil.getDecl)1 DataTypeDecl (abs.frontend.ast.DataTypeDecl)1 DataTypeUse (abs.frontend.ast.DataTypeUse)1 Decl (abs.frontend.ast.Decl)1 EqExp (abs.frontend.ast.EqExp)1 ParametricDataTypeDecl (abs.frontend.ast.ParametricDataTypeDecl)1 PureExp (abs.frontend.ast.PureExp)1 TypeParameterDecl (abs.frontend.ast.TypeParameterDecl)1 TypeSynDecl (abs.frontend.ast.TypeSynDecl)1 ABSTerm (apet.testCases.ABSTerm)1