Search in sources :

Example 1 with Context

use of de.prob.model.eventb.Context in project prob2 by bendisposto.

the class EventBModelTranslator method printPragmas.

private void printPragmas(final IPrologTermOutput pto) {
    for (Machine machine : model.getChildrenOfType(Machine.class)) {
        EventBMachine ebM = (EventBMachine) machine;
        for (EventBVariable var : ebM.getVariables()) {
            if (var.hasUnit()) {
                pto.openTerm("pragma");
                pto.printAtom("unit");
                pto.printAtom(machine.getName());
                pto.printAtom(var.getName());
                pto.openList();
                pto.printAtom(var.getUnit());
                pto.closeList();
                pto.closeTerm();
            }
        }
    }
    for (Context context : model.getChildrenOfType(Context.class)) {
        for (EventBConstant constant : context.getConstants()) {
            if (constant.hasUnit()) {
                pto.openTerm("pragma");
                pto.printAtom("unit");
                pto.printAtom(context.getName());
                pto.printAtom(constant.getName());
                pto.openList();
                pto.printAtom(constant.getUnit());
                pto.closeList();
                pto.closeTerm();
            }
        }
    }
}
Also used : Context(de.prob.model.eventb.Context) EventBVariable(de.prob.model.eventb.EventBVariable) EventBConstant(de.prob.model.eventb.EventBConstant) EventBMachine(de.prob.model.eventb.EventBMachine) EventBMachine(de.prob.model.eventb.EventBMachine) Machine(de.prob.model.representation.Machine)

Example 2 with Context

use of de.prob.model.eventb.Context in project prob2 by bendisposto.

the class EventBModelTranslator method extractContextHierarchy.

private List<Context> extractContextHierarchy(final EventBMachine machine, EventBModel model) {
    List<Context> contexts = new ArrayList<>();
    for (Context c : machine.getSees()) {
        Context seenContext = model.getContext(c.getName());
        contexts.add(seenContext);
        List<Context> contextHierarchy = extractContextHierarchy(seenContext, model);
        for (Context context : contextHierarchy) {
            if (!contexts.contains(context)) {
                contexts.add(context);
            }
        }
    }
    return contexts;
}
Also used : Context(de.prob.model.eventb.Context) ArrayList(java.util.ArrayList)

Example 3 with Context

use of de.prob.model.eventb.Context in project prob2 by bendisposto.

the class MachineXmlHandler method beginContextExtraction.

private void beginContextExtraction(final Attributes attributes) {
    String name = attributes.getValue("name");
    if (model.getComponent(name) != null) {
        extractingContext = false;
        return;
    }
    extractingContext = true;
    internalContext = new Context(name);
    axiomCache.put(name, new HashMap<>());
    extendedContexts = new ArrayList<>();
    axioms = new ArrayList<>();
    inheritedAxioms = new ArrayList<>();
    sets = new ArrayList<>();
    constants = new ArrayList<>();
}
Also used : Context(de.prob.model.eventb.Context)

Example 4 with Context

use of de.prob.model.eventb.Context 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 5 with Context

use of de.prob.model.eventb.Context in project prob2 by bendisposto.

the class ComponentExtractor method caseAProcedureParseUnit.

@Override
public void caseAProcedureParseUnit(final AProcedureParseUnit node) {
    String name = node.getName().getText();
    LinkedList<TIdentifierLiteral> seen = node.getSeen();
    Context ctx = null;
    if (node.getSeen().size() == 1) {
        String cName = seen.getFirst().getText();
        ctx = getContext(cName);
    } else if (node.getSeen().size() > 1) {
        throw new IllegalArgumentException("Error in " + name + " definition: " + node.getStartPos() + " only one context may be seen by a procedure");
    }
    Procedure procedure = new Procedure(name, ctx, typeEnv);
    ProcedureExtractor pE = new ProcedureExtractor(procedure, node, typeEnv);
    modelM = modelM.addProcedure(pE.getProcedure());
}
Also used : Context(de.prob.model.eventb.Context) Procedure(de.prob.model.eventb.algorithm.Procedure) TIdentifierLiteral(de.be4.eventbalg.core.parser.node.TIdentifierLiteral)

Aggregations

Context (de.prob.model.eventb.Context)11 ArrayList (java.util.ArrayList)4 EventBMachine (de.prob.model.eventb.EventBMachine)3 TIdentifierLiteral (de.be4.eventbalg.core.parser.node.TIdentifierLiteral)2 ASeesModelClause (de.be4.classicalb.core.parser.node.ASeesModelClause)1 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)1 ContextModifier (de.prob.model.eventb.ContextModifier)1 EventBConstant (de.prob.model.eventb.EventBConstant)1 EventBVariable (de.prob.model.eventb.EventBVariable)1 MachineModifier (de.prob.model.eventb.MachineModifier)1 Procedure (de.prob.model.eventb.algorithm.Procedure)1 AbstractElement (de.prob.model.representation.AbstractElement)1 Machine (de.prob.model.representation.Machine)1 ModelElementList (de.prob.model.representation.ModelElementList)1