use of jkind.lustre.TupleExpr in project AGREE by loonwerks.
the class AgreeNodeToLustreContract method nodeAssertsToEqs.
private static List<Equation> nodeAssertsToEqs(AgreeNode agreeNode) {
List<Equation> eqs = new ArrayList<>();
for (AgreeStatement statement : agreeNode.assertions) {
if (AgreeUtils.referenceIsInContract(statement.reference, agreeNode.compInst)) {
BinaryExpr expr = (BinaryExpr) statement.expr;
if ((expr.op != BinaryOp.EQUAL)) {
throw new AgreeException("Unexpected expression type in AGREE AST asssertion");
}
Expr leftExpr = expr.left;
Expr rightExpr = expr.right;
List<IdExpr> ids = new ArrayList<>();
if (leftExpr instanceof TupleExpr) {
TupleExpr tuple = (TupleExpr) leftExpr;
for (Expr element : tuple.elements) {
ids.add((IdExpr) element);
}
} else {
ids.add((IdExpr) leftExpr);
}
eqs.add(new Equation(ids, rightExpr));
}
}
return eqs;
}
use of jkind.lustre.TupleExpr in project AGREE by loonwerks.
the class LustreContractAstBuilder method addCondactCall.
protected static void addCondactCall(AgreeNode agreeNode, String nodePrefix, List<AgreeVar> inputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
List<Expr> inputIds = new ArrayList<>();
List<Expr> initOutputsVals = new ArrayList<>();
List<IdExpr> nodeOutputIds = new ArrayList<>();
for (VarDecl var : lustreNode.inputs) {
inputIds.add(new IdExpr(prefix + var.id));
}
for (VarDecl var : lustreNode.outputs) {
AgreeVar outputVar = (AgreeVar) var;
String dummyName = prefix + var.id + "__DUMMY";
AgreeVar dummyVar = new AgreeVar(dummyName, outputVar.type, outputVar.reference, outputVar.compInst, outputVar.featInst);
if (!inputs.contains(dummyVar)) {
inputs.add(dummyVar);
}
initOutputsVals.add(new IdExpr(dummyName));
nodeOutputIds.add(new IdExpr(prefix + var.id));
}
if (agreeNode.timing == TimingModel.LATCHED) {
throw new AgreeException("check how we do this in the generic lustre translation now" + " to make sure that it is correct");
}
Expr condactExpr = new CondactExpr(clockExpr, new NodeCallExpr(lustreNode.id, inputIds), initOutputsVals);
Expr condactOutput;
if (nodeOutputIds.size() > 1) {
condactOutput = new TupleExpr(nodeOutputIds);
} else {
condactOutput = nodeOutputIds.get(0);
}
Expr condactCall = new BinaryExpr(condactOutput, BinaryOp.EQUAL, condactExpr);
assertions.add(new AgreeStatement("", condactCall, null));
}
use of jkind.lustre.TupleExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method getEquationStatements.
private GatheredVariablesAndConstraints getEquationStatements(EList<SpecStatement> specs, Map<String, jkind.lustre.Expr> rewriteMap) {
GatheredVariablesAndConstraints result = new GatheredVariablesAndConstraints();
for (SpecStatement spec : specs) {
if (spec instanceof EqStatement) {
EqStatement eq = (EqStatement) spec;
EList<Arg> lhs = eq.getLhs();
if (eq.getExpr() != null) {
Expr expr = doSwitch(eq.getExpr()).accept(new SubstitutionVisitor(rewriteMap));
if (lhs.size() != 1) {
List<Expr> ids = new ArrayList<>();
for (Arg arg : lhs) {
ids.add(new IdExpr(arg.getName()));
}
TupleExpr tuple = new TupleExpr(ids);
expr = new BinaryExpr(tuple, BinaryOp.EQUAL, expr);
} else {
expr = new BinaryExpr(new IdExpr(lhs.get(0).getName()), BinaryOp.EQUAL, expr);
}
result.assertions.add(new AgreeStatement("", expr, spec));
}
result.obligations.addAll(getConstraintsFromArgs(lhs, eq));
}
}
return result;
}
use of jkind.lustre.TupleExpr in project AGREE by loonwerks.
the class FrameAssertionHelper method valueToExpr.
private static Expr valueToExpr(final Value value) {
assert value != null;
if (value instanceof ArrayValue) {
final ArrayValue arrayValue = (ArrayValue) value;
final ArrayList<Expr> exprList = new ArrayList<Expr>(arrayValue.elements.size());
for (final Value childValue : arrayValue.elements) {
exprList.add(valueToExpr(childValue));
}
return new ArrayExpr(exprList);
} else if (value instanceof BooleanValue) {
return new BoolExpr(((BooleanValue) value).value);
} else if (value instanceof EnumValue) {
return new IdExpr(((EnumValue) value).value);
} else if (value instanceof IntegerValue) {
return new IntExpr(((IntegerValue) value).value);
} else if (value instanceof RealValue) {
final BigFraction fraction = ((RealValue) value).value;
return new BinaryExpr(new RealExpr(new BigDecimal(fraction.getNumerator())), BinaryOp.DIVIDE, new RealExpr(new BigDecimal(fraction.getDenominator())));
}
if (value instanceof TupleValue) {
final TupleValue tupleValue = (TupleValue) value;
final ArrayList<Expr> exprList = new ArrayList<Expr>(tupleValue.elements.size());
for (final Value childValue : tupleValue.elements) {
exprList.add(valueToExpr(childValue));
}
return new TupleExpr(exprList);
} else {
throw new RuntimeException("Unhandled case. Value is of type: " + value.getClass());
}
}
Aggregations