Search in sources :

Example 1 with DataTypeType

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

the class ClassGenerator method generateParameterDescription.

private void generateParameterDescription(Type paramtype) {
    ecs.print("<<\"" + paramtype.getQualifiedName() + "\">>,");
    ecs.print(" {");
    if (paramtype.isDataType()) {
        DataTypeType paramdatatype = (DataTypeType) paramtype;
        if (paramdatatype.hasTypeArgs()) {
            String interp = "";
            for (Type typearg : paramdatatype.getTypeArgs()) {
                ecs.print(interp);
                interp = ", ";
                generateParameterDescription(typearg);
            }
        }
    }
    ecs.print(" }");
}
Also used : Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) DataTypeType(abs.frontend.typechecker.DataTypeType)

Example 2 with DataTypeType

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

the class TypeExtensionHelper method checkEq.

public void checkEq(Type lht, Type rht, ASTNode<?> origin) {
    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++) {
                checkEq(dtr.getTypeArg(i), dtl.getTypeArg(i), origin);
            }
        }
    }
    if (lht.isReferenceType() && rht.isReferenceType()) {
        for (TypeSystemExtension tse : obs) {
            tse.checkEq(rht, lht, origin);
        }
    }
}
Also used : DataTypeType(abs.frontend.typechecker.DataTypeType)

Example 3 with DataTypeType

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

Example 4 with DataTypeType

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

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

the class OtherAnalysisTests method awaitRewriteModule1.

@Test
public void awaitRewriteModule1() {
    Model.doAACrewrite = false;
    Model m = assertParseOk("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();}}");
    ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
    ReturnStmt ret = (ReturnStmt) c.getMethod(0).getBlock().getStmt(0);
    assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
    assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
    Model.doAACrewrite = true;
    m = assertParseOk("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.WITH_STD_LIB);
    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(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) ClassDecl(abs.frontend.ast.ClassDecl) VarDeclStmt(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) DataTypeType(abs.frontend.typechecker.DataTypeType) ReturnStmt(abs.frontend.ast.ReturnStmt) Stmt(abs.frontend.ast.Stmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

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