Search in sources :

Example 1 with Type

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

the class MaudeCompilerHelper method emitParameterValueList.

public static void emitParameterValueList(PrintStream stream, abs.frontend.ast.List<PureExp> params, java.util.List<Type> paramTypes) {
    if (params.getNumChild() == 0) {
        stream.print("emp ");
    } else {
        boolean inlist = false;
        stream.print("(");
        for (int i = 0; i < params.getNumChild(); i++) {
            PureExp param = params.getChild(i);
            Type t = paramTypes.get(i);
            boolean needConversion = t.isIntType() && param.getType().isRatType();
            if (inlist)
                stream.print(":: ");
            else
                inlist = true;
            if (needConversion)
                stream.print("\"ABS.StdLib.truncate\"(");
            param.generateMaude(stream);
            if (needConversion)
                stream.print(")");
        }
        stream.print(") ");
    }
}
Also used : Type(abs.frontend.typechecker.Type) PureExp(abs.frontend.ast.PureExp)

Example 2 with Type

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

the class StringBasedABSTestRunnerGenerator method generateMainBlock.

private TestRunnerScriptBuilder generateMainBlock(TestRunnerScriptBuilder imports) {
    TestRunnerScriptBuilder builder = new TestRunnerScriptBuilder();
    builder.increaseIndent();
    Set<Type> paramNames = new HashSet<>();
    builder.append("Set<Fut<Unit>> ").append(futs).append(" = EmptySet;").newLine();
    builder.append("Fut<Unit> ").append(fut).append(";").newLine();
    for (InterfaceDecl key : tests.keySet()) {
        builder.append("//Test cases for ").append(key.getType().getQualifiedName()).newLine();
        for (ClassDecl clazz : tests.get(key)) {
            builder.append("//Test cases for implementation ").append(clazz.getName()).newLine();
            paramNames.addAll(generateTestClassImpl(key, clazz, builder));
        }
    }
    generateWaitSync(builder);
    generateImports(imports, paramNames);
    return builder;
}
Also used : Type(abs.frontend.typechecker.Type) ClassDecl(abs.frontend.ast.ClassDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) HashSet(java.util.HashSet)

Example 3 with Type

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

the class StringBasedABSTestRunnerGenerator method generateDataPoints.

/**
 * Generates data points for test class {@code clazz}
 *
 * @param inf
 * @param clazz
 * @param paramNames
 * @param main
 * @return The data type the set return type is parametric on, null if
 *         {@code inf} does not define a data point method or {@code clazz}
 *         does not implement such method.
 */
private Type generateDataPoints(InterfaceDecl inf, ClassDecl clazz, Set<Type> paramNames, TestRunnerScriptBuilder main) {
    MethodSig dataPoint = findDataPoints(inf);
    if (dataPoint == null) {
        return null;
    }
    /*
         * It must be a Set of data
         */
    Type data = ((ParametricDataTypeUse) dataPoint.getReturnType()).getParams().iterator().next().getType();
    /*
         * make sure the return type can be resolved TODO this needs to be
         * resolved recursively
         */
    paramNames.add(data);
    /*
         * create an object in the same cog as main for retrieving the data
         * points
         */
    String objName = uncap(clazz.getName()) + "dataPoint";
    String dataSet = dataPointSetName(clazz);
    newObj(main, inf, clazz, objName, false);
    main.append(dataPoint.getReturnType()).append(" ").append(dataSet).append(" = ").append(objName).append(".").append(dataPoint.getName()).append("();").newLine();
    return data;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) Type(abs.frontend.typechecker.Type)

Example 4 with Type

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

the class TypingTest method functionTypeArgs4.

@Test
public void functionTypeArgs4() {
    Model m = assertParseOkStdLib(" data Foo<A> = Bar(A,Bool); " + "def Bool f<A>(Foo<A> o) = case o { Bar(a,b) => b; } ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    Type type = ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    assertEquals(m.getBoolType(), type);
}
Also used : ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) UnionType(abs.frontend.typechecker.UnionType) Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 5 with Type

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

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