1 %import "bindings/swig.h"
7 // nspace completely broken with Java packaging
13 template <class T> class set {};
14 template <class K, class V, class H> class hash_map {};
18 // Perl's headers define "seed" to Perl_seed, which breaks
19 // gmpxx.h; undo the damage for our CVC4 module.
24 // OCaml's headers define "invalid_argument" and "flush" to
25 // caml_invalid_argument and caml_flush, which breaks C++
26 // standard headers; undo this damage
28 // Unfortunately, this code isn't inserted early enough. swig puts
29 // an include <stdexcept> very early, which breaks linking due to a
30 // nonexistent std::caml_invalid_argument symbol.. ridiculous!
33 # if defined(flush) || defined(invalid_argument)
34 # error "flush" or "invalid_argument" (or both) is defined by the ocaml headers. You must #undef it above before inclusion of <stdexcept>.
37 # undef invalid_argument
38 #endif /* SWIGOCAML */
47 #include <ext/hash_map>
51 #include "util/sexpr.h"
52 #include "util/exception.h"
53 #include "expr/type.h"
54 #include "expr/expr.h"
55 #include "util/datatype.h"
56 #include "expr/command.h"
59 #include "bindings/java_stream_adapters.h"
60 std::set<JavaInputStreamAdapter*> CVC4::JavaInputStreamAdapter::s_adapters;
64 %template(vectorCommandPtr) std::vector< CVC4::Command* >;
65 %template(vectorType) std::vector< CVC4::Type >;
66 %template(vectorExpr) std::vector< CVC4::Expr >;
67 %template(vectorVectorExpr) std::vector< std::vector< CVC4::Expr > >;
68 %template(vectorDatatypeType) std::vector< CVC4::DatatypeType >;
69 %template(vectorSExpr) std::vector< CVC4::SExpr >;
70 %template(vectorString) std::vector< std::string >;
71 %template(vectorPairStringType) std::vector< std::pair< std::string, CVC4::Type > >;
72 %template(pairStringType) std::pair< std::string, CVC4::Type >;
73 %template(setType) std::set< CVC4::Type >;
74 %template(hashmapExpr) std::hash_map< CVC4::Expr, CVC4::Expr, CVC4::ExprHashFunction >;
76 // This is unfortunate, but seems to be necessary; if we leave NULL
77 // defined, swig will expand it to "(void*) 0", and some of swig's
78 // helper functions won't compile properly.
83 #include "bindings/java_iterator_adapter.h"
84 #include "bindings/java_stream_adapters.h"
89 } catch(CVC4::Exception& e) {
91 ss << e.what() << ": " << e.getMessage();
92 std::string explanation = ss.str();
93 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
97 // Create a mapping from C++ Exceptions to Java Exceptions.
98 // This is in a couple of throws typemaps, simply because it's sensitive to SWIG's concept of which namespace we're in.
99 %typemap(throws) Exception %{
100 std::string name = "edu/nyu/acsys/CVC4/$1_type";
102 size_t i = name.find("::");
103 if(i != std::string::npos) {
104 size_t j = name.rfind("::");
106 name.replace(i, j - i + 2, "/");
109 jclass clazz = jenv->FindClass(name.c_str());
110 assert(clazz != NULL && jenv->ExceptionOccurred() == NULL);
111 jmethodID method = jenv->GetMethodID(clazz, "<init>", "(JZ)V");
112 assert(method != NULL && jenv->ExceptionOccurred() == NULL);
113 jthrowable t = static_cast<jthrowable>(jenv->NewObject(clazz, method, reinterpret_cast<long>(new $1_type($1)), true));
114 assert(t != NULL && jenv->ExceptionOccurred() == NULL);
115 int status = jenv->Throw(t);
118 %typemap(throws) CVC4::Exception %{
119 std::string name = "edu/nyu/acsys/$1_type";
120 size_t i = name.find("::");
121 if(i != std::string::npos) {
122 size_t j = name.rfind("::");
124 name.replace(i, j - i + 2, "/");
126 jclass clazz = jenv->FindClass(name.c_str());
127 assert(clazz != NULL && jenv->ExceptionOccurred() == NULL);
128 jmethodID method = jenv->GetMethodID(clazz, "<init>", "(JZ)V");
129 assert(method != NULL && jenv->ExceptionOccurred() == NULL);
130 jthrowable t = static_cast<jthrowable>(jenv->NewObject(clazz, method, reinterpret_cast<long>(new $1_type($1)), true));
131 assert(t != NULL && jenv->ExceptionOccurred() == NULL);
132 int status = jenv->Throw(t);
136 %typemap(throws) ModalException = Exception;
137 %typemap(throws) LogicException = Exception;
138 %typemap(throws) OptionException = Exception;
139 %typemap(throws) IllegalArgumentException = Exception;
140 %typemap(throws) AssertionException = Exception;
142 %typemap(throws) CVC4::TypeCheckingException = CVC4::Exception;
143 %typemap(throws) CVC4::ScopeException = CVC4::Exception;
144 %typemap(throws) CVC4::IllegalArgumentException = CVC4::Exception;
145 %typemap(throws) CVC4::AssertionException = CVC4::Exception;
146 %typemap(throws) CVC4::parser::InputStreamException = CVC4::Exception;
147 %typemap(throws) CVC4::parser::ParserException = CVC4::Exception;
149 // Generate an error if the mapping from C++ CVC4 Exception to Java CVC4 Exception doesn't exist above
150 %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{
151 #error "exception $1_type doesn't map to Java correctly---please edit src/cvc4.i and add it"
154 %include "java/typemaps.i" // primitive pointers and references
155 %include "java/std_string.i" // map std::string to java.lang.String
156 %include "java/arrays_java.i" // C arrays to Java arrays
157 %include "java/various.i" // map char** to java.lang.String[]
159 // Functions on the C++ side taking std::ostream& should on the Java side
160 // take a java.io.OutputStream. A JavaOutputStreamAdapter is created in
161 // the wrapper which creates and passes on a std::stringstream to the C++
162 // function. Then on exit, the string from the stringstream is dumped to
163 // the Java-side OutputStream.
164 %typemap(jni) std::ostream& "jlong"
165 %typemap(jtype) std::ostream& "long"
166 %typemap(jstype) std::ostream& "java.io.OutputStream"
168 pre=" edu.nyu.acsys.CVC4.JavaOutputStreamAdapter temp$javainput = new edu.nyu.acsys.CVC4.JavaOutputStreamAdapter();", pgcppname="temp$javainput",
169 post=" new java.io.PrintStream($javainput).print(temp$javainput.toString());")
170 std::ostream& "edu.nyu.acsys.CVC4.JavaOutputStreamAdapter.getCPtr(temp$javainput)"
172 %typemap(jni) std::istream& "jlong"
173 %typemap(jtype) std::istream& "long"
174 %typemap(jstype) std::istream& "java.io.InputStream"
176 pre=" edu.nyu.acsys.CVC4.JavaInputStreamAdapter temp$javainput = edu.nyu.acsys.CVC4.JavaInputStreamAdapter.get($javainput);", pgcppname="temp$javainput",
178 std::istream& "edu.nyu.acsys.CVC4.JavaInputStreamAdapter.getCPtr(temp$javainput)"
179 %typemap(in) jobject inputStream %{
180 $1 = jenv->NewGlobalRef($input);
182 %typemap(out) CVC4::JavaInputStreamAdapter* %{
184 *(CVC4::JavaInputStreamAdapter **)&$result = $1;
186 %typemap(javacode) CVC4::JavaInputStreamAdapter %{
187 private static java.util.HashMap<java.io.InputStream, JavaInputStreamAdapter> streams =
188 new java.util.HashMap<java.io.InputStream, JavaInputStreamAdapter>();
189 public static JavaInputStreamAdapter get(java.io.InputStream is) {
190 if(streams.containsKey(is)) {
191 return (JavaInputStreamAdapter) streams.get(is);
193 JavaInputStreamAdapter adapter = new JavaInputStreamAdapter(is);
194 streams.put(is, adapter);
198 %typemap(javafinalize) CVC4::JavaInputStreamAdapter %{
199 protected void finalize() {
200 streams.remove(getInputStream());
204 %ignore CVC4::JavaInputStreamAdapter::init(JNIEnv*);
205 %ignore CVC4::JavaInputStreamAdapter::pullAdapters(JNIEnv*);
206 %ignore CVC4::JavaInputStreamAdapter::pull(JNIEnv*);
207 %javamethodmodifiers CVC4::JavaInputStreamAdapter::getInputStream() const "private";
208 %javamethodmodifiers CVC4::JavaInputStreamAdapter::JavaInputStreamAdapter(jobject) "private";
210 %exception CVC4::parser::Parser::nextCommand() %{
212 CVC4::JavaInputStreamAdapter::pullAdapters(jenv);
214 } catch(CVC4::Exception& e) {
215 std::stringstream ss;
216 ss << e.what() << ": " << e.getMessage();
217 std::string explanation = ss.str();
218 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
221 %exception CVC4::parser::Parser::nextExpression() %{
223 CVC4::JavaInputStreamAdapter::pullAdapters(jenv);
225 } catch(CVC4::Exception& e) {
226 std::stringstream ss;
227 ss << e.what() << ": " << e.getMessage();
228 std::string explanation = ss.str();
229 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
232 %exception CVC4::JavaInputStreamAdapter::~JavaInputStreamAdapter() %{
234 jenv->DeleteGlobalRef(arg1->getInputStream());
236 } catch(CVC4::Exception& e) {
237 std::stringstream ss;
238 ss << e.what() << ": " << e.getMessage();
239 std::string explanation = ss.str();
240 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
244 #endif /* SWIGJAVA */
246 %include "util/integer.i"
247 %include "util/rational.i"
248 %include "util/exception.i"
249 %include "util/language.i"
250 %include "options/options.i"
251 %include "util/cardinality.i"
252 %include "util/bool.i"
253 %include "util/sexpr.i"
254 %include "util/statistics.i"
255 %include "util/result.i"
256 %include "util/configuration.i"
257 %include "util/bitvector.i"
258 %include "util/subrange_bound.i"
259 %include "util/array.i"
260 %include "util/array_store_all.i"
261 %include "util/predicate.i"
262 %include "util/hash.i"
264 %include "expr/type.i"
265 %include "util/ascription_type.i"
266 %include "util/datatype.i"
267 %include "util/tuple.i"
268 %include "util/record.i"
269 %include "util/regexp.i"
270 %include "util/uninterpreted_constant.i"
272 %include "expr/kind.i"
273 %include "expr/expr.i"
274 %include "expr/command.i"
275 %include "expr/symbol_table.i"
276 %include "expr/expr_manager.i"
277 %include "expr/expr_stream.i"
278 %include "expr/variable_type_map.i"
280 %include "theory/logic_info.i"
282 %include "smt/smt_engine.i"
283 %include "smt/modal_exception.i"
284 %include "smt/logic_exception.i"
286 %include "options/options.i"
287 %include "options/option_exception.i"
289 %include "parser/cvc4parser.i"