use of de.be4.classicalb.core.parser.node.Node in project prob2 by bendisposto.
the class EventBModelTranslator method printProlog.
public void printProlog(final IPrologTermOutput pto) {
RodinPosPrinter labelPrinter = new RodinPosPrinter();
List<Node> machineNodes = new ArrayList<>();
List<Node> contextNodes = new ArrayList<>();
for (EventBMachineTranslator trans : machineTranslators) {
machineNodes.add(trans.translateMachine());
labelPrinter.addNodeInfos(trans.getNodeInfos());
}
for (ContextTranslator t : contextTranslators) {
contextNodes.add(t.translateContext());
labelPrinter.addNodeInfos(t.getNodeInfos());
}
ASTProlog printer = new ASTProlog(pto, labelPrinter);
pto.openTerm("load_event_b_project");
pto.openList();
for (Node node : machineNodes) {
node.apply(printer);
}
pto.closeList();
pto.openList();
for (Node node : contextNodes) {
node.apply(printer);
}
pto.closeList();
pto.openList();
pto.openTerm("exporter_version");
pto.printNumber(3);
pto.closeTerm();
for (ProofObligation po : proofObligations) {
po.toProlog(pto);
}
theoryTranslator.toProlog(pto);
printPragmas(pto);
pto.closeList();
pto.printVariable("_Error");
pto.closeTerm();
}
use of de.be4.classicalb.core.parser.node.Node 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;
}
use of de.be4.classicalb.core.parser.node.Node 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.be4.classicalb.core.parser.node.Node 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());
}
use of de.be4.classicalb.core.parser.node.Node in project prob2 by bendisposto.
the class MachineExtractor method caseAEvent.
@Override
public void caseAEvent(final AEvent node) {
EventExtractor eE = new EventExtractor(new Event(node.getName().getText(), EventType.ORDINARY, false), machineM.getMachine().getRefines(), typeEnv, getComment(node.getComments()));
node.apply(eE);
machineM = new MachineModifier(machineM.getMachine().addTo(BEvent.class, eE.getEvent()), typeEnv);
}
Aggregations