Search in sources :

Example 21 with PureExp

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

the class MethodTestCaseBuilder method makeMethodCall.

private Call makeMethodCall(String testName, Set<String> heapNames, String methodName, List<ABSData> inArgs, boolean sync) {
    if (inArgs.size() == 0) {
        throw new IllegalStateException("Inputs for a method must at least have a reference");
    }
    ABSData r = inArgs.get(0);
    if (!(r instanceof ABSRef)) {
        throw new IllegalStateException("Inputs for a method must at least have a reference");
    }
    PureExp[] ps = new PureExp[inArgs.size() - 1];
    for (int i = 1; i < inArgs.size(); i++) {
        ABSData d = inArgs.get(i);
        PureExp exp = pureExpBuilder.createPureExpression(testName, heapNames, d);
        ps[i - 1] = exp;
    }
    String rn = getABSDataValue(r);
    VarUse var = new VarUse(heapRefBuilder.heapReferenceForTest(testName, rn));
    Call call = getCall(var, methodName, sync, ps);
    return call;
}
Also used : Call(abs.frontend.ast.Call) PreviousCall(apet.testCases.PreviousCall) AbsASTBuilderUtil.getCall(abs.backend.tests.AbsASTBuilderUtil.getCall) ABSRef(apet.testCases.ABSRef) ABSData(apet.testCases.ABSData) PureExp(abs.frontend.ast.PureExp) VarUse(abs.frontend.ast.VarUse)

Example 22 with PureExp

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

the class PureExpressionBuilder method parseValue.

DataConstructorExp parseValue(String currentHeapReference, List<String> initialisationsOrders, String testName, Set<String> heap, ABSTerm term) {
    final DataConstructorExp result = new DataConstructorExp();
    String fn = getABSTermFunctor(term);
    result.setConstructor(fn);
    result.setParamList(new abs.frontend.ast.List<PureExp>());
    List<ABSData> vs = getABSTermArgs(term);
    for (int i = 0; i < vs.size(); i++) {
        result.setParam(createPureExpression(currentHeapReference, initialisationsOrders, testName, heap, vs.get(i)), i);
    }
    return result;
}
Also used : DataConstructorExp(abs.frontend.ast.DataConstructorExp) ABSData(apet.testCases.ABSData) PureExp(abs.frontend.ast.PureExp)

Example 23 with PureExp

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

Example 24 with PureExp

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

the class AnnotationUtil method addToAnnotations.

private static void addToAnnotations(List<Annotation> annotations, Access annotationType, int expansionId) {
    IntLiteral indexLiteral = new IntLiteral(Integer.toString(expansionId));
    Annotation toAdd = getAnnotation(annotations, annotationType);
    if (toAdd == null) {
        toAdd = new TypedAnnotation(new ListLiteral(new List<>()), annotationType);
        annotations.add(toAdd);
    }
    PureExp value = toAdd.getValue();
    if (value instanceof ListLiteral) {
        ListLiteral list = (ListLiteral) value;
        for (PureExp exp : list.getPureExps()) {
            if (exp instanceof IntLiteral) {
                IntLiteral intLiteral = (IntLiteral) exp;
                if (intLiteral.getContent().equals(indexLiteral.getContent())) {
                    return;
                }
            }
        }
        list.addPureExp(indexLiteral);
    } else {
        throw new IllegalArgumentException("Annotation list contains invalid expansion annotation");
    }
}
Also used : ListLiteral(abs.frontend.ast.ListLiteral) IntLiteral(abs.frontend.ast.IntLiteral) TypedAnnotation(abs.frontend.ast.TypedAnnotation) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation) TypedAnnotation(abs.frontend.ast.TypedAnnotation)

Example 25 with PureExp

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

the class AnnotationUtil method getExpansionId.

/**
 * Gets the expansion ID of a function declaration. If the function declaration is not an expansion, -1 is
 * returned.
 *
 * @param decl a function declaration
 * @return an expansion ID, or -1
 * @throws NullPointerException if decl is null
 */
public static int getExpansionId(FunctionDecl decl) {
    Objects.requireNonNull(decl);
    Annotation annotation = getAnnotation(decl.getAnnotationsNoTransform(), expansionType());
    if (annotation == null) {
        return -1;
    }
    PureExp value = annotation.getValue();
    if (value instanceof IntLiteral) {
        IntLiteral intValue = (IntLiteral) value;
        try {
            int result = Integer.parseInt(intValue.getContent());
            return result < 0 ? -1 : result;
        } catch (NumberFormatException e) {
            return -1;
        }
    } else {
        return -1;
    }
}
Also used : IntLiteral(abs.frontend.ast.IntLiteral) PureExp(abs.frontend.ast.PureExp) Annotation(abs.frontend.ast.Annotation) TypedAnnotation(abs.frontend.ast.TypedAnnotation)

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