Search in sources :

Example 1 with TypeParameter

use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.

the class TypingTest method functionTypeArgs5.

@Test
public void functionTypeArgs5() {
    Model m = assertParseOkStdLib("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(abs.frontend.ast.TypeParameterDecl) ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) TypeParameter(abs.frontend.typechecker.TypeParameter) Model(abs.frontend.ast.Model) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 2 with TypeParameter

use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.

the class TypeExtensionHelper method checkFnApp.

public void checkFnApp(FnApp f) {
    FunctionDecl decl = (FunctionDecl) f.getDecl();
    if (decl instanceof ParametricFunctionDecl) {
        HashMap<TypeParameter, Type> map = new HashMap<>();
        for (int i = 0; i < decl.getNumParam(); i++) {
            Type t = f.getParam(i).getType();
            Type arg = decl.getParam(i).getType();
            checkTypeParameter(map, t, arg, f.getParam(i));
        }
    } else {
        checkAssignable(null, decl, f);
    }
}
Also used : TypeParameter(abs.frontend.typechecker.TypeParameter) BoundedType(abs.frontend.typechecker.BoundedType) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) HashMap(java.util.HashMap)

Example 3 with TypeParameter

use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.

the class TypeExtensionHelper method checkTypeParameter.

private void checkTypeParameter(HashMap<TypeParameter, Type> map, Type rht, Type lht, ASTNode<?> origin) {
    rht = resolveBoundedType(rht);
    if (rht.isBoundedType())
        return;
    if (lht.isTypeParameter() && rht.isReferenceType()) {
        TypeParameter typeParam = (TypeParameter) lht;
        Type lt = map.get(typeParam);
        if (lt != null) {
            checkEq(lt, rht, origin);
        } else {
            map.put(typeParam, rht);
        }
    } else if (lht.isDataType()) {
        DataTypeType argdt = (DataTypeType) lht;
        if (argdt.hasTypeArgs()) {
            DataTypeType dt = (DataTypeType) rht;
            for (int i = 0; i < dt.numTypeArgs(); i++) {
                checkTypeParameter(map, dt.getTypeArg(i), argdt.getTypeArg(i), origin);
            }
        }
    } else if (lht.isReferenceType()) {
        checkEq(lht, rht, origin);
    }
}
Also used : TypeParameter(abs.frontend.typechecker.TypeParameter) BoundedType(abs.frontend.typechecker.BoundedType) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) DataTypeType(abs.frontend.typechecker.DataTypeType)

Example 4 with TypeParameter

use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.

the class TypingTest method functionTypeArgs.

@Test
public void functionTypeArgs() {
    Model m = assertParseOkStdLib(" 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(abs.frontend.ast.ParametricFunctionDecl) TypeParameter(abs.frontend.typechecker.TypeParameter) Model(abs.frontend.ast.Model) DataTypeType(abs.frontend.typechecker.DataTypeType) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 5 with TypeParameter

use of abs.frontend.typechecker.TypeParameter in project abstools by abstools.

the class TypingTest method functionTypeArgs3.

@Test
public void functionTypeArgs3() {
    Model m = assertParseOkStdLib(" def A f<A>(Maybe<A> o) = case o { Just(a) => a; } ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    TypeParameterDecl typeParameter = d.getTypeParameter(0);
    TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    TypeParameterDecl decl = type.getDecl();
    assertEquals(typeParameter, decl);
}
Also used : TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) TypeParameter(abs.frontend.typechecker.TypeParameter) Model(abs.frontend.ast.Model) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Aggregations

TypeParameter (abs.frontend.typechecker.TypeParameter)6 DataTypeType (abs.frontend.typechecker.DataTypeType)4 FrontendTest (abs.frontend.FrontendTest)3 Model (abs.frontend.ast.Model)3 ParametricFunctionDecl (abs.frontend.ast.ParametricFunctionDecl)3 BoundedType (abs.frontend.typechecker.BoundedType)3 Type (abs.frontend.typechecker.Type)3 Test (org.junit.Test)3 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)2 TypeParameterDecl (abs.frontend.ast.TypeParameterDecl)2 HashMap (java.util.HashMap)2