Search in sources :

Example 6 with Stmt

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

the class TreeUtilsTest method findChildrenListNotNull.

@Test
public void findChildrenListNotNull() {
    Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    List<Stmt> children = functionDecl.getFunctionDef().findChildren(Stmt.class);
    assertNotNull(children);
    assertTrue(children.isEmpty());
}
Also used : Model(abs.frontend.ast.Model) FunctionDecl(abs.frontend.ast.FunctionDecl) Stmt(abs.frontend.ast.Stmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 7 with Stmt

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

the class ABSUnitTestCaseBuilder method createObjectsInHeap.

void createObjectsInHeap(String testMethodName, Set<String> heapNames, Map<String, InterfaceTypeUse> objectsInHeap, ClassDecl testClass, Map<ABSRef, ABSObject> initialHeap, Block testMethodBlock) {
    String setMethodForTest = testCaseNameBuilder.initialTestMethodName(testMethodName);
    Block modifyBlock = initialiseDeltaForTestClass(testClass, testCaseNameBuilder.initialTestMethodName(testMethodName));
    testMethodBlock.addStmtNoTransform(getExpStmt(getCall(getThis(), setMethodForTest, true)));
    Map<String, String> typeHierarchy = new HashMap<String, String>();
    Map<String, List<Stmt>> initialisations = new HashMap<String, List<Stmt>>();
    List<String> initialisationsOrders = new ArrayList<String>();
    for (ABSRef r : initialHeap.keySet()) {
        makeSetStatements(typeHierarchy, initialisations, initialisationsOrders, testMethodName, heapNames, initialHeap, objectsInHeap, r, initialHeap.get(r), testClass);
    }
    for (String ref : initialisationsOrders) {
        for (Stmt s : initialisations.get(ref)) {
            modifyBlock.addStmtNoTransform(s);
        }
    }
    String testClassName = testClass.getName();
    DeltaDecl delta = deltaBuilder.getDeltaFor(testClassName);
    ModifyClassModifier cm = null;
    for (ModuleModifier m : delta.getModuleModifiers()) {
        if (m.getName().equals(testClassName)) {
            cm = (ModifyClassModifier) m;
            break;
        }
    }
    for (String r : objectsInHeap.keySet()) {
        FieldDecl field = new FieldDecl();
        field.setName(r);
        InterfaceTypeUse inf = objectsInHeap.get(r);
        field.setAccess(inf);
        testClass.addField(field);
        // allow access of subtype information
        cm.addModifier(new RemoveFieldModifier(field.treeCopyNoTransform()));
        FieldDecl newField = new FieldDecl();
        newField.setName(r);
        newField.setAccess(new InterfaceTypeUse(typeHierarchy.get(inf.getName()), new abs.frontend.ast.List<abs.frontend.ast.Annotation>()));
        cm.addModifier(new AddFieldModifier(newField));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoveFieldModifier(abs.frontend.ast.RemoveFieldModifier) DeltaDecl(abs.frontend.ast.DeltaDecl) AbsASTBuilderUtil.getExpStmt(abs.backend.tests.AbsASTBuilderUtil.getExpStmt) Stmt(abs.frontend.ast.Stmt) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) FieldDecl(abs.frontend.ast.FieldDecl) ABSRef(apet.testCases.ABSRef) ModuleModifier(abs.frontend.ast.ModuleModifier) InterfaceTypeUse(abs.frontend.ast.InterfaceTypeUse) Block(abs.frontend.ast.Block) List(java.util.List) ArrayList(java.util.ArrayList) AddFieldModifier(abs.frontend.ast.AddFieldModifier)

Example 8 with Stmt

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

the class AnnotationUtil method annotateCall.

/**
 * <p>Annotates the parent Statement or Function node with an ExpansionCall annotation.</p>
 *
 * <p>If said node already has an annotation with the ExpansionCall type, the expansionIndex will be added to the
 * existing annotation.</p>
 *
 * @param call the call to use as a starting point to look for a Stmt or FunctionDecl parent
 * @param expansionId the ID of the called Expansion
 * @throws IllegalArgumentException if there is no Stmt or FunctionDecl parent
 */
public static void annotateCall(FnApp call, int expansionId) {
    Stmt parent = call.closestParent(Stmt.class);
    if (parent == null) {
        FunctionDecl parentFunction = call.closestParent(FunctionDecl.class);
        if (parentFunction == null) {
            throw new IllegalArgumentException("Function call has no parent Statement or FunctionDecl: " + call);
        }
        addToAnnotations(parentFunction.getAnnotations(), expansionCallType(), expansionId);
    } else {
        addToAnnotations(parent.getAnnotations(), expansionCallType(), expansionId);
    }
}
Also used : Stmt(abs.frontend.ast.Stmt) FunctionDecl(abs.frontend.ast.FunctionDecl)

Aggregations

Stmt (abs.frontend.ast.Stmt)8 ClassDecl (abs.frontend.ast.ClassDecl)4 FrontendTest (abs.frontend.FrontendTest)3 Test (org.junit.Test)3 AbsASTBuilderUtil.getExpStmt (abs.backend.tests.AbsASTBuilderUtil.getExpStmt)2 FunctionDecl (abs.frontend.ast.FunctionDecl)2 Model (abs.frontend.ast.Model)2 PureExp (abs.frontend.ast.PureExp)2 ReturnStmt (abs.frontend.ast.ReturnStmt)2 VarDeclStmt (abs.frontend.ast.VarDeclStmt)2 Type (abs.frontend.typechecker.Type)2 ArrayList (java.util.ArrayList)2 DeclNamePredicate (abs.backend.tests.AbsASTBuilderUtil.DeclNamePredicate)1 AbsASTBuilderUtil.getCall (abs.backend.tests.AbsASTBuilderUtil.getCall)1 AddFieldModifier (abs.frontend.ast.AddFieldModifier)1 AssignStmt (abs.frontend.ast.AssignStmt)1 Block (abs.frontend.ast.Block)1 Call (abs.frontend.ast.Call)1 DeltaDecl (abs.frontend.ast.DeltaDecl)1 Exp (abs.frontend.ast.Exp)1