Search in sources :

Example 36 with Model

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());
}
Also used : VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) LetExp(org.abs_models.frontend.ast.LetExp) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 37 with Model

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());
}
Also used : VarOrFieldDecl(org.abs_models.frontend.ast.VarOrFieldDecl) LetExp(org.abs_models.frontend.ast.LetExp) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 38 with Model

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());
}
Also used : ParamDecl(org.abs_models.frontend.ast.ParamDecl) Model(org.abs_models.frontend.ast.Model) VarUse(org.abs_models.frontend.ast.VarUse) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 39 with Model

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());
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) DeltaAccess(org.abs_models.frontend.ast.DeltaAccess) AddMethodModifier(org.abs_models.frontend.ast.AddMethodModifier) Model(org.abs_models.frontend.ast.Model) Block(org.abs_models.frontend.ast.Block) List(org.abs_models.frontend.ast.List) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) SkipStmt(org.abs_models.frontend.ast.SkipStmt) ModifyClassModifier(org.abs_models.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 40 with Model

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"));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Aggregations

Model (org.abs_models.frontend.ast.Model)268 Test (org.junit.Test)227 FrontendTest (org.abs_models.frontend.FrontendTest)101 ClassDecl (org.abs_models.frontend.ast.ClassDecl)72 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)34 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)29 ABSTest (org.abs_models.ABSTest)22 ProductDecl (org.abs_models.frontend.ast.ProductDecl)17 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)15 HashSet (java.util.HashSet)13 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 PrintStream (java.io.PrintStream)12 Product (org.abs_models.frontend.ast.Product)11 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 VarUse (org.abs_models.frontend.ast.VarUse)11 Feature (org.abs_models.frontend.ast.Feature)10 File (java.io.File)9 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)9 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)9 KindedName (org.abs_models.frontend.typechecker.KindedName)9