Search in sources :

Example 1 with SafetyInterval

use of edu.umn.cs.crisys.safety.safety.SafetyInterval in project AMASE by loonwerks.

the class FaultASTBuilder method addSafetyEqInterval.

/**
 * Add saftey eq intervals to the safetyEqAsserts and safetyEqVars lists.
 *
 * @param fault	The fault with these interval eq stmts.
 * @param stmt	The IntervalEq statement
 */
private void addSafetyEqInterval(Fault fault, IntervalEq stmt) {
    Expr lhsIdExpr = new IdExpr(stmt.getLhs_int().getName());
    SafetyInterval iv = stmt.getInterv();
    BinaryOp leftOp = ((iv instanceof ClosedSafetyInterval) || (iv instanceof OpenLeftSafetyInterval)) ? BinaryOp.GREATEREQUAL : BinaryOp.GREATER;
    BinaryOp rightOp = ((iv instanceof ClosedSafetyInterval) || (iv instanceof OpenLeftSafetyInterval)) ? BinaryOp.LESSEQUAL : BinaryOp.LESS;
    Expr leftSideExpr = new BinaryExpr(lhsIdExpr, leftOp, builder.doSwitch(iv.getLow()));
    Expr rightSideExpr = new BinaryExpr(lhsIdExpr, rightOp, builder.doSwitch(iv.getHigh()));
    Expr expr = new BinaryExpr(leftSideExpr, BinaryOp.AND, rightSideExpr);
    fault.safetyEqAsserts.add(new AgreeStatement("", expr, stmt));
    // Get type in Lustre/JKind format
    com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef typeDef = AgreeTypeSystem.typeDefFromType(stmt.getLhs_int().getType());
    Type type = SafetyUtil.getLustreType(typeDef);
    // Throw exception if type is neither real nor int
    if ((type == null) || (type.toString().equals("bool"))) {
        new SafetyException("Interval statement types can only be real or int. The problem interval is called: " + stmt.getLhs_int().getName() + ".");
    }
    // Add to safetyEqVars list
    fault.safetyEqVars.add(new AgreeVar(stmt.getLhs_int().getName(), type, this.agreeNode.reference, this.agreeNode.compInst));
}
Also used : OpenLeftSafetyInterval(edu.umn.cs.crisys.safety.safety.OpenLeftSafetyInterval) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) Expr(jkind.lustre.Expr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) ClosedSafetyInterval(edu.umn.cs.crisys.safety.safety.ClosedSafetyInterval) ClosedSafetyInterval(edu.umn.cs.crisys.safety.safety.ClosedSafetyInterval) OpenLeftSafetyInterval(edu.umn.cs.crisys.safety.safety.OpenLeftSafetyInterval) SafetyInterval(edu.umn.cs.crisys.safety.safety.SafetyInterval) BinaryOp(jkind.lustre.BinaryOp)

Example 2 with SafetyInterval

use of edu.umn.cs.crisys.safety.safety.SafetyInterval in project AMASE by loonwerks.

the class DurationStatementImpl method basicSetInterv.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetInterv(SafetyInterval newInterv, NotificationChain msgs) {
    SafetyInterval oldInterv = interv;
    interv = newInterv;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SafetyPackage.DURATION_STATEMENT__INTERV, oldInterv, newInterv);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) SafetyInterval(edu.umn.cs.crisys.safety.safety.SafetyInterval)

Example 3 with SafetyInterval

use of edu.umn.cs.crisys.safety.safety.SafetyInterval in project AMASE by loonwerks.

the class IntervalEqImpl method basicSetInterv.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetInterv(SafetyInterval newInterv, NotificationChain msgs) {
    SafetyInterval oldInterv = interv;
    interv = newInterv;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SafetyPackage.INTERVAL_EQ__INTERV, oldInterv, newInterv);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) SafetyInterval(edu.umn.cs.crisys.safety.safety.SafetyInterval)

Example 4 with SafetyInterval

use of edu.umn.cs.crisys.safety.safety.SafetyInterval in project AMASE by loonwerks.

the class SafetyValidator method checkIntervalEqStatement.

/**
 * Interval eq stmts:
 * Checks:
 * - Only primitive types supported for intervals.
 * - The interval type matches high and low parameters of interval.
 * - High and low parameters of interval are same type.
 * @param intervalEq
 */
@Check(CheckType.FAST)
public void checkIntervalEqStatement(IntervalEq intervalEq) {
    Arg arg = intervalEq.getLhs_int();
    String typeName = "";
    SafetyInterval interval = intervalEq.getInterv();
    Expr low = interval.getLow();
    Expr high = interval.getHigh();
    if (arg.getType() instanceof PrimType) {
        typeName = ((PrimType) arg.getType()).getName();
        if (typeName.equalsIgnoreCase("bool")) {
            error(arg, "Boolean intervals are not allowed. Only real or int intervals are supported.");
        }
    } else {
        error(arg, "The only types that are supported for intervals are real and int.");
    }
    // Negative values are allowed: hence the check for UnaryExpr
    if (low instanceof UnaryExpr) {
        UnaryExpr unex_low = (UnaryExpr) low;
        if (!(unex_low.getExpr() instanceof IntLitExpr) & !(unex_low.getExpr() instanceof RealLitExpr)) {
            error(low, "Only real and integer types are supported for intervals.");
        }
        if (high instanceof UnaryExpr) {
            UnaryExpr unex_high = (UnaryExpr) high;
            if (!(unex_high.getExpr() instanceof IntLitExpr) & !(unex_high.getExpr() instanceof RealLitExpr)) {
                error(high, "Only real and integer types are supported for intervals.");
            }
            testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), unex_high.getExpr());
        } else {
            testLowAndHighTypes(intervalEq, typeName, unex_low.getExpr(), high);
        }
    } else {
        testLowAndHighTypes(intervalEq, typeName, low, high);
    }
}
Also used : RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) Arg(com.rockwellcollins.atc.agree.agree.Arg) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) SafetyInterval(edu.umn.cs.crisys.safety.safety.SafetyInterval) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr) Check(org.eclipse.xtext.validation.Check)

Aggregations

SafetyInterval (edu.umn.cs.crisys.safety.safety.SafetyInterval)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 AgreeTypeSystem (com.rockwellcollins.atc.agree.AgreeTypeSystem)1 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 Expr (com.rockwellcollins.atc.agree.agree.Expr)1 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)1 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)1 PrevExpr (com.rockwellcollins.atc.agree.agree.PrevExpr)1 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)1 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)1 UnaryExpr (com.rockwellcollins.atc.agree.agree.UnaryExpr)1 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)1 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)1 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)1 ClosedSafetyInterval (edu.umn.cs.crisys.safety.safety.ClosedSafetyInterval)1 OpenLeftSafetyInterval (edu.umn.cs.crisys.safety.safety.OpenLeftSafetyInterval)1 BinaryExpr (jkind.lustre.BinaryExpr)1 BinaryOp (jkind.lustre.BinaryOp)1 BoolExpr (jkind.lustre.BoolExpr)1