Search in sources :

Example 16 with Type

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

the class TypeExtensionHelper method checkDataConstructorExp.

public void checkDataConstructorExp(DataConstructorExp e) {
    DataConstructor decl = (DataConstructor) e.getDecl();
    if (decl.getDataTypeDecl() instanceof ParametricDataTypeDecl) {
        HashMap<TypeParameter, Type> map = new HashMap<>();
        for (int i = 0; i < decl.getNumConstructorArg(); i++) {
            Type rht = e.getParam(i).getType();
            Type arg = decl.getConstructorArg(i).getType();
            checkTypeParameter(map, rht, arg, e.getParam(i));
        }
    }
}
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 17 with Type

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

the class TypeExtensionHelper method checkOverride.

@Override
public void checkOverride(MethodSig impl, MethodSig overriden) {
    for (TypeSystemExtension tse : obs) {
        tse.checkOverride(impl, overriden);
    }
    assert overriden.getParent().getParent() instanceof InterfaceDecl;
    Type expectedReturnType = overriden.getType();
    Type actualReturnType = impl.getType();
    checkAssignable(actualReturnType, expectedReturnType, impl);
    for (int i = 0; i < overriden.getNumParam(); i++) {
        Type texpected = overriden.getParam(i).getType();
        Type tactual = impl.getParam(i).getType();
        checkAssignable(texpected, tactual, impl);
    }
}
Also used : BoundedType(abs.frontend.typechecker.BoundedType) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType)

Example 18 with Type

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

the class TypeHierarchyContentProvider method getElements.

@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof Type) {
        Type type = (Type) inputElement;
        if (type.getDecl() != null) {
            return new Object[] { type.getDecl() };
        }
        if (type instanceof UnionType) {
            UnionType unionType = (UnionType) type;
            java.util.List<Object> result = new ArrayList<Object>();
            for (InterfaceType t : unionType.getTypes()) {
                for (Object e : getElements(t)) {
                    result.add(e);
                }
            }
            return result.toArray();
        }
    }
    return nothing;
}
Also used : UnionType(abs.frontend.typechecker.UnionType) Type(abs.frontend.typechecker.Type) InterfaceType(abs.frontend.typechecker.InterfaceType) UnionType(abs.frontend.typechecker.UnionType) InterfaceType(abs.frontend.typechecker.InterfaceType) ArrayList(java.util.ArrayList)

Example 19 with Type

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

the class StringBasedABSTestRunnerGenerator method generateTestClassImpl.

private Set<Type> generateTestClassImpl(InterfaceDecl inf, ClassDecl clazz, TestRunnerScriptBuilder main) {
    Set<Type> paramNames = new HashSet<>();
    Type dataType = generateDataPoints(inf, clazz, paramNames, main);
    String namePrefix = clazz.getName();
    int instance = 0;
    for (MethodSig method : getTestMethods(inf)) {
        boolean needdata = method.getParamList().iterator().hasNext();
        if (needdata) {
            if (dataType == null) {
                throw new IllegalStateException("Test method requires arguments but test class defines no data point");
            }
            /*
                 * a while loop over all data points
                 */
            String dataPointSet = dataPointSetName(clazz);
            // begin while
            main.append("while (hasNext(").append(dataPointSet).append(")) {").newLine().increaseIndent();
            main.append("Pair<Set<").append(dataType).append(">,").append(dataType).append("> nt = next(").append(dataPointSet).append(");").newLine();
            main.append(dataType).append(" ").append(dataValue).append(" = snd(nt);").newLine();
            main.append(dataPointSet).append(" = fst(nt);").newLine();
        }
        /*
             * Add those methods that are not ignored
             */
        if (!isIgnored(clazz, method)) {
            main.append("//Test cases for method ").append(method.getName()).newLine();
            String objectRef = uncap(namePrefix) + instance;
            main = newCog(main, inf, clazz, objectRef);
            generateAsyncTestCall(main, objectRef, method);
        }
        if (needdata) {
            // end while
            main.decreaseIndent().append("}").newLine();
        }
        instance++;
    }
    return paramNames;
}
Also used : MethodSig(abs.frontend.ast.MethodSig) Type(abs.frontend.typechecker.Type) HashSet(java.util.HashSet)

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