summaryrefslogtreecommitdiff
path: root/src/proof/unsat_core.i
diff options
context:
space:
mode:
authorAndres Noetzli <andres.noetzli@gmail.com>2019-05-16 00:18:48 +0000
committerAina Niemetz <aina.niemetz@gmail.com>2019-05-15 17:18:48 -0700
commit62d361071ea54c9b7cba882313ab4dedef6f1286 (patch)
tree2e721a2fb77769a2824955a2b47fdf8b86203da3 /src/proof/unsat_core.i
parentfc8907afc08d7b418471a537f9c23e9964df82df (diff)
Fix iterators in Java API (#3000)
Fixes #2989. SWIG 3 seems to have an issue properly resolving `T::const_iterator::value_type` if that type itself is a `typedef`. This is for example the case in the `UnsatCore` class, which `typedef`s `const_iterator` to `std::vector<Expr>::const_iterator`. As a workaround, this commit changes the `JavaIteratorAdapter` class to take two template parameters, one of which is the `value_type`. The commit also adds a compile-time assertion that `T::const_iterator::value_type` can be converted to `value_type` to avoid nasty surprises. A nice side-effect of this solution is that explicit `typemap`s are not necessary anymore, so they are removed. Additionally, the commit adds a `toString()` method for the Java API of `UnsatCore` and adds examples that show and test the iteration over the unsat core and the statistics. Iterating over `Statistics` now returns instances of `Statistic` instead of `Object[]`, which is a bit cleaner and requires less glue code.
Diffstat (limited to 'src/proof/unsat_core.i')
-rw-r--r--src/proof/unsat_core.i31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/proof/unsat_core.i b/src/proof/unsat_core.i
index cee78da06..d3fd615ce 100644
--- a/src/proof/unsat_core.i
+++ b/src/proof/unsat_core.i
@@ -21,8 +21,16 @@
%ignore CVC4::UnsatCore::begin() const;
%ignore CVC4::UnsatCore::end() const;
%extend CVC4::UnsatCore {
- CVC4::JavaIteratorAdapter<CVC4::UnsatCore> iterator() {
- return CVC4::JavaIteratorAdapter<CVC4::UnsatCore>(*$self);
+ CVC4::JavaIteratorAdapter<CVC4::UnsatCore, CVC4::Expr> iterator()
+ {
+ return CVC4::JavaIteratorAdapter<CVC4::UnsatCore, CVC4::Expr>(*$self);
+ }
+
+ std::string toString()
+ {
+ std::stringstream ss;
+ ss << (*$self);
+ return ss.str();
}
}
@@ -30,10 +38,10 @@
%typemap(javainterfaces) CVC4::UnsatCore "java.lang.Iterable<edu.nyu.acsys.CVC4.Expr>";
// the JavaIteratorAdapter should not be public, and implements Iterator
-%typemap(javaclassmodifiers) CVC4::JavaIteratorAdapter<CVC4::UnsatCore> "class";
-%typemap(javainterfaces) CVC4::JavaIteratorAdapter<CVC4::UnsatCore> "java.util.Iterator<edu.nyu.acsys.CVC4.Expr>";
+%typemap(javaclassmodifiers) CVC4::JavaIteratorAdapter<CVC4::UnsatCore, CVC4::Expr> "class";
+%typemap(javainterfaces) CVC4::JavaIteratorAdapter<CVC4::UnsatCore, CVC4::Expr> "java.util.Iterator<edu.nyu.acsys.CVC4.Expr>";
// add some functions to the Java side (do it here because there's no way to do these in C++)
-%typemap(javacode) CVC4::JavaIteratorAdapter<CVC4::UnsatCore> "
+%typemap(javacode) CVC4::JavaIteratorAdapter<CVC4::UnsatCore, CVC4::Expr> "
public void remove() {
throw new java.lang.UnsupportedOperationException();
}
@@ -47,13 +55,7 @@
}
"
// getNext() just allows C++ iterator access from Java-side next(), make it private
-%javamethodmodifiers CVC4::JavaIteratorAdapter<CVC4::UnsatCore>::getNext() "private";
-
-// map the types appropriately
-%typemap(jni) CVC4::UnsatCore::const_iterator::value_type "jobject";
-%typemap(jtype) CVC4::UnsatCore::const_iterator::value_type "edu.nyu.acsys.CVC4.Expr";
-%typemap(jstype) CVC4::UnsatCore::const_iterator::value_type "edu.nyu.acsys.CVC4.Expr";
-%typemap(javaout) CVC4::UnsatCore::const_iterator::value_type { return $jnicall; }
+%javamethodmodifiers CVC4::JavaIteratorAdapter<CVC4::UnsatCore, CVC4::Expr>::getNext() "private";
#endif /* SWIGJAVA */
@@ -61,9 +63,10 @@
#ifdef SWIGJAVA
+%include <std_vector.i>
+
%include "bindings/java_iterator_adapter.h"
-%include "bindings/java_stream_adapters.h"
-%template(JavaIteratorAdapter_UnsatCore) CVC4::JavaIteratorAdapter<CVC4::UnsatCore>;
+%template(JavaIteratorAdapter_UnsatCore) CVC4::JavaIteratorAdapter<CVC4::UnsatCore, CVC4::Expr>;
#endif /* SWIGJAVA */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback