Search in sources :

Example 6 with AEvent

use of de.be4.eventb.core.parser.node.AEvent in project probparsers by bendisposto.

the class CommentTest method testAtSignInComment.

@Test
public void testAtSignInComment() throws Exception {
    final Start rootNode = parseInput("machine AtSignInComment\nevents\nevent testEvent\nthen\n@act1 skip\n@act2 skip\n// MyComment@act2\nend\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final AEvent event = (AEvent) parseUnit.getEvents().get(0);
    final LinkedList<PAction> actions = event.getActions();
    AAction labeledAction = (AAction) actions.get(0);
    assertEquals("act1", labeledAction.getName().getText());
    assertEquals("skip", labeledAction.getAction().getText());
    assertEquals(0, labeledAction.getComments().size());
    labeledAction = (AAction) actions.get(1);
    assertEquals("act2", labeledAction.getName().getText());
    assertEquals("skip", labeledAction.getAction().getText());
    assertNotNull(labeledAction.getComments());
    assertEquals("MyComment@act2", labeledAction.getComments().get(0).getText());
}
Also used : PAction(de.be4.eventb.core.parser.node.PAction) Start(de.be4.eventb.core.parser.node.Start) AEvent(de.be4.eventb.core.parser.node.AEvent) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) AAction(de.be4.eventb.core.parser.node.AAction) Test(org.junit.Test)

Example 7 with AEvent

use of de.be4.eventb.core.parser.node.AEvent 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

Test (org.junit.Test)5 AEvent (de.be4.eventbalg.core.parser.node.AEvent)3 AEvent (de.be4.classicalb.core.parser.node.AEvent)2 AEventsModelClause (de.be4.classicalb.core.parser.node.AEventsModelClause)2 AWitness (de.be4.classicalb.core.parser.node.AWitness)2 PEvent (de.be4.classicalb.core.parser.node.PEvent)2 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)2 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)2 PWitness (de.be4.classicalb.core.parser.node.PWitness)2 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)2 AEvent (de.be4.eventb.core.parser.node.AEvent)2 AMachineParseUnit (de.be4.eventb.core.parser.node.AMachineParseUnit)2 Start (de.be4.eventb.core.parser.node.Start)2 AMachineParseUnit (de.be4.eventbalg.core.parser.node.AMachineParseUnit)2 Start (de.be4.eventbalg.core.parser.node.Start)2 Event (de.prob.model.eventb.Event)2 AAssignSubstitution (de.be4.classicalb.core.parser.node.AAssignSubstitution)1 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)1 AEventBModelParseUnit (de.be4.classicalb.core.parser.node.AEventBModelParseUnit)1 ATruthPredicate (de.be4.classicalb.core.parser.node.ATruthPredicate)1