Search in sources :

Example 16 with TypeError

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

the class TypeCheckerHelper method checkForDuplicatesOfVarDecl.

/**
 * checks whether the local variable v was already defined in the current function
 */
public static void checkForDuplicatesOfVarDecl(SemanticConditionList e, VarDeclStmt v) {
    String varName = v.getVarDecl().getName();
    VarOrFieldDecl otherVar = v.lookupVarOrFieldName(varName, false);
    if (otherVar != null && v.inSameMethodOrBlock(otherVar)) {
        e.add(new TypeError(v, ErrorMessage.VARIABLE_ALREADY_DECLARED, varName));
    }
}
Also used : TypeError(abs.frontend.analyser.TypeError)

Example 17 with TypeError

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

the class TypeCheckerHelper method typeCheckDeltaClause.

public static void typeCheckDeltaClause(DeltaClause clause, Map<String, DeltaDecl> deltaNames, Set<String> definedFeatures, SemanticConditionList e) {
    /* Does the delta exist? */
    final Deltaspec spec = clause.getDeltaspec();
    if (!deltaNames.containsKey(spec.getDeltaID()))
        e.add(new TypeError(spec, ErrorMessage.NAME_NOT_RESOLVABLE, spec.getDeltaID()));
    else {
        DeltaDecl dd = deltaNames.get(spec.getDeltaID());
        if (dd.getNumParam() != spec.getNumDeltaparam()) {
            e.add(new TypeError(spec, ErrorMessage.WRONG_NUMBER_OF_ARGS, dd.getNumParam(), spec.getNumDeltaparam()));
        } else {
            for (int i = 0; i < dd.getNumParam(); i++) {
                DeltaParamDecl formal = dd.getParam(i);
                Deltaparam actual = spec.getDeltaparam(i);
                // TODO: W00t?!
                if (actual instanceof Const) {
                    Value a = ((Const) actual).getValue();
                    if (!formal.accepts(a)) {
                        e.add(new TypeError(a, ErrorMessage.CANNOT_ASSIGN, a.getName(), formal.getType().getSimpleName()));
                    }
                }
            }
        }
    }
    /* Do the referenced features exist? */
    if (clause.hasAppCond()) {
        clause.getAppCond().typeCheck(definedFeatures, e);
    }
    if (clause.hasFromAppCond()) {
        clause.getFromAppCond().typeCheck(definedFeatures, e);
    }
    /* What about deltas mentioned in the 'after' clause? */
    for (DeltaID did : clause.getAfterDeltaIDs()) {
        if (!deltaNames.containsKey(did.getName())) {
            e.add(new TypeError(did, ErrorMessage.NAME_NOT_RESOLVABLE, did.getName()));
        }
    }
}
Also used : 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