Add --lte-restrict-inst-closure option. Push dt.size fairness constraints inside...
[cvc5.git] / src / cvc4.i
1 %import "bindings/swig.h"
2
3 %include "stdint.i"
4 %include "stl.i"
5
6 %module CVC4
7 // nspace completely broken with Java packaging
8 //%nspace;
9
10 namespace std {
11 class istream;
12 class ostream;
13 template <class T> class set {};
14 template <class K, class V, class H> class hash_map {};
15 }
16
17 %{
18 // Perl's headers define "seed" to Perl_seed, which breaks
19 // gmpxx.h; undo the damage for our CVC4 module.
20 #ifdef SWIGPERL
21 # undef seed
22 #endif /* SWIGPERL */
23
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
27 //
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!
31 //
32 #ifdef SWIGOCAML
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>.
35 # endif /* flush */
36 # undef flush
37 # undef invalid_argument
38 #endif /* SWIGOCAML */
39
40 namespace CVC4 {}
41 using namespace CVC4;
42
43 #include <iostream>
44 #include <vector>
45 #include <set>
46 #include <string>
47 #include <ext/hash_map>
48 #include <typeinfo>
49 #include <cassert>
50
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
58 #ifdef SWIGJAVA
59 #include "bindings/java_stream_adapters.h"
60 std::set<JavaInputStreamAdapter*> CVC4::JavaInputStreamAdapter::s_adapters;
61 #endif
62 %}
63
64 #ifdef SWIGPYTHON
65 %pythonappend CVC4::SmtEngine::SmtEngine %{
66 self.thisown = 0
67 %}
68 %pythonappend CVC4::ExprManager::ExprManager %{
69 self.thisown = 0
70 %}
71 #endif /* SWIGPYTHON */
72
73 %template(vectorCommandPtr) std::vector< CVC4::Command* >;
74 %template(vectorType) std::vector< CVC4::Type >;
75 %template(vectorExpr) std::vector< CVC4::Expr >;
76 %template(vectorUnsignedInt) std::vector< unsigned int >;
77 %template(vectorVectorExpr) std::vector< std::vector< CVC4::Expr > >;
78 %template(vectorDatatypeType) std::vector< CVC4::DatatypeType >;
79 %template(vectorSExpr) std::vector< CVC4::SExpr >;
80 %template(vectorString) std::vector< std::string >;
81 %template(vectorPairStringType) std::vector< std::pair< std::string, CVC4::Type > >;
82 %template(pairStringType) std::pair< std::string, CVC4::Type >;
83 %template(setOfType) std::set< CVC4::Type >;
84 %template(hashmapExpr) std::hash_map< CVC4::Expr, CVC4::Expr, CVC4::ExprHashFunction >;
85
86 // This is unfortunate, but seems to be necessary; if we leave NULL
87 // defined, swig will expand it to "(void*) 0", and some of swig's
88 // helper functions won't compile properly.
89 #undef NULL
90
91 #ifdef SWIGJAVA
92
93 #include "bindings/java_iterator_adapter.h"
94 #include "bindings/java_stream_adapters.h"
95
96 %exception %{
97 try {
98 $action
99 } catch(CVC4::Exception& e) {
100 std::stringstream ss;
101 ss << e.what() << ": " << e.getMessage();
102 std::string explanation = ss.str();
103 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
104 }
105 %}
106
107 // Create a mapping from C++ Exceptions to Java Exceptions.
108 // This is in a couple of throws typemaps, simply because it's sensitive to SWIG's concept of which namespace we're in.
109 %typemap(throws) Exception %{
110 std::string name = "edu/nyu/acsys/CVC4/$1_type";
111 /*
112 size_t i = name.find("::");
113 if(i != std::string::npos) {
114 size_t j = name.rfind("::");
115 assert(i <= j);
116 name.replace(i, j - i + 2, "/");
117 }
118 */
119 jclass clazz = jenv->FindClass(name.c_str());
120 assert(clazz != NULL && jenv->ExceptionOccurred() == NULL);
121 jmethodID method = jenv->GetMethodID(clazz, "<init>", "(JZ)V");
122 assert(method != NULL && jenv->ExceptionOccurred() == NULL);
123 jthrowable t = static_cast<jthrowable>(jenv->NewObject(clazz, method, reinterpret_cast<long>(new $1_type($1)), true));
124 assert(t != NULL && jenv->ExceptionOccurred() == NULL);
125 int status = jenv->Throw(t);
126 assert(status == 0);
127 %}
128 %typemap(throws) CVC4::Exception %{
129 std::string name = "edu/nyu/acsys/$1_type";
130 size_t i = name.find("::");
131 if(i != std::string::npos) {
132 size_t j = name.rfind("::");
133 assert(i <= j);
134 name.replace(i, j - i + 2, "/");
135 }
136 jclass clazz = jenv->FindClass(name.c_str());
137 assert(clazz != NULL && jenv->ExceptionOccurred() == NULL);
138 jmethodID method = jenv->GetMethodID(clazz, "<init>", "(JZ)V");
139 assert(method != NULL && jenv->ExceptionOccurred() == NULL);
140 jthrowable t = static_cast<jthrowable>(jenv->NewObject(clazz, method, reinterpret_cast<long>(new $1_type($1)), true));
141 assert(t != NULL && jenv->ExceptionOccurred() == NULL);
142 int status = jenv->Throw(t);
143 assert(status == 0);
144 %}
145
146 %typemap(throws) ModalException = Exception;
147 %typemap(throws) LogicException = Exception;
148 %typemap(throws) OptionException = Exception;
149 %typemap(throws) IllegalArgumentException = Exception;
150 %typemap(throws) AssertionException = Exception;
151
152 %typemap(throws) CVC4::TypeCheckingException = CVC4::Exception;
153 %typemap(throws) CVC4::ScopeException = CVC4::Exception;
154 %typemap(throws) CVC4::IllegalArgumentException = CVC4::Exception;
155 %typemap(throws) CVC4::AssertionException = CVC4::Exception;
156 %typemap(throws) CVC4::UnsafeInterruptException = CVC4::Exception;
157 %typemap(throws) CVC4::parser::InputStreamException = CVC4::Exception;
158 %typemap(throws) CVC4::parser::ParserException = CVC4::Exception;
159
160 %typemap(throws) CVC4::RationalFromDoubleException = Exception;
161
162 // Generate an error if the mapping from C++ CVC4 Exception to Java CVC4 Exception doesn't exist above
163 %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{
164 #error "exception $1_type doesn't map to Java correctly---please edit src/cvc4.i and add it"
165 %}
166
167 %include "java/typemaps.i" // primitive pointers and references
168 %include "java/std_string.i" // map std::string to java.lang.String
169 %include "java/arrays_java.i" // C arrays to Java arrays
170 %include "java/various.i" // map char** to java.lang.String[]
171
172 // Functions on the C++ side taking std::ostream& should on the Java side
173 // take a java.io.OutputStream. A JavaOutputStreamAdapter is created in
174 // the wrapper which creates and passes on a std::stringstream to the C++
175 // function. Then on exit, the string from the stringstream is dumped to
176 // the Java-side OutputStream.
177 %typemap(jni) std::ostream& "jlong"
178 %typemap(jtype) std::ostream& "long"
179 %typemap(jstype) std::ostream& "java.io.OutputStream"
180 %typemap(javain,
181 pre=" edu.nyu.acsys.CVC4.JavaOutputStreamAdapter temp$javainput = new edu.nyu.acsys.CVC4.JavaOutputStreamAdapter();", pgcppname="temp$javainput",
182 post=" new java.io.PrintStream($javainput).print(temp$javainput.toString());")
183 std::ostream& "edu.nyu.acsys.CVC4.JavaOutputStreamAdapter.getCPtr(temp$javainput)"
184
185 %typemap(jni) std::istream& "jlong"
186 %typemap(jtype) std::istream& "long"
187 %typemap(jstype) std::istream& "java.io.InputStream"
188 %typemap(javain,
189 pre=" edu.nyu.acsys.CVC4.JavaInputStreamAdapter temp$javainput = edu.nyu.acsys.CVC4.JavaInputStreamAdapter.get($javainput);", pgcppname="temp$javainput",
190 post="")
191 std::istream& "edu.nyu.acsys.CVC4.JavaInputStreamAdapter.getCPtr(temp$javainput)"
192 %typemap(in) jobject inputStream %{
193 $1 = jenv->NewGlobalRef($input);
194 %}
195 %typemap(out) CVC4::JavaInputStreamAdapter* %{
196 $1->pull(jenv);
197 *(CVC4::JavaInputStreamAdapter **)&$result = $1;
198 %}
199 %typemap(javacode) CVC4::JavaInputStreamAdapter %{
200 private static java.util.HashMap<java.io.InputStream, JavaInputStreamAdapter> streams =
201 new java.util.HashMap<java.io.InputStream, JavaInputStreamAdapter>();
202 public static JavaInputStreamAdapter get(java.io.InputStream is) {
203 if(streams.containsKey(is)) {
204 return (JavaInputStreamAdapter) streams.get(is);
205 }
206 JavaInputStreamAdapter adapter = new JavaInputStreamAdapter(is);
207 streams.put(is, adapter);
208 return adapter;
209 }
210 %}
211 %typemap(javafinalize) CVC4::JavaInputStreamAdapter %{
212 protected void finalize() {
213 streams.remove(getInputStream());
214 delete();
215 }
216 %}
217 %ignore CVC4::JavaInputStreamAdapter::init(JNIEnv*);
218 %ignore CVC4::JavaInputStreamAdapter::pullAdapters(JNIEnv*);
219 %ignore CVC4::JavaInputStreamAdapter::pull(JNIEnv*);
220 %javamethodmodifiers CVC4::JavaInputStreamAdapter::getInputStream() const "private";
221 %javamethodmodifiers CVC4::JavaInputStreamAdapter::JavaInputStreamAdapter(jobject) "private";
222
223 %exception CVC4::parser::Parser::nextCommand() %{
224 try {
225 CVC4::JavaInputStreamAdapter::pullAdapters(jenv);
226 $action
227 } catch(CVC4::Exception& e) {
228 std::stringstream ss;
229 ss << e.what() << ": " << e.getMessage();
230 std::string explanation = ss.str();
231 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
232 }
233 %}
234 %exception CVC4::parser::Parser::nextExpression() %{
235 try {
236 CVC4::JavaInputStreamAdapter::pullAdapters(jenv);
237 $action
238 } catch(CVC4::Exception& e) {
239 std::stringstream ss;
240 ss << e.what() << ": " << e.getMessage();
241 std::string explanation = ss.str();
242 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
243 }
244 %}
245 %exception CVC4::JavaInputStreamAdapter::~JavaInputStreamAdapter() %{
246 try {
247 jenv->DeleteGlobalRef(arg1->getInputStream());
248 $action
249 } catch(CVC4::Exception& e) {
250 std::stringstream ss;
251 ss << e.what() << ": " << e.getMessage();
252 std::string explanation = ss.str();
253 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, explanation.c_str());
254 }
255 %}
256
257 /* Copied (and modified) from java.swg; the standard swig version causes
258 * negative BigInteger to be interpreted unsigned. Here we throw an
259 * exception. */
260 %typemap(in) unsigned long long {
261 jclass clazz;
262 jmethodID mid;
263 jbyteArray ba;
264 jbyte* bae;
265 jsize sz;
266 int i;
267
268 if (!$input) {
269 SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
270 return $null;
271 }
272 clazz = JCALL1(GetObjectClass, jenv, $input);
273 mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
274 ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
275 bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
276 sz = JCALL1(GetArrayLength, jenv, ba);
277 if((bae[0] & 0x80) != 0) {
278 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "BigInteger argument must be nonnegative.");
279 }
280 jsize test_sz = sz;
281 if(sz > 1 && bae[0] == 0) {
282 --test_sz;
283 }
284 if(test_sz > sizeof(unsigned long long)) {
285 SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "BigInteger argument out of bounds.");
286 }
287 $1 = 0;
288 for(i=0; i<sz; i++) {
289 $1 = ($1 << 8) | ($1_type)(unsigned char)bae[i];
290 }
291 JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
292 }
293
294 #endif /* SWIGJAVA */
295
296 %include "util/exception.i"
297 %include "util/unsafe_interrupt_exception.i"
298 %include "util/integer.i"
299 %include "util/rational.i"
300 //%include "util/floatingpoint.i"
301 %include "util/language.i"
302 %include "util/cardinality.i"
303 %include "util/bool.i"
304 %include "util/sexpr.i"
305 %include "options/options.i"
306 %include "util/statistics.i"
307 %include "util/result.i"
308 %include "util/configuration.i"
309 %include "util/bitvector.i"
310 %include "util/subrange_bound.i"
311 %include "util/array.i"
312 %include "util/array_store_all.i"
313 %include "util/predicate.i"
314 %include "util/hash.i"
315
316 %include "expr/type.i"
317 %include "util/ascription_type.i"
318 %include "util/emptyset.i"
319 %include "util/datatype.i"
320 %include "util/tuple.i"
321 %include "util/record.i"
322 %include "util/regexp.i"
323 %include "util/uninterpreted_constant.i"
324 %include "util/proof.i"
325 %include "util/resource_manager.i"
326 %include "util/unsat_core.i"
327
328 %include "expr/kind.i"
329 %include "expr/expr.i"
330 %include "expr/command.i"
331 %include "expr/symbol_table.i"
332 %include "expr/expr_manager.i"
333 %include "expr/expr_stream.i"
334 %include "expr/variable_type_map.i"
335
336 %include "theory/logic_info.i"
337
338 %include "smt/smt_engine.i"
339 %include "smt/modal_exception.i"
340 %include "smt/logic_exception.i"
341
342 %include "options/options.i"
343 %include "options/option_exception.i"
344
345 %include "parser/cvc4parser.i"