Search in sources :

Example 21 with TypeError

use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.

the class LocationTypeExtension method checkAssignable.

@Override
public void checkAssignable(Type adaptTo, AdaptDirection dir, Type rht, Type lht, ASTNode<?> n) {
    LocationType lhlt = getLocationType(lht);
    LocationType rhlt = getLocationType(rht);
    LocationType adaptedRhlt = rhlt;
    if (adaptTo != null) {
        adaptedRhlt = rhlt.adaptTo(getLocationType(adaptTo), dir);
    }
    if (!adaptedRhlt.isSubtypeOf(lhlt)) {
        errors.add(new TypeError(n, ErrorMessage.LOCATION_TYPE_CANNOT_ASSIGN, adaptedRhlt.toString(), lhlt.toString()));
    }
}
Also used : TypeError(org.abs_models.frontend.analyser.TypeError)

Example 22 with TypeError

use of org.abs_models.frontend.analyser.TypeError 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)

Example 23 with TypeError

use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.

the class ConstraintSolver method resolveEq.

/**
 * Resolve one eq constrained
 * @param resolved - Already resolved vars and their type
 * @param eq - The constraint to resolve
 */
private void resolveEq(Map<LocationTypeVar, LocationType> resolved, Constraint.Eq eq) {
    LocationTypeVar expected = getRewritten(eq.expected);
    LocationTypeVar actual = getRewritten(eq.actual);
    ASTNode<?> node = eq.node;
    if (expected == actual)
        return;
    if (expected.isLocationType() && actual.isLocationType()) {
        errors.add(new LocationTypeInferException(new TypeError(node, ErrorMessage.LOCATION_TYPE_CANNOT_ASSIGN, expected.toString(), actual.toString())));
        return;
    }
    if (expected.isLocationType()) {
        rewrite(actual, expected);
        resolved.put(actual, expected.asLocationType());
        return;
    }
    if (actual.isLocationType()) {
        rewrite(expected, actual);
        resolved.put(expected, actual.asLocationType());
        return;
    }
    rewrite(expected, actual);
}
Also used : TypeError(org.abs_models.frontend.analyser.TypeError) LocationTypeVar(org.abs_models.frontend.typechecker.locationtypes.LocationTypeVar)

Example 24 with TypeError

use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.

the class NullCheckerExtension method checkVarDeclStmt.

@Override
public void checkVarDeclStmt(VarDeclStmt varDeclStmt) {
    VarDecl d = varDeclStmt.getVarDecl();
    Type t = d.getType();
    setAnnotatedType(t, varDeclStmt);
    if (!shouldHaveNullableType(t))
        return;
    NullableType nt = getNullableTypeDefault(t);
    if (nt == NullableType.Nonnull && !d.hasInitExp()) {
        errors.add(new TypeError(varDeclStmt, ErrorMessage.NULLABLE_TYPE_MISMATCH, NullableType.Null.toString(), nt.toString()));
    }
}
Also used : Type(org.abs_models.frontend.typechecker.Type) TypeError(org.abs_models.frontend.analyser.TypeError)

Example 25 with TypeError

use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.

the class DeltaSamplesTest method test_ticket329.

@Test
public void test_ticket329() throws Exception {
    Model m = assertParseFileOk("abssamples/deltas/bug329.abs");
    SemanticConditionList errs = m.typeCheck();
    /* We are expecting a missing delta in product M.PL: */
    assertThat(errs.getFirstError(), instanceOf(TypeError.class));
    TypeError te = (TypeError) errs.getFirstError();
    Assert.assertEquals(ErrorMessage.NAME_NOT_RESOLVABLE, te.msg);
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) TypeError(org.abs_models.frontend.analyser.TypeError) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

TypeError (org.abs_models.frontend.analyser.TypeError)25 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)3 Model (org.abs_models.frontend.ast.Model)3 LocationTypeVar (org.abs_models.frontend.typechecker.locationtypes.LocationTypeVar)3 java.util (java.util)2 HashSet (java.util.HashSet)2 FrontendTest (org.abs_models.frontend.FrontendTest)2 ErrorMessage (org.abs_models.frontend.analyser.ErrorMessage)2 SemanticWarning (org.abs_models.frontend.analyser.SemanticWarning)2 org.abs_models.frontend.ast (org.abs_models.frontend.ast)2 FieldDecl (org.abs_models.frontend.ast.FieldDecl)2 PureExp (org.abs_models.frontend.ast.PureExp)2 Type (org.abs_models.frontend.typechecker.Type)2 TypeAnnotation (org.abs_models.frontend.typechecker.TypeAnnotation)2 AdaptDirection (org.abs_models.frontend.typechecker.ext.AdaptDirection)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SemanticError (org.abs_models.frontend.analyser.SemanticError)1