use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeVar visit(AgreeVar e) {
String name = e.id;
Type type = e.type.accept(lustreTypeMapVisitor);
EObject reference = e.reference;
ComponentInstance compInst = e.compInst;
FeatureInstance featInst = e.featInst;
return new AgreeVar(name, type, reference, compInst, featInst);
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class AgreeASTMapVisitor method visit.
@Override
public AgreeConnection visit(AgreeConnection e) {
if (e instanceof AgreeAADLConnection) {
AgreeAADLConnection aadlConn = (AgreeAADLConnection) e;
AgreeNode sourceNode = null;
if (aadlConn.sourceNode != null) {
sourceNode = visitedNodes.get(aadlConn.sourceNode.compInst);
}
AgreeNode destinationNode = null;
if (aadlConn.destinationNode != null) {
destinationNode = visitedNodes.get(aadlConn.destinationNode.compInst);
}
AgreeVar sourVar = visit(aadlConn.sourceVarName);
AgreeVar destVar = visit(aadlConn.destinationVarName);
ConnectionType type = aadlConn.type;
boolean latched = aadlConn.latched;
boolean delayed = aadlConn.delayed;
EObject reference = aadlConn.reference;
return new AgreeAADLConnection(sourceNode, destinationNode, sourVar, destVar, type, latched, delayed, reference);
} else if (e instanceof AgreeOverriddenConnection) {
AgreeOverriddenConnection overriddenCon = (AgreeOverriddenConnection) e;
AgreeStatement statement = visit(overriddenCon.statement);
return new AgreeOverriddenConnection(statement, overriddenCon.aadlConn);
}
throw new AgreeException("Unhandled Agree connection type " + e.getClass());
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class LustreAstBuilder method getAssumeGuaranteeLustreProgram.
public static Program getAssumeGuaranteeLustreProgram(AgreeProgram agreeProgram) {
nodes = new ArrayList<>();
uninterpretedFcns = new ArrayList<>();
AgreeNode flatNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
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<>();
List<String> ivcs = new ArrayList<>();
int j = 0;
for (AgreeStatement assumption : flatNode.assumptions) {
String assumName = assumeSuffix + j++;
locals.add(new AgreeVar(assumName, NamedType.BOOL, assumption.reference, flatNode.compInst, null));
IdExpr assumId = new IdExpr(assumName);
equations.add(new Equation(assumId, assumption.expr));
assertions.add(assumId);
// Else add the defined ivc list.
if (flatNode.getFaultTreeFlag() == false) {
ivcs.add(assumId.id);
}
}
for (AgreeStatement assertion : flatNode.assertions) {
assertions.add(assertion.expr);
}
// add assumption and monolithic lemmas first (helps with proving)
for (AgreeVar var : flatNode.outputs) {
if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
properties.add(var.id);
}
inputs.add(var);
}
// add property that all assumption history is true
Expr assumeConj = new BoolExpr(true);
for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
assumeConj = new BinaryExpr(new IdExpr(subNode.id + "__" + assumeHistSufix), BinaryOp.AND, assumeConj);
}
AgreeVar assumeHistVar = new AgreeVar(assumeHistSufix, NamedType.BOOL, agreeProgram.topNode.compInst.getComponentClassifier(), agreeProgram.topNode.compInst, null);
locals.add(assumeHistVar);
equations.add(new Equation(new IdExpr(assumeHistVar.id), assumeConj));
properties.add(assumeHistVar.id);
int k = 0;
for (AgreeStatement patternPropState : flatNode.patternProps) {
String patternVarName = patternPropSuffix + k++;
locals.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(patternVarName), patternPropState.expr));
properties.add(patternVarName);
}
int lemmaCount = 0;
for (AgreeStatement lemma : flatNode.lemmas) {
String lemmaName = lemmaSuffix + lemmaCount++;
locals.add(new AgreeVar(lemmaName, NamedType.BOOL, lemma.reference, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(lemmaName), lemma.expr));
properties.add(lemmaName);
}
int i = 0;
for (AgreeStatement guarantee : flatNode.guarantees) {
String guarName = guarSuffix + i++;
locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
properties.add(guarName);
}
if (flatNode.getFaultTreeFlag()) {
ivcs.addAll(agreeProgram.topNode.getivcElements());
}
for (AgreeVar var : flatNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : flatNode.locals) {
locals.add(var);
}
equations.addAll(flatNode.localEquations);
assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(flatNode.eventTimes));
NodeBuilder builder = new NodeBuilder("main");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.addIvcs(ivcs);
Node main = builder.build();
nodes.add(main);
nodes.addAll(agreeProgram.globalLustreNodes);
nodes.add(getHistNode());
// add realtime constraint nodes
nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
Program program = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(main.id).build();
return program;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class LustreAstBuilder method getConsistencyLustreNode.
protected static Node getConsistencyLustreNode(AgreeNode agreeNode, boolean withAssertions) {
final String stuffPrefix = "__STUFF";
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<>();
List<String> ivcs = new ArrayList<>();
Expr stuffConj = new BoolExpr(true);
int stuffAssumptionIndex = 0;
for (AgreeStatement assumption : agreeNode.assumptions) {
AgreeVar stuffAssumptionVar = new AgreeVar(stuffPrefix + assumeSuffix + stuffAssumptionIndex++, NamedType.BOOL, assumption.reference, agreeNode.compInst, null);
locals.add(stuffAssumptionVar);
ivcs.add(stuffAssumptionVar.id);
IdExpr stuffAssumptionId = new IdExpr(stuffAssumptionVar.id);
equations.add(new Equation(stuffAssumptionId, assumption.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssumptionId);
}
int stuffGuaranteeIndex = 0;
for (AgreeStatement guarantee : agreeNode.guarantees) {
AgreeVar stuffGuaranteeVar = new AgreeVar(stuffPrefix + guarSuffix + stuffGuaranteeIndex++, NamedType.BOOL, guarantee.reference, agreeNode.compInst, null);
locals.add(stuffGuaranteeVar);
ivcs.add(stuffGuaranteeVar.id);
IdExpr stuffGuaranteeId = new IdExpr(stuffGuaranteeVar.id);
equations.add(new Equation(stuffGuaranteeId, guarantee.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffGuaranteeId);
}
if (withAssertions) {
equations.addAll(agreeNode.localEquations);
} else {
for (AgreeEquation eq : agreeNode.localEquations) {
if (AgreeUtils.referenceIsInContract(eq.reference, agreeNode.compInst)) {
equations.add(eq);
}
}
}
// TODO should we include lemmas in the consistency check?
// for(AgreeStatement guarantee : agreeNode.lemmas){
// histConj = new BinaryExpr(histConj, BinaryOp.AND, guarantee.expr);
// }
int stuffAssertionIndex = 0;
if (withAssertions) {
for (AgreeStatement assertion : agreeNode.assertions) {
AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
locals.add(stuffAssertionVar);
IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
equations.add(new Equation(stuffAssertionId, assertion.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
}
} else {
// equations and type equations. That would clear this up.
for (AgreeStatement assertion : agreeNode.assertions) {
if (AgreeUtils.referenceIsInContract(assertion.reference, agreeNode.compInst)) {
AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
locals.add(stuffAssertionVar);
IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
equations.add(new Equation(stuffAssertionId, assertion.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
}
}
}
// add realtime constraints
Set<AgreeVar> eventTimes = new HashSet<>();
if (withAssertions) {
eventTimes.addAll(agreeNode.eventTimes);
} else {
for (AgreeVar eventVar : agreeNode.eventTimes) {
if (AgreeUtils.referenceIsInContract(eventVar.reference, agreeNode.compInst)) {
eventTimes.add(eventVar);
}
}
}
assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(eventTimes));
for (AgreeVar var : agreeNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.outputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.locals) {
if (withAssertions) {
locals.add(var);
} else {
if (AgreeUtils.referenceIsInContract(var.reference, agreeNode.compInst)) {
locals.add(var);
}
}
}
EObject classifier = agreeNode.compInst.getComponentClassifier();
AgreeVar countVar = new AgreeVar("__COUNT", NamedType.INT, null, null, null);
AgreeVar stuffVar = new AgreeVar(stuffPrefix, NamedType.BOOL, null, null, null);
AgreeVar histVar = new AgreeVar("__HIST", NamedType.BOOL, null, null, null);
AgreeVar propVar = new AgreeVar("__PROP", NamedType.BOOL, classifier, agreeNode.compInst, null);
locals.add(countVar);
locals.add(stuffVar);
locals.add(histVar);
locals.add(propVar);
IdExpr countId = new IdExpr(countVar.id);
IdExpr stuffId = new IdExpr(stuffVar.id);
IdExpr histId = new IdExpr(histVar.id);
IdExpr propId = new IdExpr(propVar.id);
equations.add(new Equation(stuffId, stuffConj));
Expr histExpr = new UnaryExpr(UnaryOp.PRE, histId);
histExpr = LustreExprFactory.makeANDExpr(histExpr, stuffId);
histExpr = new BinaryExpr(stuffId, BinaryOp.ARROW, histExpr);
equations.add(new Equation(histId, histExpr));
Expr countExpr = new UnaryExpr(UnaryOp.PRE, countId);
countExpr = new BinaryExpr(countExpr, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
countExpr = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, countExpr);
equations.add(new Equation(countId, countExpr));
IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
int consistDetph = prefs.getInt(PreferenceConstants.PREF_CONSIST_DEPTH);
Expr propExpr = new BinaryExpr(countId, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(consistDetph)));
propExpr = new BinaryExpr(propExpr, BinaryOp.AND, histId);
equations.add(new Equation(propId, new UnaryExpr(UnaryOp.NOT, propExpr)));
properties.add(propId.id);
NodeBuilder builder = new NodeBuilder("consistency");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.addIvcs(ivcs);
Node node = builder.build();
return node;
}
use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AGREE by loonwerks.
the class LustreAstBuilder method flattenAgreeNode.
protected static AgreeNode flattenAgreeNode(AgreeProgram agreeProgram, AgreeNode agreeNode, String nodePrefix) {
List<AgreeVar> inputs = new ArrayList<>();
List<AgreeVar> outputs = new ArrayList<>();
List<AgreeVar> locals = new ArrayList<>();
List<AgreeStatement> patternProps = new ArrayList<>();
List<AgreeEquation> equations = new ArrayList<>();
List<AgreeStatement> assertions = new ArrayList<>();
Set<AgreeVar> timeEvents = new HashSet<>(agreeNode.eventTimes);
Expr someoneTicks = null;
for (AgreeNode subAgreeNode : agreeNode.subNodes) {
String prefix = subAgreeNode.id + AgreeASTBuilder.dotChar;
Expr clockExpr = getClockExpr(agreeNode, subAgreeNode);
if (someoneTicks == null) {
someoneTicks = clockExpr;
} else {
someoneTicks = new BinaryExpr(someoneTicks, BinaryOp.OR, clockExpr);
}
AgreeNode flatNode = flattenAgreeNode(agreeProgram, subAgreeNode, nodePrefix + subAgreeNode.id + AgreeASTBuilder.dotChar);
Node lustreNode = addSubNodeLustre(agreeProgram, agreeNode, nodePrefix, flatNode);
addInputsAndOutputs(agreeNode, inputs, outputs, patternProps, flatNode, lustreNode, prefix);
addTimeEvents(timeEvents, flatNode, prefix, assertions);
addNodeCall(agreeNode, assertions, prefix, clockExpr, lustreNode);
addHistoricalAssumptionConstraint(agreeNode, prefix, clockExpr, assertions, lustreNode);
}
if (agreeNode.timing == TimingModel.ASYNC) {
if (someoneTicks == null) {
throw new AgreeException("Somehow we generated a clock constraint without any clocks." + " Perhaps none of your subcomponents have an agree annex?");
}
assertions.add(new AgreeStatement("someone ticks", someoneTicks, null));
}
addConnectionConstraints(agreeNode, assertions);
// add any clock constraints
assertions.addAll(agreeNode.assertions);
assertions.add(new AgreeStatement("", agreeNode.clockConstraint, null));
inputs.addAll(agreeNode.inputs);
outputs.addAll(agreeNode.outputs);
locals.addAll(agreeNode.locals);
equations.addAll(agreeNode.localEquations);
patternProps.addAll(agreeNode.patternProps);
AgreeNodeBuilder builder = new AgreeNodeBuilder(agreeNode.id);
builder.addInput(inputs);
builder.addOutput(outputs);
builder.addLocal(locals);
builder.addLocalEquation(equations);
builder.addIvcElements(agreeNode.getivcElements());
builder.addSubNode(agreeNode.subNodes);
builder.addAssertion(assertions);
builder.addAssumption(agreeNode.assumptions);
builder.addGuarantee(agreeNode.guarantees);
builder.addLemma(agreeNode.lemmas);
builder.addPatternProp(patternProps);
builder.setClockConstraint(new BoolExpr(true));
builder.setInitialConstraint(agreeNode.initialConstraint);
builder.setClockVar(agreeNode.clockVar);
builder.setReference(agreeNode.reference);
builder.setTiming(null);
builder.addEventTime(timeEvents);
builder.setCompInst(agreeNode.compInst);
builder.setFaultTreeFlag(agreeNode.faultTreeFlag);
return builder.build();
}
Aggregations