Search in sources :

Example 1 with ModelElementList

use of de.prob.model.representation.ModelElementList in project prob2 by bendisposto.

the class ComponentExtractor method caseAMachineParseUnit.

@Override
public void caseAMachineParseUnit(final AMachineParseUnit node) {
    String name = node.getName().getText();
    MachineModifier machineM = new MachineModifier(new EventBMachine(name), typeEnv);
    ModelElementList<Context> seen = new ModelElementList<>();
    for (TIdentifierLiteral contextName : node.getSeenNames()) {
        String cName = contextName.getText();
        AbstractElement context = getContext(cName);
        seen = seen.addElement((Context) context);
    }
    machineM = machineM.setSees(seen);
    if (node.getRefinesNames().size() == 1) {
        String mname = node.getRefinesNames().getFirst().getText();
        EventBMachine machine = getMachine(mname);
        machineM = machineM.setRefines(machine);
    } else if (node.getRefinesNames().size() > 1) {
        throw new IllegalArgumentException("Machines can only refine one abstract machine. Found " + node.getRefinesNames().size() + " refined machines");
    }
    machineM = machineM.addComment(getComment(node.getComments()));
    MachineExtractor mE = new MachineExtractor(machineM, typeEnv);
    node.apply(mE);
    modelM = modelM.addMachine(mE.getMachine());
}
Also used : Context(de.prob.model.eventb.Context) AbstractElement(de.prob.model.representation.AbstractElement) ModelElementList(de.prob.model.representation.ModelElementList) EventBMachine(de.prob.model.eventb.EventBMachine) MachineModifier(de.prob.model.eventb.MachineModifier) TIdentifierLiteral(de.be4.eventbalg.core.parser.node.TIdentifierLiteral)

Example 2 with ModelElementList

use of de.prob.model.representation.ModelElementList 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)

Aggregations

ModelElementList (de.prob.model.representation.ModelElementList)2 AOperation (de.be4.classicalb.core.parser.node.AOperation)1 APreconditionSubstitution (de.be4.classicalb.core.parser.node.APreconditionSubstitution)1 ASelectSubstitution (de.be4.classicalb.core.parser.node.ASelectSubstitution)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 TIdentifierLiteral (de.be4.eventbalg.core.parser.node.TIdentifierLiteral)1 Context (de.prob.model.eventb.Context)1 EventBMachine (de.prob.model.eventb.EventBMachine)1 MachineModifier (de.prob.model.eventb.MachineModifier)1 AbstractElement (de.prob.model.representation.AbstractElement)1 Action (de.prob.model.representation.Action)1 Guard (de.prob.model.representation.Guard)1 ArrayList (java.util.ArrayList)1