use of jkind.api.results.Renaming in project AGREE by loonwerks.
the class AgreeMenuListener method addViewCounterexampleMenu.
private void addViewCounterexampleMenu(IMenuManager manager, AnalysisResult original) {
AnalysisResult result = transformResult(original);
final List<Counterexample> cexs = getCounterexamples(result);
final Property property = getProperty(result);
CexExtractorRegistry cexReg = (CexExtractorRegistry) ExtensionRegistry.getRegistry(ExtensionRegistry.CEX_EXTRACTOR_EXT_ID);
List<CexExtractor> extractors = cexReg.getCexExtractors();
if (cexs != null) {
for (Counterexample cex : cexs) {
final String cexType = getCounterexampleType(result);
Map<String, EObject> tempRefMap = linker.getReferenceMap(result.getParent());
if (tempRefMap == null) {
tempRefMap = linker.getReferenceMap(result);
}
Layout tempLayout = linker.getLayout(result.getParent());
if (tempLayout == null) {
tempLayout = linker.getLayout(result);
}
Renaming tempRenaming = linker.getRenaming(result.getParent());
if (tempRenaming == null) {
tempRenaming = linker.getRenaming(result);
}
final Layout layout = tempLayout;
final Map<String, EObject> refMap = tempRefMap;
final AgreeRenaming renaming = (AgreeRenaming) tempRenaming;
final Counterexample translatedCex = translateCounterexampleArrayIndices(cex);
MenuManager sub = new MenuManager("View " + cexType + "Counterexample in");
manager.add(sub);
sub.add(new Action("Console") {
@Override
public void run() {
viewCexConsole(translatedCex, layout, refMap, renaming);
}
});
sub.add(new Action("Eclipse") {
@Override
public void run() {
viewCexEclipse(translatedCex, layout, refMap);
}
});
sub.add(new Action("Spreadsheet") {
@Override
public void run() {
viewCexSpreadsheet(translatedCex, layout);
}
});
InvalidProperty invalid = findInvalidProperty(original);
if (invalid != null) {
String report = invalid.getReport();
if (report != null) {
sub.add(new Action("Web Browser") {
@Override
public void run() {
viewCexBrowser(report);
}
});
}
}
// send counterexamples to external plugins
EObject agreeProperty = refMap.get(result.getName());
ComponentImplementation compImpl = linker.getComponent(result.getParent());
for (CexExtractor ex : extractors) {
sub.add(new Action(ex.getDisplayText()) {
@Override
public void run() {
ex.receiveCex(compImpl, property, agreeProperty, cex, refMap);
}
});
}
}
}
}
use of jkind.api.results.Renaming in project AGREE by loonwerks.
the class AgreeMenuListener method viewCexConsole.
private void viewCexConsole(final Counterexample cex, final Layout layout, Map<String, EObject> refMap, final AgreeRenaming renaming) {
final MessageConsole console = findConsole("Counterexample");
showConsole(console);
console.clearConsole();
console.addPatternMatchListener(new AgreePatternListener(refMap));
/*
* From the Eclipse API: "Clients should avoid writing large amounts of
* output to this stream in the UI thread. The console needs to process
* the output in the UI thread and if the client hogs the UI thread
* writing output to the console, the console will not be able to
* process the output."
*/
new Thread(() -> {
try (MessageConsoleStream out = console.newMessageStream()) {
for (String category : layout.getCategories()) {
if (isEmpty(category, cex, layout)) {
continue;
}
printHLine(out, cex.getLength());
if (category == "") {
out.println("Variables for the selected component implementation");
} else {
out.println("Variables for " + category);
}
printHLine(out, cex.getLength());
out.print(String.format("%-60s", "Variable Name"));
for (int k1 = 0; k1 < cex.getLength(); k1++) {
out.print(String.format("%-15s", k1));
}
out.println();
printHLine(out, cex.getLength());
List<Signal<Value>> inputSignals = new ArrayList<>();
List<Signal<Value>> outputSignals = new ArrayList<>();
List<Signal<Value>> stateSignals = new ArrayList<>();
for (Signal<Value> signal : cex.getCategorySignals(layout, category)) {
// dont' print out values for properties
if (signal.getName().contains(":")) {
continue;
}
String signalName = signal.getName();
EObject ref = renaming.findBestReference(signalName);
boolean isInput = (ref instanceof org.osate.aadl2.Port) ? ((org.osate.aadl2.Port) ref).isIn() : false;
boolean isOutput = (ref instanceof org.osate.aadl2.Port) ? ((org.osate.aadl2.Port) ref).isOut() : false;
if (isInput) {
inputSignals.add(signal);
} else if (isOutput) {
outputSignals.add(signal);
} else {
stateSignals.add(signal);
}
}
out.println("Inputs:");
inputSignals.forEach(it -> printSignal(out, it, cex.getLength()));
out.println("State:");
stateSignals.forEach(it -> printSignal(out, it, cex.getLength()));
out.println("Outputs:");
outputSignals.forEach(it -> printSignal(out, it, cex.getLength()));
out.println();
}
printHLine(out, cex.getLength());
// print uninterpreted functions using Jkind CounterexampleFormatter
AgreeUninterpretedFunctionFormatter uFcnFormatter = new AgreeUninterpretedFunctionFormatter(cex);
out.println(uFcnFormatter.functions());
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}
Aggregations