use of com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter in project AGREE by loonwerks.
the class LustreContractAstBuilder method addInitConstraint.
protected static void addInitConstraint(AgreeNode agreeNode, List<AgreeVar> outputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
if (agreeNode.timing != TimingModel.SYNC) {
String tickedName = subAgreeNode.id + "___TICKED";
outputs.add(new AgreeVar(tickedName, NamedType.BOOL, null, agreeNode.compInst, null));
Expr tickedId = new IdExpr(tickedName);
Expr preTicked = new UnaryExpr(UnaryOp.PRE, tickedId);
Expr tickedOrPre = new BinaryExpr(clockExpr, BinaryOp.OR, preTicked);
Expr initOrTicked = new BinaryExpr(clockExpr, BinaryOp.ARROW, tickedOrPre);
Expr tickedEq = new BinaryExpr(tickedId, BinaryOp.EQUAL, initOrTicked);
assertions.add(new AgreeStatement("", tickedEq, null));
// we have two re-write the ids in the initial expressions
IdRewriter rewriter = id -> new IdExpr(prefix + id.id);
Expr newInit = subAgreeNode.initialConstraint.accept(new IdRewriteVisitor(rewriter));
Expr initConstr = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, newInit);
assertions.add(new AgreeStatement("", initConstr, null));
// we also need to add hold expressions for the assumptions and
// lemmas
Expr assumeLemmaTrue = new BoolExpr(true);
for (VarDecl lustreVar : lustreNode.inputs) {
AgreeVar var = (AgreeVar) lustreVar;
if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
assumeLemmaTrue = new BinaryExpr(assumeLemmaTrue, BinaryOp.AND, new IdExpr(prefix + var.id));
}
}
assumeLemmaTrue = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, assumeLemmaTrue);
assertions.add(new AgreeStatement("", assumeLemmaTrue, null));
}
}
Aggregations