Search in sources :

Example 1 with ReturnStmt

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

the class TypingTest method testContextDecl.

@Test
public void testContextDecl() {
    Model m = assertParseOk("class C implements I { I m() { return this; } } interface I { }");
    ClassDecl d = (ClassDecl) m.getDecls().iterator().next();
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(d, s.getRetExp().getContextDecl());
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 2 with ReturnStmt

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

the class TypingTest method testThisTyping.

@Test
public void testThisTyping() {
    Model m = assertParseOk("class C implements I { I m() { return this; } } interface I { }");
    ClassDecl d = (ClassDecl) m.lookupModule("UnitTest").getDecl(0);
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(m.lookupModule("UnitTest").getDecl(1), ((UnionType) s.getRetExp().getType()).getType(0).getDecl());
}
Also used : UnionType(abs.frontend.typechecker.UnionType) ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 3 with ReturnStmt

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

the class OriginalCallTest method originalCall3.

@Test
public void originalCall3() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Int one() { return 1; } }" + "delta D; uses M;" + "modifies class C { modifies Int one() { Int x = original(); return x + 1; } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertEquals(1, cls.getMethods().getNumChild());
    DeltaDecl delta1 = findDelta(model, "D");
    // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1)));
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta1)));
    assertEquals(2, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("one"));
    // make sure method has the right body
    assertTrue(cls.getMethod(0).getBlock().getStmt(1) instanceof ReturnStmt);
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("one$ORIGIN_core"));
    // make sure method has the right body
    assertTrue(cls.getMethod(1).getBlock().getStmt(0) instanceof ReturnStmt);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test)

Example 4 with ReturnStmt

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

the class JavaGeneratorHelper method generateMethodBody.

public static void generateMethodBody(PrintStream stream, final MethodImpl m, boolean isFliMethod) {
    boolean addReturn = false;
    if (m.getMethodSig().getReturnType().getType().isUnitType()) {
        if (m.getBlock().getNumStmt() == 0 || (!(m.getBlock().getStmt(m.getBlock().getNumStmt() - 1) instanceof ReturnStmt))) {
            addReturn = true;
        }
    }
    stream.println(" {");
    stream.println("__ABS_checkSameCOG(); ");
    if (!isFliMethod && m.isForeign()) {
        stream.print("return this.");
        stream.print(FLI_METHOD_PREFIX + JavaBackend.getMethodName(m.getMethodSig().getName()));
        JavaGeneratorHelper.generateParamArgs(stream, m.getMethodSig().getParams());
        stream.println(";");
    } else {
        stream.println("if (__ABS_getRuntime().debuggingEnabled()) {");
        stream.println(Task.class.getName() + "<?> __ABS_currentTask = __ABS_getRuntime().getCurrentTask();");
        stream.println("__ABS_currentTask.newStackFrame(this, \"" + m.getMethodSig().getName() + "\");");
        for (ParamDecl d : m.getMethodSig().getParams()) {
            stream.print("__ABS_currentTask.setLocalVariable(");
            stream.println("\"" + d.getName() + "\"," + d.getName() + ");");
        }
        stream.println("}");
        m.getBlock().generateJava(stream, addReturn);
    }
    stream.println("}");
}
Also used : ParamDecl(abs.frontend.ast.ParamDecl) ReturnStmt(abs.frontend.ast.ReturnStmt)

Example 5 with ReturnStmt

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

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