Search in sources :

Example 6 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType in project abstools by abstools.

the class LocationTypeTests method fieldDecl.

@Test
public void fieldDecl() {
    Model m = assertParse("interface I { } class C { [Far] I i; }", WITH_STD_LIB);
    ClassDecl decl = getFirstClassDecl(m);
    LocationType ft = LocationTypeExtension.getLocationTypeFromAnnotations(decl.getField(0).getType());
    assertEquals(LocationType.FAR, ft);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) LocationType(abs.frontend.typechecker.locationtypes.LocationType) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 7 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType in project abstools by abstools.

the class LocationTypeTests method assertInfer.

private Model assertInfer(String code, LocationType expected, boolean fails) {
    Model m = assertParse(code, WITH_STD_LIB);
    // m.setLocationTypingEnabled(true);
    LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
    m.registerTypeSystemExtension(ltie);
    SemanticConditionList e = m.typeCheck();
    // System.out.println(ltie.getConstraints());
    assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage(), fails, e.containsErrors());
    // assertEquals(fails, generated == null);
    if (expected != null) {
        VarDeclStmt vds = ((VarDeclStmt) m.getMainBlock().getStmt(0));
        LocationType t = ltie.getResults().get(LocationTypeInferrerExtension.getLV(vds.getVarDecl().getType()));
        assertTrue(t.toString(), expected == LocationType.FAR ? t == LocationType.FAR || t.isParametricFar() : expected == t);
    }
    return m;
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) VarDeclStmt(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Example 8 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType in project abstools by abstools.

the class LocationTypeInferrerExtension method getFarTypes.

private List<LocationType> getFarTypes(ASTNode<?> originatingNode) {
    HasCogs node = null;
    String prefix = "";
    if (precision == LocationTypingPrecision.GLOBAL_FAR) {
        node = originatingNode.getCompilationUnit().getModel();
        prefix = "G";
    }
    if (precision == LocationTypingPrecision.COMPILATION_UNIT_LOCAL_FAR) {
        node = originatingNode.getCompilationUnit();
        prefix = "U";
    }
    if (precision == LocationTypingPrecision.MODULE_LOCAL_FAR) {
        node = originatingNode.getModuleDecl();
        prefix = "M";
    }
    if (precision == LocationTypingPrecision.CLASS_LOCAL_FAR) {
        Decl d = originatingNode.getContextDecl();
        if (d instanceof ClassDecl) {
            node = d;
            prefix = "C";
        }
        Block b = originatingNode.getContextBlock();
        if (b instanceof MainBlock) {
            node = b;
            prefix = "C";
        }
    }
    if (precision == LocationTypingPrecision.METHOD_LOCAL_FAR) {
        Block b = originatingNode.getContextBlock();
        if (b != null) {
            node = b;
            prefix = "M";
        }
    }
    if (node == null) {
        return Collections.emptyList();
    }
    final List<LocationType> e = farTypes.get(node);
    if (e != null) {
        return e;
    } else {
        List<LocationType> result = new ArrayList<>();
        int numberOfNewCogs = node.getNumberOfNewCogExpr();
        if (numberOfNewCogs > THRESHOLD) {
            numberOfNewCogs = THRESHOLD;
        }
        for (int i = 0; i < numberOfNewCogs; i++) {
            result.add(LocationType.createParametricFar(prefix + i));
        }
        farTypes.put(node, result);
        return result;
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) HasCogs(abs.frontend.analyser.HasCogs) Block(abs.frontend.ast.Block) MainBlock(abs.frontend.ast.MainBlock) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl) MainBlock(abs.frontend.ast.MainBlock) LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Example 9 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType in project abstools by abstools.

the class LocationTypeInferrerExtension method addNewVar.

private LocationTypeVariable addNewVar(Type t, ASTNode<?> originatingNode, ASTNode<?> typeNode) {
    // check consistency of annotations
    LocationTypeExtension.getLocationTypeFromAnnotations(t, originatingNode);
    LocationTypeVariable ltv = getLV(t);
    if (ltv != null)
        return ltv;
    LocationType lt = getLocationTypeOrDefault(t, originatingNode);
    LocationTypeVariable tv;
    if (lt.isInfer()) {
        tv = LocationTypeVariable.newVar(constraints, typeNode, true, getFarTypes(originatingNode), LocationTypeExtension.getLocationTypeFromAnnotations(t, originatingNode));
    } else if (lt.isFar() && precision != LocationTypingPrecision.BASIC) {
        tv = LocationTypeVariable.newVar(constraints, typeNode, true, getFarTypes(originatingNode), LocationTypeExtension.getLocationTypeFromAnnotations(t, originatingNode));
        @SuppressWarnings("unchecked") MultiListIterable<LocationType> fars = new MultiListIterable<>(Arrays.asList(LocationType.FAR), getFarTypes(originatingNode));
        constraints.add(Constraint.constConstraint(tv, fars, Constraint.MUST_HAVE));
    } else {
        tv = LocationTypeVariable.getFromLocationType(lt);
    }
    annotateVar(t, tv);
    return tv;
}
Also used : LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Example 10 with LocationType

use of abs.frontend.typechecker.locationtypes.LocationType in project abstools by abstools.

the class SatGenerator method initializeConstraints.

private void initializeConstraints() {
    for (LocationType lt : LocationType.ALLVISTYPES) {
        LocationTypeVariable cltv = LocationTypeVariable.getFromLocationType(lt);
        constraints.add(Constraint.declConstraint(cltv));
        constraints.add(Constraint.constConstraint(cltv, lt, Constraint.MUST_HAVE));
    }
}
Also used : LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Aggregations

LocationType (abs.frontend.typechecker.locationtypes.LocationType)13 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)6 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)6 Model (abs.frontend.ast.Model)5 FrontendTest (abs.frontend.FrontendTest)3 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)3 IOException (java.io.IOException)3 IPersistentPreferenceStore (org.eclipse.jface.preference.IPersistentPreferenceStore)3 Test (org.junit.Test)3 ClassDecl (abs.frontend.ast.ClassDecl)2 InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)2 HashMap (java.util.HashMap)2 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)1 HasCogs (abs.frontend.analyser.HasCogs)1 SemanticError (abs.frontend.analyser.SemanticError)1 ASTNode (abs.frontend.ast.ASTNode)1