Search in sources :

Example 1 with ReturnStmt

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

the class TypeCheckerTest method classParamsRewrite.

@Test
public void classParamsRewrite() {
    Model m = assertParse("class C(Bool b) { Bool m() { return b; } }");
    ModuleDecl u = m.lookupModule("UnitTest");
    ClassDecl c = (ClassDecl) u.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
    MethodImpl me = c.lookupMethod("m");
    ReturnStmt r = (ReturnStmt) me.getBlock().getStmt(0);
    VarOrFieldUse vu = (VarOrFieldUse) r.getRetExp();
    ParamDecl d = (ParamDecl) vu.getDecl();
    assertThat(d.getParent().getParent(), instanceOf(ClassDecl.class));
    assertThat(vu.getClass().getName(), vu, instanceOf(FieldUse.class));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) FieldUse(org.abs_models.frontend.ast.FieldUse) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) KindedName(org.abs_models.frontend.typechecker.KindedName) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 2 with ReturnStmt

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

the class TypeCheckerTest method classParamsRewrite2.

@Test
public void classParamsRewrite2() {
    Model m = assertParse("class C(Bool b) { Bool m(Bool x) { return x; } }");
    ModuleDecl u = m.lookupModule("UnitTest");
    ClassDecl c = (ClassDecl) u.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
    MethodImpl me = c.lookupMethod("m");
    ReturnStmt r = (ReturnStmt) me.getBlock().getStmt(0);
    VarOrFieldUse vu = (VarOrFieldUse) r.getRetExp();
    ParamDecl d = (ParamDecl) vu.getDecl();
    assertThat(d.getParent().getParent(), instanceOf(MethodSig.class));
    assertThat(vu.getClass().getName(), vu, instanceOf(VarUse.class));
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) KindedName(org.abs_models.frontend.typechecker.KindedName) VarUse(org.abs_models.frontend.ast.VarUse) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 3 with ReturnStmt

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

the class TypingTest method testFieldUse.

@Test
public void testFieldUse() {
    Model m = assertParse(" class C { Bool f; Bool m() { return this.f; } }");
    ClassDecl d = (ClassDecl) m.lookup(new KindedName(KindedName.Kind.CLASS, "UnitTest.C"));
    FieldDecl f = d.getField(0);
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(f.getType(), s.getRetExp().getType());
}
Also used : FieldDecl(org.abs_models.frontend.ast.FieldDecl) ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) KindedName(org.abs_models.frontend.typechecker.KindedName) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 4 with ReturnStmt

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

the class TypingTest method testContextDecl.

@Test
public void testContextDecl() {
    Model m = assertParse("class C implements I { I m() { return this; } } interface I { }");
    ClassDecl d = (ClassDecl) m.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(d, s.getRetExp().getContextDecl());
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) KindedName(org.abs_models.frontend.typechecker.KindedName) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 5 with ReturnStmt

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

Aggregations

ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)11 ClassDecl (org.abs_models.frontend.ast.ClassDecl)10 Test (org.junit.Test)10 FrontendTest (org.abs_models.frontend.FrontendTest)9 Model (org.abs_models.frontend.ast.Model)9 KindedName (org.abs_models.frontend.typechecker.KindedName)6 MethodImpl (org.abs_models.frontend.ast.MethodImpl)4 ParamDecl (org.abs_models.frontend.ast.ParamDecl)4 ABSTest (org.abs_models.ABSTest)3 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)3 VarOrFieldUse (org.abs_models.frontend.ast.VarOrFieldUse)3 FieldDecl (org.abs_models.frontend.ast.FieldDecl)2 MethodSig (org.abs_models.frontend.ast.MethodSig)2 Stmt (org.abs_models.frontend.ast.Stmt)2 VarUse (org.abs_models.frontend.ast.VarUse)2 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)1 Exp (org.abs_models.frontend.ast.Exp)1 FieldUse (org.abs_models.frontend.ast.FieldUse)1 VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)1 VarOrFieldDecl (org.abs_models.frontend.ast.VarOrFieldDecl)1