Search in sources :

Example 1 with PModelClause

use of de.be4.classicalb.core.parser.node.PModelClause in project prob2 by bendisposto.

the class EventBMachineTranslator method translateMachine.

public Node translateMachine() {
    AEventBModelParseUnit ast = new AEventBModelParseUnit();
    ast.setName(new TIdentifierLiteral(machine.getName()));
    List<PModelClause> clauses = new ArrayList<>();
    clauses.add(processContexts());
    ARefinesModelClause refines = processRefines();
    if (refines != null) {
        clauses.add(refines);
    }
    clauses.add(processVariables());
    clauses.addAll(processInvariantsAndTheorems());
    AVariantModelClause variant = processVariant();
    if (variant != null) {
        clauses.add(variant);
    }
    clauses.add(processEvents());
    ast.setModelClauses(clauses);
    return ast;
}
Also used : ARefinesModelClause(de.be4.classicalb.core.parser.node.ARefinesModelClause) AEventBModelParseUnit(de.be4.classicalb.core.parser.node.AEventBModelParseUnit) PModelClause(de.be4.classicalb.core.parser.node.PModelClause) AVariantModelClause(de.be4.classicalb.core.parser.node.AVariantModelClause) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 2 with PModelClause

use of de.be4.classicalb.core.parser.node.PModelClause 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);
}
Also used : AEqualPredicate(de.be4.classicalb.core.parser.node.AEqualPredicate) PModelClause(de.be4.classicalb.core.parser.node.PModelClause) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PEvent(de.be4.classicalb.core.parser.node.PEvent) AEventBModelParseUnit(de.be4.classicalb.core.parser.node.AEventBModelParseUnit) AWitness(de.be4.classicalb.core.parser.node.AWitness) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) PWitness(de.be4.classicalb.core.parser.node.PWitness) AEvent(de.be4.classicalb.core.parser.node.AEvent) ATruthPredicate(de.be4.classicalb.core.parser.node.ATruthPredicate) AEventsModelClause(de.be4.classicalb.core.parser.node.AEventsModelClause) AAssignSubstitution(de.be4.classicalb.core.parser.node.AAssignSubstitution) Test(org.junit.Test)

Example 3 with PModelClause

use of de.be4.classicalb.core.parser.node.PModelClause in project prob2 by bendisposto.

the class EventBMachineTranslator method processInvariantsAndTheorems.

private List<PModelClause> processInvariantsAndTheorems() {
    List<PModelClause> invsAndTheorems = new ArrayList<>();
    List<PPredicate> invs = new ArrayList<>();
    List<PPredicate> thms = new ArrayList<>();
    List<EventBInvariant> allInvs = machine.getInvariants();
    for (EventBInvariant ebInv : allInvs) {
        PPredicate ppred = (PPredicate) ((EventB) ebInv.getPredicate()).getAst();
        nodeInfos.put(ppred, new Tuple2<>(machine.getName(), ebInv.getName()));
        if (ebInv.isTheorem()) {
            thms.add(ppred);
        } else {
            invs.add(ppred);
        }
    }
    invsAndTheorems.add(new AInvariantModelClause(invs));
    invsAndTheorems.add(new ATheoremsModelClause(thms));
    return invsAndTheorems;
}
Also used : PModelClause(de.be4.classicalb.core.parser.node.PModelClause) AInvariantModelClause(de.be4.classicalb.core.parser.node.AInvariantModelClause) ArrayList(java.util.ArrayList) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) ATheoremsModelClause(de.be4.classicalb.core.parser.node.ATheoremsModelClause) EventBInvariant(de.prob.model.eventb.EventBInvariant)

Aggregations

PModelClause (de.be4.classicalb.core.parser.node.PModelClause)3 AEventBModelParseUnit (de.be4.classicalb.core.parser.node.AEventBModelParseUnit)2 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)2 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)2 ArrayList (java.util.ArrayList)2 AAssignSubstitution (de.be4.classicalb.core.parser.node.AAssignSubstitution)1 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)1 AEvent (de.be4.classicalb.core.parser.node.AEvent)1 AEventsModelClause (de.be4.classicalb.core.parser.node.AEventsModelClause)1 AInvariantModelClause (de.be4.classicalb.core.parser.node.AInvariantModelClause)1 ARefinesModelClause (de.be4.classicalb.core.parser.node.ARefinesModelClause)1 ATheoremsModelClause (de.be4.classicalb.core.parser.node.ATheoremsModelClause)1 ATruthPredicate (de.be4.classicalb.core.parser.node.ATruthPredicate)1 AVariantModelClause (de.be4.classicalb.core.parser.node.AVariantModelClause)1 AWitness (de.be4.classicalb.core.parser.node.AWitness)1 PEvent (de.be4.classicalb.core.parser.node.PEvent)1 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)1 PWitness (de.be4.classicalb.core.parser.node.PWitness)1 EventBInvariant (de.prob.model.eventb.EventBInvariant)1 Test (org.junit.Test)1