use of org.abs_models.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 org.abs_models.frontend.ast.ReturnStmt in project abstools by abstools.
the class OtherAnalysisTests method awaitRewriteModule1.
@Test
public void awaitRewriteModule1() {
Model m = assertParse("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.TYPE_CHECK, Config.WITHOUT_DESUGARING_AFTER_TYPECHECK);
ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
Stmt stmt = c.getMethod(0).getBlock().getStmt(0);
ReturnStmt ret = (ReturnStmt) stmt;
assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
m = assertParse("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.TYPE_CHECK);
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());
}
use of org.abs_models.frontend.ast.ReturnStmt in project abstools by abstools.
the class TypingTest method testThisTyping.
@Test
public void testThisTyping() {
Model m = assertParse("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 org.abs_models.frontend.ast.ReturnStmt in project abstools by abstools.
the class TypeCheckerTest method classParamsMethodShadowsField.
@Test
public void classParamsMethodShadowsField() {
Model m = assertParse("class C(Bool b) { Bool m(Bool b) { 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(MethodSig.class));
assertThat(vu.getClass().getName(), vu, instanceOf(VarUse.class));
}
use of org.abs_models.frontend.ast.ReturnStmt in project abstools by abstools.
the class OriginalCallTest method originalCall3.
@Test
public void originalCall3() throws DeltaModellingException {
Model model = assertParse("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);
}
Aggregations