Search in sources :

Example 6 with Type

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

the class TypeExtensionHelper method checkFnApp.

public void checkFnApp(FnApp f) {
    FunctionDecl decl = (FunctionDecl) f.getDecl();
    if (decl instanceof ParametricFunctionDecl) {
        HashMap<TypeParameter, Type> map = new HashMap<>();
        for (int i = 0; i < decl.getNumParam(); i++) {
            Type t = f.getParam(i).getType();
            Type arg = decl.getParam(i).getType();
            checkTypeParameter(map, t, arg, f.getParam(i));
        }
    } else {
        checkAssignable(null, decl, f);
    }
}
Also used : TypeParameter(abs.frontend.typechecker.TypeParameter) BoundedType(abs.frontend.typechecker.BoundedType) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) HashMap(java.util.HashMap)

Example 7 with Type

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

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

the class ProposalFactory method makeMethodSigProposal.

private CompletionProposal makeMethodSigProposal(MethodSig methodSig, String name) {
    String visibleName = ABSContentOutlineUtils.formatMethodSig(methodSig).toString();
    String replacement = name + "()";
    int cursorposition = name.length() + 1;
    Decl classorinterfacedecl = methodSig.getContextDecl();
    Type type = classorinterfacedecl.getType();
    visibleName += " -- " + type.getSimpleName();
    CompletionProposal proposal = new CompletionProposal(replacement, documentOffset, qualifier.length(), cursorposition, getImageForASTNode(methodSig), visibleName, null, getAdditionalProposalInfo(methodSig));
    return proposal;
}
Also used : Type(abs.frontend.typechecker.Type) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Example 9 with Type

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

the class ProposalFactory method addFieldUseProposals.

private void addFieldUseProposals(FieldUse accessNode) {
    if (accessNode == null) {
        throw new IllegalArgumentException("AccessNode may not be null!");
    }
    Type type = accessNode.getContextDecl().getType();
    addMethodProposal(type);
}
Also used : Type(abs.frontend.typechecker.Type)

Example 10 with Type

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

the class JavaGeneratorHelper method generateAsyncCall.

private static void generateAsyncCall(PrintStream stream, final String calleeString, final PureExp callee, final Type calleeType, final List<PureExp> args, final List<ParamDecl> params, final MethodSig sig, final List<Annotation> annotations) {
    final java.util.List<Type> paramTypes = sig.getTypes();
    stream.print(ABSRuntime.class.getName() + ".getCurrentRuntime().asyncCall(");
    String targetType = JavaBackend.getQualifiedString(calleeType);
    stream.println("new " + AbstractAsyncCallRT.class.getName() + "<" + targetType + ">(");
    stream.println("this,");
    if (callee instanceof ThisExp) {
        if (calleeString != null)
            stream.print(calleeString);
        else
            callee.generateJava(stream);
    } else {
        stream.print(ABSRuntime.class.getName() + ".checkForNull(");
        if (calleeString != null)
            stream.print(calleeString);
        else
            callee.generateJava(stream);
        stream.print(")");
    }
    stream.println(",");
    PureExp rtAttr;
    rtAttr = CompilerUtils.getAnnotationValueFromSimpleName(annotations, "Deadline");
    if (rtAttr == null)
        stream.print("new ABS.StdLib.Duration_InfDuration()");
    else
        rtAttr.generateJava(stream);
    stream.println(",");
    rtAttr = CompilerUtils.getAnnotationValueFromSimpleName(annotations, "Cost");
    if (rtAttr == null)
        stream.print("new ABS.StdLib.Duration_InfDuration()");
    else
        rtAttr.generateJava(stream);
    stream.println(",");
    rtAttr = CompilerUtils.getAnnotationValueFromSimpleName(annotations, "Critical");
    if (rtAttr == null)
        stream.print(ABSBool.class.getName() + ".FALSE");
    else
        rtAttr.generateJava(stream);
    stream.println(") {");
    int i = 0;
    for (Type t : paramTypes) {
        stream.println(JavaBackend.getQualifiedString(t) + " arg" + i + ";");
        i++;
    }
    generateTaskGetArgsMethod(stream, paramTypes.size());
    generateTaskInitMethod(stream, paramTypes);
    stream.println("public java.lang.String methodName() {");
    stream.println("return \"" + sig.getName() + "\";");
    stream.println("}");
    stream.println("public Object execute() {");
    stream.print("return target." + JavaBackend.getMethodName(sig.getName()) + "(");
    for (i = 0; i < paramTypes.size(); i++) {
        if (i > 0)
            stream.print(",");
        stream.println("arg" + i);
        if (paramTypes.get(i).isIntType())
            stream.print(".truncate()");
    }
    stream.println(");");
    stream.println("}");
    stream.print("}.init");
    if (args != null)
        JavaGeneratorHelper.generateArgs(stream, args, paramTypes);
    else
        JavaGeneratorHelper.generateParamArgs(stream, params);
    stream.println(")");
}
Also used : AbstractAsyncCallRT(abs.backend.java.lib.runtime.AbstractAsyncCallRT) Type(abs.frontend.typechecker.Type) ABSBool(abs.backend.java.lib.types.ABSBool) PureExp(abs.frontend.ast.PureExp) ThisExp(abs.frontend.ast.ThisExp)

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