Search in sources :

Example 1 with Exp

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

the class VarResolutionTest method testLocalVar.

@Test
public void testLocalVar() {
    Exp e = getSecondExp("interface I { } { I i = null; i = i; }");
    VarUse u = (VarUse) e;
    VarDecl decl = (VarDecl) u.getDecl();
    assertEquals("i", decl.getName());
}
Also used : PatternVarDecl(org.abs_models.frontend.ast.PatternVarDecl) VarDecl(org.abs_models.frontend.ast.VarDecl) NegExp(org.abs_models.frontend.ast.NegExp) Exp(org.abs_models.frontend.ast.Exp) LetExp(org.abs_models.frontend.ast.LetExp) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 2 with Exp

use of org.abs_models.frontend.ast.Exp 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 Exp

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

the class FreeVarTest method letExp3.

@Test
public void letExp3() {
    Exp e = getSecondExp("{ Bool b = True; Bool c = let (Bool b) = b in b; }");
    assertEquals(e.getFreeVars(), "b");
}
Also used : Exp(org.abs_models.frontend.ast.Exp) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 4 with Exp

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

the class FreeVarTest method ifExpr.

@Test
public void ifExpr() {
    Exp e = getExp("{ Int x = 3; Int y = 4; Int z = 5; Int a = when x == 3 then y else z; }", 3);
    assertEquals(e.getFreeVars(), "x", "y", "z");
}
Also used : Exp(org.abs_models.frontend.ast.Exp) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 5 with Exp

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

the class FreeVarTest method varUseExp.

@Test
public void varUseExp() {
    Exp e = getSecondExp("{ Bool b = True; Bool c = b; }");
    assertEquals(e.getFreeVars(), "b");
}
Also used : Exp(org.abs_models.frontend.ast.Exp) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

FrontendTest (org.abs_models.frontend.FrontendTest)24 Exp (org.abs_models.frontend.ast.Exp)24 Test (org.junit.Test)24 ClassDecl (org.abs_models.frontend.ast.ClassDecl)1 LetExp (org.abs_models.frontend.ast.LetExp)1 MethodImpl (org.abs_models.frontend.ast.MethodImpl)1 NegExp (org.abs_models.frontend.ast.NegExp)1 PatternVarDecl (org.abs_models.frontend.ast.PatternVarDecl)1 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)1 Stmt (org.abs_models.frontend.ast.Stmt)1 VarDecl (org.abs_models.frontend.ast.VarDecl)1 VarUse (org.abs_models.frontend.ast.VarUse)1