Search in sources :

Example 1 with TypeParameterDecl

use of org.abs_models.frontend.ast.TypeParameterDecl 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 2 with TypeParameterDecl

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

the class JavaGeneratorHelper method generateTypeParameters.

public static void generateTypeParameters(PrintStream stream, Decl dtd, boolean plusExtends) {
    List<TypeParameterDecl> typeParams = null;
    if (dtd instanceof HasTypeParameters) {
        typeParams = ((HasTypeParameters) dtd).getTypeParameters();
    } else
        return;
    if (typeParams.getNumChild() > 0) {
        stream.print("<");
        boolean isFirst = true;
        for (TypeParameterDecl d : typeParams) {
            if (isFirst)
                isFirst = false;
            else
                stream.print(",");
            stream.print(d.getName());
            if (plusExtends)
                stream.print(" extends " + ABSValue.class.getName());
        }
        stream.print(">");
    }
}
Also used : TypeParameterDecl(org.abs_models.frontend.ast.TypeParameterDecl) HasTypeParameters(org.abs_models.frontend.ast.HasTypeParameters) ABSValue(org.abs_models.backend.java.lib.types.ABSValue)

Example 3 with TypeParameterDecl

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

the class TypingTest method functionTypeArgs3.

@Test
public void functionTypeArgs3() {
    Model m = assertParse(" 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(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)

Aggregations

TypeParameterDecl (org.abs_models.frontend.ast.TypeParameterDecl)3 FrontendTest (org.abs_models.frontend.FrontendTest)2 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)2 Model (org.abs_models.frontend.ast.Model)2 ParametricFunctionDecl (org.abs_models.frontend.ast.ParametricFunctionDecl)2 TypeParameter (org.abs_models.frontend.typechecker.TypeParameter)2 Test (org.junit.Test)2 ABSValue (org.abs_models.backend.java.lib.types.ABSValue)1 HasTypeParameters (org.abs_models.frontend.ast.HasTypeParameters)1