Search in sources :

Example 6 with DataTypeType

use of abs.frontend.typechecker.DataTypeType 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 7 with DataTypeType

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

the class TypeExtensionHelper method annotateType.

public void annotateType(Type t, ASTNode<?> originatingNode, ASTNode<?> typeNode) {
    if (t.isDataType()) {
        DataTypeType dt = (DataTypeType) t;
        if (dt.hasTypeArgs()) {
            ParametricDataTypeUse pu = null;
            // typeNode maybe a type synonym
            if (typeNode instanceof ParametricDataTypeUse)
                pu = (ParametricDataTypeUse) typeNode;
            int i = 0;
            for (Type ta : dt.getTypeArgs()) {
                ASTNode<?> childTypeNode = null;
                if (pu != null)
                    childTypeNode = pu.getParam(i);
                annotateType(ta, originatingNode, childTypeNode);
                i++;
            }
        }
    }
    if (t.isReferenceType() || t.isNullType()) {
        for (TypeSystemExtension tse : obs) {
            tse.annotateType(t, originatingNode, typeNode);
        }
    }
}
Also used : BoundedType(abs.frontend.typechecker.BoundedType) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) DataTypeType(abs.frontend.typechecker.DataTypeType)

Aggregations

DataTypeType (abs.frontend.typechecker.DataTypeType)7 Type (abs.frontend.typechecker.Type)4 FrontendTest (abs.frontend.FrontendTest)2 Model (abs.frontend.ast.Model)2 BoundedType (abs.frontend.typechecker.BoundedType)2 TypeParameter (abs.frontend.typechecker.TypeParameter)2 Test (org.junit.Test)2 ClassDecl (abs.frontend.ast.ClassDecl)1 ParametricFunctionDecl (abs.frontend.ast.ParametricFunctionDecl)1 ReturnStmt (abs.frontend.ast.ReturnStmt)1 Stmt (abs.frontend.ast.Stmt)1 VarDeclStmt (abs.frontend.ast.VarDeclStmt)1