Search in sources :

Example 1 with Stmt

use of abs.frontend.ast.Stmt 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 2 with Stmt

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

the class SchedulerChecker method checkNewExp.

@Override
public void checkNewExp(NewExp e) {
    Stmt stmt = CompilerUtils.findStmtForExpression(e);
    PureExp sched = CompilerUtils.getAnnotationValueFromName(stmt.getAnnotations(), "ABS.Scheduler.Scheduler");
    if (sched != null) {
        ClassDecl decl = (ClassDecl) (e.lookup(new KindedName(KindedName.Kind.CLASS, e.getClassName())));
        checkScheduleExp(sched, decl, stmt);
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) PureExp(abs.frontend.ast.PureExp) Stmt(abs.frontend.ast.Stmt)

Example 3 with Stmt

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

the class FrontendTest method getTypeOfNthAssignment.

protected Type getTypeOfNthAssignment(Model m, int n) {
    int count = 0;
    for (Stmt s : m.getMainBlock().getStmts()) {
        Type t = null;
        if (s instanceof AssignStmt) {
            AssignStmt as = (AssignStmt) s;
            t = as.getValue().getType();
        } else if (s instanceof VarDeclStmt) {
            VarDeclStmt vd = (VarDeclStmt) s;
            if (vd.getVarDecl().hasInitExp()) {
                t = vd.getVarDecl().getInitExp().getType();
            }
        }
        if (t != null) {
            count++;
            if (count == n) {
                return t;
            }
        }
    }
    return null;
}
Also used : Type(abs.frontend.typechecker.Type) AssignStmt(abs.frontend.ast.AssignStmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) AssignStmt(abs.frontend.ast.AssignStmt) Stmt(abs.frontend.ast.Stmt) ExpressionStmt(abs.frontend.ast.ExpressionStmt)

Example 4 with Stmt

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

the class FreeVarTest method fieldUse.

@Test
public void fieldUse() {
    ClassDecl clazz = getFirstClassDecl(assertParseOkStdLib("class C {" + "Int i = 0;" + "Int m() {" + "return i + 1;" + "}" + "}"));
    MethodImpl method = clazz.lookupMethod("m");
    assertNotNull(method);
    Stmt stmt = method.getBlock().getStmt(0);
    assertTrue(stmt instanceof ReturnStmt);
    ReturnStmt returnStmt = (ReturnStmt) stmt;
    Exp exp = returnStmt.getRetExp();
    assertEquals(exp.getFreeVars(), "i");
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) MethodImpl(abs.frontend.ast.MethodImpl) Exp(abs.frontend.ast.Exp) ReturnStmt(abs.frontend.ast.ReturnStmt) Stmt(abs.frontend.ast.Stmt) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 5 with Stmt

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

the class OtherAnalysisTests method awaitRewriteModule1.

@Test
public void awaitRewriteModule1() {
    Model.doAACrewrite = false;
    Model m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}");
    ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
    ReturnStmt ret = (ReturnStmt) c.getMethod(0).getBlock().getStmt(0);
    assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
    assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
    Model.doAACrewrite = true;
    m = assertParseOk("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.WITH_STD_LIB);
    c = (ClassDecl) m.lookupModule("C").getDecl(0);
    Stmt s = c.getMethod(0).getBlock().getStmt(0);
    VarDeclStmt b = (VarDeclStmt) s;
    Type t = ((DataTypeType) b.getVarDecl().getType()).getTypeArg(0);
    assertEquals("A.X", t.getQualifiedName());
}
Also used : Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) ClassDecl(abs.frontend.ast.ClassDecl) VarDeclStmt(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) DataTypeType(abs.frontend.typechecker.DataTypeType) ReturnStmt(abs.frontend.ast.ReturnStmt) Stmt(abs.frontend.ast.Stmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

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