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();
}
}
}
}
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;
}
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<>();
}
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());
}
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());
}
Aggregations