Search in sources :

Example 1 with ErrorMessage

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

the class TypeCheckerHelper method checkForDuplicateDecls.

public static void checkForDuplicateDecls(ModuleDecl mod, SemanticConditionList errors) {
    Map<KindedName, ResolvedName> duplicateNames = new HashMap<>();
    Map<KindedName, ResolvedName> names = getVisibleNames(mod, duplicateNames);
    for (KindedName n : duplicateNames.keySet()) {
        ResolvedName rn = names.get(n);
        ResolvedName origrn = duplicateNames.get(n);
        ErrorMessage msg = null;
        String location = "";
        Decl decl = null;
        if (origrn instanceof ResolvedDeclName) {
            decl = ((ResolvedDeclName) origrn).getDecl();
        } else if (origrn instanceof ResolvedAmbigiousName) {
            decl = ((AmbiguousDecl) ((ResolvedAmbigiousName) origrn).getDecl()).getAlternative().get(0);
        }
        if (decl != null && !decl.getFileName().equals(Main.UNKNOWN_FILENAME)) {
            location = " at " + decl.getFileName() + ":" + decl.getStartLine() + ":" + decl.getStartColumn();
        }
        switch(n.getKind()) {
            case CLASS:
                msg = ErrorMessage.DUPLICATE_CLASS_NAME;
                break;
            case FUN:
                msg = ErrorMessage.DUPLICATE_FUN_NAME;
                break;
            case PARTIAL_FUN:
                msg = ErrorMessage.DUPLICATE_PARTIAL_FUN_NAME;
                break;
            case DATA_CONSTRUCTOR:
                msg = ErrorMessage.DUPLICATE_CONSTRUCTOR;
                break;
            case TYPE_DECL:
                msg = ErrorMessage.DUPLICATE_TYPE_DECL;
                break;
            case TRAIT_DECL:
                msg = ErrorMessage.DUPLICATE_TRAIT_NAME;
                break;
            case MODULE:
                // doesn't happen, no modules within modules
                assert false;
                break;
            default:
                // detect if we added a new KindedName.Kind
                assert false;
                break;
        }
        errors.add(new TypeError(rn.getDecl(), msg, n.getName(), location));
    }
}
Also used : TypeError(org.abs_models.frontend.analyser.TypeError) ErrorMessage(org.abs_models.frontend.analyser.ErrorMessage)

Aggregations

ErrorMessage (org.abs_models.frontend.analyser.ErrorMessage)1 TypeError (org.abs_models.frontend.analyser.TypeError)1