Search in sources :

Example 81 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class TypeCheckerTest method ticket414_futNeedsDataType1.

@Test
public void ticket414_futNeedsDataType1() {
    Model m = assertParse("module M; interface I {} { Fut<I> fi; }");
    assertFalse(m.hasErrors());
    Block b = m.getMainBlock();
    assertNotNull(b);
    VarDeclStmt s = (VarDeclStmt) b.getStmt(0);
    ParametricDataTypeUse u = (ParametricDataTypeUse) s.getVarDecl().getTypeUse();
    // Have:
    TypeUse tu = u.getParam(0);
    assertEquals("I", tu.getName());
    assertThat(tu, instanceOf(InterfaceTypeUse.class));
    assertThat(tu.getType(), instanceOf(InterfaceType.class));
    assertThat(tu.getDecl(), instanceOf(InterfaceDecl.class));
}
Also used : DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) InterfaceType(org.abs_models.frontend.typechecker.InterfaceType) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) Block(org.abs_models.frontend.ast.Block) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 82 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class TypeCheckerTest method classParamsRewrite2.

@Test
public void classParamsRewrite2() {
    Model m = assertParse("class C(Bool b) { Bool m(Bool x) { return x; } }");
    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));
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) KindedName(org.abs_models.frontend.typechecker.KindedName) VarUse(org.abs_models.frontend.ast.VarUse) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 83 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class TypeCheckerTest method test_Movecogto1.

@Test
public void test_Movecogto1() {
    Model m = assertParse("class C { Unit do() { movecogto 1; }}");
    SemanticConditionList errs = m.typeCheck();
    assertTrue(m.hasTypeErrors());
    Assert.assertEquals(ErrorMessage.EXPECTED_DC, errs.getFirstError().msg);
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 84 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class TypeCheckerTest method ticket414_futNeedsDataType2.

@Test
public void ticket414_futNeedsDataType2() {
    Model m = assertParse("module M; data I = I; { Fut<I> fi; }");
    assertFalse(m.hasErrors());
    Block b = m.getMainBlock();
    assertNotNull(b);
    VarDeclStmt s = (VarDeclStmt) b.getStmt(0);
    ParametricDataTypeUse u = (ParametricDataTypeUse) s.getVarDecl().getTypeUse();
    // Have:
    TypeUse tu = u.getParam(0);
    assertEquals("I", tu.getName());
    assertThat(tu, instanceOf(DataTypeUse.class));
}
Also used : DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) Block(org.abs_models.frontend.ast.Block) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 85 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class TreeUtilsTest method findChildrenListLazy.

@Test
public void findChildrenListLazy() {
    Model model = assertParse("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    List<PureExp> children = functionDecl.getFunctionDef().findChildren(PureExp.class, true);
    assertEquals(1, children.size());
    assertTrue(children.get(0) instanceof FnApp);
}
Also used : FnApp(org.abs_models.frontend.ast.FnApp) Model(org.abs_models.frontend.ast.Model) PureExp(org.abs_models.frontend.ast.PureExp) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) FrontendTest(org.abs_models.frontend.FrontendTest) 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