From: Morgan Deters Date: Wed, 20 Aug 2014 22:16:01 +0000 (-0400) Subject: Java-side interface improvements for unsat cores. X-Git-Tag: cvc5-1.0.0~6657 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f76b86fac5da035de8531fddbd6a694103b3efaf;p=cvc5.git Java-side interface improvements for unsat cores. --- diff --git a/src/util/unsat_core.i b/src/util/unsat_core.i index 78b1360e7..9fc0dcda6 100644 --- a/src/util/unsat_core.i +++ b/src/util/unsat_core.i @@ -2,4 +2,50 @@ #include "util/unsat_core.h" %} +#ifdef SWIGJAVA + +// Instead of UnsatCore::begin() and end(), create an +// iterator() method on the Java side that returns a Java-style +// Iterator. +%ignore CVC4::UnsatCore::begin(); +%ignore CVC4::UnsatCore::end(); +%ignore CVC4::UnsatCore::begin() const; +%ignore CVC4::UnsatCore::end() const; +%extend CVC4::UnsatCore { + CVC4::JavaIteratorAdapter iterator() { + return CVC4::JavaIteratorAdapter(*$self); + } +} + +// UnsatCore is "iterable" on the Java side +%typemap(javainterfaces) CVC4::UnsatCore "java.lang.Iterable"; + +// the JavaIteratorAdapter should not be public, and implements Iterator +%typemap(javaclassmodifiers) CVC4::JavaIteratorAdapter "class"; +%typemap(javainterfaces) CVC4::JavaIteratorAdapter "java.util.Iterator"; +// add some functions to the Java side (do it here because there's no way to do these in C++) +%typemap(javacode) CVC4::JavaIteratorAdapter " + public void remove() { + throw new java.lang.UnsupportedOperationException(); + } + + public edu.nyu.acsys.CVC4.Expr next() { + if(hasNext()) { + return getNext(); + } else { + throw new java.util.NoSuchElementException(); + } + } +" +// getNext() just allows C++ iterator access from Java-side next(), make it private +%javamethodmodifiers CVC4::JavaIteratorAdapter::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; } + +#endif /* SWIGJAVA */ + %include "util/unsat_core.h"