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));
}
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;
}
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;
}
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);
}
}
Aggregations