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);
}
}
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));
}
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);
}
}
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;
}
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);
}
Aggregations