Search in sources :

Example 21 with Equation

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

the class LustreAstBuilder method getHist.

protected static Equation getHist(IdExpr histId, Expr expr) {
    Expr preHist = new UnaryExpr(UnaryOp.PRE, histId);
    Expr preAndNow = LustreExprFactory.makeANDExpr(preHist, expr);
    return new Equation(histId, new BinaryExpr(expr, BinaryOp.ARROW, preAndNow));
}
Also used : UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) UnaryExpr(jkind.lustre.UnaryExpr)

Example 22 with Equation

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

the class LustreContractAstBuilder method getContractLustreProgram.

public static Program getContractLustreProgram(AgreeProgram agreeProgram) {
    nodes = new ArrayList<>();
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    AgreeNode flatNode = flattenAgreeNodeKindContract(agreeProgram.topNode, "_TOP__");
    List<Expr> assertions = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> outputs = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<String> properties = new ArrayList<>();
    List<Expr> requires = new ArrayList<>();
    List<Expr> ensures = new ArrayList<>();
    for (AgreeStatement assertion : flatNode.assertions) {
        assertions.add(assertion.expr);
    }
    for (AgreeStatement assumption : flatNode.assumptions) {
        requires.add(assumption.expr);
    }
    for (AgreeStatement guarantee : flatNode.lemmas) {
        ensures.add(guarantee.expr);
    }
    for (AgreeStatement guarantee : flatNode.guarantees) {
        ensures.add(guarantee.expr);
    }
    for (AgreeVar var : flatNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        outputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            throw new AgreeException("This shouldn't happen");
        }
    }
    Contract contract = new Contract(requires, ensures);
    NodeBuilder builder = new NodeBuilder("_TOP");
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.setContract(contract);
    Node main = builder.build();
    nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(main);
    Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TypeDef(jkind.lustre.TypeDef) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Contract(jkind.lustre.Contract)

Example 23 with Equation

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

the class AgreeRealtimeCalendarBuilder method getFallNode.

private static Node getFallNode() {
    NodeBuilder builder = new NodeBuilder(FALL_NODE_NAME);
    builder.addInput(new VarDecl("input", NamedType.BOOL));
    builder.addOutput(new VarDecl("output", NamedType.BOOL));
    IdExpr inputId = new IdExpr("input");
    IdExpr outputId = new IdExpr("output");
    Expr outputExpr = new UnaryExpr(UnaryOp.PRE, inputId);
    Expr notInput = new UnaryExpr(UnaryOp.NOT, inputId);
    outputExpr = new BinaryExpr(outputExpr, BinaryOp.AND, notInput);
    outputExpr = new BinaryExpr(notInput, BinaryOp.ARROW, outputExpr);
    builder.addEquation(new Equation(outputId, outputExpr));
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr)

Example 24 with Equation

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

the class GenerateUfcObligationsVisitor method constructNewNode.

/**
 * Method for constructing new programs using the UFC obligations.
 */
private Node constructNewNode(Node existing, ObligationSet obs) {
    List<VarDecl> locals = new ArrayList<>(existing.locals);
    List<Equation> equations = new ArrayList<>(existing.equations);
    // List<String> properties = new ArrayList<>(existing.properties);
    // Change: MWW 5/6: Don't really want existing properties here.
    List<String> properties = new ArrayList<>();
    /* writing the TCG obligations back as trap properties by negating them... */
    for (int i = 0; i < obs.positivePolarity.size(); i++) {
        String varName = TRAP_PROP_PREFIX + i;
        Obligation ob = obs.positivePolarity.get(i);
        locals.add(new VarDecl(varName, NamedType.BOOL));
        equations.add(new Equation(new IdExpr(varName), new UnaryExpr(UnaryOp.NOT, ob.getObligationExpr())));
        properties.add(varName);
        // renaming information
        if (renaming != null) {
            renaming.addRenaming(varName, ob.getEqAssignId(), ob.getTestedCondition().toString(), new HashSet<Obligation>(Arrays.asList(ob)));
        }
        System.out.println("Renaming: mapping " + varName + " --> " + ob.getEqAssignId());
    }
    Node newNode = new Node(existing.id, existing.inputs, existing.outputs, locals, equations, properties, existing.assertions, null, null, new ArrayList<String>());
    return newNode;
}
Also used : Obligation(com.rockwellcollins.atc.tcg.obligations.ufc.Obligation) IdExpr(jkind.lustre.IdExpr) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) UnaryExpr(jkind.lustre.UnaryExpr) VarDecl(jkind.lustre.VarDecl)

Example 25 with Equation

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

the class GenerateUfcObligationsVisitor method visit.

@Override
public ObligationSet visit(Node node) {
    typeReconstructor.setNodeContext(node);
    if (node.id.equals(initialProgram.main) || !this.generateForMainNodeObligationsOnly) {
        typeReconstructor.setNodeContext(node);
        currentNode = node;
        ObligationSet allExprs = new ObligationSet();
        for (Equation equation : node.equations) {
            allExprs.addAll(equation.accept(this));
        }
        for (Expr assertion : node.assertions) {
            allExprs.addAll(assertion(assertion));
        }
        if (!node.properties.isEmpty()) {
            for (String property : node.properties) {
                allExprs.addAll(property(property));
            }
        }
        obligations.put(node, allExprs);
        currentNode = null;
    } else {
        obligations.put(node, new ObligationSet());
    }
    return null;
}
Also used : ObligationSet(com.rockwellcollins.atc.tcg.obligations.ufc.ObligationSet) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) RecordExpr(jkind.lustre.RecordExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayExpr(jkind.lustre.ArrayExpr) IdExpr(jkind.lustre.IdExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) Equation(jkind.lustre.Equation)

Aggregations

Equation (jkind.lustre.Equation)52 IdExpr (jkind.lustre.IdExpr)48 Expr (jkind.lustre.Expr)43 BinaryExpr (jkind.lustre.BinaryExpr)40 NodeCallExpr (jkind.lustre.NodeCallExpr)35 UnaryExpr (jkind.lustre.UnaryExpr)35 VarDecl (jkind.lustre.VarDecl)34 BoolExpr (jkind.lustre.BoolExpr)33 NodeBuilder (jkind.lustre.builders.NodeBuilder)30 ArrayList (java.util.ArrayList)27 IfThenElseExpr (jkind.lustre.IfThenElseExpr)26 IntExpr (jkind.lustre.IntExpr)20 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)14 TupleExpr (jkind.lustre.TupleExpr)12 Node (jkind.lustre.Node)11 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)10 RealExpr (jkind.lustre.RealExpr)10 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)9 RecordAccessExpr (jkind.lustre.RecordAccessExpr)8 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)7