use of de.be4.classicalb.core.parser.node.PWitness in project probparsers by bendisposto.
the class StructureTest method testWitnessTick.
@Test
public void testWitnessTick() throws Exception {
final Start root = parseInput("machine WitnessTick\nevents\nevent Eve\nwith\n@x' x' :: NAT\nend\nend", false);
final AMachineParseUnit parseUnit = (AMachineParseUnit) root.getPParseUnit();
final LinkedList<PEvent> events = parseUnit.getEvents();
assertEquals(1, events.size());
final AEvent event = (AEvent) events.get(0);
final LinkedList<PWitness> witnesses = event.getWitnesses();
assertEquals(1, witnesses.size());
assertEquals("x'", ((AWitness) witnesses.get(0)).getName().getText());
}
use of de.be4.classicalb.core.parser.node.PWitness in project probparsers by bendisposto.
the class ASTPrologTest method testEvent.
@Test
public void testEvent() throws BCompoundException {
final AEventBModelParseUnit model = new AEventBModelParseUnit();
model.setName(new TIdentifierLiteral("mm"));
final AEventsModelClause events = new AEventsModelClause();
model.setModelClauses(Arrays.asList((PModelClause) events));
AEvent event = new AEvent();
events.setEvent(Arrays.asList((PEvent) event));
event.setEventName(new TIdentifierLiteral("testevent"));
event.setVariables(Arrays.asList(createId("param")));
event.setGuards(Arrays.asList((PPredicate) new ATruthPredicate()));
PSubstitution subst1 = new AAssignSubstitution(Arrays.asList(createId("x")), Arrays.asList(createId("param")));
event.setAssignments(Arrays.asList(subst1));
PWitness witness = new AWitness(new TIdentifierLiteral("ab"), new AEqualPredicate(createId("ab"), createId("y")));
event.setWitness(Arrays.asList(witness));
event.setRefines(Arrays.asList(new TIdentifierLiteral("abstract1"), new TIdentifierLiteral("abstract2")));
checkAST(0, "event_b_model($,mm,[events($,[" + "event($,testevent,[abstract1,abstract2],[identifier($,param)],[truth($)],[]," + "[assign($,[identifier($,x)],[identifier($,param)])]," + "[witness($,identifier(%,ab),equal($,identifier($,ab),identifier($,y)))])])])", model);
}
use of de.be4.classicalb.core.parser.node.PWitness in project probparsers by bendisposto.
the class StructureTest method testWitnessTick.
@Test
public void testWitnessTick() throws Exception {
final Start root = parseInput("machine WitnessTick\nevents\nevent Eve\nwith\n@x' x' :: NAT\nend\nend", false);
final AMachineParseUnit parseUnit = (AMachineParseUnit) root.getPParseUnit();
final LinkedList<PEvent> events = parseUnit.getEvents();
assertEquals(1, events.size());
final AEvent event = (AEvent) events.get(0);
final LinkedList<PWitness> witnesses = event.getWitnesses();
assertEquals(1, witnesses.size());
assertEquals("x'", ((AWitness) witnesses.get(0)).getName().getText());
}
use of de.be4.classicalb.core.parser.node.PWitness 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);
}
Aggregations