Search in sources :

Example 1 with SemanticError

use of abs.frontend.analyser.SemanticError 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.qualifiedName();
    if (deprecatedConstructors.contains(cname) && !(cname.startsWith(p.getModuleDecl().getName()))) {
        e.add(new SemanticWarning(p, ErrorMessage.DEPRECATED_CONSTRUCTOR, c.qualifiedName()));
    }
    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(abs.frontend.analyser.SemanticError) TypeError(abs.frontend.analyser.TypeError) SemanticWarning(abs.frontend.analyser.SemanticWarning)

Example 2 with SemanticError

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

the class IncrementalModelBuilder method typeCheckModel.

public synchronized SemanticConditionList typeCheckModel(IProgressMonitor monitor, boolean locationTypeChecking, String defaultloctype, String locationTypePrecision, boolean checkProducts) throws NoModelException, TypecheckInternalException {
    if (model == null)
        throw new NoModelException();
    if (model.hasParserErrors())
        // don't typecheck if the model has parsererrors
        return new SemanticConditionList();
    // throw new TypecheckInternalException(new Exception("Model has parser errors!"));
    // model.flushCache();
    flushAll(model);
    model.getTypeExt().clearTypeSystemExtensions();
    if (locationTypeChecking) {
        LocationType defaultLocType = LocationType.createFromName(defaultloctype);
        LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
        this.ltie = ltie;
        ltie.setDefaultType(defaultLocType);
        ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(locationTypePrecision));
        model.registerTypeSystemExtension(ltie);
    }
    try {
        SemanticConditionList semerrors = model.getErrors();
        /* Don't typecheck with semerrors, it might trip up. */
        if (!semerrors.containsErrors())
            semerrors = model.typeCheck();
        /* Check products for errors.
			 * Only the first error is reported (if any), on the product AST-node.
			 * TODO: May be time-consuming for large projects, hence the checkProducts-switch.
			 *       Also could use a timer to switch off if it becomes excessive.
			 * TODO: Use Eclipse's nested markers to show ALL contained errors?
			 * TODO: The outline could indicate the broken product as well.
			 */
        if (!semerrors.containsErrors() && checkProducts) {
            // arbitrary value
            monitor = new SubProgressMonitor(monitor, 10);
            monitor.beginTask("Checking products", model.getProductDecls().size());
            for (ProductDecl p : model.getProductDecls()) {
                monitor.subTask("Checking " + p.getName());
                Model m2 = model.treeCopyNoTransform();
                m2.flushTreeCache();
                try {
                    m2.flattenForProduct(p);
                    SemanticConditionList p_errs = m2.typeCheck();
                    if (p_errs.containsErrors()) {
                        // Only show first error, on product
                        semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), p_errs.getFirstError().getMessage()));
                    }
                } catch (WrongProgramArgumentException e) {
                    semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                } catch (DeltaModellingException e) {
                    /* We we have a better location for error reporting? */
                    final ASTNode<?> loc;
                    if (e instanceof DeltaModellingWithNodeException)
                        loc = ((DeltaModellingWithNodeException) e).getNode();
                    else
                        loc = p;
                    if (e.getDelta() == null)
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                    else
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT_WITH_DELTA, p.getName(), e.getDelta().getName(), e.getMessage()));
                }
            }
            monitor.done();
        }
        return semerrors;
    } catch (TypeCheckerException e) {
        return new SemanticConditionList(e);
    } catch (RuntimeException e) {
        throw new TypecheckInternalException(e);
    }
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) DeltaModellingWithNodeException(abs.frontend.delta.DeltaModellingWithNodeException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) TypeCheckerException(abs.frontend.typechecker.TypeCheckerException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticError(abs.frontend.analyser.SemanticError) Model(abs.frontend.ast.Model) ASTNode(abs.frontend.ast.ASTNode) LocationType(abs.frontend.typechecker.locationtypes.LocationType) DeltaModellingException(abs.frontend.delta.DeltaModellingException)

Example 3 with SemanticError

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

the class ProductLineAnalysisHelper method wellFormedProductLine.

/*
     * Check that the 'productline' declaration is well formed. This means...
     * - after clauses do not reference any deltaIDs that do not have their own delta clause
     * - deltas named in the productline correspond to actual DeltaDecls
     */
protected static boolean wellFormedProductLine(ProductLine pl, SemanticConditionList e) {
    boolean wellformed = true;
    // preliminaries
    final Set<String> declaredDeltas = pl.getModel().getDeltaDeclsMap().keySet();
    final Set<String> referencedDeltas = new HashSet<>(pl.getDeltaClauses().getNumChild());
    for (DeltaClause clause : pl.getDeltaClauses()) referencedDeltas.add(clause.getDeltaspec().getDeltaID());
    // check
    for (DeltaClause clause : pl.getDeltaClauses()) {
        // ensure deltas in the productline correspond to actual DeltaDecls
        if (!declaredDeltas.contains(clause.getDeltaspec().getDeltaID())) {
            e.add(new SemanticError(clause, ErrorMessage.NO_DELTA_DECL, clause.getDeltaspec().getDeltaID()));
            wellformed = false;
        }
        // ensure 'after' clauses do not reference any deltaIDs that do not have their own delta clause
        for (DeltaID id : clause.getAfterDeltaIDs()) {
            String afterID = id.getName();
            if (!referencedDeltas.contains(afterID)) {
                e.add(new SemanticError(clause, ErrorMessage.MISSING_DELTA_CLAUSE_ERROR, afterID, pl.getName()));
                wellformed = false;
            }
        }
    }
    return wellformed;
}
Also used : SemanticError(abs.frontend.analyser.SemanticError) HashSet(java.util.HashSet)

Aggregations

SemanticError (abs.frontend.analyser.SemanticError)3 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)1 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 SemanticWarning (abs.frontend.analyser.SemanticWarning)1 TypeError (abs.frontend.analyser.TypeError)1 ASTNode (abs.frontend.ast.ASTNode)1 Model (abs.frontend.ast.Model)1 ProductDecl (abs.frontend.ast.ProductDecl)1 DeltaModellingException (abs.frontend.delta.DeltaModellingException)1 DeltaModellingWithNodeException (abs.frontend.delta.DeltaModellingWithNodeException)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)1 HashSet (java.util.HashSet)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1