Search in sources :

Example 16 with PureExp

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

the class JavaGeneratorHelper method generateAwaitAsyncCall.

public static void generateAwaitAsyncCall(PrintStream stream, AwaitAsyncCall call) {
    final PureExp callee = call.getCallee();
    final List<PureExp> params = call.getParams();
    final MethodSig sig = call.getMethodSig();
    final List<Annotation> annotations = call.getAnnotations();
    // FIXME: implement await, assignment afterwards
    // OutputStream exprOStream = new ByteArrayOutputStream();
    // PrintStream exprStream = new PrintStream(exprOStream);
    // ClaimGuard guard = new ClaimGuard();
    // // Necessary temporary variables are written to "stream" and the
    // // await-expression is written to exprStream
    // 
    // // FIXME: implement await, assignment afterwards
    // guard.generateJavaGuard(stream, exprStream);
    // stream.print(JavaBackendConstants.ABSRUNTIME + ".await(");
    // stream.print(exprOStream.toString());
    // stream.println(");");
    generateAsyncCall(stream, null, callee, callee.getType(), params, null, sig, annotations);
}
Also used : MethodSig(abs.frontend.ast.MethodSig) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation)

Example 17 with PureExp

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

the class SchedulerChecker method checkClassDecl.

@Override
public void checkClassDecl(ClassDecl decl) {
    PureExp sched = CompilerUtils.getAnnotationValueFromName(decl.getAnnotations(), "ABS.Scheduler.Scheduler");
    checkScheduleExp(sched, decl, decl);
}
Also used : PureExp(abs.frontend.ast.PureExp)

Example 18 with PureExp

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

the class ABSUnitTestCaseBuilder method buildTestCase.

/**
 * @param testCase
 * @param testClass
 * @param method
 * @param access
 * @param unitUnderTest
 */
void buildTestCase(TestCase testCase, ClassDecl testClass, MethodImpl method, Access access, String unitUnderTest) {
    // initial arg
    List<ABSData> inputArguments = getInputArgs(testCase);
    String testName = method.getMethodSig().getName();
    Block block = method.getBlock();
    Map<String, InterfaceTypeUse> typesOfObjectInHeap = new HashMap<String, InterfaceTypeUse>();
    for (ABSData d : inputArguments) {
        typesOfObjectInHeap.putAll(getTypesFromABSData(testName, d));
    }
    Map<ABSRef, ABSObject> initial = getInitialState(testCase);
    for (ABSObject obj : initial.values()) {
        typesOfObjectInHeap.putAll(getTypesFromABSObject(testName, obj));
    }
    Set<String> initialHeapNames = referenceNames(initial.keySet());
    createObjectsInHeap(testName, initialHeapNames, typesOfObjectInHeap, testClass, initial, block);
    List<PreviousCall> calls = getPreviousCalls(testCase);
    List<Exp> previous = makePreviousCalls(testName, initialHeapNames, calls);
    for (Exp pc : previous) {
        // does not care about return value
        block.addStmtNoTransform(getExpStmt(pc));
    }
    // test execution
    Exp test = makeTestExecution(testName, initialHeapNames, unitUnderTest, inputArguments);
    final boolean hasReturnValue;
    if (access instanceof DataTypeUse && ((DataTypeUse) access).getName().equals("Unit")) {
        // no return value
        block.addStmtNoTransform(getExpStmt(test));
        hasReturnValue = false;
    } else {
        block.addStmtNoTransform(getVarDecl("returnValue", access.treeCopyNoTransform(), test));
        hasReturnValue = true;
    }
    Map<ABSRef, ABSObject> finalHeap = getAfterState(testCase);
    if (finalHeap.isEmpty()) {
        // the method under test is side-effect free?
        // use the initial heap as oracle
        finalHeap = initial;
    }
    Set<String> finalHeapNames = referenceNames(finalHeap.keySet());
    // need to remember which objects in the heap we have already handled.
    Set<String> visited = new HashSet<String>();
    // assertions of object states can be done in the heap assertions
    if (hasReturnValue) {
        ABSData rd = getReturnData(testCase);
        PureExp exp = pureExpBuilder.createPureExpression(testName, finalHeapNames, rd);
        block.addStmtNoTransform(getExpStmt(getCall(new VarUse(ASSERT_HELPER), "assertTrue", true, new EqExp(new VarUse("returnValue"), exp))));
    }
    // check return value (using deltas)
    makeGetAndAssertStatements(testName, finalHeapNames, testClass, finalHeap, visited, block);
}
Also used : HashMap(java.util.HashMap) DataTypeUse(abs.frontend.ast.DataTypeUse) ABSObject(apet.testCases.ABSObject) PureExp(abs.frontend.ast.PureExp) VarUse(abs.frontend.ast.VarUse) EqExp(abs.frontend.ast.EqExp) ABSRef(apet.testCases.ABSRef) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) Block(abs.frontend.ast.Block) ABSData(apet.testCases.ABSData) EqExp(abs.frontend.ast.EqExp) PureExp(abs.frontend.ast.PureExp) Exp(abs.frontend.ast.Exp) NullExp(abs.frontend.ast.NullExp) PreviousCall(apet.testCases.PreviousCall) HashSet(java.util.HashSet)

Example 19 with PureExp

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

Example 20 with PureExp

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

the class FunctionTestCaseBuilder method makeTestExecution.

@Override
Exp makeTestExecution(String testName, Set<String> heap, String testExecutionName, List<ABSData> inArgs) {
    abs.frontend.ast.List<PureExp> ps = new abs.frontend.ast.List<PureExp>();
    FnApp fa = new FnApp();
    if (inArgs.size() == 0) {
        throw new IllegalStateException("Inputs for a method must at least have a reference");
    }
    fa.setName(testExecutionName);
    fa.setParamList(ps);
    for (int i = 0; i < inArgs.size(); i++) {
        ABSData d = inArgs.get(i);
        PureExp exp = pureExpBuilder.createPureExpression(testName, heap, d);
        fa.setParam(exp, i);
    }
    return fa;
}
Also used : FnApp(abs.frontend.ast.FnApp) List(java.util.List) ABSData(apet.testCases.ABSData) PureExp(abs.frontend.ast.PureExp)

Aggregations

PureExp (abs.frontend.ast.PureExp)26 FunctionDecl (abs.frontend.ast.FunctionDecl)8 FrontendTest (abs.frontend.FrontendTest)7 Model (abs.frontend.ast.Model)7 Test (org.junit.Test)7 VarUse (abs.frontend.ast.VarUse)6 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)5 ABSData (apet.testCases.ABSData)5 Annotation (abs.frontend.ast.Annotation)4 FnApp (abs.frontend.ast.FnApp)4 IntLiteral (abs.frontend.ast.IntLiteral)4 ABSRef (apet.testCases.ABSRef)3 PreviousCall (apet.testCases.PreviousCall)3 ABSBool (abs.backend.java.lib.types.ABSBool)2 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 DataTypeUse (abs.frontend.ast.DataTypeUse)2 EqExp (abs.frontend.ast.EqExp)2