Search in sources :

Example 1 with Stmt

use of org.abs_models.frontend.ast.Stmt in project abstools by abstools.

the class TreeUtilsTest method findChildrenListNotNull.

@Test
public void findChildrenListNotNull() {
    Model model = assertParse("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(org.abs_models.frontend.ast.Model) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Stmt(org.abs_models.frontend.ast.Stmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 2 with Stmt

use of org.abs_models.frontend.ast.Stmt in project abstools by abstools.

the class FreeVarTest method fieldUse.

@Test
public void fieldUse() {
    ClassDecl clazz = getFirstClassDecl(assertParse("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(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) Exp(org.abs_models.frontend.ast.Exp) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) Stmt(org.abs_models.frontend.ast.Stmt) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 3 with Stmt

use of org.abs_models.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(org.abs_models.frontend.typechecker.Type) AssignStmt(org.abs_models.frontend.ast.AssignStmt) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Stmt(org.abs_models.frontend.ast.Stmt) AssignStmt(org.abs_models.frontend.ast.AssignStmt) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) ExpressionStmt(org.abs_models.frontend.ast.ExpressionStmt)

Example 4 with Stmt

use of org.abs_models.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(org.abs_models.frontend.ast.Stmt) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl)

Example 5 with Stmt

use of org.abs_models.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 = AnnotationHelper.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(org.abs_models.frontend.ast.ClassDecl) PureExp(org.abs_models.frontend.ast.PureExp) KindedName(org.abs_models.frontend.typechecker.KindedName) Stmt(org.abs_models.frontend.ast.Stmt)

Aggregations

Stmt (org.abs_models.frontend.ast.Stmt)6 FrontendTest (org.abs_models.frontend.FrontendTest)3 ClassDecl (org.abs_models.frontend.ast.ClassDecl)3 Test (org.junit.Test)3 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)2 Model (org.abs_models.frontend.ast.Model)2 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)2 VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)2 Type (org.abs_models.frontend.typechecker.Type)2 AssignStmt (org.abs_models.frontend.ast.AssignStmt)1 Exp (org.abs_models.frontend.ast.Exp)1 ExpressionStmt (org.abs_models.frontend.ast.ExpressionStmt)1 MethodImpl (org.abs_models.frontend.ast.MethodImpl)1 PureExp (org.abs_models.frontend.ast.PureExp)1 DataTypeType (org.abs_models.frontend.typechecker.DataTypeType)1 KindedName (org.abs_models.frontend.typechecker.KindedName)1