Search in sources :

Example 1 with TypeParameterDecl

use of abs.frontend.ast.TypeParameterDecl 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 TypeParameterDecl

use of abs.frontend.ast.TypeParameterDecl in project abstools by abstools.

the class PureExpressionBuilder method importType.

void importType(Decl decl) {
    importModules.add(decl.getModuleDecl().getName());
    if (decl instanceof TypeSynDecl) {
        decl = resolveTypeSynonym((TypeSynDecl) decl);
        importModules.add(decl.getModuleDecl().getName());
    }
    // import type parameters
    if (decl instanceof ParametricDataTypeDecl) {
        for (TypeParameterDecl t : ((ParametricDataTypeDecl) decl).getTypeParameters()) {
            Decl type = getDecl(model, Decl.class, namePred(t.getName()));
            if (type == null) {
                // most likely a generic type
                continue;
            }
            importType(type);
        }
    }
}
Also used : TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) AbsASTBuilderUtil.getDecl(abs.backend.tests.AbsASTBuilderUtil.getDecl) DataTypeDecl(abs.frontend.ast.DataTypeDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) Decl(abs.frontend.ast.Decl) TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) ParametricDataTypeDecl(abs.frontend.ast.ParametricDataTypeDecl) TypeSynDecl(abs.frontend.ast.TypeSynDecl)

Example 3 with TypeParameterDecl

use of abs.frontend.ast.TypeParameterDecl 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)

Example 4 with TypeParameterDecl

use of abs.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(abs.frontend.ast.TypeParameterDecl) HasTypeParameters(abs.frontend.ast.HasTypeParameters) ABSValue(abs.backend.java.lib.types.ABSValue)

Aggregations

TypeParameterDecl (abs.frontend.ast.TypeParameterDecl)4 FrontendTest (abs.frontend.FrontendTest)2 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)2 Model (abs.frontend.ast.Model)2 ParametricFunctionDecl (abs.frontend.ast.ParametricFunctionDecl)2 TypeParameter (abs.frontend.typechecker.TypeParameter)2 Test (org.junit.Test)2 ABSValue (abs.backend.java.lib.types.ABSValue)1 AbsASTBuilderUtil.getDecl (abs.backend.tests.AbsASTBuilderUtil.getDecl)1 DataTypeDecl (abs.frontend.ast.DataTypeDecl)1 Decl (abs.frontend.ast.Decl)1 HasTypeParameters (abs.frontend.ast.HasTypeParameters)1 InterfaceDecl (abs.frontend.ast.InterfaceDecl)1 ParametricDataTypeDecl (abs.frontend.ast.ParametricDataTypeDecl)1 TypeSynDecl (abs.frontend.ast.TypeSynDecl)1