use of com.rockwellcollins.atc.agree.agree.GuaranteeStatement 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.GuaranteeStatement 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.GuaranteeStatement 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