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());
}
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());
}
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);
}
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("}");
}
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");
}
Aggregations