use of jkind.lustre.Function in project AGREE by loonwerks.
the class AgreeASTBuilder method caseUninterpretedFnDef.
@Override
public Expr caseUninterpretedFnDef(UninterpretedFnDef uFnDef) {
String functionName = AgreeUtils.getNodeName(uFnDef).replace("::", "__");
for (Function function : uninterpretedFunc) {
if (function.id.equals(functionName)) {
return null;
}
}
List<VarDecl> inputs = agreeVarsFromArgs(uFnDef.getArgs(), null);
Type outType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(uFnDef.getType()));
if (outType != null) {
VarDecl outVar = new VarDecl("_outvar", outType);
List<VarDecl> outputs = Collections.singletonList(outVar);
Function function = new Function(functionName, inputs, outputs);
addToFunctionList(function);
}
return null;
}
use of jkind.lustre.Function in project AGREE by loonwerks.
the class AgreeASTPrettyprinter method visit.
@Override
public Void visit(AgreeProgram program) {
if (program.containsRealTimePatterns) {
write("-- Program contains real-time patterns");
newline();
newline();
}
write("-- Program top-level node is: " + program.topNode.id);
newline();
newline();
if (!program.globalTypes.isEmpty()) {
for (Type type : program.globalTypes) {
String name = "dummy";
if (type instanceof RecordType) {
name = ((RecordType) type).id;
} else if (type instanceof EnumType) {
name = ((EnumType) type).id;
}
TypeDef typeDef = new TypeDef(Location.NULL, name, type);
typeDef.accept(this);
newline();
}
newline();
}
if (!program.globalLustreNodes.isEmpty()) {
Iterator<Node> iterator = program.globalLustreNodes.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
}
if (!program.uninterpretedFunctions.isEmpty()) {
Iterator<Function> iterator = program.uninterpretedFunctions.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
}
Iterator<AgreeNode> iterator = program.agreeNodes.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
return null;
}
use of jkind.lustre.Function in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeProgram visit(AgreeProgram e) {
List<AgreeNode> agreeNodes = new ArrayList<>();
for (AgreeNode node : e.agreeNodes) {
AgreeNode visitedNode = visitedNodes.get(node.compInst);
if (visitedNode == null) {
visitedNode = this.visit(node);
}
agreeNodes.add(visitedNode);
}
List<Node> globalLustreNodes = new ArrayList<>();
for (Node node : e.globalLustreNodes) {
globalLustreNodes.add(this.visit(node));
}
List<Function> uninterpretedFunctions = new ArrayList<>();
for (Function function : e.uninterpretedFunctions) {
uninterpretedFunctions.add(this.visit(function));
}
List<jkind.lustre.Type> globalTypes = new ArrayList<>();
for (Type ty : e.globalTypes) {
globalTypes.add(ty.accept(lustreTypeMapVisitor));
}
AgreeNode topNode = this.visit(e.topNode);
return new AgreeProgram(agreeNodes, globalLustreNodes, uninterpretedFunctions, globalTypes, topNode);
}
use of jkind.lustre.Function in project AGREE by loonwerks.
the class LustreAstBuilder method getRealizabilityLustreProgram.
// private static AgreeProgram translate(AgreeProgram program){
// return AgreeInlineLatchedConnections.translate(program);
// }
public static Program getRealizabilityLustreProgram(AgreeProgram agreeProgram) {
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
List<Expr> assertions = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<VarDecl> inputs = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<String> properties = new ArrayList<>();
AgreeNode topNode = agreeProgram.topNode;
for (AgreeStatement assumption : topNode.assumptions) {
assertions.add(assumption.expr);
}
int i = 0;
for (AgreeStatement guarantee : topNode.guarantees) {
String guarName = guarSuffix + i++;
locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, topNode.compInst, null));
equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
properties.add(guarName);
}
List<String> inputStrs = new ArrayList<>();
for (AgreeVar var : topNode.inputs) {
inputs.add(var);
inputStrs.add(var.id);
}
for (AgreeVar var : topNode.outputs) {
inputs.add(var);
}
// and type equations. This would clear this up
for (AgreeStatement statement : topNode.assertions) {
if (AgreeUtils.referenceIsInContract(statement, topNode.compInst)) {
// this is a strange hack we have to do. we have to make
// equation and property
// statements not assertions. They should all be binary
// expressions with an
// equals operator. We will need to removing their corresponding
// variable
// from the inputs and add them to the local variables
BinaryExpr binExpr;
IdExpr varId;
try {
binExpr = (BinaryExpr) statement.expr;
varId = (IdExpr) binExpr.left;
} catch (ClassCastException e) {
// some equation variables are assertions for
// subrange types. do not translate these to
// local equations. Just add them to assertions
assertions.add(statement.expr);
continue;
}
boolean found = false;
int index;
for (index = 0; index < inputs.size(); index++) {
VarDecl var = inputs.get(index);
if (var.id.equals(varId.id)) {
found = true;
break;
}
}
if (!found || binExpr.op != BinaryOp.EQUAL) {
throw new AgreeException("Something went very wrong with the lustre generation in the realizability analysis");
}
locals.add(inputs.remove(index));
equations.add(new Equation(varId, binExpr.right));
}
}
NodeBuilder builder = new NodeBuilder("main");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.setRealizabilityInputs(inputStrs);
Node main = builder.build();
List<Node> nodes = new ArrayList<>();
nodes.add(main);
nodes.addAll(agreeProgram.globalLustreNodes);
List<Function> uFunctions = new ArrayList<>();
uFunctions.addAll(agreeProgram.uninterpretedFunctions);
Program program = new ProgramBuilder().addTypes(types).addFunctions(uFunctions).addNodes(nodes).setMain(main.id).build();
return program;
}
use of jkind.lustre.Function in project AGREE by loonwerks.
the class AgreeASTBuilder method caseCallExpr.
/*
* CallExpr could be a node call, a regular function call, or an uninterpreted function call.
* The former two cases will return a NodeCallExpr, the third case will return a FunctionCallExpr.
*/
@Override
public Expr caseCallExpr(CallExpr expr) {
NamedElement namedEl = expr.getRef().getElm();
String fnName = AgreeUtils.getNodeName(namedEl);
boolean found = false;
for (Node node : globalNodes) {
if (node.id.equals(fnName)) {
found = true;
break;
}
}
if (!found) {
for (Function function : uninterpretedFunc) {
if (function.id.equals(fnName)) {
found = true;
break;
}
}
}
if (!found) {
DoubleDotRef fn = expr.getRef();
doSwitch(fn.getElm());
// for dReal integration
if (fnName.substring(0, 7).equalsIgnoreCase("dreal__")) {
fnName = namedEl.getName();
}
}
List<Expr> argResults = new ArrayList<>();
for (com.rockwellcollins.atc.agree.agree.Expr argExpr : expr.getArgs()) {
argResults.add(doSwitch(argExpr));
}
if (functionNameExists(fnName)) {
FunctionCallExpr functionCall = new FunctionCallExpr(fnName.replace("::", "__"), argResults);
return functionCall;
}
NodeCallExpr nodeCall = new NodeCallExpr(fnName.replace("::", "__"), argResults);
return nodeCall;
}
Aggregations