use of com.rockwellcollins.atc.agree.analysis.AgreeException 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 com.rockwellcollins.atc.agree.analysis.AgreeException 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;
}
use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.
the class LustreContractAstBuilder method addInputsAndOutputs.
protected static void addInputsAndOutputs(List<AgreeVar> inputs, List<AgreeVar> outputs, AgreeNode subAgreeNode, Node lustreNode, String prefix) {
for (AgreeVar var : subAgreeNode.inputs) {
AgreeVar input = new AgreeVar(prefix + var.id, var.type, var.reference, var.compInst, var.featInst);
inputs.add(input);
}
for (AgreeVar var : subAgreeNode.outputs) {
AgreeVar output = new AgreeVar(prefix + var.id, var.type, var.reference, var.compInst, var.featInst);
outputs.add(output);
}
// }
if (!subAgreeNode.locals.isEmpty()) {
throw new AgreeException("What is an example of this?");
}
inputs.add(subAgreeNode.clockVar);
}
use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.
the class AgreePatternBuilder method getIntervalType.
private AgreePatternInterval getIntervalType(TimeInterval interval) {
if (interval == null) {
return null;
}
Expr low = builder.doSwitch(interval.getLow());
Expr high = builder.doSwitch(interval.getHigh());
IntervalType type;
if (interval instanceof OpenTimeInterval) {
type = IntervalType.OPEN;
} else if (interval instanceof OpenLeftTimeInterval) {
type = IntervalType.OPEN_LEFT;
} else if (interval instanceof OpenRightTimeInterval) {
type = IntervalType.OPEN_RIGHT;
} else if (interval instanceof ClosedTimeInterval) {
type = IntervalType.CLOSED;
} else {
throw new AgreeException("Unhandled TimeInterval type: " + interval.getClass());
}
return new AgreePatternInterval(type, low, high);
}
use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.
the class AgreePatternBuilder method caseWhenOccursStatment.
@Override
public AgreeStatement caseWhenOccursStatment(WhenOccursStatment object) {
IdExpr condition = (IdExpr) builder.doSwitch(object.getCondition());
IdExpr effect = (IdExpr) builder.doSwitch(object.getEvent());
Expr timesExpr = builder.doSwitch(object.getTimes());
boolean exclusive = object.getExcl() != null;
if (!(timesExpr instanceof IntExpr)) {
throw new AgreeException("Expected an integer literal in 'When Occurs' pattern");
}
BigInteger times = ((IntExpr) timesExpr).value;
AgreePatternInterval interval = getIntervalType(object.getInterval());
return new AgreeTimesPattern(str, ref, exclusive, condition, effect, interval, null, TriggerType.CONDITION, TriggerType.CONDITION, times, null);
}
Aggregations