Search in sources :

Example 1 with AWhileStmt

use of de.be4.eventbalg.core.parser.node.AWhileStmt in project prob2 by bendisposto.

the class AlgorithmExtractor method extractStmt.

private Block extractStmt(final Block b, final PStmt pStmt) throws ModelGenerationException {
    if (pStmt instanceof AWhileStmt) {
        AWhileStmt whileStmt = (AWhileStmt) pStmt;
        return b.While(whileStmt.getCondition().getText(), extractStmts(whileStmt.getStatements()), extractInvariant(b, whileStmt.getInvariant()), extractVariant(b, whileStmt.getVariant()));
    }
    if (pStmt instanceof AIfStmt) {
        AIfStmt ifStmt = (AIfStmt) pStmt;
        Block thenBlock = extractStmts(ifStmt.getThen());
        Block elseBlock = extractStmts(ifStmt.getElse());
        return b.If(ifStmt.getCondition().getText(), thenBlock, elseBlock);
    }
    if (pStmt instanceof AAssertStmt) {
        return b.Assert(((AAssertStmt) pStmt).getPredicate().getText());
    }
    if (pStmt instanceof AAssignStmt) {
        return b.Assign(((AAssignStmt) pStmt).getAction().getText());
    }
    if (pStmt instanceof ASimpleAssignStmt) {
        return b.Assign(((ASimpleAssignStmt) pStmt).getAction().getText());
    }
    if (pStmt instanceof AReturnStmt) {
        return b.Return(getIdList(((AReturnStmt) pStmt).getIdentifiers()));
    }
    if (pStmt instanceof ACallStmt) {
        return b.Call(((ACallStmt) pStmt).getName().getText(), getIdList(((ACallStmt) pStmt).getArguments()), getIdList(((ACallStmt) pStmt).getResults()));
    }
    throw new IllegalArgumentException("Unsupported statement type: " + pStmt.getClass() + " " + pStmt.getStartPos());
}
Also used : ASimpleAssignStmt(de.be4.eventbalg.core.parser.node.ASimpleAssignStmt) ACallStmt(de.be4.eventbalg.core.parser.node.ACallStmt) Block(de.prob.model.eventb.algorithm.ast.Block) AWhileStmt(de.be4.eventbalg.core.parser.node.AWhileStmt) AAssertStmt(de.be4.eventbalg.core.parser.node.AAssertStmt) AAssignStmt(de.be4.eventbalg.core.parser.node.AAssignStmt) AIfStmt(de.be4.eventbalg.core.parser.node.AIfStmt) AReturnStmt(de.be4.eventbalg.core.parser.node.AReturnStmt)

Aggregations

AAssertStmt (de.be4.eventbalg.core.parser.node.AAssertStmt)1 AAssignStmt (de.be4.eventbalg.core.parser.node.AAssignStmt)1 ACallStmt (de.be4.eventbalg.core.parser.node.ACallStmt)1 AIfStmt (de.be4.eventbalg.core.parser.node.AIfStmt)1 AReturnStmt (de.be4.eventbalg.core.parser.node.AReturnStmt)1 ASimpleAssignStmt (de.be4.eventbalg.core.parser.node.ASimpleAssignStmt)1 AWhileStmt (de.be4.eventbalg.core.parser.node.AWhileStmt)1 Block (de.prob.model.eventb.algorithm.ast.Block)1