Search in sources :

Example 31 with BoolExpr

use of jkind.lustre.BoolExpr in project AGREE by loonwerks.

the class InputConstraintToLustreValueExpression method lustreExprToValue.

// Only binary, unary, and literal expressions are supported
private static Value lustreExprToValue(final Expr lustreExpr) {
    if (lustreExpr instanceof BoolExpr) {
        return BooleanValue.fromBoolean(((BoolExpr) lustreExpr).value);
    } else if (lustreExpr instanceof IntExpr) {
        return new IntegerValue(((IntExpr) lustreExpr).value);
    } else if (lustreExpr instanceof RealExpr) {
        final RealExpr realExpr = (RealExpr) lustreExpr;
        return new RealValue(BigFraction.valueOf(realExpr.value));
    } else if (lustreExpr instanceof BinaryExpr) {
        final BinaryExpr binaryExpr = (BinaryExpr) lustreExpr;
        final Value leftValue = lustreExprToValue(binaryExpr.left);
        final Value rightValue = lustreExprToValue(binaryExpr.right);
        return leftValue.applyBinaryOp(binaryExpr.op, rightValue);
    } else if (lustreExpr instanceof UnaryExpr) {
        final UnaryExpr unaryExpr = (UnaryExpr) lustreExpr;
        final Value operandValue = lustreExprToValue(unaryExpr.expr);
        return operandValue.applyUnaryOp(unaryExpr.op);
    }
    throw new RuntimeException("Unsupported expression: " + lustreExpr);
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IntegerValue(jkind.lustre.values.IntegerValue) BinaryExpr(jkind.lustre.BinaryExpr) RealValue(jkind.lustre.values.RealValue) IntegerValue(jkind.lustre.values.IntegerValue) Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue) IntExpr(jkind.lustre.IntExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr)

Example 32 with BoolExpr

use of jkind.lustre.BoolExpr in project AGREE by loonwerks.

the class Main method testBoolean.

private static void testBoolean() throws IOException {
    System.out.println("=============Boolean Test=============");
    final Evaluator baseEvaluator = createEvaluator(INPUT_DIRECTORY + "symb_test_bool.lus");
    final Evaluator evaluator = new Evaluator(baseEvaluator, Arrays.asList(new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("in1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("in2"), BinaryOp.EQUAL, new BoolExpr(true))));
    testValue("in1", evaluator, BooleanValue.TRUE);
    testValue("in2", evaluator, BooleanValue.TRUE);
    testValue("out1", evaluator, BooleanValue.TRUE);
    testValue("out2", evaluator, BooleanValue.TRUE);
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Evaluator(edu.uah.rsesc.aadlsimulator.agree.eval.Evaluator)

Example 33 with BoolExpr

use of jkind.lustre.BoolExpr in project AGREE by loonwerks.

the class AgreeCalendarUtils method getAllClksHaveTicked.

public static List<Equation> getAllClksHaveTicked(String name, String clkPref, List<Expr> clks) {
    Expr result = new BoolExpr(true);
    List<Equation> eqs = new ArrayList<>();
    int i = 0;
    for (Expr clk : clks) {
        Equation clkHasTicked = getClkHasTicked(new IdExpr(clkPref + i), clk);
        result = new BinaryExpr(result, BinaryOp.AND, clkHasTicked.lhs.get(0));
        eqs.add(clkHasTicked);
        i++;
    }
    eqs.add(new Equation(new IdExpr(name), result));
    return eqs;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation)

Aggregations

BoolExpr (jkind.lustre.BoolExpr)33 BinaryExpr (jkind.lustre.BinaryExpr)32 IdExpr (jkind.lustre.IdExpr)31 Expr (jkind.lustre.Expr)27 UnaryExpr (jkind.lustre.UnaryExpr)25 NodeCallExpr (jkind.lustre.NodeCallExpr)24 IntExpr (jkind.lustre.IntExpr)19 IfThenElseExpr (jkind.lustre.IfThenElseExpr)16 ArrayList (java.util.ArrayList)13 RealExpr (jkind.lustre.RealExpr)13 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)12 Equation (jkind.lustre.Equation)12 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)10 VarDecl (jkind.lustre.VarDecl)10 NodeBuilder (jkind.lustre.builders.NodeBuilder)10 Node (jkind.lustre.Node)9 TupleExpr (jkind.lustre.TupleExpr)9 RecordAccessExpr (jkind.lustre.RecordAccessExpr)8 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)7 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)6