Search in sources :

Example 6 with Event

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

Example 7 with Event

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

the class ProofExtractor method addProofs.

private void addProofs(final EventBMachine m) {
    for (Map.Entry<String, String> entry : descriptions.entrySet()) {
        String name = entry.getKey();
        String desc = entry.getValue();
        boolean isDischarged = discharged.contains(name);
        String[] split = name.split("/");
        String type;
        if (split.length == 1) {
            type = split[0];
        } else if (split.length == 2) {
            type = split[1];
        } else {
            type = split[2];
        }
        String source = m.getName();
        List<Tuple2<String, String>> elements = new ArrayList<>();
        if ("GRD".equals(type)) {
            Event concreteEvent = m.getEvent(split[0]);
            for (Event event : concreteEvent.getRefines()) {
                if (event.getGuards().getElement(split[1]) != null) {
                    EventBGuard guard = event.getGuards().getElement(split[1]);
                    elements.add(new Tuple2<>("event", event.getName()));
                    elements.add(new Tuple2<>("guard", guard.getName()));
                }
            }
            elements.add(new Tuple2<>("event", concreteEvent.getName()));
            proofs.add(new ProofObligation(source, name, isDischarged, desc, elements));
        } else if ("INV".equals(type)) {
            elements.add(new Tuple2<>("event", "invariant"));
            proofs.add(new ProofObligation(source, name, isDischarged, desc, elements));
        } else if ("THM".equals(type)) {
            if (split.length == 2) {
                elements.add(new Tuple2<>("invariant", split[0]));
            } else {
                elements.add(new Tuple2<>("guard", split[1]));
                elements.add(new Tuple2<>("event", split[0]));
            }
            proofs.add(new ProofObligation(source, name, isDischarged, desc, elements));
        } else if ("WD".equals(type)) {
            if (split.length == 2) {
                elements.add(new Tuple2<>("invariant", split[0]));
            } else {
                Event event = m.getEvent(split[0]);
                if (event.getActions().getElement(split[1]) != null) {
                    elements.add(new Tuple2<>("event", event.getName()));
                    elements.add(new Tuple2<>("action", split[1]));
                } else {
                    elements.add(new Tuple2<>("event", event.getName()));
                    elements.add(new Tuple2<>("guard", split[1]));
                }
                proofs.add(new ProofObligation(source, name, isDischarged, desc, elements));
            }
        } else {
            proofs.add(new ProofObligation(source, name, isDischarged, desc, elements));
        }
    }
}
Also used : Tuple2(de.prob.util.Tuple2) ProofObligation(de.prob.model.eventb.ProofObligation) ArrayList(java.util.ArrayList) Event(de.prob.model.eventb.Event) EventBGuard(de.prob.model.eventb.EventBGuard) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Event (de.prob.model.eventb.Event)7 ArrayList (java.util.ArrayList)3 EventBGuard (de.prob.model.eventb.EventBGuard)2 EventParameter (de.prob.model.eventb.EventParameter)2 BEvent (de.prob.model.representation.BEvent)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 AEvent (de.be4.eventbalg.core.parser.node.AEvent)1 ClassicalBMachine (de.prob.model.classicalb.ClassicalBMachine)1 Operation (de.prob.model.classicalb.Operation)1 EventBAction (de.prob.model.eventb.EventBAction)1 EventBMachine (de.prob.model.eventb.EventBMachine)1 MachineModifier (de.prob.model.eventb.MachineModifier)1