Search in sources :

Example 1 with TypeAnnotation

use of org.abs_models.frontend.typechecker.TypeAnnotation in project abstools by abstools.

the class AnnotationTests method assertHasLocAnnotation.

private void assertHasLocAnnotation(Type t, String s) {
    List<TypeAnnotation> anns = t.getTypeAnnotations();
    TypeAnnotation a = anns.get(0);
    assertEquals("LocationType", a.getType().getSimpleName());
    assertEquals(s, ((DataConstructorExp) a.getValue()).getDecl().getName());
}
Also used : TypeAnnotation(org.abs_models.frontend.typechecker.TypeAnnotation) DataConstructorExp(org.abs_models.frontend.ast.DataConstructorExp)

Example 2 with TypeAnnotation

use of org.abs_models.frontend.typechecker.TypeAnnotation 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;
}
Also used : TypeAnnotation(org.abs_models.frontend.typechecker.TypeAnnotation) TypeError(org.abs_models.frontend.analyser.TypeError)

Example 3 with TypeAnnotation

use of org.abs_models.frontend.typechecker.TypeAnnotation 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;
}
Also used : TypeAnnotation(org.abs_models.frontend.typechecker.TypeAnnotation) TypeError(org.abs_models.frontend.analyser.TypeError)

Aggregations

TypeAnnotation (org.abs_models.frontend.typechecker.TypeAnnotation)3 TypeError (org.abs_models.frontend.analyser.TypeError)2 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1