Search in sources :

Example 11 with Type

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

the class FrontendTest method getTypeOfNthAssignment.

protected Type getTypeOfNthAssignment(Model m, int n) {
    int count = 0;
    for (Stmt s : m.getMainBlock().getStmts()) {
        Type t = null;
        if (s instanceof AssignStmt) {
            AssignStmt as = (AssignStmt) s;
            t = as.getValue().getType();
        } else if (s instanceof VarDeclStmt) {
            VarDeclStmt vd = (VarDeclStmt) s;
            if (vd.getVarDecl().hasInitExp()) {
                t = vd.getVarDecl().getInitExp().getType();
            }
        }
        if (t != null) {
            count++;
            if (count == n) {
                return t;
            }
        }
    }
    return null;
}
Also used : Type(abs.frontend.typechecker.Type) AssignStmt(abs.frontend.ast.AssignStmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) AssignStmt(abs.frontend.ast.AssignStmt) Stmt(abs.frontend.ast.Stmt) ExpressionStmt(abs.frontend.ast.ExpressionStmt)

Example 12 with Type

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

Example 13 with Type

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

the class JavaGeneratorHelper method generateTaskInitMethod.

private static void generateTaskInitMethod(PrintStream stream, final java.util.List<Type> paramTypes) {
    int i;
    stream.print("public " + abs.backend.java.lib.runtime.AsyncCall.class.getName() + "<?> init(");
    i = 0;
    for (Type t : paramTypes) {
        if (i > 0)
            stream.print(",");
        stream.print(JavaBackend.getQualifiedString(t) + " _arg" + i);
        i++;
    }
    stream.println(") {");
    for (i = 0; i < paramTypes.size(); i++) {
        stream.println("arg" + i + " = _arg" + i + ";");
    }
    stream.println("return this;");
    stream.println("}");
}
Also used : Type(abs.frontend.typechecker.Type) AbstractAsyncCall(abs.backend.java.lib.runtime.AbstractAsyncCall) AwaitAsyncCall(abs.frontend.ast.AwaitAsyncCall) AsyncCall(abs.frontend.ast.AsyncCall)

Example 14 with Type

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

the class TypeExtensionHelper method checkAssignable.

public void checkAssignable(Type callee, HasParams params, ASTNode<?> n) {
    java.util.List<Type> paramsTypes = params.getTypes();
    for (int i = 0; i < paramsTypes.size(); i++) {
        Type argType = paramsTypes.get(i);
        PureExp exp = ((HasActualParams) n).getParams().getChild(i);
        checkAssignable(callee, AdaptDirection.TO, exp.getType(), argType, n);
    }
}
Also used : BoundedType(abs.frontend.typechecker.BoundedType) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType)

Example 15 with Type

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

Type (abs.frontend.typechecker.Type)19 DataTypeType (abs.frontend.typechecker.DataTypeType)9 BoundedType (abs.frontend.typechecker.BoundedType)6 TypeParameter (abs.frontend.typechecker.TypeParameter)3 FrontendTest (abs.frontend.FrontendTest)2 ClassDecl (abs.frontend.ast.ClassDecl)2 MethodSig (abs.frontend.ast.MethodSig)2 Model (abs.frontend.ast.Model)2 PureExp (abs.frontend.ast.PureExp)2 Stmt (abs.frontend.ast.Stmt)2 VarDeclStmt (abs.frontend.ast.VarDeclStmt)2 UnionType (abs.frontend.typechecker.UnionType)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 AbstractAsyncCall (abs.backend.java.lib.runtime.AbstractAsyncCall)1 AbstractAsyncCallRT (abs.backend.java.lib.runtime.AbstractAsyncCallRT)1 ABSBool (abs.backend.java.lib.types.ABSBool)1 AssignStmt (abs.frontend.ast.AssignStmt)1 AsyncCall (abs.frontend.ast.AsyncCall)1