Search in sources :

Example 96 with IdExpr

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

the class AgreeASTBuilder method getAssignmentStatements.

private List<AgreeStatement> getAssignmentStatements(EList<SpecStatement> specs) {
    List<AgreeStatement> assigns = new ArrayList<>();
    for (SpecStatement spec : specs) {
        if (spec instanceof AssignStatement) {
            Expr expr = doSwitch(((AssignStatement) spec).getExpr());
            NamedElement id = ((AssignStatement) spec).getId();
            expr = new BinaryExpr(new IdExpr(id.getName()), BinaryOp.EQUAL, expr);
            assigns.add(new AgreeStatement("", expr, spec));
        }
    }
    return assigns;
}
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) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AssignStatement(com.rockwellcollins.atc.agree.agree.AssignStatement) NamedElement(org.osate.aadl2.NamedElement)

Example 97 with IdExpr

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

the class AgreeASTBuilder method caseEnumLitExpr.

@Override
public Expr caseEnumLitExpr(EnumLitExpr aadlEnum) {
    NamedElement ne = aadlEnum.getEnumType().getElm();
    String typeStr = ne.getQualifiedName().replace("::", "__").replace(".", dotChar);
    return new IdExpr(typeStr + "_" + aadlEnum.getValue());
}
Also used : IdExpr(jkind.lustre.IdExpr) NamedElement(org.osate.aadl2.NamedElement)

Example 98 with IdExpr

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

the class AgreeASTBuilder method nodeEqToEq.

// helper method for above
private Equation nodeEqToEq(NodeEq nodeEq) {
    Expr expr = doSwitch(nodeEq.getExpr());
    List<IdExpr> ids = new ArrayList<>();
    for (Arg arg : nodeEq.getLhs()) {
        ids.add(new IdExpr(arg.getName()));
    }
    Equation eq = new Equation(ids, expr);
    return eq;
}
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) IdExpr(jkind.lustre.IdExpr) Arg(com.rockwellcollins.atc.agree.agree.Arg) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation)

Example 99 with IdExpr

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

the class AgreeASTBuilder method caseNodeDef.

@Override
public Expr caseNodeDef(NodeDef expr) {
    String nodeName = AgreeUtils.getNodeName(expr);
    for (Node node : globalNodes) {
        if (node.id.equals(nodeName)) {
            return null;
        }
    }
    List<VarDecl> inputs = agreeVarsFromArgs(expr.getArgs(), null);
    List<VarDecl> outputs = agreeVarsFromArgs(expr.getRets(), null);
    NodeBodyExpr body = expr.getNodeBody();
    List<VarDecl> internals = agreeVarsFromArgs(body.getLocs(), null);
    List<Equation> eqs = new ArrayList<>();
    List<String> props = new ArrayList<>();
    // TODO are node lemmas deprecated?
    String lemmaName = "__nodeLemma";
    int lemmaIndex = 0;
    for (NodeStmt stmt : body.getStmts()) {
        if (stmt instanceof NodeLemma) {
            NodeLemma nodeLemma = (NodeLemma) stmt;
            String propName = lemmaName + lemmaIndex++;
            IdExpr eqId = new IdExpr(propName);
            internals.add(new VarDecl(eqId.id, NamedType.BOOL));
            Expr eqExpr = doSwitch(nodeLemma.getExpr());
            Equation eq = new Equation(eqId, eqExpr);
            eqs.add(eq);
            props.add(eqId.id);
        } else if (stmt instanceof NodeEq) {
            eqs.add(nodeEqToEq((NodeEq) stmt));
        }
    }
    NodeBuilder builder = new NodeBuilder(nodeName);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(internals);
    builder.addEquations(eqs);
    builder.addProperties(props);
    Node n = builder.build();
    addToNodeList(n);
    return null;
}
Also used : NodeStmt(com.rockwellcollins.atc.agree.agree.NodeStmt) IdExpr(jkind.lustre.IdExpr) NodeLemma(com.rockwellcollins.atc.agree.agree.NodeLemma) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeEq(com.rockwellcollins.atc.agree.agree.NodeEq) NodeBuilder(jkind.lustre.builders.NodeBuilder) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) 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) VarDecl(jkind.lustre.VarDecl)

