Search in sources :

Example 1 with EventBMachine

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();
            }
        }
    }
}
Also used : Context(de.prob.model.eventb.Context) EventBVariable(de.prob.model.eventb.EventBVariable) EventBConstant(de.prob.model.eventb.EventBConstant) EventBMachine(de.prob.model.eventb.EventBMachine) EventBMachine(de.prob.model.eventb.EventBMachine) Machine(de.prob.model.representation.Machine)

Example 2 with EventBMachine

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;
}
Also used : ArrayList(java.util.ArrayList) EventBMachine(de.prob.model.eventb.EventBMachine)

Example 3 with EventBMachine

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);
        }
    }
}
Also used : AbstractElement(de.prob.model.representation.AbstractElement) SAXParser(javax.xml.parsers.SAXParser) EventBMachine(de.prob.model.eventb.EventBMachine) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 4 with EventBMachine

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());
}
Also used : Context(de.prob.model.eventb.Context) AbstractElement(de.prob.model.representation.AbstractElement) ModelElementList(de.prob.model.representation.ModelElementList) EventBMachine(de.prob.model.eventb.EventBMachine) MachineModifier(de.prob.model.eventb.MachineModifier) TIdentifierLiteral(de.be4.eventbalg.core.parser.node.TIdentifierLiteral)

Example 5 with EventBMachine

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;
}
Also used : EventParameter(de.prob.model.eventb.EventParameter) AbstractElement(de.prob.model.representation.AbstractElement) ClassicalBMachine(de.prob.model.classicalb.ClassicalBMachine) ArrayList(java.util.ArrayList) Event(de.prob.model.eventb.Event) EventBMachine(de.prob.model.eventb.EventBMachine) Operation(de.prob.model.classicalb.Operation)

Aggregations

EventBMachine (de.prob.model.eventb.EventBMachine)6 Context (de.prob.model.eventb.Context)3 AbstractElement (de.prob.model.representation.AbstractElement)3 ArrayList (java.util.ArrayList)3 TIdentifierLiteral (de.be4.eventbalg.core.parser.node.TIdentifierLiteral)1 ClassicalBMachine (de.prob.model.classicalb.ClassicalBMachine)1 Operation (de.prob.model.classicalb.Operation)1 Event (de.prob.model.eventb.Event)1 EventBConstant (de.prob.model.eventb.EventBConstant)1 EventBVariable (de.prob.model.eventb.EventBVariable)1 EventParameter (de.prob.model.eventb.EventParameter)1 MachineModifier (de.prob.model.eventb.MachineModifier)1 Machine (de.prob.model.representation.Machine)1 ModelElementList (de.prob.model.representation.ModelElementList)1 File (java.io.File)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 SAXException (org.xml.sax.SAXException)1