use of jkind.lustre.BinaryOp in project AGREE by loonwerks.
the class AgreeASTBuilder method caseBinaryExpr.
@Override
public Expr caseBinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr expr) {
Expr leftExpr = doSwitch(expr.getLeft());
Expr rightExpr = doSwitch(expr.getRight());
String op = expr.getOp();
BinaryOp binOp = null;
switch(op) {
case "+":
binOp = BinaryOp.PLUS;
break;
case "-":
binOp = BinaryOp.MINUS;
break;
case "*":
binOp = BinaryOp.MULTIPLY;
break;
case "/":
binOp = BinaryOp.DIVIDE;
break;
case "mod":
binOp = BinaryOp.MODULUS;
break;
case "div":
binOp = BinaryOp.INT_DIVIDE;
break;
case "<=>":
case "=":
binOp = BinaryOp.EQUAL;
break;
case "!=":
case "<>":
binOp = BinaryOp.NOTEQUAL;
break;
case ">":
binOp = BinaryOp.GREATER;
break;
case "<":
binOp = BinaryOp.LESS;
break;
case ">=":
binOp = BinaryOp.GREATEREQUAL;
break;
case "<=":
binOp = BinaryOp.LESSEQUAL;
break;
case "or":
binOp = BinaryOp.OR;
break;
case "and":
binOp = BinaryOp.AND;
return LustreExprFactory.makeANDExpr(leftExpr, rightExpr);
case "xor":
binOp = BinaryOp.XOR;
break;
case "=>":
binOp = BinaryOp.IMPLIES;
break;
case "->":
binOp = BinaryOp.ARROW;
break;
}
assert (binOp != null);
BinaryExpr binExpr = new BinaryExpr(leftExpr, binOp, rightExpr);
return binExpr;
}
use of jkind.lustre.BinaryOp in project AGREE by loonwerks.
the class AgreePatternTranslator method translatePatternEffectHoldConstraint.
private Expr translatePatternEffectHoldConstraint(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
AgreeVar timeCauseVar = getTimeOf(causeId.id, builder, pattern);
AgreeVar timeoutVar = new AgreeVar(TIMEOUT_PREFIX + patternIndex, NamedType.REAL, pattern);
builder.addOutput(timeoutVar);
Expr timeoutExpr = expr("timeout = if timeCause >= 0.0 then (timeCause + l) else -1.0", to("timeout", timeoutVar), to("timeCause", timeCauseVar), to("l", pattern.effectInterval.low));
builder.addAssertion(new AgreeStatement(null, timeoutExpr, pattern.reference));
builder.addEventTime(timeoutVar);
BinaryOp left = getIntervalLeftOp(pattern.effectInterval);
BinaryOp right = getIntervalRightOp(pattern.effectInterval);
Expr intervalLeft = expr("timeCause + l", to("timeCause", timeCauseVar), to("l", pattern.effectInterval.low));
Expr intervalRight = expr("timeCause + h", to("timeCause", timeCauseVar), to("h", pattern.effectInterval.high));
intervalLeft = new BinaryExpr(intervalLeft, left, timeExpr);
intervalRight = new BinaryExpr(timeExpr, right, intervalRight);
Expr inInterval = new BinaryExpr(intervalLeft, BinaryOp.AND, intervalRight);
String constrString;
if (pattern.effectIsExclusive) {
constrString = "if timeCause > -1.0 and inInterval then effectTrue else not effectTrue";
} else {
constrString = "timeCause > -1.0 => inInterval => effectTrue";
}
Expr expr = expr(constrString, to("timeCause", timeCauseVar), to("inInterval", inInterval), to("effectTrue", effectId));
return expr;
}
use of jkind.lustre.BinaryOp 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 jkind.lustre.BinaryOp in project AGREE by loonwerks.
the class AgreePatternTranslator method getTimeRangeConstraint.
private static Expr getTimeRangeConstraint(Expr timeRangeId, AgreePatternInterval interval) {
Expr occurs = new BinaryExpr(timeRangeId, BinaryOp.MINUS, timeExpr);
BinaryOp left = getIntervalLeftOp(interval);
BinaryOp right = getIntervalRightOp(interval);
Expr lower = new BinaryExpr(interval.low, left, occurs);
Expr higher = new BinaryExpr(occurs, right, interval.high);
return new BinaryExpr(lower, BinaryOp.AND, higher);
}
use of jkind.lustre.BinaryOp in project AGREE by loonwerks.
the class AgreePatternTranslator method translatePatternConditionProperty.
private Expr translatePatternConditionProperty(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
EObject varReference = pattern.reference;
AgreeVar recordVar = new AgreeVar(RECORD_PREFIX + patternIndex, NamedType.BOOL, varReference);
AgreeVar windowVar = new AgreeVar(WINDOW_PREFIX + patternIndex, NamedType.BOOL, varReference);
builder.addInput(recordVar);
builder.addLocal(windowVar);
AgreeVar tRecord = getTimeOf(recordVar.id, builder, pattern);
Expr expr = expr("record => cause", to("record", recordVar), to("cause", causeId));
builder.addAssertion(new AgreeStatement(null, expr, varReference));
BinaryOp left = getIntervalLeftOp(pattern.effectInterval);
BinaryOp right = getIntervalRightOp(pattern.effectInterval);
Equation eq = equation("in_window = (trecord <> -1.0) and " + "(l + trecord " + left + " time) and (time " + right + " h + trecord);", to("in_window", windowVar), to("trecord", tRecord), to("time", timeExpr), to("l", pattern.effectInterval.low), to("h", pattern.effectInterval.high));
builder.addLocalEquation(new AgreeEquation(eq, varReference));
return expr("in_window => effect", to("in_window", windowVar), to("effect", effectId));
}
Aggregations