Example 100 with IdExpr

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

the class LustreCondactNodeVisitor method translate.

public static Node translate(AgreeProgram agreeProgram, AgreeNode agreeNode, Node node) {
    if (node.outputs.size() != 1) {
        throw new AgreeException("We expect that this node only has a single output representing " + "all constraints for the contract");
    }
    LustreCondactNodeVisitor visitor = new LustreCondactNodeVisitor(agreeProgram, node);
    NodeBuilder builder = new NodeBuilder(node);
    builder.clearEquations();
    builder.addInput(new AgreeVar(clockVarName, NamedType.BOOL, null));
    addTickedEq(builder);
    addInitEq(builder);
    Expr holdExpr = new BoolExpr(true);
    // make clock hold exprs
    for (AgreeVar var : agreeNode.outputs) {
        Expr varId = new IdExpr(var.id);
        Expr preVar = new UnaryExpr(UnaryOp.PRE, varId);
        holdExpr = new BinaryExpr(holdExpr, BinaryOp.AND, new BinaryExpr(varId, BinaryOp.EQUAL, preVar));
    }
    holdExpr = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, holdExpr);
    for (int i = 0; i < agreeNode.assumptions.size(); i++) {
        Expr varId = new IdExpr(LustreAstBuilder.assumeSuffix + i);
        Expr preVar = new UnaryExpr(UnaryOp.PRE, varId);
        preVar = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, preVar);
        holdExpr = new BinaryExpr(holdExpr, BinaryOp.AND, new BinaryExpr(varId, BinaryOp.EQUAL, preVar));
    }
    holdExpr = expr("(not clk => holdExpr)", to("clk", clockVarName), to("holdExpr", holdExpr));
    // make the constraint for the initial outputs
    Expr initConstr = expr("not ticked => initExpr", to("ticked", tickedVarName), to("initExpr", agreeNode.initialConstraint));
    // re-write the old expression using the visitor
    for (Equation eq : node.equations) {
        if (eq.lhs.size() != 1) {
            throw new AgreeException("we expect that all eqs have a single lhs now");
        }
        IdExpr var = eq.lhs.get(0);
        boolean isLocal = false;
        for (VarDecl local : node.locals) {
            if (local.id.equals(var.id)) {
                isLocal = true;
                break;
            }
        }
        if (isLocal) {
            Expr newExpr = eq.expr.accept(visitor);
            newExpr = new IfThenElseExpr(new IdExpr(clockVarName), newExpr, new UnaryExpr(UnaryOp.PRE, var));
            builder.addEquation(new Equation(eq.lhs, newExpr));
        } else {
            // this is the only output
            Expr newExpr = eq.expr.accept(visitor);
            newExpr = new BinaryExpr(new IdExpr(clockVarName), BinaryOp.IMPLIES, newExpr);
            builder.addEquation(new Equation(eq.lhs, new BinaryExpr(initConstr, BinaryOp.AND, new BinaryExpr(holdExpr, BinaryOp.AND, newExpr))));
        }
    }
    // this var equations should be populated by the visitor call above
    builder.addEquations(visitor.stateVarEqs);
    builder.addLocals(visitor.stateVars);
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) VarDecl(jkind.lustre.VarDecl) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Aggregations

IdExpr (jkind.lustre.IdExpr)133 BinaryExpr (jkind.lustre.BinaryExpr)96 Expr (jkind.lustre.Expr)95 BoolExpr (jkind.lustre.BoolExpr)82 NodeCallExpr (jkind.lustre.NodeCallExpr)81 UnaryExpr (jkind.lustre.UnaryExpr)75 IfThenElseExpr (jkind.lustre.IfThenElseExpr)64 IntExpr (jkind.lustre.IntExpr)53 ArrayList (java.util.ArrayList)52 Equation (jkind.lustre.Equation)46 VarDecl (jkind.lustre.VarDecl)41 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)38 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)37 RecordAccessExpr (jkind.lustre.RecordAccessExpr)37 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)29 RealExpr (jkind.lustre.RealExpr)29 NodeBuilder (jkind.lustre.builders.NodeBuilder)29 TupleExpr (jkind.lustre.TupleExpr)25 ArrayExpr (jkind.lustre.ArrayExpr)14 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)13