use of org.abs_models.frontend.ast.Model in project abstools by abstools.
the class VarResolutionTest method testNestedLetExp5.
@Test
public void testNestedLetExp5() {
Model m = assertParse("def Bool f(Bool b) = let (Bool x) = b in let (Bool x) = x in x;");
LetExp e = (LetExp) getFirstFunctionExpr(m);
LetExp e2 = (LetExp) e.getExp();
VarOrFieldDecl decl = e.getVar();
VarUse u = (VarUse) e2.getVal();
assertEquals(decl, u.getDecl());
}
use of org.abs_models.frontend.ast.Model in project abstools by abstools.
the class VarResolutionTest method testNestedLetExp2.
@Test
public void testNestedLetExp2() {
Model m = assertParse(" def Bool f(Bool b) = let (Bool x) = let (Bool x) = b in x in x;");
LetExp e = (LetExp) getFirstFunctionExpr(m);
VarOrFieldDecl decl = e.getVar();
VarUse u = (VarUse) e.getExp();
assertEquals(decl, u.getDecl());
}
use of org.abs_models.frontend.ast.Model in project abstools by abstools.
the class VarResolutionTest method testFunctionParam.
@Test
public void testFunctionParam() {
Model m = assertParse(" def Bool f(Bool b) = b;");
VarUse u = (VarUse) getFirstFunctionExpr(m);
ParamDecl d = (ParamDecl) u.getDecl();
assertEquals("b", d.getName());
}
use of org.abs_models.frontend.ast.Model in project abstools by abstools.
the class TraitTest method addAddModifierAtRuntimeBackComp.
@Test
public void addAddModifierAtRuntimeBackComp() {
Model model = assertParse("module M;" + "class C { Unit m(){skip;} }");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
MethodSig sig = AbsASTBuilderUtil.createMethodSig("n", AbsASTBuilderUtil.getUnit());
MethodImpl impl = new MethodImpl(sig, new Block(new List<>(), new List<>(new SkipStmt())));
AddMethodModifier opr = new AddMethodModifier(impl);
assertNotNull(opr.getMethodImpl());
ModifyClassModifier mcn = new ModifyClassModifier();
mcn.setName("M.C");
DeltaAccess acc = new DeltaAccess(cls.getModuleDecl().getName());
DeltaDecl dd = new DeltaDecl();
dd.setName("MyDelta");
dd.setImportedModule(acc);
dd.addModuleModifier(mcn);
mcn.addModifier(opr);
mcn.setParent(dd);
acc.setParent(dd);
opr.setParent(mcn);
sig.setParent(opr);
CompilationUnit cu = model.getCompilationUnitList().getChild(0);
cu.addDeltaDecl(dd);
dd.setParent(cu);
model.applyDelta(dd);
assertEquals(2, cls.getMethods().getNumChild());
}
use of org.abs_models.frontend.ast.Model in project abstools by abstools.
the class TraitTest method multipleNameResolveSteps.
@Test
public void multipleNameResolveSteps() {
Model model = assertParse("\n" + "module M;" + "export T;" + "trait T = { Unit myMethod(){ skip; } }" + "\n" + "module N;" + "export U;" + "import T from M;" + "trait U = T modifies {}" + "class C { uses U; }" + "\n" + "module O;" + "import U from N;" + "class D { uses U; }");
ClassDecl cls = (ClassDecl) findDecl(model, "N", "C");
ClassDecl cls2 = (ClassDecl) findDecl(model, "O", "D");
assertNotNull(cls);
assertTrue(cls.getMethods().getNumChild() == 0);
assertNotNull(cls2);
assertTrue(cls2.getMethods().getNumChild() == 0);
model.applyTraits();
assertTrue(cls.getMethods().getNumChild() == 1);
assertTrue(cls.getMethod(0).getMethodSig().getName().equals("myMethod"));
assertTrue(cls2.getMethods().getNumChild() == 1);
assertTrue(cls2.getMethod(0).getMethodSig().getName().equals("myMethod"));
}
Aggregations