use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class DeltaSamplesTest method test_ticket329_missingLineNo.
@Test
public void test_ticket329_missingLineNo() 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);
Assert.assertEquals(10, te.getLine());
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class ConstraintSolver method resolveSub.
/**
* Resolve one sub constrained
* @param resolved - Already resolved vars and their type
* @param sub - The constraint to resolve
*/
private void resolveSub(Map<LocationTypeVar, LocationType> resolved, Constraint.Sub sub) {
LocationTypeVar expected = getRewritten(sub.expected);
LocationTypeVar actual = getRewritten(sub.actual);
ASTNode<?> node = sub.node;
if (expected == actual) {
return;
}
if (expected.isLocationType() && actual.isLocationType()) {
if (!expected.asLocationType().isSubtypeOf(actual.asLocationType())) {
errors.add(new LocationTypeInferException(new TypeError(node, ErrorMessage.LOCATION_TYPE_CANNOT_ASSIGN, expected.toString(), actual.toString())));
}
return;
}
if (actual == BOTTOM) {
throw new IllegalArgumentException("Cannot resolve constraint " + expected + " <: BOTTOM");
}
if (actual == NEAR) {
add(Constraint.eq(expected, NEAR, node));
return;
}
if (actual == FAR) {
add(Constraint.eq(expected, FAR, node));
return;
}
if (actual == SOMEWHERE) {
// Useless
return;
}
if (expected == SOMEWHERE) {
add(Constraint.eq(actual, SOMEWHERE, node));
return;
}
if (expected == BOTTOM) {
// Useless
return;
}
List<Constraint> expectedCs = constraints.get(expected);
List<Constraint> actualCs = constraints.get(actual);
if (expectedCs.size() <= 1 && actualCs.size() <= 1) {
add(Constraint.eq(expected, actual, node));
return;
}
if (actualCs.stream().filter(c -> c.isSub() && ((Constraint.Sub) c).actual == actual).count() == 1) {
add(Constraint.eq(expected, actual, node));
return;
}
if (expected == NEAR && actualCs.stream().anyMatch(c -> c.isSub() && ((Constraint.Sub) c).expected == FAR)) {
add(Constraint.eq(actual, SOMEWHERE, node));
return;
}
// Search for reverse (actual <: expected)
// Search in smaller list
List<Constraint> toSearch = expectedCs.size() < actualCs.size() ? expectedCs : actualCs;
if (toSearch.stream().anyMatch(c -> c.isSub() && ((Constraint.Sub) c).expected == actual && ((Constraint.Sub) c).actual == expected)) {
add(Constraint.eq(expected, actual, node));
return;
}
keep(sub);
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class NullCheckerExtension method checkClassDecl.
@Override
public void checkClassDecl(ClassDecl decl) {
for (ParamDecl p : decl.getParams()) {
setAnnotatedType(p.getType(), p);
}
List<FieldDecl> nonNullFields = new ArrayList<>();
for (FieldDecl f : decl.getFields()) {
setAnnotatedType(f.getType(), f);
if (f.nonnull() && !f.hasInitExp()) {
nonNullFields.add(f);
}
}
if (nonNullFields.isEmpty())
return;
if (!decl.hasInitBlock()) {
errors.add(new TypeError(nonNullFields.get(0), ErrorMessage.NULLABLE_TYPE_MISMATCH, NullableType.Nonnull.toString(), NullableType.Nullable.toString()));
return;
}
// Get all fields that are nonNull at the end of the init block
BitVec<VarOrFieldDecl> out = decl.getInitBlock().exit().nonnull_in();
for (FieldDecl f : nonNullFields) {
if (!out.contains(f)) {
errors.add(new TypeError(f, ErrorMessage.NULLABLE_TYPE_MISMATCH, NullableType.Nonnull.toString(), NullableType.Nullable.toString()));
}
}
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class NullCheckerExtension method getNullableTypeFromAnnotation.
public static NullableType getNullableTypeFromAnnotation(Type t) {
NullableType res = null;
for (TypeAnnotation an : t.getTypeAnnotations()) {
if (an.getType().getQualifiedName().equals("ABS.StdLib.NullableType")) {
DataConstructorExp de = (DataConstructorExp) an.getValue();
String name = de.getDecl().getName();
if (res != null) {
throw new NullCheckerException(new TypeError(an.getValue(), ErrorMessage.NULLABLE_TYPE_MULTIPLE, new String[0]));
} else {
if (!shouldHaveNullableType(t)) {
throw new NullCheckerException(new TypeError(an.getValue(), ErrorMessage.NULLABLE_TYPE_ONLY_REF_OR_FUT, t.toString()));
}
res = NullableType.fromName(name);
}
}
}
return res;
}
use of org.abs_models.frontend.analyser.TypeError in project abstools by abstools.
the class LocationTypeExtension method getLocationTypeFromAnnotations.
public static LocationType getLocationTypeFromAnnotations(Type t) {
LocationType res = null;
for (TypeAnnotation an : t.getTypeAnnotations()) {
if (an.getType().getQualifiedName().equals("ABS.StdLib.LocationType")) {
DataConstructorExp de = (DataConstructorExp) an.getValue();
String name = de.getDecl().getName();
if (res != null) {
throw new LocationTypeCheckerException(new TypeError(an.getValue(), ErrorMessage.LOCATION_TYPE_MULTIPLE, new String[0]));
} else {
res = LocationType.createFromName(name);
}
}
}
return res;
}
Aggregations