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"
57 #include "bindings/java_stream_adapters.h"
59 std::set<JavaInputStreamAdapter*> CVC4::JavaInputStreamAdapter::s_adapters;
62 %template(vectorCommandPtr) std::vector< CVC4::Command* >;
63 %template(vectorType) std::vector< CVC4::Type >;
64 %template(vectorExpr) std::vector< CVC4::Expr >;
65 %template(vectorVectorExpr) std::vector< std::vector< CVC4::Expr > >;
66 %template(vectorDatatypeType) std::vector< CVC4::DatatypeType >;
67 %template(vectorSExpr) std::vector< CVC4::SExpr >;
68 %template(vectorString) std::vector< std::string >;
69 %template(setType) std::set< CVC4::Type >;
70 %template(hashmapExpr) std::hash_map< CVC4::Expr, CVC4::Expr, CVC4::ExprHashFunction >;
72 // This is unfortunate, but seems to be necessary; if we leave NULL
73 // defined, swig will expand it to "(void*) 0", and some of swig's
74 // helper functions won't compile properly.
79 #include "bindings/java_iterator_adapter.h"
80 #include "bindings/java_stream_adapters.h"
85 } catch(CVC4::Exception& e) {
87 ss << e.what() << ": " << e.getMessage();
88 std::string explanation = ss.str();
89 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
93 // Create a mapping from C++ Exceptions to Java Exceptions.
94 // This is in a couple of throws typemaps, simply because it's sensitive to SWIG's concept of which namespace we're in.
95 %typemap(throws) Exception %{
96 std::string name = "edu/nyu/acsys/$1_type";
97 size_t i = name.find("::");
98 if(i != std::string::npos) {
99 size_t j = name.rfind("::");
101 name.replace(i, j - i + 2, "/");
103 jclass clazz = jenv->FindClass(name.c_str());
104 assert(clazz != NULL && jenv->ExceptionOccurred() == NULL);
105 jmethodID method = jenv->GetMethodID(clazz, "<init>", "(JZ)V");
106 assert(method != NULL && jenv->ExceptionOccurred() == NULL);
107 jthrowable t = static_cast<jthrowable>(jenv->NewObject(clazz, method, reinterpret_cast<long>(new $1_type($1)), true));
108 assert(t != NULL && jenv->ExceptionOccurred() == NULL);
109 int status = jenv->Throw(t);
112 %typemap(throws) CVC4::Exception %{
113 std::string name = "edu/nyu/acsys/$1_type";
114 size_t i = name.find("::");
115 if(i != std::string::npos) {
116 size_t j = name.rfind("::");
118 name.replace(i, j - i + 2, "/");
120 jclass clazz = jenv->FindClass(name.c_str());
121 assert(clazz != NULL && jenv->ExceptionOccurred() == NULL);
122 jmethodID method = jenv->GetMethodID(clazz, "<init>", "(JZ)V");
123 assert(method != NULL && jenv->ExceptionOccurred() == NULL);
124 jthrowable t = static_cast<jthrowable>(jenv->NewObject(clazz, method, reinterpret_cast<long>(new $1_type($1)), true));
125 assert(t != NULL && jenv->ExceptionOccurred() == NULL);
126 int status = jenv->Throw(t);
130 %typemap(throws) ModalException = Exception;
131 %typemap(throws) LogicException = Exception;
132 %typemap(throws) OptionException = Exception;
133 %typemap(throws) IllegalArgumentException = Exception;
134 %typemap(throws) AssertionException = Exception;
136 %typemap(throws) CVC4::TypeCheckingException = CVC4::Exception;
137 %typemap(throws) CVC4::ScopeException = CVC4::Exception;
138 %typemap(throws) CVC4::IllegalArgumentException = CVC4::Exception;
139 %typemap(throws) CVC4::AssertionException = CVC4::Exception;
140 %typemap(throws) CVC4::parser::InputStreamException = CVC4::Exception;
141 %typemap(throws) CVC4::parser::ParserException = CVC4::Exception;
143 // Generate an error if the mapping from C++ CVC4 Exception to Java CVC4 Exception doesn't exist above
144 %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{
145 #error "exception $1_type doesn't map to Java correctly---please edit src/cvc4.i and add it"
148 %include "java/typemaps.i" // primitive pointers and references
149 %include "java/std_string.i" // map std::string to java.lang.String
150 %include "java/arrays_java.i" // C arrays to Java arrays
151 %include "java/various.i" // map char** to java.lang.String[]
153 // Functions on the C++ side taking std::ostream& should on the Java side
154 // take a java.io.OutputStream. A JavaOutputStreamAdapter is created in
155 // the wrapper which creates and passes on a std::stringstream to the C++
156 // function. Then on exit, the string from the stringstream is dumped to
157 // the Java-side OutputStream.
158 %typemap(jni) std::ostream& "jlong"
159 %typemap(jtype) std::ostream& "long"
160 %typemap(jstype) std::ostream& "java.io.OutputStream"
162 pre=" edu.nyu.acsys.CVC4.JavaOutputStreamAdapter temp$javainput = new edu.nyu.acsys.CVC4.JavaOutputStreamAdapter();", pgcppname="temp$javainput",
163 post=" new java.io.PrintStream($javainput).print(temp$javainput.toString());")
164 std::ostream& "edu.nyu.acsys.CVC4.JavaOutputStreamAdapter.getCPtr(temp$javainput)"
166 %typemap(jni) std::istream& "jlong"
167 %typemap(jtype) std::istream& "long"
168 %typemap(jstype) std::istream& "java.io.InputStream"
170 pre=" edu.nyu.acsys.CVC4.JavaInputStreamAdapter temp$javainput = edu.nyu.acsys.CVC4.JavaInputStreamAdapter.get($javainput);", pgcppname="temp$javainput",
172 std::istream& "edu.nyu.acsys.CVC4.JavaInputStreamAdapter.getCPtr(temp$javainput)"
173 %typemap(in) jobject inputStream %{
174 $1 = jenv->NewGlobalRef($input);
176 %typemap(out) CVC4::JavaInputStreamAdapter* %{
178 *(CVC4::JavaInputStreamAdapter **)&$result = $1;
180 %typemap(javacode) CVC4::JavaInputStreamAdapter %{
181 private static java.util.HashMap<java.io.InputStream, JavaInputStreamAdapter> streams =
182 new java.util.HashMap<java.io.InputStream, JavaInputStreamAdapter>();
183 public static JavaInputStreamAdapter get(java.io.InputStream is) {
184 if(streams.containsKey(is)) {
185 return (JavaInputStreamAdapter) streams.get(is);
187 JavaInputStreamAdapter adapter = new JavaInputStreamAdapter(is);
188 streams.put(is, adapter);
192 %typemap(javafinalize) CVC4::JavaInputStreamAdapter %{
193 protected void finalize() {
194 streams.remove(getInputStream());
198 %ignore CVC4::JavaInputStreamAdapter::init(JNIEnv*);
199 %ignore CVC4::JavaInputStreamAdapter::pullAdapters(JNIEnv*);
200 %ignore CVC4::JavaInputStreamAdapter::pull(JNIEnv*);
201 %javamethodmodifiers CVC4::JavaInputStreamAdapter::getInputStream() const "private";
202 %javamethodmodifiers CVC4::JavaInputStreamAdapter::JavaInputStreamAdapter(jobject) "private";
204 %exception CVC4::parser::Parser::nextCommand() %{
206 CVC4::JavaInputStreamAdapter::pullAdapters(jenv);
208 } catch(CVC4::Exception& e) {
209 std::stringstream ss;
210 ss << e.what() << ": " << e.getMessage();
211 std::string explanation = ss.str();
212 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
215 %exception CVC4::parser::Parser::nextExpression() %{
217 CVC4::JavaInputStreamAdapter::pullAdapters(jenv);
219 } catch(CVC4::Exception& e) {
220 std::stringstream ss;
221 ss << e.what() << ": " << e.getMessage();
222 std::string explanation = ss.str();
223 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
226 %exception CVC4::JavaInputStreamAdapter::~JavaInputStreamAdapter() %{
228 jenv->DeleteGlobalRef(arg1->getInputStream());
230 } catch(CVC4::Exception& e) {
231 std::stringstream ss;
232 ss << e.what() << ": " << e.getMessage();
233 std::string explanation = ss.str();
234 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
238 #endif /* SWIGJAVA */
240 %include "util/integer.i"
241 %include "util/rational.i"
242 %include "util/exception.i"
243 %include "util/language.i"
244 %include "options/options.i"
245 %include "util/cardinality.i"
246 %include "util/bool.i"
247 %include "util/sexpr.i"
248 %include "util/statistics.i"
249 %include "util/output.i"
250 %include "util/result.i"
251 %include "util/configuration.i"
252 %include "util/bitvector.i"
253 %include "util/subrange_bound.i"
254 %include "util/array.i"
255 %include "util/array_store_all.i"
256 %include "util/predicate.i"
257 %include "util/hash.i"
259 %include "expr/type.i"
260 %include "util/ascription_type.i"
261 %include "util/datatype.i"
262 %include "util/tuple.i"
263 %include "util/record.i"
264 %include "util/uninterpreted_constant.i"
266 %include "expr/kind.i"
267 %include "expr/expr.i"
268 %include "expr/command.i"
269 %include "expr/symbol_table.i"
270 %include "expr/expr_manager.i"
271 %include "expr/expr_stream.i"
272 %include "expr/variable_type_map.i"
274 %include "theory/logic_info.i"
276 %include "smt/smt_engine.i"
277 %include "smt/modal_exception.i"
278 %include "smt/logic_exception.i"
280 %include "options/options.i"
281 %include "options/option_exception.i"
283 %include "parser/cvc4parser.i"