Search in sources :

Example 1 with ProBError

use of de.prob.exception.ProBError in project prob2 by bendisposto.

the class ConstraintBasedRefinementCheckCommand method processResult.

@Override
public void processResult(final ISimplifiedROMap<String, PrologTerm> bindings) {
    final PrologTerm resultTerm = bindings.get(RESULT_VARIABLE);
    final ListPrologTerm resultStringTerm = (ListPrologTerm) bindings.get(RESULT_STRINGS_VARIABLE);
    final StringBuilder sb = new StringBuilder();
    for (PrologTerm t : resultStringTerm) {
        sb.append(PrologTerm.atomicString(t));
        sb.append('\n');
    }
    resultsString = sb.toString();
    if (resultTerm.hasFunctor("time_out", 0)) {
        this.result = ResultType.INTERRUPTED;
    } else if (resultTerm.hasFunctor("true", 0)) {
        // Errors were found
        this.result = ResultType.VIOLATION_FOUND;
    // TODO extract message
    } else if (resultTerm.hasFunctor("false", 0)) {
        // Errors were not found
        this.result = ResultType.NO_VIOLATION_FOUND;
    } else {
        throw new ProBError("unexpected result from refinement check: " + resultTerm);
    }
}
Also used : ListPrologTerm(de.prob.prolog.term.ListPrologTerm) ProBError(de.prob.exception.ProBError) PrologTerm(de.prob.prolog.term.PrologTerm) ListPrologTerm(de.prob.prolog.term.ListPrologTerm)

Example 2 with ProBError

use of de.prob.exception.ProBError 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 3 with ProBError

use of de.prob.exception.ProBError in project prob2 by bendisposto.

the class ClassicalBFactory method parseFile.

/**
 * Parse a file into an AST {@link Start}.
 *
 * @param model
 *            {@link File} containing B machine
 * @param bparser
 *            {@link BParser} for parsing
 * @return {@link Start} AST after parsing model with {@link BParser} bparser
 * @throws IOException
 *             if an I/O error occurred
 * @throws ProBError
 *             if the file could not be parsed
 */
public Start parseFile(final File model, final BParser bparser) throws IOException {
    try {
        logger.trace("Parsing main file '{}'", model.getAbsolutePath());
        Start ast = null;
        ast = bparser.parseFile(model, false);
        return ast;
    } catch (BCompoundException e) {
        throw new ProBError(e);
    }
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) ProBError(de.prob.exception.ProBError) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 4 with ProBError

use of de.prob.exception.ProBError in project prob2 by bendisposto.

the class ConsistencyChecker method call.

@Override
public IModelCheckingResult call() throws Exception {
    long time = System.currentTimeMillis();
    if (goal != null) {
        try {
            SetBGoalCommand cmd = new SetBGoalCommand(goal);
            s.execute(cmd);
        } catch (ProBError e) {
            return new CheckError("Type error in specified goal.");
        }
    }
    // When goal is undefined, isFinished will be executed anyways
    s.execute(job);
    IModelCheckingResult result = job.getResult();
    if (ui != null) {
        ui.isFinished(jobId, System.currentTimeMillis() - time, result, job.getStats());
    }
    return result;
}
Also used : SetBGoalCommand(de.prob.animator.command.SetBGoalCommand) ProBError(de.prob.exception.ProBError)

Example 5 with ProBError

use of de.prob.exception.ProBError in project prob2 by bendisposto.

the class Api method brules_load.

/**
 * Load a B rules machine from the given file.
 *
 * @param file the path of the file to load
 * @param prefs the preferences to use
 * @return the {@link StateSpace} for the loaded machine
 */
public StateSpace brules_load(final String file, final Map<String, String> prefs) throws IOException {
    final RulesModelFactory bRulesFactory = modelFactoryProvider.getBRulesFactory();
    final RulesProject rulesProject = new RulesProject();
    final ParsingBehaviour parsingBehaviour = new ParsingBehaviour();
    parsingBehaviour.setAddLineNumbers(true);
    rulesProject.setParsingBehaviour(parsingBehaviour);
    rulesProject.parseProject(new File(file));
    rulesProject.checkAndTranslateProject();
    if (rulesProject.hasErrors()) {
        throw new ProBError(new BCompoundException(rulesProject.getBExceptionList()));
    }
    return bRulesFactory.extract(new File(file), rulesProject).load(prefs);
}
Also used : RulesModelFactory(de.prob.model.brules.RulesModelFactory) RulesProject(de.be4.classicalb.core.parser.rules.RulesProject) ParsingBehaviour(de.be4.classicalb.core.parser.ParsingBehaviour) File(java.io.File) ProBError(de.prob.exception.ProBError) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Aggregations

ProBError (de.prob.exception.ProBError)7 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)4 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)2 Start (de.be4.classicalb.core.parser.node.Start)2 RecursiveMachineLoader (de.be4.classicalb.core.parser.analysis.prolog.RecursiveMachineLoader)1 BException (de.be4.classicalb.core.parser.exceptions.BException)1 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)1 GetTotalNumberOfErrorsCommand (de.prob.animator.command.GetTotalNumberOfErrorsCommand)1 SetBGoalCommand (de.prob.animator.command.SetBGoalCommand)1 StateError (de.prob.animator.domainobjects.StateError)1 RulesModelFactory (de.prob.model.brules.RulesModelFactory)1 ListPrologTerm (de.prob.prolog.term.ListPrologTerm)1 PrologTerm (de.prob.prolog.term.PrologTerm)1 State (de.prob.statespace.State)1 File (java.io.File)1 Collection (java.util.Collection)1