@Override public IResponse define_fun(Idefine_fun cmd) { IResponse res = super.define_fun(cmd); if (res.isError()) return res; try { if (cmd.resultSort().isBool() && cmd.parameters().size() > 0) { StringBuilder sb = new StringBuilder(); sb.append("(DEFPRED ("); sb.append(translate(cmd.symbol())); int n = cmd.parameters().size(); for (int i = 0; i < n; i++) { sb.append(" X"); sb.append(i); } sb.append("))\n"); String s = solverProcess.sendAndListen(sb.toString()); // FIXME - check for error in s -- System.out.println("HEARD " + s); res = smtConfig.responseFactory.success(); } else { res = smtConfig.responseFactory.success(); } IExpr.IFactory f = smtConfig.exprFactory; assertExpr(f.fcn(f.symbol("="), cmd.symbol(), cmd.expression())); } catch (IOException e) { res = smtConfig.responseFactory.error( "Failed to declare-fun: " + e.getMessage(), null); // FIXME - position? } catch (IVisitor.VisitorException e) { res = smtConfig.responseFactory.error("Failed to declare-fun: " + e.getMessage(), null); } return res; }
@Override public IResponse check_sat() { IResponse res = super.check_sat(); if (res.isError()) return res; try { // String s = solverProcess.sendAndListen("(BG_PUSH (EQ 0 0))\r\n"); // s = solverProcess.sendAndListen("(EQ 0 1)\r\n"); // if (s.contains("Valid.")) res = smtConfig.responseFactory.unsat(); // else if (s.contains("Invalid.")) res = smtConfig.responseFactory.sat(); // else res = smtConfig.responseFactory.unknown(); String msg = "(NOT (AND TRUE " + conjunction + "\n))\n"; String s = solverProcess.sendAndListen(msg); // FIXME - what about errors in SImplify // smtConfig.log.logOut("HEARD: " + s); if (s.contains("Valid.")) res = smtConfig.responseFactory.unsat(); else if (s.contains("Invalid.")) res = smtConfig.responseFactory.sat(); else res = smtConfig.responseFactory.unknown(); checkSatStatus = res; // s = solverProcess.sendAndListen("(BG_POP)\r\n"); } catch (IOException e) { res = smtConfig.responseFactory.error("Failed to check-sat"); } return res; }
// @ requires number >= 0; @Override public IResponse push(int number) { IResponse status = super.push(number); if (!status.isOK()) return status; try { while (--number >= 0) { pushesStack.add(0, conjunction); String s = solverProcess.sendAndListen("(BG_PUSH (EQ 0 0))"); // FIXME - check for error in s -- System.out.println("HEARD " + s); } return smtConfig.responseFactory.success(); } catch (IOException e) { return smtConfig.responseFactory.error("Failed to push"); } }
public void run() { while (true) { IResponse resp = responseQueue.removeResponse(); Integer respId = (Integer) resp.getId(); SPFSession session = sessions.remove(respId); FutureSPFResult result = results.remove(respId); DNSLookupContinuation cont = (DNSLookupContinuation) session.getAttribute(ATTRIBUTE_STAGED_EXECUTOR_CONTINUATION); DNSResponse response; if (resp.getException() != null) { response = new DNSResponse((TimeoutException) resp.getException()); } else { response = new DNSResponse(resp.getValue()); } try { cont = cont.getListener().onDNSResponse(response, session); if (cont != null) { invokeAsynchService(session, result, cont, false); } else { execute(session, result, false); } } catch (Exception e) { SPFChecker checker = null; while (e != null) { while (checker == null || !(checker instanceof SPFCheckerExceptionCatcher)) { checker = session.popChecker(); } try { ((SPFCheckerExceptionCatcher) checker).onException(e, session); e = null; } catch (SPFResultException ex) { e = ex; } finally { checker = null; } } execute(session, result, false); } } }
@Override public IResponse set_logic(String logicName, /*@Nullable*/ IPos pos) { // FIXME - discrimninate among logics boolean lSet = logicSet != null; IResponse status = super.set_logic(logicName, pos); if (!status.isOK()) return status; if (logicName.contains("BV")) { return smtConfig.responseFactory.error( "The simplify solver does not yet support the bit-vector theory", pos); } if (lSet) { pushesStack.clear(); push(1); } return smtConfig.responseFactory.success(); }
@Override public IResponse assertExpr(IExpr sexpr) { IResponse res = super.assertExpr(sexpr); if (!res.isOK()) return res; try { String translatedSexpr = translate(sexpr); if (translatedSexpr == null) { return smtConfig.responseFactory.error( "Failure in translating expression: " + smtConfig.defaultPrinter.toString(sexpr), sexpr.pos()); } conjunction = conjunction + " \n" + translatedSexpr; // String s = solverProcess.sendAndListen("(BG_PUSH ",translatedSexpr," )\r\n"); // System.out.println("HEARD: " + s); } catch (VisitorException e) { return smtConfig.responseFactory.error(e.getMessage(), e.pos); } return smtConfig.responseFactory.success(); }