use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class LustreCondactNodeVisitor method addInitEq.
private static void addInitEq(NodeBuilder builder) {
builder.addLocal(new AgreeVar(initVarName, NamedType.BOOL, null));
builder.addEquation(equation("initVar = clk and (true -> not pre(ticked));", to("initVar", initVarName), to("ticked", tickedVarName), to("clk", clockVarName)));
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar 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();
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class LustreCondactNodeVisitor method visit.
@Override
public Expr visit(UnaryExpr e) {
if (e.op == UnaryOp.PRE) {
IdExpr stateVarId = stateVarMap.get(e.toString());
if (stateVarId != null) {
return stateVarId;
}
stateVarId = new IdExpr(statVarPrefix + numStateVars++);
stateVarMap.put(e.toString(), stateVarId);
Expr stateVarExpr = new UnaryExpr(UnaryOp.PRE, e.expr.accept(this));
stateVarExpr = expr("if clk then stateVarExpr else (pre stateVar)", to("stateVar", stateVarId), to("stateVarExpr", stateVarExpr), to("clk", clockVarName));
stateVars.add(new AgreeVar(stateVarId.id, e.accept(typeReconstructor), null));
stateVarEqs.add(new Equation(stateVarId, stateVarExpr));
return stateVarId;
}
return new UnaryExpr(e.op, e.expr.accept(this));
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class RenamingVisitor method getReferenceStr.
private String getReferenceStr(AgreeVar var) {
String prefix = getCategory(rootInstance, var);
if (prefix == null) {
return null;
}
if (var.id.endsWith(AgreeASTBuilder.clockIDSuffix)) {
return null;
}
String seperator = (prefix == "" ? "" : ".");
EObject reference = var.reference;
String suffix = "";
if (var.id.endsWith(AgreeASTBuilder.eventSuffix + AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
suffix = "._EVENT_._LATCHED_";
} else if (var.id.endsWith(AgreeASTBuilder.eventSuffix)) {
suffix = "._EVENT_";
} else if (var.id.endsWith(AgreeInlineLatchedConnections.LATCHED_SUFFIX)) {
suffix = "._LATCHED_";
}
if (reference instanceof GuaranteeStatement) {
String id = ((GuaranteeStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return id + ((GuaranteeStatement) reference).getStr();
} else if (reference instanceof AssumeStatement) {
String id = ((AssumeStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return prefix + " assume: " + id + ((AssumeStatement) reference).getStr();
} else if (reference instanceof LemmaStatement) {
String id = ((LemmaStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return prefix + " lemma: " + id + ((LemmaStatement) reference).getStr();
} else if (reference instanceof ReachableStatement) {
renaming.addInvertedProperty(var.id);
String id = ((ReachableStatement) reference).getName();
if (id == null || id.isEmpty()) {
id = "";
} else {
id = "[" + id + "] ";
}
return prefix + " reachable: " + id + ((ReachableStatement) reference).getStr();
} else if (reference instanceof AssertStatement) {
throw new AgreeException("We really didn't expect to see an assert statement here");
} else if (reference instanceof Arg) {
return prefix + seperator + ((Arg) reference).getName() + suffix;
} else if (reference instanceof EqStatement) {
return prefix + "eq " + String.join(", ", ((EqStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
} else if (reference instanceof InputStatement) {
return prefix + "agree_input " + String.join(", ", ((InputStatement) reference).getLhs().stream().map(lhs -> argToString(lhs)).collect(Collectors.toList()));
} else if (reference instanceof DataPort) {
return prefix + seperator + ((DataPort) reference).getName() + suffix;
} else if (reference instanceof EventPort) {
return prefix + seperator + ((EventPort) reference).getName() + suffix;
} else if (reference instanceof EventDataPort) {
return prefix + seperator + ((EventDataPort) reference).getName() + suffix;
} else if (reference instanceof FeatureGroup) {
String featName = ((FeatureGroup) reference).getName();
String varName = var.toString();
featName = varName.substring(varName.indexOf(featName)).replace("__", ".");
return prefix + seperator + featName;
} else if (reference instanceof PropertyStatement) {
return prefix + seperator + ((PropertyStatement) reference).getName();
} else if (reference instanceof Property) {
return "AADL property " + ((Property) reference).getName();
} else if (reference instanceof GetPropertyExpr) {
return "Get_Property(" + ((GetPropertyExpr) reference).getContainingClassifier().getName() + ", " + ((Property) ((GetPropertyExpr) reference).getProp()).getName() + ")";
} else if (reference instanceof ComponentType || reference instanceof ComponentImplementation || reference instanceof SystemImplementation) {
if (var.id.equals(LustreAstBuilder.assumeHistSufix)) {
return "Subcomponent Assumptions";
}
return "Result";
} else if (reference instanceof AgreeStatement) {
return prefix + reference.toString();
}
throw new AgreeException("Unhandled reference type: '" + reference.getClass().getName() + "'");
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class AgreePatternTranslator method translateNode.
private AgreeNode translateNode(AgreeNode node, boolean isTopNode) {
AgreeNodeBuilder builder = new AgreeNodeBuilder(node);
// this has to be done first because the pattern translation
// for guarantees/lemmas/assumptions add additional assertions
builder.clearAssertions();
createTimeFunctions(node, builder);
for (AgreeStatement statement : node.assertions) {
if (statement instanceof AgreePattern) {
containsRealTimePatterns = true;
Expr transExpr = translatePattern((AgreePattern) statement, builder, false);
statement = new AgreeStatement(statement.string, transExpr, statement.reference);
}
builder.addAssertion(statement);
}
builder.clearGuarantees();
for (AgreeStatement statement : node.guarantees) {
if (statement instanceof AgreePattern) {
containsRealTimePatterns = true;
Expr transExpr = translatePattern((AgreePattern) statement, builder, isTopNode);
statement = new AgreeStatement(statement.string, transExpr, statement.reference);
}
builder.addGuarantee(statement);
}
builder.clearLemmas();
for (AgreeStatement statement : node.lemmas) {
if (statement instanceof AgreePattern) {
containsRealTimePatterns = true;
Expr transExpr = translatePattern((AgreePattern) statement, builder, isTopNode);
statement = new AgreeStatement(statement.string, transExpr, statement.reference);
}
builder.addLemma(statement);
}
builder.clearAssumptions();
for (AgreeStatement statement : node.assumptions) {
if (statement instanceof AgreePattern) {
containsRealTimePatterns = true;
Expr transExpr = translatePattern((AgreePattern) statement, builder, !isTopNode);
statement = new AgreeStatement(statement.string, transExpr, statement.reference);
}
builder.addAssumption(statement);
}
builder.clearSubNodes();
for (AgreeNode subNode : node.subNodes) {
builder.addSubNode(new AgreePatternTranslator().translateNode(subNode, false));
}
builder.addInput(new AgreeVar(timeExpr.id, NamedType.REAL, null, node.compInst, null));
return builder.build();
}
Aggregations