Search in sources :

Example 1 with SemanticWarning

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

the class NullCheckerExtension method checkCondition.

public void checkCondition(PureExp cond) {
    VarOrFieldDecl d = cond.testsNotNull();
    if (d != null) {
        if (cond.nonnull_in().contains(d)) {
            errors.add(new SemanticWarning(cond, ErrorMessage.NULLABLE_TYPE_COND_ALWAYS_SAME, "true"));
        }
        if (cond.null_in().contains(d)) {
            errors.add(new SemanticWarning(cond, ErrorMessage.NULLABLE_TYPE_COND_ALWAYS_SAME, "false"));
        }
        return;
    }
    d = cond.testsNull();
    if (d != null) {
        if (cond.nonnull_in().contains(d)) {
            errors.add(new SemanticWarning(cond, ErrorMessage.NULLABLE_TYPE_COND_ALWAYS_SAME, "false"));
        }
        if (cond.null_in().contains(d)) {
            errors.add(new SemanticWarning(cond, ErrorMessage.NULLABLE_TYPE_COND_ALWAYS_SAME, "true"));
        }
    }
}
Also used : SemanticWarning(org.abs_models.frontend.analyser.SemanticWarning)

Example 2 with SemanticWarning

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

the class TypeCheckerHelper method typeCheck.

public static void typeCheck(ConstructorPattern p, SemanticConditionList e, Type t) {
    DataConstructor c = p.getDataConstructor();
    if (c == null) {
        e.add(new SemanticError(p, ErrorMessage.CONSTRUCTOR_NOT_RESOLVABLE, p.getConstructor()));
        return;
    }
    String cname = c.getQualifiedName();
    if (deprecatedConstructors.contains(cname) && !(cname.startsWith(p.getModuleDecl().getName()))) {
        e.add(new SemanticWarning(p, ErrorMessage.DEPRECATED_CONSTRUCTOR, cname));
    }
    if (c.getNumConstructorArg() != p.getNumParam()) {
        e.add(new TypeError(p, ErrorMessage.WRONG_NUMBER_OF_ARGS, c.getNumConstructorArg(), p.getNumParam()));
        return;
    }
    // isExceptionType only for clarity, since exceptions are datatypes
    assert t.isDataType() || t.isExceptionType() : t;
    if (!t.isExceptionType()) {
        if (!t.getDecl().equals(c.getDataTypeDecl())) {
            e.add(new TypeError(p, ErrorMessage.WRONG_CONSTRUCTOR, t.toString(), p.getConstructor()));
        }
    }
    Type myType = p.getType();
    if (!(myType instanceof DataTypeType))
        return;
    if (!(t instanceof DataTypeType)) {
        e.add(new TypeError(p, ErrorMessage.TYPE_MISMATCH, myType, t));
        return;
    }
    DataTypeType myDType = (DataTypeType) myType;
    DataTypeType otherType = (DataTypeType) t;
    if (!myDType.getDecl().equals(otherType.getDecl())) {
        e.add(new TypeError(p, ErrorMessage.TYPE_MISMATCH, myDType, t));
        return;
    }
    typeCheckMatchingParamsPattern(e, p, c);
}
Also used : SemanticError(org.abs_models.frontend.analyser.SemanticError) TypeError(org.abs_models.frontend.analyser.TypeError) SemanticWarning(org.abs_models.frontend.analyser.SemanticWarning)

Example 3 with SemanticWarning

use of org.abs_models.frontend.analyser.SemanticWarning 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;
            List<Annotation> ann = ca.getTypeUse().getAnnotations();
            PureExp keyann = AnnotationHelper.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 : TypeError(org.abs_models.frontend.analyser.TypeError) SemanticWarning(org.abs_models.frontend.analyser.SemanticWarning) HashSet(java.util.HashSet)

Example 4 with SemanticWarning

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

the class MainBlockChecker method checkModel.

@Override
public void checkModel(Model model) {
    int nMainBlocks = 0;
    for (CompilationUnit u : model.getCompilationUnits()) {
        for (ModuleDecl m : u.getModuleDecls()) {
            if (m.hasBlock()) {
                nMainBlocks = nMainBlocks + 1;
            }
        }
    }
    if (nMainBlocks == 0) {
        CompilationUnit c = model.getCompilationUnit(0);
        errors.add(new SemanticWarning(c, ErrorMessage.MAIN_BLOCK_NOT_FOUND, "dummy string to keep constructor happy"));
    } else if (nMainBlocks > 1) {
        Block b = model.getMainBlock();
        String moduleName = ((ModuleDecl) (b.getParent().getParent())).getName();
        for (CompilationUnit u : model.getCompilationUnits()) {
            for (ModuleDecl m : u.getModuleDecls()) {
                if (m.hasBlock() && m.getBlock() != b) {
                    errors.add(new SemanticWarning(m.getBlock(), ErrorMessage.MAIN_BLOCK_AMBIGUOUS, moduleName));
                }
            }
        }
    }
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) Block(org.abs_models.frontend.ast.Block) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) SemanticWarning(org.abs_models.frontend.analyser.SemanticWarning)

Aggregations

SemanticWarning (org.abs_models.frontend.analyser.SemanticWarning)4 TypeError (org.abs_models.frontend.analyser.TypeError)2 HashSet (java.util.HashSet)1 SemanticError (org.abs_models.frontend.analyser.SemanticError)1 Block (org.abs_models.frontend.ast.Block)1 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)1 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)1