Search in sources :

Example 1 with AdaptDirection

use of org.abs_models.frontend.typechecker.ext.AdaptDirection in project abstools by abstools.

the class ConstraintSolver method resolveAdapt.

/**
 * Resolve one adapt constrained
 * @param resolved - Already resolved vars and their type
 * @param adapt - The constraint to resolve
 */
private void resolveAdapt(Map<LocationTypeVar, LocationType> resolved, Constraint.Adapt adapt) {
    LocationTypeVar expected = getRewritten(adapt.expected);
    LocationTypeVar actual = getRewritten(adapt.actual);
    AdaptDirection dir = adapt.dir;
    LocationTypeVar adaptTo = getRewritten(adapt.adaptTo);
    ASTNode<?> node = adapt.node;
    if (!resolved.containsKey(adaptTo)) {
        keep(adapt);
        return;
    }
    if (adaptTo == NEAR) {
        add(Constraint.eq(expected, actual, node));
        return;
    }
    if (adaptTo == SOMEWHERE) {
        add(Constraint.eq(expected, SOMEWHERE, node));
        return;
    }
    if (adaptTo == FAR) {
        LocationTypeVar res;
        if (actual == NEAR) {
            res = FAR;
        } else if (actual == SOMEWHERE) {
            res = SOMEWHERE;
        } else if (actual == BOTTOM) {
            errors.add(new LocationTypeInferException(new TypeError(node, ErrorMessage.LOCATION_TYPE_CALL_ON_BOTTOM, new String[0])));
            return;
        } else if (actual == FAR) {
            res = SOMEWHERE;
        } else {
            keep(adapt);
            return;
        }
        add(Constraint.eq(expected, res, node));
        return;
    }
    keep(adapt);
}
Also used : TypeError(org.abs_models.frontend.analyser.TypeError) AdaptDirection(org.abs_models.frontend.typechecker.ext.AdaptDirection) LocationTypeVar(org.abs_models.frontend.typechecker.locationtypes.LocationTypeVar)

Aggregations

TypeError (org.abs_models.frontend.analyser.TypeError)1 AdaptDirection (org.abs_models.frontend.typechecker.ext.AdaptDirection)1 LocationTypeVar (org.abs_models.frontend.typechecker.locationtypes.LocationTypeVar)1