Search in sources :

Example 6 with DataTypeType

use of org.abs_models.frontend.typechecker.DataTypeType in project abstools by abstools.

the class OtherAnalysisTests method awaitRewriteModule1.

@Test
public void awaitRewriteModule1() {
    Model m = assertParse("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.TYPE_CHECK, Config.WITHOUT_DESUGARING_AFTER_TYPECHECK);
    ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
    Stmt stmt = c.getMethod(0).getBlock().getStmt(0);
    ReturnStmt ret = (ReturnStmt) stmt;
    assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
    assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
    m = assertParse("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.TYPE_CHECK);
    c = (ClassDecl) m.lookupModule("C").getDecl(0);
    Stmt s = c.getMethod(0).getBlock().getStmt(0);
    VarDeclStmt b = (VarDeclStmt) s;
    Type t = ((DataTypeType) b.getVarDecl().getType()).getTypeArg(0);
    assertEquals("A.X", t.getQualifiedName());
}
Also used : Type(org.abs_models.frontend.typechecker.Type) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType) ClassDecl(org.abs_models.frontend.ast.ClassDecl) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) Stmt(org.abs_models.frontend.ast.Stmt) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 7 with DataTypeType

use of org.abs_models.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(org.abs_models.frontend.typechecker.BoundedType) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType) Type(org.abs_models.frontend.typechecker.Type) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType)

Example 8 with DataTypeType

use of org.abs_models.frontend.typechecker.DataTypeType in project abstools by abstools.

the class TypeExtensionHelper method checkAssignable.

public void checkAssignable(Type adaptTo, AdaptDirection dir, Type rht, Type lht, ASTNode<?> n) {
    rht = resolveBoundedType(rht);
    if (lht.isDataType() && rht.isDataType()) {
        DataTypeType dtl = (DataTypeType) lht;
        DataTypeType dtr = (DataTypeType) rht;
        if (dtl.hasTypeArgs() && dtr.hasTypeArgs() && dtl.getTypeArgs().size() == dtr.getTypeArgs().size()) {
            for (int i = 0; i < dtl.getTypeArgs().size(); i++) {
                checkAssignable(adaptTo, dir, dtr.getTypeArg(i), dtl.getTypeArg(i), n);
            }
        }
    }
    if (lht.isReferenceType() && rht.isReferenceType()) {
        for (TypeSystemExtension tse : obs) {
            tse.checkAssignable(adaptTo, dir, rht, lht, n);
        }
    }
}
Also used : DataTypeType(org.abs_models.frontend.typechecker.DataTypeType)

Example 9 with DataTypeType

use of org.abs_models.frontend.typechecker.DataTypeType 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)

Aggregations

DataTypeType (org.abs_models.frontend.typechecker.DataTypeType)9 Type (org.abs_models.frontend.typechecker.Type)6 BoundedType (org.abs_models.frontend.typechecker.BoundedType)3 TypeParameter (org.abs_models.frontend.typechecker.TypeParameter)3 FrontendTest (org.abs_models.frontend.FrontendTest)2 Model (org.abs_models.frontend.ast.Model)2 Test (org.junit.Test)2 ABSString (org.abs_models.backend.java.lib.types.ABSString)1 TypeError (org.abs_models.frontend.analyser.TypeError)1 ClassDecl (org.abs_models.frontend.ast.ClassDecl)1 FieldDecl (org.abs_models.frontend.ast.FieldDecl)1 FnApp (org.abs_models.frontend.ast.FnApp)1 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)1 ParamDecl (org.abs_models.frontend.ast.ParamDecl)1 ParametricFunctionDecl (org.abs_models.frontend.ast.ParametricFunctionDecl)1 PureExp (org.abs_models.frontend.ast.PureExp)1 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)1 Stmt (org.abs_models.frontend.ast.Stmt)1 VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)1 VarOrFieldUse (org.abs_models.frontend.ast.VarOrFieldUse)1