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);
}
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;
}
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;
}
}
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;
}
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));
}
}
Aggregations