Search in sources :

Example 1 with BinaryOp

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;
}
Also used : EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) BinaryExpr(jkind.lustre.BinaryExpr) BinaryOp(jkind.lustre.BinaryOp)

Example 2 with BinaryOp

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;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Example 3 with BinaryOp

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));
}
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 4 with BinaryOp

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);
}
Also used : BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) BinaryOp(jkind.lustre.BinaryOp)

Example 5 with BinaryOp

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));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) EObject(org.eclipse.emf.ecore.EObject) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Aggregations

BinaryExpr (jkind.lustre.BinaryExpr)8 BinaryOp (jkind.lustre.BinaryOp)8 BoolExpr (jkind.lustre.BoolExpr)8 Expr (jkind.lustre.Expr)8 IdExpr (jkind.lustre.IdExpr)8 NodeCallExpr (jkind.lustre.NodeCallExpr)8 IfThenElseExpr (jkind.lustre.IfThenElseExpr)7 RealExpr (jkind.lustre.RealExpr)7 UnaryExpr (jkind.lustre.UnaryExpr)7 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)6 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)3 Equation (jkind.lustre.Equation)2 RecordAccessExpr (jkind.lustre.RecordAccessExpr)2 TupleExpr (jkind.lustre.TupleExpr)2 EObject (org.eclipse.emf.ecore.EObject)2 AgreeTypeSystem (com.rockwellcollins.atc.agree.AgreeTypeSystem)1 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)1 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)1 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)1