use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.
the class CreateLocalVariablesForPropertyExpressions method transform.
public static SimulationProgram transform(final SimulationProgram program) {
final Program lustreProgram = program.getLustreProgram();
final SimulationProgramBuilder builder = new SimulationProgramBuilder(program);
// Build mappings between Agree Statements, expressions, and Agree Nodes
final Map<Expr, AgreeStatement> exprToStatementMap = new HashMap<>();
final Map<AgreeStatement, AgreeNode> agreeStatementToAgreeNodeMap = new HashMap<>();
for (final AgreeNode agreeNode : program.getAllAgreeNodes()) {
for (final AgreeStatement statement : agreeNode.assertions) {
if (statement.reference instanceof AssertStatement) {
exprToStatementMap.put(statement.expr, statement);
agreeStatementToAgreeNodeMap.put(statement, agreeNode);
}
}
for (final AgreeStatement statement : agreeNode.assumptions) {
exprToStatementMap.put(statement.expr, statement);
agreeStatementToAgreeNodeMap.put(statement, agreeNode);
}
for (final AgreeStatement statement : agreeNode.guarantees) {
exprToStatementMap.put(statement.expr, statement);
agreeStatementToAgreeNodeMap.put(statement, agreeNode);
}
}
// Create local variables for assert statements, assumptions, and guarantees
final ProgramBuilder lustreBuilder = new ProgramBuilder(lustreProgram).clearNodes();
for (final Node lustreNode : lustreProgram.nodes) {
lustreBuilder.addNode(VariableCreator.transform(lustreNode, exprToStatementMap, agreeStatementToAgreeNodeMap));
}
builder.setLustreProgram(lustreBuilder.build());
return builder.build();
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeNode visit(AgreeNode e) {
String id = e.id;
List<AgreeVar> inputs = new ArrayList<>();
for (AgreeVar input : e.inputs) {
inputs.add(this.visit(input));
}
List<AgreeVar> outputs = new ArrayList<>();
for (AgreeVar output : e.outputs) {
outputs.add(this.visit(output));
}
List<AgreeVar> locals = new ArrayList<>();
for (AgreeVar local : e.locals) {
locals.add(this.visit(local));
}
// Note that nodes and connections contain cross-references to each
// other. But, valid model structure requires that connections
// refer only to features on the this node and the sub-nodes. Thus,
// we may visit the sub-nodes first, and then use the result of that
// in visiting the connections.
//
List<AgreeNode> subNodes = new ArrayList<>();
for (AgreeNode subnode : e.subNodes) {
subNodes.add(this.visit(subnode));
}
List<AgreeConnection> connections = new ArrayList<>();
for (AgreeConnection conn : e.connections) {
connections.add(this.visit(conn));
}
List<AgreeStatement> assertions = new ArrayList<>();
for (AgreeStatement stmt : e.assertions) {
assertions.add(this.visit(stmt));
}
List<AgreeStatement> assumptions = new ArrayList<>();
for (AgreeStatement stmt : e.assumptions) {
assumptions.add(this.visit(stmt));
}
List<AgreeStatement> guarantees = new ArrayList<>();
for (AgreeStatement stmt : e.guarantees) {
guarantees.add(this.visit(stmt));
}
List<AgreeStatement> lemmas = new ArrayList<>();
for (AgreeStatement stmt : e.lemmas) {
lemmas.add(this.visit(stmt));
}
List<AgreeStatement> patternProps = new ArrayList<>();
for (AgreeStatement stmt : e.patternProps) {
patternProps.add(this.visit(stmt));
}
List<AgreeEquation> localEqs = new ArrayList<>();
for (AgreeEquation eq : e.localEquations) {
localEqs.add(this.visit(eq));
}
Expr clockConstraint = e.clockConstraint.accept(this);
Expr initialConstraint = e.initialConstraint.accept(this);
AgreeVar clockVar = this.visit(e.clockVar);
EObject reference = e.reference;
TimingModel timing = e.timing;
// ComponentInstance compinst = e.compInst;
AgreeNodeBuilder builder = new AgreeNodeBuilder(id);
builder.addInput(inputs);
builder.addOutput(outputs);
builder.addLocal(locals);
builder.addConnection(connections);
builder.addSubNode(subNodes);
builder.addAssertion(assertions);
builder.addAssumption(assumptions);
builder.addGuarantee(guarantees);
builder.addLemma(lemmas);
builder.addLocalEquation(localEqs);
builder.addPatternProp(patternProps);
builder.setClockConstraint(clockConstraint);
builder.setInitialConstraint(initialConstraint);
builder.setClockVar(clockVar);
builder.setReference(reference);
builder.setTiming(timing);
builder.setCompInst(e.compInst);
builder.addTimeFall(e.timeFallMap);
builder.addTimeRise(e.timeRiseMap);
builder.addTimeOf(e.timeOfMap);
AgreeNode result = builder.build();
visitedNodes.put(e.compInst, result);
return result;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.
the class AgreeNodeToLustreContract method translateNode.
private static Node translateNode(AgreeNode agreeNode) {
List<VarDecl> inputs = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<Equation> eqs = new ArrayList<>();
List<Expr> assertions = new ArrayList<>();
List<String> properties = new ArrayList<>();
inputs.addAll(agreeNode.inputs);
inputs.addAll(agreeNode.outputs);
inputs.addAll(agreeNode.locals);
eqs.addAll(nodeAssertsToEqs(agreeNode));
// right now the AGREE AST just has assertions over input variables
// this step allows us to inline some of these as local variables
// to the node
List<IdExpr> ids = gatherIds(eqs);
List<VarDecl> inlinedVars = new ArrayList<>();
for (VarDecl var : inputs) {
for (IdExpr id : ids) {
if (id.id.equals(var.id)) {
inlinedVars.add(var);
}
}
}
inputs.removeAll(inlinedVars);
locals.addAll(inlinedVars);
for (AgreeStatement statement : agreeNode.assumptions) {
assertions.add(statement.expr);
}
int i = 0;
for (AgreeStatement statement : agreeNode.guarantees) {
String guarName = "__GUARANTEE" + i++;
properties.add(guarName);
locals.add(new VarDecl(guarName, NamedType.BOOL));
eqs.add(new Equation(new IdExpr(guarName), statement.expr));
}
NodeBuilder builder = new NodeBuilder(agreeNode.id);
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(eqs);
builder.addProperties(properties);
builder.addAssertions(assertions);
return builder.build();
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement 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 com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.
the class LustreAstBuilder method getLustreNode.
protected static Node getLustreNode(AgreeNode agreeNode, String nodePrefix) {
List<VarDecl> inputs = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<Expr> assertions = new ArrayList<>();
List<String> ivcs = agreeNode.getivcElements();
List<String> properties = new ArrayList<>();
// add assumption history variable
IdExpr assumHist = new IdExpr(assumeHistSufix);
inputs.add(new AgreeVar(assumHist.id, NamedType.BOOL, null, agreeNode.compInst, null));
int i = 0;
for (AgreeStatement statement : agreeNode.assumptions) {
String inputName = assumeSuffix + i++;
inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
IdExpr assumeId = new IdExpr(inputName);
assertions.add(new BinaryExpr(assumeId, BinaryOp.EQUAL, statement.expr));
}
int j = 0;
for (AgreeStatement statement : agreeNode.lemmas) {
String inputName = lemmaSuffix + j++;
inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
properties.add(inputName);
IdExpr lemmaId = new IdExpr(inputName);
assertions.add(new BinaryExpr(lemmaId, BinaryOp.EQUAL, statement.expr));
}
int k = 0;
Expr guarConjExpr = new BoolExpr(true);
for (AgreeStatement statement : agreeNode.guarantees) {
String inputName = guarSuffix + k++;
locals.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
IdExpr guarId = new IdExpr(inputName);
equations.add(new Equation(guarId, statement.expr));
if (agreeNode.getFaultTreeFlag() == false) {
ivcs.add(guarId.id);
} else {
// check if it's leaf node
if (!agreeNode.compInst.getComponentInstances().isEmpty()) {
ivcs.add(guarId.id);
}
}
guarConjExpr = LustreExprFactory.makeANDExpr(guarId, guarConjExpr);
}
// assert that if the assumptions have held historically, then the
// gurantees hold
assertions.add(new BinaryExpr(assumHist, BinaryOp.IMPLIES, guarConjExpr));
for (AgreeStatement statement : agreeNode.assertions) {
assertions.add(statement.expr);
}
// create properties for the patterns
int l = 0;
for (AgreeStatement patternPropState : agreeNode.patternProps) {
String patternVarName = patternPropSuffix + l++;
inputs.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, agreeNode.compInst, null));
assertions.add(new BinaryExpr(new IdExpr(patternVarName), BinaryOp.EQUAL, patternPropState.expr));
}
Expr assertExpr = new BoolExpr(true);
for (Expr expr : assertions) {
assertExpr = LustreExprFactory.makeANDExpr(expr, assertExpr);
}
String outputName = "__ASSERT";
List<VarDecl> outputs = new ArrayList<>();
outputs.add(new VarDecl(outputName, NamedType.BOOL));
equations.add(new Equation(new IdExpr(outputName), assertExpr));
// gather the remaining inputs
for (AgreeVar var : agreeNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.outputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.locals) {
locals.add(var);
}
for (AgreeEquation equation : agreeNode.localEquations) {
equations.add(equation);
}
NodeBuilder builder = new NodeBuilder(nodePrefix + agreeNode.id);
builder.addInputs(inputs);
builder.addOutputs(outputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addIvcs(ivcs);
return builder.build();
}
Aggregations