Search in sources :

Example 1 with ParametricFunctionDecl

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

the class TypingTest method functionTypeParams.

@Test
public void functionTypeParams() {
    Model m = assertParse(" def A f<A>(A a) = a ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    assertEquals(d.getTypeParameter(0), ((TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType()).getDecl());
}
Also used : ParametricFunctionDecl(org.abs_models.frontend.ast.ParametricFunctionDecl) Model(org.abs_models.frontend.ast.Model) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 2 with ParametricFunctionDecl

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

the class TypingTest method functionTypeArgs2.

@Test
public void functionTypeArgs2() {
    Model m = assertParse(" def Maybe<A> f<A>(Maybe<A> o) = o ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    assertEquals(d.getTypeUse().getType(), ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType());
}
Also used : ParametricFunctionDecl(org.abs_models.frontend.ast.ParametricFunctionDecl) Model(org.abs_models.frontend.ast.Model) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 3 with ParametricFunctionDecl

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

the class TypingTest method functionTypeArgs5.

@Test
public void functionTypeArgs5() {
    Model m = assertParse("def B nth<B>(List<B> list, Int n) = nth(tail(list), n-1) ; ");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    TypeParameterDecl typeParameter = d.getTypeParameter(0);
    TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    assertEquals(typeParameter.getName(), type.getDecl().getName());
}
Also used : TypeParameterDecl(org.abs_models.frontend.ast.TypeParameterDecl) ParametricFunctionDecl(org.abs_models.frontend.ast.ParametricFunctionDecl) TypeParameter(org.abs_models.frontend.typechecker.TypeParameter) Model(org.abs_models.frontend.ast.Model) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 4 with ParametricFunctionDecl

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

the class TypingTest method functionTypeArgs.

@Test
public void functionTypeArgs() {
    Model m = assertParse(" def Maybe<A> f<A>() = None ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    DataTypeType t = (DataTypeType) d.getTypeUse().getType();
    TypeParameter typeArg = (TypeParameter) t.getTypeArg(0);
    assertEquals(typeArg.getDecl(), d.getTypeParameter(0));
}
Also used : ParametricFunctionDecl(org.abs_models.frontend.ast.ParametricFunctionDecl) TypeParameter(org.abs_models.frontend.typechecker.TypeParameter) Model(org.abs_models.frontend.ast.Model) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 5 with ParametricFunctionDecl

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

the class TypingTest method functionTypeArgs4.

@Test
public void functionTypeArgs4() {
    Model m = assertParse(" data Foo<A> = Bar(A,Bool); " + "def Bool f<A>(Foo<A> o) = case o { Bar(a,b) => b; } ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    Type type = ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    assertEquals(m.getBoolType(), type);
}
Also used : ParametricFunctionDecl(org.abs_models.frontend.ast.ParametricFunctionDecl) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType) Type(org.abs_models.frontend.typechecker.Type) UnionType(org.abs_models.frontend.typechecker.UnionType) Model(org.abs_models.frontend.ast.Model) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

FrontendTest (org.abs_models.frontend.FrontendTest)6 Model (org.abs_models.frontend.ast.Model)6 ParametricFunctionDecl (org.abs_models.frontend.ast.ParametricFunctionDecl)6 Test (org.junit.Test)6 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)3 TypeParameter (org.abs_models.frontend.typechecker.TypeParameter)3 TypeParameterDecl (org.abs_models.frontend.ast.TypeParameterDecl)2 DataTypeType (org.abs_models.frontend.typechecker.DataTypeType)2 Type (org.abs_models.frontend.typechecker.Type)1 UnionType (org.abs_models.frontend.typechecker.UnionType)1