Search in sources :

Example 6 with ReturnStmt

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

Example 7 with ReturnStmt

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

the class TypingTest method testFieldUse.

@Test
public void testFieldUse() {
    Model m = assertParseOkStdLib(" class C { Bool f; Bool m() { return this.f; } }");
    ClassDecl d = (ClassDecl) m.lookup(new 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(abs.frontend.ast.FieldDecl) ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) KindedName(abs.frontend.typechecker.KindedName) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 8 with ReturnStmt

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

the class DeltaForGetSetFieldsBuilder method addGetter.

AddMethodModifier addGetter(Exp returnValue, String fieldName, Access returnType) {
    MethodSig sig = new MethodSig(testCaseNameBuilder.getterMethodName(fieldName), new abs.frontend.ast.List<Annotation>(), returnType, new abs.frontend.ast.List<ParamDecl>());
    Block block = new Block();
    ReturnStmt rs = new ReturnStmt();
    rs.setRetExp(new FieldUse(fieldName));
    block.addStmtNoTransform(rs);
    MethodImpl method = new MethodImpl(sig, block, false);
    AddMethodModifier modifier = new AddMethodModifier(method);
    return modifier;
}
Also used : AbsASTBuilderUtil.createMethodSig(abs.backend.tests.AbsASTBuilderUtil.createMethodSig) MethodSig(abs.frontend.ast.MethodSig) MethodImpl(abs.frontend.ast.MethodImpl) ParamDecl(abs.frontend.ast.ParamDecl) FieldUse(abs.frontend.ast.FieldUse) AddMethodModifier(abs.frontend.ast.AddMethodModifier) Block(abs.frontend.ast.Block) ReturnStmt(abs.frontend.ast.ReturnStmt) Annotation(abs.frontend.ast.Annotation)

Aggregations

ReturnStmt (abs.frontend.ast.ReturnStmt)8 ClassDecl (abs.frontend.ast.ClassDecl)6 Test (org.junit.Test)6 FrontendTest (abs.frontend.FrontendTest)5 Model (abs.frontend.ast.Model)5 MethodImpl (abs.frontend.ast.MethodImpl)2 ParamDecl (abs.frontend.ast.ParamDecl)2 Stmt (abs.frontend.ast.Stmt)2 AbsASTBuilderUtil.createMethodSig (abs.backend.tests.AbsASTBuilderUtil.createMethodSig)1 AddMethodModifier (abs.frontend.ast.AddMethodModifier)1 Annotation (abs.frontend.ast.Annotation)1 Block (abs.frontend.ast.Block)1 DeltaDecl (abs.frontend.ast.DeltaDecl)1 Exp (abs.frontend.ast.Exp)1 FieldDecl (abs.frontend.ast.FieldDecl)1 FieldUse (abs.frontend.ast.FieldUse)1 MethodSig (abs.frontend.ast.MethodSig)1 VarDeclStmt (abs.frontend.ast.VarDeclStmt)1 DataTypeType (abs.frontend.typechecker.DataTypeType)1 KindedName (abs.frontend.typechecker.KindedName)1