From: trevor_hansen Date: Thu, 10 Nov 2011 13:01:41 +0000 (+0000) Subject: Improvement. Extra c-api options from Stephan Falke. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=bdd337a567ac60151e4f3006f2c5ce8ada2da98e;p=francis%2Fstp.git Improvement. Extra c-api options from Stephan Falke. git-svn-id: https://stp-fast-prover.svn.sourceforge.net/svnroot/stp-fast-prover/trunk/stp@1410 e59a4935-1847-0410-ae03-e826735625c1 --- diff --git a/src/absrefine_counterexample/AbsRefine_CounterExample.h b/src/absrefine_counterexample/AbsRefine_CounterExample.h index 4edefcd..0fc6942 100644 --- a/src/absrefine_counterexample/AbsRefine_CounterExample.h +++ b/src/absrefine_counterexample/AbsRefine_CounterExample.h @@ -100,6 +100,9 @@ namespace BEEV //to e ASTNode GetCounterExample(bool t, const ASTNode& e); + //queries the counterexample, and returns a vector of index-value pairs for e + std::vector > GetCounterExampleArray(bool t, const ASTNode& e); + int CounterExampleSize(void) const { return CounterExampleMap.size(); diff --git a/src/absrefine_counterexample/CounterExample.cpp b/src/absrefine_counterexample/CounterExample.cpp index f633774..f3a21da 100644 --- a/src/absrefine_counterexample/CounterExample.cpp +++ b/src/absrefine_counterexample/CounterExample.cpp @@ -618,6 +618,66 @@ namespace BEEV return output; } //End of GetCounterExample + // FUNCTION: queries the counterexample, and returns the number of array locations for e + std::vector > AbsRefine_CounterExample::GetCounterExampleArray(bool t, const ASTNode& e) + { + std::vector > entries; + + //input is valid, no counterexample to print + if (bm->ValidFlag) + { + return entries; + } + + //t is true if SAT solver generated a counterexample, else it is + //false + if (!t) + { + return entries; + } + + // Take a copy of the counterexample map, 'cause TermToConstTermUsingModel + // changes it. Which breaks the iterator otherwise. + const ASTNodeMap c(CounterExampleMap); + + ASTNodeMap::const_iterator it = c.begin(); + ASTNodeMap::const_iterator itend = c.end(); + for (; it != itend; it++) + { + const ASTNode& f = it->first; + const ASTNode& se = it->second; + + if (ARRAY_TYPE == se.GetType()) + { + FatalError("TermToConstTermUsingModel: " + "entry in counterexample is an arraytype. bogus:", se); + } + + //skip over introduced variables + if (f.GetKind() == SYMBOL && (bm->FoundIntroducedSymbolSet( + f))) + { + continue; + } + if (f.GetKind() == READ && f[0] == e && f[0].GetKind() == SYMBOL && f[1].GetKind() == BVCONST) + { + ASTNode rhs; + if (BITVECTOR_TYPE == se.GetType()) + { + rhs = TermToConstTermUsingModel(se, false); + } + else + { + rhs = ComputeFormulaUsingModel(se); + } + assert(rhs.isConstant()); + entries.push_back(std::make_pair(f[1], rhs)); + } + } + + return entries; + } //End of GetCounterExampleArray + // FUNCTION: prints a counterexample for INVALID inputs. iterate // through the CounterExampleMap data structure and print it to // stdout diff --git a/src/c_interface/c_interface.cpp b/src/c_interface/c_interface.cpp index 849f131..29d9ac7 100644 --- a/src/c_interface/c_interface.cpp +++ b/src/c_interface/c_interface.cpp @@ -624,6 +624,27 @@ Expr vc_getCounterExample(VC vc, Expr e) { return output; } +void vc_getCounterExampleArray(VC vc, Expr e, Expr **indices, Expr **values, int *size) { + nodestar a = (nodestar)e; + bmstar b = (bmstar)(((stpstar)vc)->bm); + ctrexamplestar ce = (ctrexamplestar)(((stpstar)vc)->Ctr_Example); + + bool t = false; + if(ce->CounterExampleSize()) + t = true; + + std::vector > entries = ce->GetCounterExampleArray(t, *a); + *size = entries.size(); + if (*size != 0) { + *indices = (Expr *) malloc(*size * sizeof(Expr*)); + *values = (Expr *) malloc(*size * sizeof(Expr*)); + for (int i = 0; i < *size; ++i) { + (*indices)[i] = new node(entries[i].first); + (*values)[i] = new node(entries[i].second); + } + } +} + int vc_counterexample_size(VC vc) { bmstar b = (bmstar)(((stpstar)vc)->bm); ctrexamplestar ce = (ctrexamplestar)(((stpstar)vc)->Ctr_Example); diff --git a/src/c_interface/c_interface.h b/src/c_interface/c_interface.h index a8fd947..b4f57b3 100644 --- a/src/c_interface/c_interface.h +++ b/src/c_interface/c_interface.h @@ -215,6 +215,9 @@ extern "C" { //! Return the counterexample after a failed query. Expr vc_getCounterExample(VC vc, Expr e); + //! Return an array from a counterexample after a failed query. + void vc_getCounterExampleArray(VC vc, Expr e, Expr **indices, Expr **values, int *size); + //! get size of counterexample, i.e. the number of variables/array //locations in the counterexample. int vc_counterexample_size(VC vc);