Search in sources :

Example 1 with EventParameter

use of de.prob.model.eventb.EventParameter in project prob2 by bendisposto.

the class MachineXmlHandler method addEventParameter.

private void addEventParameter(final Attributes attributes) {
    String name = attributes.getValue("name");
    parameters.add(new EventParameter(name));
}
Also used : EventParameter(de.prob.model.eventb.EventParameter)

Example 2 with EventParameter

use of de.prob.model.eventb.EventParameter 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)

Example 3 with EventParameter

use of de.prob.model.eventb.EventParameter in project prob2 by bendisposto.

the class EventBMachineTranslator method processEvents.

private AEventsModelClause processEvents() {
    List<PEvent> events = new ArrayList<>();
    for (Event e : machine.getEvents()) {
        AEvent event = new AEvent();
        event.setEventName(new TIdentifierLiteral(e.getName()));
        event.setStatus(extractEventStatus(e));
        nodeInfos.put(event, new Tuple2<>(machine.getName(), e.getName()));
        List<TIdentifierLiteral> refined = new ArrayList<>();
        for (Event ref : e.getRefines()) {
            refined.add(new TIdentifierLiteral(ref.getName()));
        }
        event.setRefines(refined);
        List<PExpression> params = new ArrayList<>();
        for (EventParameter eventParameter : e.getParameters()) {
            PExpression pExpression = (PExpression) eventParameter.getExpression().getAst();
            nodeInfos.put(pExpression, new Tuple2<>(machine.getName(), eventParameter.getName()));
            params.add(pExpression);
        }
        event.setVariables(params);
        List<PPredicate> guards = new ArrayList<>();
        List<PPredicate> thms = new ArrayList<>();
        for (EventBGuard eventBGuard : e.getGuards()) {
            PPredicate ppred = (PPredicate) ((EventB) eventBGuard.getPredicate()).getAst();
            nodeInfos.put(ppred, new Tuple2<>(machine.getName(), eventBGuard.getName()));
            if (eventBGuard.isTheorem()) {
                thms.add(ppred);
            } else {
                guards.add(ppred);
            }
        }
        event.setGuards(guards);
        event.setTheorems(thms);
        List<PWitness> witnesses = new ArrayList<>();
        for (Witness witness : e.getWitnesses()) {
            PPredicate ppred = (PPredicate) witness.getPredicate().getAst();
            nodeInfos.put(ppred, new Tuple2<>(machine.getName(), witness.getName()));
            witnesses.add(new AWitness(new TIdentifierLiteral(witness.getName()), ppred));
        }
        event.setWitness(witnesses);
        List<PSubstitution> actions = new ArrayList<>();
        for (EventBAction eventBAction : e.getActions()) {
            PSubstitution psub = (PSubstitution) ((EventB) eventBAction.getCode()).getAst();
            nodeInfos.put(psub, new Tuple2<>(machine.getName(), eventBAction.getName()));
            actions.add(psub);
        }
        event.setAssignments(actions);
        events.add(event);
    }
    return new AEventsModelClause(events);
}
Also used : ArrayList(java.util.ArrayList) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) EventBGuard(de.prob.model.eventb.EventBGuard) PEvent(de.be4.classicalb.core.parser.node.PEvent) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression) EventParameter(de.prob.model.eventb.EventParameter) AWitness(de.be4.classicalb.core.parser.node.AWitness) PWitness(de.be4.classicalb.core.parser.node.PWitness) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) AEvent(de.be4.classicalb.core.parser.node.AEvent) AWitness(de.be4.classicalb.core.parser.node.AWitness) Witness(de.prob.model.eventb.Witness) PWitness(de.be4.classicalb.core.parser.node.PWitness) Event(de.prob.model.eventb.Event) AEvent(de.be4.classicalb.core.parser.node.AEvent) PEvent(de.be4.classicalb.core.parser.node.PEvent) EventBAction(de.prob.model.eventb.EventBAction) AEventsModelClause(de.be4.classicalb.core.parser.node.AEventsModelClause)

Aggregations

EventParameter (de.prob.model.eventb.EventParameter)3 Event (de.prob.model.eventb.Event)2 ArrayList (java.util.ArrayList)2 AEvent (de.be4.classicalb.core.parser.node.AEvent)1 AEventsModelClause (de.be4.classicalb.core.parser.node.AEventsModelClause)1 AWitness (de.be4.classicalb.core.parser.node.AWitness)1 PEvent (de.be4.classicalb.core.parser.node.PEvent)1 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)1 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)1 PWitness (de.be4.classicalb.core.parser.node.PWitness)1 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)1 ClassicalBMachine (de.prob.model.classicalb.ClassicalBMachine)1 Operation (de.prob.model.classicalb.Operation)1 EventBAction (de.prob.model.eventb.EventBAction)1 EventBGuard (de.prob.model.eventb.EventBGuard)1 EventBMachine (de.prob.model.eventb.EventBMachine)1 Witness (de.prob.model.eventb.Witness)1 AbstractElement (de.prob.model.representation.AbstractElement)1