Search in sources :

Example 6 with Type

use of de.be4.classicalb.core.parser.IDefinitions.Type 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)

Example 7 with Type

use of de.be4.classicalb.core.parser.IDefinitions.Type in project prob2 by bendisposto.

the class RulesMachineRun method start.

public void start() {
    logger.info("Starting rules machine run: {}", this.runnerFile.getAbsolutePath());
    stopWatch.start(Timer.PARSING);
    boolean hasParseErrors = parseAndTranslateRulesProject();
    logger.info("Time to parse rules project: {} ms", stopWatch.stop(Timer.PARSING));
    if (hasParseErrors) {
        logger.error("RULES_MACHINE has errors!");
        return;
    }
    this.executeRun = rulesMachineRunner.createRulesMachineExecuteRun(this.rulesProject, runnerFile, this.proBCorePreferences, continueAfterErrors, this.getStateSpace());
    try {
        stopWatch.start(Timer.EXECUTE_RUN);
        logger.info("Start execute ...");
        this.executeRun.start();
        logger.info("Execute run finished. Time: {} ms", stopWatch.stop(Timer.EXECUTE_RUN));
    } catch (ProBError e) {
        logger.error("ProBError: {}", e.getMessage());
        if (executeRun.getExecuteModelCommand() != null) {
            try {
                State finalState = executeRun.getExecuteModelCommand().getFinalState();
                // explores the final state and can throw a ProBError
                Collection<StateError> stateErrors = finalState.getStateErrors();
                for (StateError stateError : stateErrors) {
                    this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, stateError.getLongDescription(), e));
                }
            } catch (ProBError e2) {
                // Enumeration errors
                this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, e2.getMessage(), e2));
                return;
            }
        } else {
            /*- static errors such as type errors or errors while loading the  state space */
            this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, e.getMessage(), e));
            /*- no final state is available and thus we can not create RuleResults */
            return;
        }
    } catch (Exception e) {
        logger.error("Unexpected error occured: {}", e.getMessage(), e);
        // storing all error messages
        this.errors.add(new Error(ERROR_TYPES.PROB_ERROR, e.getMessage(), e));
        return;
    } finally {
        if (executeRun.getUsedStateSpace() != null) {
            GetTotalNumberOfErrorsCommand totalNumberOfErrorsCommand = new GetTotalNumberOfErrorsCommand();
            executeRun.getUsedStateSpace().execute(totalNumberOfErrorsCommand);
            totalNumberOfProBCliErrors = totalNumberOfErrorsCommand.getTotalNumberOfErrors();
        }
    }
    this.stateSpace = this.executeRun.getUsedStateSpace();
    stopWatch.start(Timer.EXTRACT_RESULTS);
    this.ruleResults = new RuleResults(this.rulesProject, executeRun.getExecuteModelCommand().getFinalState(), maxNumberOfReportedCounterExamples);
    logger.info("Time to extract results from final state: {}", stopWatch.stop(Timer.EXTRACT_RESULTS));
}
Also used : StateError(de.prob.animator.domainobjects.StateError) State(de.prob.statespace.State) GetTotalNumberOfErrorsCommand(de.prob.animator.command.GetTotalNumberOfErrorsCommand) Collection(java.util.Collection) ProBError(de.prob.exception.ProBError) StateError(de.prob.animator.domainobjects.StateError) ProBError(de.prob.exception.ProBError) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 8 with Type

use of de.be4.classicalb.core.parser.IDefinitions.Type in project probparsers by bendisposto.

the class DefinitionsTest method testExprOrSubst3.

@Test
public void testExprOrSubst3() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr==g(x)\nOPERATIONS\nop=PRE defExpr=42 THEN defExpr END\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        assertEquals("Expecting substitution here but found definition with type 'Expression'", cause.getLocalizedMessage());
    // IGNORE, is expected
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 9 with Type

use of de.be4.classicalb.core.parser.IDefinitions.Type in project probparsers by bendisposto.

the class DefinitionsTest method testExprOrSubst4.

@Test
public void testExprOrSubst4() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr==g(x)\nOPERATIONS\nop=BEGIN defExpr; a:=defExpr END\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        assertEquals("Expecting expression here but found definition with type 'Substitution'", cause.getLocalizedMessage());
    // IGNORE, is expected
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 10 with Type

use of de.be4.classicalb.core.parser.IDefinitions.Type in project probparsers by bendisposto.

the class DefinitionsTest method testExprOrSubstWParams4.

@Test
public void testExprOrSubstWParams4() {
    final String testMachine = "MACHINE Test\nDEFINITIONS\ndefExpr(x)==g(x)\nOPERATIONS\nop=BEGIN defExpr(x); a:=defExpr(x) END\nEND";
    try {
        getTreeAsString(testMachine);
        fail("Expected exception was not thrown");
    } catch (final BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        assertEquals("Expecting expression here but found definition with type 'Substitution'", cause.getLocalizedMessage());
    // IGNORE, is expected
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Helpers.getTreeAsString(util.Helpers.getTreeAsString) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)8 Type (de.be4.classicalb.core.parser.IDefinitions.Type)6 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)5 Test (org.junit.Test)5 Helpers.getTreeAsString (util.Helpers.getTreeAsString)5 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)3 LinkedList (java.util.LinkedList)3 BParser (de.be4.classicalb.core.parser.BParser)2 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)2 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)2 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)2 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)2 PDefinition (de.be4.classicalb.core.parser.node.PDefinition)2 TDefLiteralSubstitution (de.be4.classicalb.core.parser.node.TDefLiteralSubstitution)2 Token (de.be4.classicalb.core.preparser.node.Token)2 File (java.io.File)2 BLexer (de.be4.classicalb.core.parser.BLexer)1 MockedDefinitions (de.be4.classicalb.core.parser.MockedDefinitions)1 BException (de.be4.classicalb.core.parser.exceptions.BException)1 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)1