use of com.rockwellcollins.atc.agree.agree.LemmaStatement 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.agree.LemmaStatement in project AGREE by loonwerks.
the class AgreeMenuListener method addResultsLinkingMenu.
private void addResultsLinkingMenu(IMenuManager manager, AnalysisResult result) {
if (result instanceof PropertyResult) {
PropertyResult pr = (PropertyResult) result;
Map<String, EObject> refMap = linker.getReferenceMap(pr.getParent());
EObject property = refMap.get(pr.getName());
if (property instanceof GuaranteeStatement) {
manager.add(createHyperlinkAction("Go To Guarantee", property));
}
if (property instanceof LemmaStatement) {
manager.add(createHyperlinkAction("Go To Lemma", property));
}
if (property instanceof AssumeStatement) {
manager.add(createHyperlinkAction("Go To Assumption", property));
}
if (property instanceof CallExpr) {
manager.add(createHyperlinkAction("Go To Node Call", property));
}
if (property instanceof AgreeStatement) {
AgreeStatement statement = (AgreeStatement) property;
if (statement.reference instanceof AgreePattern) {
AgreePattern pattern = (AgreePattern) statement.reference;
manager.add(createHyperlinkAction("Go To Pattern", pattern.reference));
}
}
}
}
use of com.rockwellcollins.atc.agree.agree.LemmaStatement 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.agree.LemmaStatement in project AGREE by loonwerks.
the class CreateSimulationProperties method transform.
public static SimulationProgram transform(final SimulationProgram program) {
final Program lustreProgram = program.getLustreProgram();
if (lustreProgram.nodes.size() != 1) {
throw new IllegalArgumentException("Only lustre programs with exactly one node are supported");
}
final SimulationProgramBuilder builder = new SimulationProgramBuilder(program);
final Node mainNode = lustreProgram.getMainNode();
// Build a new main node which includes support statements
final NodeBuilder lustreNodeBuilder = new NodeBuilder(mainNode);
// Create simulation properties for each local variable that references a lemma, assume, guarantee, or assert statement
lustreNodeBuilder.clearIvc();
final Map<String, SimulationProperty> idToSimulationPropertyMap = new HashMap<>();
// Create a mapping from the component instance/variable reference to a collection of Lustre Id's that will be used to create the simulation properties
final Map<ComponentInstance, Map<EObject, Collection<String>>> componentInstanceToReferenceToVarIdMap = new HashMap<>();
for (final VarDecl local : mainNode.locals) {
if (local instanceof AgreeVar) {
final AgreeVar var = (AgreeVar) local;
if (var.reference instanceof LemmaStatement || var.reference instanceof AssumeStatement || var.reference instanceof GuaranteeStatement || var.reference instanceof AssertStatement) {
final boolean createSimProp = (!(var.reference instanceof AssumeStatement) || var.compInst == var.compInst.getSystemInstance()) || var instanceof SimulationPropertyVar;
if (createSimProp) {
Map<EObject, Collection<String>> referenceToVarIdMap = componentInstanceToReferenceToVarIdMap.get(var.compInst);
if (referenceToVarIdMap == null) {
referenceToVarIdMap = new HashMap<>();
componentInstanceToReferenceToVarIdMap.put(var.compInst, referenceToVarIdMap);
}
Collection<String> varIds = referenceToVarIdMap.get(var.reference);
if (varIds == null) {
varIds = new HashSet<>();
referenceToVarIdMap.put(var.reference, varIds);
}
varIds.add(var.id);
}
}
}
}
// Create the simulation properties.
// A single simulation property will be created for each component instance, reference combination.
int propertyIndex = 0;
for (final Entry<ComponentInstance, Map<EObject, Collection<String>>> componentInstanceToReferenceToVarIdMapEntry : componentInstanceToReferenceToVarIdMap.entrySet()) {
final ComponentInstance propComponentInstance = componentInstanceToReferenceToVarIdMapEntry.getKey();
for (Entry<EObject, Collection<String>> referenceToVarIdsEntry : componentInstanceToReferenceToVarIdMapEntry.getValue().entrySet()) {
final EObject propReference = referenceToVarIdsEntry.getKey();
final Collection<String> propLustreIds = referenceToVarIdsEntry.getValue();
final String propertyDesc = getDescription(propComponentInstance, propReference);
final String enablementVariableId;
// Only properties which cause the simulation to be halted may be disabled.
// That is: only top-level assumptions and non-top-level guarantees may be disabled
final boolean disableable = (propReference instanceof GuaranteeStatement && propComponentInstance != propComponentInstance.getSystemInstance()) || (propReference instanceof AssumeStatement && propComponentInstance == propComponentInstance.getSystemInstance());
if (disableable) {
enablementVariableId = propertyEnablementPrefix + propertyIndex;
lustreNodeBuilder.addLocal(new VarDecl(enablementVariableId, NamedType.BOOL));
} else {
enablementVariableId = null;
}
final SimulationProperty simProp = new SimulationProperty(propLustreIds, propertyDesc, propReference, enablementVariableId);
builder.addSimulationProperty(simProp);
propertyIndex++;
for (final String propLustreId : propLustreIds) {
idToSimulationPropertyMap.put(propLustreId, simProp);
lustreNodeBuilder.addIvc(propLustreId);
}
}
}
// Edit main node to make simulation properties inside of assertions to be disableable
final AstMapVisitor propertyVarDisableTransformation = new AstMapVisitor() {
@Override
public Expr visit(final IdExpr e) {
final SimulationProperty simProp = idToSimulationPropertyMap.get(e.id);
if (simProp != null && simProp.getEnablementVariableId() != null) {
return new BinaryExpr(new UnaryExpr(UnaryOp.NOT, new IdExpr(simProp.getEnablementVariableId())), BinaryOp.OR, e);
}
return super.visit(e);
}
@Override
public Equation visit(final Equation e) {
// Don't transform the equations for simulation properties
if (e.lhs.size() == 1 && idToSimulationPropertyMap.containsKey(e.lhs.get(0))) {
return e;
}
return super.visit(e);
}
};
// Transform assertions and equations
lustreNodeBuilder.clearAssertions();
for (final Expr assertion : mainNode.assertions) {
lustreNodeBuilder.addAssertion(assertion.accept(propertyVarDisableTransformation));
}
lustreNodeBuilder.clearEquations();
for (final Equation eq : mainNode.equations) {
lustreNodeBuilder.addEquation((Equation) eq.accept(propertyVarDisableTransformation));
}
// Build a new program with the new main node
final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(lustreProgram);
lustreProgramBuilder.clearNodes();
lustreProgramBuilder.addNode(lustreNodeBuilder.build());
builder.setLustreProgram(lustreProgramBuilder.build());
return builder.build();
}
Aggregations