Search in sources :

Example 6 with TypeError

use of abs.frontend.analyser.TypeError in project abstools by abstools.

the class ClassKindTypeExtension method checkNewExp.

@Override
public void checkNewExp(NewExp e) {
    ClassDecl d = (ClassDecl) e.lookup(new KindedName(Kind.CLASS, e.getClassName()));
    List<Annotation> anns = AnnotationHelper.getAnnotationsOfType(d.getAnnotations(), "ABS.StdLib.ClassKindAnnotation");
    if (!anns.isEmpty()) {
        String name = ((DataConstructorExp) anns.get(0).getValue()).getDecl().getName();
        if (e.hasLocal()) {
            if (name.equals("COG")) {
                errors.add(new TypeError(e, ErrorMessage.CLASSKIND_PLAIN, d.getName()));
            }
        } else {
            if (!name.equals("COG")) {
                errors.add(new TypeError(e, ErrorMessage.CLASSKIND_COG, d.getName()));
            }
        }
    }
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) TypeError(abs.frontend.analyser.TypeError) KindedName(abs.frontend.typechecker.KindedName) Annotation(abs.frontend.ast.Annotation)

Example 7 with TypeError

use of abs.frontend.analyser.TypeError in project abstools by abstools.

the class HttpExportChecker method checkDataTypeDecl.

@Override
public void checkDataTypeDecl(DataTypeDecl decl) {
    for (DataConstructor c : decl.getDataConstructors()) {
        Set<String> names = new HashSet<>();
        for (ConstructorArg ca : c.getConstructorArgs()) {
            ASTNode arg = null;
            String key = null;
            abs.frontend.ast.List<Annotation> ann = ca.getTypeUse().getAnnotations();
            PureExp keyann = CompilerUtils.getAnnotationValueFromName(ann, "ABS.StdLib.HTTPName");
            if (keyann != null) {
                if (!(keyann instanceof StringLiteral)) {
                    errors.add(new TypeError(keyann, ErrorMessage.WRONG_HTTPNAME, keyann.getType()));
                } else {
                    key = ((StringLiteral) keyann).getContent();
                    arg = keyann;
                }
            }
            if (ca.hasSelectorName() && key == null) {
                key = ca.getSelectorName().toString();
                arg = ca.getSelectorName();
            }
            if (key != null) {
                if (names.contains(key)) {
                    errors.add(new SemanticWarning(arg, ErrorMessage.DUPLICATE_HTTPNAME, key));
                } else {
                    names.add(key);
                }
            }
        }
    }
}
Also used : abs.frontend.ast(abs.frontend.ast) TypeError(abs.frontend.analyser.TypeError) SemanticWarning(abs.frontend.analyser.SemanticWarning) HashSet(java.util.HashSet)

Example 8 with TypeError

use of abs.frontend.analyser.TypeError in project abstools by abstools.

the class DeltaSamplesTest method test_ticket329.

@Test
public void test_ticket329() throws Exception {
    Model m = assertParseFileOk("tests/abssamples/deltas/bug329.abs", true);
    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(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) TypeError(abs.frontend.analyser.TypeError) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 9 with TypeError

use of abs.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("tests/abssamples/deltas/bug329.abs", true);
    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());
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) TypeError(abs.frontend.analyser.TypeError) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 10 with TypeError

use of abs.frontend.analyser.TypeError in project abstools by abstools.

the class LocationTypeExtension method getLocationTypeFromAnnotations.

public static LocationType getLocationTypeFromAnnotations(Type t, ASTNode<?> originatingNode) {
    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);
            }
        }
    }
    /*
        if (originatingNode != null && originatingNode instanceof ConstructorArg) {
            if (res == null || !res.isSomewhere()) {
                throw new LocationTypeCheckerException(new TypeError(originatingNode,ErrorMessage.LOCATION_TYPE_DATACONSTR_MUST_BE_SOMEWHERE, new String[0]));
            }
        }*/
    return res;
}
Also used : TypeAnnotation(abs.frontend.typechecker.TypeAnnotation) TypeError(abs.frontend.analyser.TypeError)

Aggregations

TypeError (abs.frontend.analyser.TypeError)17 FrontendTest (abs.frontend.FrontendTest)2 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)2 SemanticWarning (abs.frontend.analyser.SemanticWarning)2 FieldDecl (abs.frontend.ast.FieldDecl)2 Model (abs.frontend.ast.Model)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 ErrorMessage (abs.frontend.analyser.ErrorMessage)1 SemanticError (abs.frontend.analyser.SemanticError)1 abs.frontend.ast (abs.frontend.ast)1 Annotation (abs.frontend.ast.Annotation)1 ClassDecl (abs.frontend.ast.ClassDecl)1 FnApp (abs.frontend.ast.FnApp)1 FunctionDecl (abs.frontend.ast.FunctionDecl)1 ParamDecl (abs.frontend.ast.ParamDecl)1 PureExp (abs.frontend.ast.PureExp)1 TypedVarOrFieldDecl (abs.frontend.ast.TypedVarOrFieldDecl)1 VarOrFieldDecl (abs.frontend.ast.VarOrFieldDecl)1 VarOrFieldUse (abs.frontend.ast.VarOrFieldUse)1