use of de.prob.model.eventb.EventBMachine in project prob2 by bendisposto.
the class EventBModelTranslator method printPragmas.
private void printPragmas(final IPrologTermOutput pto) {
for (Machine machine : model.getChildrenOfType(Machine.class)) {
EventBMachine ebM = (EventBMachine) machine;
for (EventBVariable var : ebM.getVariables()) {
if (var.hasUnit()) {
pto.openTerm("pragma");
pto.printAtom("unit");
pto.printAtom(machine.getName());
pto.printAtom(var.getName());
pto.openList();
pto.printAtom(var.getUnit());
pto.closeList();
pto.closeTerm();
}
}
}
for (Context context : model.getChildrenOfType(Context.class)) {
for (EventBConstant constant : context.getConstants()) {
if (constant.hasUnit()) {
pto.openTerm("pragma");
pto.printAtom("unit");
pto.printAtom(context.getName());
pto.printAtom(constant.getName());
pto.openList();
pto.printAtom(constant.getUnit());
pto.closeList();
pto.closeTerm();
}
}
}
}
use of de.prob.model.eventb.EventBMachine in project prob2 by bendisposto.
the class EventBModelTranslator method extractMachines.
private List<EventBMachine> extractMachines(final EventBMachine machine, EventBModel model) {
if (machine.getRefines().isEmpty()) {
return Collections.emptyList();
}
List<EventBMachine> machines = new ArrayList<>();
for (EventBMachine eventBMachine : machine.getRefines()) {
EventBMachine refinedMachine = model.getMachine(eventBMachine.getName());
machines.add(refinedMachine);
machines.addAll(extractMachines(refinedMachine, model));
}
return machines;
}
use of de.prob.model.eventb.EventBMachine in project prob2 by bendisposto.
the class MachineXmlHandler method addRefinedMachine.
private void addRefinedMachine(final Attributes attributes) {
String target = attributes.getValue("org.eventb.core.scTarget");
String machineName = target.substring(target.lastIndexOf('/') + 1, target.lastIndexOf('.'));
model = model.addRelationship(machine.getName(), machineName, ERefType.REFINES);
AbstractElement component = model.getComponent(machineName);
if (component != null) {
EventBMachine mch = (EventBMachine) component;
refines.add(mch);
} else {
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = parserFactory.newSAXParser();
String fileName = directoryPath + File.separatorChar + machineName + ".bcm";
MachineXmlHandler handler = new MachineXmlHandler(model, fileName, typeEnv);
saxParser.parse(new File(fileName), handler);
axiomCache.putAll(handler.getAxiomCache());
invariantCache.putAll(handler.getInvariantCache());
eventCache.putAll(handler.getEventCache());
refines.add(handler.getMachine());
model = handler.getModel();
} catch (IOException | ParserConfigurationException | SAXException e) {
logger.error("Error parsing XML", e);
}
}
}
use of de.prob.model.eventb.EventBMachine in project prob2 by bendisposto.
the class ComponentExtractor method caseAMachineParseUnit.
@Override
public void caseAMachineParseUnit(final AMachineParseUnit node) {
String name = node.getName().getText();
MachineModifier machineM = new MachineModifier(new EventBMachine(name), typeEnv);
ModelElementList<Context> seen = new ModelElementList<>();
for (TIdentifierLiteral contextName : node.getSeenNames()) {
String cName = contextName.getText();
AbstractElement context = getContext(cName);
seen = seen.addElement((Context) context);
}
machineM = machineM.setSees(seen);
if (node.getRefinesNames().size() == 1) {
String mname = node.getRefinesNames().getFirst().getText();
EventBMachine machine = getMachine(mname);
machineM = machineM.setRefines(machine);
} else if (node.getRefinesNames().size() > 1) {
throw new IllegalArgumentException("Machines can only refine one abstract machine. Found " + node.getRefinesNames().size() + " refined machines");
}
machineM = machineM.addComment(getComment(node.getComments()));
MachineExtractor mE = new MachineExtractor(machineM, typeEnv);
node.apply(mE);
modelM = modelM.addMachine(mE.getMachine());
}
use of de.prob.model.eventb.EventBMachine in project prob2 by bendisposto.
the class Transition method getParameterPredicates.
/**
* @return a list of string predicates representing the value of the
* parameters for this transition
*/
public List<String> getParameterPredicates() {
if (isArtificialTransition()) {
return Collections.emptyList();
}
evaluate(FormulaExpand.EXPAND);
List<String> predicates = new ArrayList<>();
AbstractElement mainComponent = stateSpace.getMainComponent();
List<String> paramNames = new ArrayList<>();
if (mainComponent instanceof ClassicalBMachine) {
Operation op = ((ClassicalBMachine) mainComponent).getOperation(getName());
paramNames = op.getParameters();
} else if (mainComponent instanceof EventBMachine) {
Event event = ((EventBMachine) mainComponent).getEvent(getName());
for (EventParameter eventParameter : event.getParameters()) {
paramNames.add(eventParameter.getName());
}
}
if (paramNames.size() == this.params.size()) {
for (int i = 0; i < paramNames.size(); i++) {
predicates.add(paramNames.get(i) + " = " + this.params.get(i));
}
}
return predicates;
}
Aggregations