Search in sources :

Example 66 with PExpression

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

the class DomBuilder method inAOperation.

@Override
public void inAOperation(final AOperation node) {
    String name = extractIdentifierName(node.getOpName());
    if (prefix != null && !prefix.equals(name)) {
        name = prefix + "." + name;
    }
    List<PExpression> paramIds = node.getParameters();
    final List<String> params = extractIdentifiers(paramIds);
    final List<String> output = extractIdentifiers(node.getReturnValues());
    Operation operation = new Operation(name, params, output);
    PSubstitution body = node.getOperationBody();
    List<ClassicalBGuard> guards = new ArrayList<>();
    if (body instanceof ASelectSubstitution) {
        PPredicate condition = ((ASelectSubstitution) body).getCondition();
        List<PPredicate> predicates = getPredicates(condition);
        for (PPredicate pPredicate : predicates) {
            guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
        }
    }
    if (body instanceof APreconditionSubstitution) {
        PPredicate condition = ((APreconditionSubstitution) body).getPredicate();
        List<PPredicate> predicates = getPredicates(condition);
        for (PPredicate pPredicate : predicates) {
            guards.add(new ClassicalBGuard(createPredicateAST(pPredicate)));
        }
    }
    List<ClassicalBAction> actions = new ArrayList<>();
    actions.add(new ClassicalBAction(createSubstitutionAST(body)));
    operation = operation.set(Action.class, new ModelElementList<>(actions));
    operation = operation.set(Guard.class, new ModelElementList<>(guards));
    operations.add(operation);
}
Also used : ASelectSubstitution(de.be4.classicalb.core.parser.node.ASelectSubstitution) Action(de.prob.model.representation.Action) ArrayList(java.util.ArrayList) ModelElementList(de.prob.model.representation.ModelElementList) AOperation(de.be4.classicalb.core.parser.node.AOperation) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) PExpression(de.be4.classicalb.core.parser.node.PExpression) APreconditionSubstitution(de.be4.classicalb.core.parser.node.APreconditionSubstitution) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) Guard(de.prob.model.representation.Guard)

Example 67 with PExpression

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

the class DomBuilder method outAMachineHeader.

@Override
public void outAMachineHeader(final AMachineHeader node) {
    name = extractIdentifierName(node.getName());
    machineId = node.getName();
    if (prefix != null && !prefix.equals(name)) {
        name = prefix + "." + name;
    }
    for (PExpression expression : node.getParameters()) {
        parameters.add(new Parameter(createExpressionAST(expression)));
    }
}
Also used : PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 68 with PExpression

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

PExpression (de.be4.classicalb.core.parser.node.PExpression)50 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)28 ArrayList (java.util.ArrayList)27 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)21 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 Test (org.junit.Test)6 Node (de.be4.classicalb.core.parser.node.Node)5 LinkedList (java.util.LinkedList)5 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)4 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)4 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)4 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)4 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)3 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 Start (de.be4.classicalb.core.parser.node.Start)3 BParser (de.be4.classicalb.core.parser.BParser)2 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)2 AMachineReference (de.be4.classicalb.core.parser.node.AMachineReference)2 AOpSubstitution (de.be4.classicalb.core.parser.node.AOpSubstitution)2