Search in sources :

Example 56 with Node

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();
}
Also used : ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) ProofObligation(de.prob.model.eventb.ProofObligation) Node(de.be4.classicalb.core.parser.node.Node) ArrayList(java.util.ArrayList)

Example 57 with Node

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;
}
Also used : ARefinesModelClause(de.be4.classicalb.core.parser.node.ARefinesModelClause) AEventBModelParseUnit(de.be4.classicalb.core.parser.node.AEventBModelParseUnit) PModelClause(de.be4.classicalb.core.parser.node.PModelClause) AVariantModelClause(de.be4.classicalb.core.parser.node.AVariantModelClause) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Example 58 with Node

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());
}
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 59 with Node

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());
}
Also used : Context(de.prob.model.eventb.Context) Procedure(de.prob.model.eventb.algorithm.Procedure) TIdentifierLiteral(de.be4.eventbalg.core.parser.node.TIdentifierLiteral)

Example 60 with Node

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);
}
Also used : BEvent(de.prob.model.representation.BEvent) AEvent(de.be4.eventbalg.core.parser.node.AEvent) Event(de.prob.model.eventb.Event) MachineModifier(de.prob.model.eventb.MachineModifier)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)42 PExpression (de.be4.classicalb.core.parser.node.PExpression)30 ArrayList (java.util.ArrayList)30 Node (de.be4.classicalb.core.parser.node.Node)20 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)16 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)11 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)8 HashSet (java.util.HashSet)8 Token (de.be4.ltl.core.parser.node.Token)7 Type (de.be4.classicalb.core.parser.IDefinitions.Type)6 IOException (java.io.IOException)6 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)5 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)5 LinkedList (java.util.LinkedList)5 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)4 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)4 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3