summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Yziquel <guillaume.yziquel@citycable.ch>2009-07-23 01:12:01 +0000
committerGuillaume Yziquel <guillaume.yziquel@citycable.ch>2009-07-23 01:12:01 +0000
commitd9ff3489f63818421055a4930c4230847a8762e3 (patch)
treebaf60e8d97a3676516000544a0f2bc0510ff642f
parent0249eea38995dfc6689c78cde861b7ec2b6b4af2 (diff)
downloadswig-d9ff3489f63818421055a4930c4230847a8762e3.tar.gz
Basic OCaml module.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/yziquel-ocaml@11438 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--Lib/ocaml/carray.i136
-rw-r--r--Lib/ocaml/class.swg66
-rw-r--r--Lib/ocaml/cstring.i271
-rw-r--r--Lib/ocaml/director.swg103
-rw-r--r--Lib/ocaml/extra-install.list5
-rw-r--r--Lib/ocaml/libswigocaml.h20
-rw-r--r--Lib/ocaml/ocaml.i61
-rw-r--r--Lib/ocaml/ocaml.swg606
-rw-r--r--Lib/ocaml/ocamldec.swg172
-rw-r--r--Lib/ocaml/ocamlhead.swg57
-rw-r--r--Lib/ocaml/ocamlkw.swg64
-rw-r--r--Lib/ocaml/preamble.swg17
-rw-r--r--Lib/ocaml/std_common.i22
-rw-r--r--Lib/ocaml/std_complex.i65
-rw-r--r--Lib/ocaml/std_deque.i31
-rw-r--r--Lib/ocaml/std_list.i222
-rw-r--r--Lib/ocaml/std_map.i173
-rw-r--r--Lib/ocaml/std_pair.i37
-rw-r--r--Lib/ocaml/std_string.i195
-rw-r--r--Lib/ocaml/std_vector.i92
-rw-r--r--Lib/ocaml/stl.i15
-rw-r--r--Lib/ocaml/swig.ml159
-rw-r--r--Lib/ocaml/swig.mli61
-rw-r--r--Lib/ocaml/swigp4.ml.in118
-rw-r--r--Lib/ocaml/typecheck.i179
-rw-r--r--Lib/ocaml/typemaps.i319
-rw-r--r--Lib/ocaml/typeregister.swg2
-rw-r--r--Source/Modules/ocaml.cxx2073
28 files changed, 376 insertions, 4965 deletions
diff --git a/Lib/ocaml/carray.i b/Lib/ocaml/carray.i
deleted file mode 100644
index bbf1ddd58..000000000
--- a/Lib/ocaml/carray.i
+++ /dev/null
@@ -1,136 +0,0 @@
-%insert(mli) %{
-type _value = c_obj
-%}
-
-%insert(ml) %{
-type _value = c_obj
-%}
-
-%define %array_tmap_out(type,what,out_f)
-%typemap(type) what [ANY] {
- int i;
- /* $*1_type */
- $result = caml_array_new($1_dim0);
- for( i = 0; i < $1_dim0; i++ ) {
- caml_array_set($result,i,out_f($1[i]));
- }
-}
-%enddef
-
-%define %array_tmap_in(type,what,in_f)
-%typemap(type) what [ANY] {
- int i;
- /* $*1_type */
- $1 = ($*1_type *)malloc( $1_size );
- for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
- $1[i] = in_f(caml_array_nth($input,i));
- }
-}
-
-%typemap(free) what [ANY] {
- free( (void *)$1 );
-}
-%enddef
-
-%define %make_simple_array_typemap(type,out_f,in_f)
-%array_tmap_out(out,type,out_f);
-%array_tmap_out(varout,type,out_f);
-%array_tmap_out(directorin,type,out_f);
-
-%array_tmap_in(in,type,in_f);
-%array_tmap_in(varin,type,in_f);
-%array_tmap_in(directorout,type,in_f);
-%enddef
-
-%make_simple_array_typemap(bool,caml_val_bool,caml_long_val);
-%make_simple_array_typemap(short,caml_val_short,caml_long_val);
-%make_simple_array_typemap(unsigned short,caml_val_ushort,caml_long_val);
-%make_simple_array_typemap(int,caml_val_int,caml_long_val);
-%make_simple_array_typemap(unsigned int,caml_val_uint,caml_long_val);
-%make_simple_array_typemap(long,caml_val_long,caml_long_val);
-%make_simple_array_typemap(unsigned long,caml_val_ulong,caml_long_val);
-%make_simple_array_typemap(size_t,caml_val_int,caml_long_val);
-%make_simple_array_typemap(float,caml_val_float,caml_double_val);
-%make_simple_array_typemap(double,caml_val_double,caml_double_val);
-
-#ifdef __cplusplus
-%typemap(in) SWIGTYPE [] {
- int i;
-
- /* $*1_type */
- $1 = new $*1_type [$1_dim0];
- for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
- $1[i] = *(($*1_ltype *)
- caml_ptr_val(caml_array_nth($input,i),
- $*1_descriptor)) ;
- }
-}
-#else
-%typemap(in) SWIGTYPE [] {
- int i;
-
- /* $*1_type */
- $1 = ($*1_type *)malloc( $1_size );
- for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
- $1[i] = *(($*1_ltype)
- caml_ptr_val(caml_array_nth($input),
- $*1_descriptor));
- }
-}
-#endif
-
-%typemap(out) SWIGTYPE [] {
- int i;
- CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
- $result = caml_array_new($1_dim0);
-
- for( i = 0; i < $1_dim0; i++ ) {
- if( fromval ) {
- caml_array_set
- ($result,
- i,
- callback(*fromval,caml_val_ptr((void *)&$1[i],$*1_descriptor)));
- } else {
- caml_array_set
- ($result,
- i,
- caml_val_ptr ((void *)&$1[i],$&1_descriptor));
- }
- }
-}
-
-%typemap(in) enum SWIGTYPE [] {
- int i;
-
- /* $*1_type */
- $1 = ($*1_type *)malloc( $1_size );
- for( i = 0; i < $1_dim0 && i < caml_array_len($input); i++ ) {
- $1[i] = ($type)
- caml_long_val_full(caml_array_nth($input),
- "$type_marker");
- }
-}
-
-%typemap(out) enum SWIGTYPE [] {
- int i;
- $result = caml_array_new($1_dim0);
-
- for( i = 0; i < $1_dim0; i++ ) {
- caml_array_set
- ($result,
- i,
- callback2(*caml_named_value(SWIG_MODULE "_int_to_enum"),
- *caml_named_value("$type_marker"),
- Val_int($1[i])));
- }
-}
-
-#ifdef __cplusplus
-%typemap(freearg) SWIGTYPE [ANY] {
- delete [] $1;
-}
-#else
-%typemap(freearg) SWIGTYPE [ANY] {
- free( (void *)$1 );
-}
-#endif
diff --git a/Lib/ocaml/class.swg b/Lib/ocaml/class.swg
deleted file mode 100644
index 0ee304cab..000000000
--- a/Lib/ocaml/class.swg
+++ /dev/null
@@ -1,66 +0,0 @@
-(*Stream:class_ctors*)
-let create_$classname_from_ptr raw_ptr =
- C_obj
-begin
- let h = Hashtbl.create 20 in
- List.iter (fun (nm,fn) -> Hashtbl.replace h nm fn)
- [ "nop", (fun args -> C_void) ;
- $classbody
- "&", (fun args -> raw_ptr) ;
- ":parents",
- (fun args ->
- C_list
- (let out = ref [] in
- Hashtbl.iter (fun x y -> out := (x,y) :: !out) h ;
- (List.map
- (fun (x,y) ->
- C_string (String.sub x 2 ((String.length x) - 2)))
- (List.filter
- (fun (x,y) ->
- ((String.length x) > 2)
- && x.[0] == ':' && x.[1] == ':') !out)))) ;
- ":classof", (fun args -> C_string "$realname") ;
- ":methods", (fun args ->
- C_list (let out = ref [] in
- Hashtbl.iter (fun x y -> out := (C_string x) :: !out) h ; !out))
- ] ;
- let rec invoke_inner raw_ptr mth arg =
- begin
- try
- let application = Hashtbl.find h mth in
- application
- (match arg with
- C_list l -> (C_list (raw_ptr :: l))
- | C_void -> (C_list [ raw_ptr ])
- | v -> (C_list [ raw_ptr ; v ]))
- with Not_found ->
- (* Try parent classes *)
- begin
- let parent_classes = [
- $baselist
- ] in
- let rec try_parent plist raw_ptr =
- match plist with
- p :: tl ->
- begin
- try
- (invoke (p raw_ptr)) mth arg
- with (BadMethodName (p,m,s)) ->
- try_parent tl raw_ptr
- end
- | [] ->
- raise (BadMethodName (raw_ptr,mth,"$realname"))
- in try_parent parent_classes raw_ptr
- end
- end in
- (fun mth arg -> invoke_inner raw_ptr mth arg)
-end
-
-let _ = Callback.register
- "create_$normalized_from_ptr"
- create_$classname_from_ptr
-
-
-(*Stream:mli*)
-val create_$classname_from_ptr : c_obj -> c_obj
-
diff --git a/Lib/ocaml/cstring.i b/Lib/ocaml/cstring.i
deleted file mode 100644
index e56258264..000000000
--- a/Lib/ocaml/cstring.i
+++ /dev/null
@@ -1,271 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * cstring.i
- *
- * This file provides typemaps and macros for dealing with various forms
- * of C character string handling. The primary use of this module
- * is in returning character data that has been allocated or changed in
- * some way.
- * ----------------------------------------------------------------------------- */
-
-/* %cstring_input_binary(TYPEMAP, SIZE)
- *
- * Macro makes a function accept binary string data along with
- * a size.
- */
-
-%define %cstring_input_binary(TYPEMAP, SIZE)
-%apply (char *STRING, int LENGTH) { (TYPEMAP, SIZE) };
-%enddef
-
-/*
- * %cstring_bounded_output(TYPEMAP, MAX)
- *
- * This macro is used to return a NULL-terminated output string of
- * some maximum length. For example:
- *
- * %cstring_bounded_output(char *outx, 512);
- * void foo(char *outx) {
- * sprintf(outx,"blah blah\n");
- * }
- *
- */
-
-%define %cstring_bounded_output(TYPEMAP,MAX)
-%typemap(ignore) TYPEMAP(char temp[MAX+1]) {
- $1 = ($1_ltype) temp;
-}
-%typemap(argout) TYPEMAP {
- $1[MAX] = 0;
- $result = caml_list_append($result,caml_val_string(str));
-}
-%enddef
-
-/*
- * %cstring_chunk_output(TYPEMAP, SIZE)
- *
- * This macro is used to return a chunk of binary string data.
- * Embedded NULLs are okay. For example:
- *
- * %cstring_chunk_output(char *outx, 512);
- * void foo(char *outx) {
- * memmove(outx, somedata, 512);
- * }
- *
- */
-
-%define %cstring_chunk_output(TYPEMAP,SIZE)
-%typemap(ignore) TYPEMAP(char temp[SIZE]) {
- $1 = ($1_ltype) temp;
-}
-%typemap(argout) TYPEMAP {
- $result = caml_list_append($result,caml_val_string_len($1,SIZE));
-}
-%enddef
-
-/*
- * %cstring_bounded_mutable(TYPEMAP, SIZE)
- *
- * This macro is used to wrap a string that's going to mutate.
- *
- * %cstring_bounded_mutable(char *in, 512);
- * void foo(in *x) {
- * while (*x) {
- * *x = toupper(*x);
- * x++;
- * }
- * }
- *
- */
-
-
-%define %cstring_bounded_mutable(TYPEMAP,MAX)
-%typemap(in) TYPEMAP(char temp[MAX+1]) {
- char *t = (char *)caml_ptr_val($input);
- strncpy(temp,t,MAX);
- $1 = ($1_ltype) temp;
-}
-%typemap(argout) TYPEMAP {
- $result = caml_list_append($result,caml_val_string_len($1,MAX));
-}
-%enddef
-
-/*
- * %cstring_mutable(TYPEMAP [, expansion])
- *
- * This macro is used to wrap a string that will mutate in place.
- * It may change size up to a user-defined expansion.
- *
- * %cstring_mutable(char *in);
- * void foo(in *x) {
- * while (*x) {
- * *x = toupper(*x);
- * x++;
- * }
- * }
- *
- */
-
-%define %cstring_mutable(TYPEMAP,...)
-%typemap(in) TYPEMAP {
- char *t = String_val($input);
- int n = string_length($input);
- $1 = ($1_ltype) t;
-#if #__VA_ARGS__ == ""
-#ifdef __cplusplus
- $1 = ($1_ltype) new char[n+1];
-#else
- $1 = ($1_ltype) malloc(n+1);
-#endif
-#else
-#ifdef __cplusplus
- $1 = ($1_ltype) new char[n+1+__VA_ARGS__];
-#else
- $1 = ($1_ltype) malloc(n+1+__VA_ARGS__);
-#endif
-#endif
- memmove($1,t,n);
- $1[n] = 0;
-}
-
-%typemap(argout) TYPEMAP {
- $result = caml_list_append($result,caml_val_string($1));
-#ifdef __cplusplus
- delete[] $1;
-#else
- free($1);
-#endif
-}
-%enddef
-
-/*
- * %cstring_output_maxsize(TYPEMAP, SIZE)
- *
- * This macro returns data in a string of some user-defined size.
- *
- * %cstring_output_maxsize(char *outx, int max) {
- * void foo(char *outx, int max) {
- * sprintf(outx,"blah blah\n");
- * }
- */
-
-%define %cstring_output_maxsize(TYPEMAP, SIZE)
-%typemap(in) (TYPEMAP, SIZE) {
- $2 = caml_val_long($input);
-#ifdef __cplusplus
- $1 = ($1_ltype) new char[$2+1];
-#else
- $1 = ($1_ltype) malloc($2+1);
-#endif
-}
-%typemap(argout) (TYPEMAP,SIZE) {
- $result = caml_list_append($result,caml_val_string($1));
-#ifdef __cplusplus
- delete [] $1;
-#else
- free($1);
-#endif
-}
-%enddef
-
-/*
- * %cstring_output_withsize(TYPEMAP, SIZE)
- *
- * This macro is used to return character data along with a size
- * parameter.
- *
- * %cstring_output_maxsize(char *outx, int *max) {
- * void foo(char *outx, int *max) {
- * sprintf(outx,"blah blah\n");
- * *max = strlen(outx);
- * }
- */
-
-%define %cstring_output_withsize(TYPEMAP, SIZE)
-%typemap(in) (TYPEMAP, SIZE) {
- int n = caml_val_long($input);
-#ifdef __cplusplus
- $1 = ($1_ltype) new char[n+1];
- $2 = ($2_ltype) new $*1_ltype;
-#else
- $1 = ($1_ltype) malloc(n+1);
- $2 = ($2_ltype) malloc(sizeof($*1_ltype));
-#endif
- *$2 = n;
-}
-%typemap(argout) (TYPEMAP,SIZE) {
- $result = caml_list_append($result,caml_val_string_len($1,$2));
-#ifdef __cplusplus
- delete [] $1;
- delete $2;
-#else
- free($1);
- free($2);
-#endif
-}
-%enddef
-
-/*
- * %cstring_output_allocate(TYPEMAP, RELEASE)
- *
- * This macro is used to return character data that was
- * allocated with new or malloc.
- *
- * %cstring_output_allocated(char **outx, free($1));
- * void foo(char **outx) {
- * *outx = (char *) malloc(512);
- * sprintf(outx,"blah blah\n");
- * }
- */
-
-%define %cstring_output_allocate(TYPEMAP, RELEASE)
-%typemap(ignore) TYPEMAP($*1_ltype temp = 0) {
- $1 = &temp;
-}
-
-%typemap(argout) TYPEMAP {
- if (*$1) {
- $result = caml_list_append($result,caml_val_string($1));
- RELEASE;
- } else {
- $result = caml_list_append($result,caml_val_ptr($1));
- }
-}
-%enddef
-
-/*
- * %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
- *
- * This macro is used to return character data that was
- * allocated with new or malloc.
- *
- * %cstring_output_allocated(char **outx, int *sz, free($1));
- * void foo(char **outx, int *sz) {
- * *outx = (char *) malloc(512);
- * sprintf(outx,"blah blah\n");
- * *sz = strlen(outx);
- * }
- */
-
-%define %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
-%typemap(ignore) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) {
- $1 = &temp;
- $2 = &tempn;
-}
-
-%typemap(argout)(TYPEMAP,SIZE) {
- if (*$1) {
- $result = caml_list_append($result,caml_val_string_len($1,$2));
- RELEASE;
- } else
- $result = caml_list_append($result,caml_val_ptr($1));
-}
-%enddef
-
-
-
-
-
-
diff --git a/Lib/ocaml/director.swg b/Lib/ocaml/director.swg
deleted file mode 100644
index 87333168f..000000000
--- a/Lib/ocaml/director.swg
+++ /dev/null
@@ -1,103 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * director.swg
- *
- * This file contains support for director classes that proxy
- * method calls from C++ to Ocaml extensions.
- *
- * ----------------------------------------------------------------------------- */
-
-#ifdef __cplusplus
-
-#include <string>
-
-namespace Swig {
- /* base class for director exceptions */
- class DirectorException {
- protected:
- std::string swig_msg;
- public:
- DirectorException(const char* msg="") {
- }
- const char *getMessage() const {
- return swig_msg.c_str();
- }
- virtual ~DirectorException() {}
- };
-
- /* type mismatch in the return value from a python method call */
- class DirectorTypeMismatchException : public Swig::DirectorException {
- public:
- DirectorTypeMismatchException(const char* msg="") {
- }
- };
-
- /* any python exception that occurs during a director method call */
- class DirectorMethodException : public Swig::DirectorException {};
-
- /* attempt to call a pure virtual method via a director method */
- class DirectorPureVirtualException : public Swig::DirectorException {
- public:
- DirectorPureVirtualException(const char* msg="") {
- }
-
- static void raise(const char *msg) {
- throw DirectorPureVirtualException(msg);
- }
- };
-
- /* simple thread abstraction for pthreads on win32 */
-#ifdef __THREAD__
-#define __PTHREAD__
-#if defined(_WIN32) || defined(__WIN32__)
-#define pthread_mutex_lock EnterCriticalSection
-#define pthread_mutex_unlock LeaveCriticalSection
-#define pthread_mutex_t CRITICAL_SECTION
-#define MUTEX_INIT(var) CRITICAL_SECTION var
-#else
-#include <pthread.h>
-#define MUTEX_INIT(var) pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
-#endif
-#endif
-
- /* director base class */
- class Director {
- private:
- /* pointer to the wrapped ocaml object */
- CAML_VALUE swig_self;
- /* flag indicating whether the object is owned by ocaml or c++ */
- mutable bool swig_disown_flag;
-
- public:
- /* wrap a ocaml object, optionally taking ownership */
- Director(CAML_VALUE self) : swig_self(self), swig_disown_flag(false) {
- register_global_root(&swig_self);
- }
-
- /* discard our reference at destruction */
- virtual ~Director() {
- remove_global_root(&swig_self);
- swig_disown();
- // Disown is safe here because we're just divorcing a reference that
- // points to us.
- }
-
- /* return a pointer to the wrapped ocaml object */
- CAML_VALUE swig_get_self() const {
- return swig_self;
- }
-
- /* acquire ownership of the wrapped ocaml object (the sense of "disown"
- * is from ocaml) */
- void swig_disown() const {
- if (!swig_disown_flag) {
- swig_disown_flag=true;
- callback(*caml_named_value("caml_obj_disown"),swig_self);
- }
- }
- };
-}
-
-#endif /* __cplusplus */
diff --git a/Lib/ocaml/extra-install.list b/Lib/ocaml/extra-install.list
deleted file mode 100644
index a63c7fc2f..000000000
--- a/Lib/ocaml/extra-install.list
+++ /dev/null
@@ -1,5 +0,0 @@
-# see top-level Makefile.in
-# libswigocaml is not needed anymore.
-swigp4.ml
-swig.mli
-swig.ml
diff --git a/Lib/ocaml/libswigocaml.h b/Lib/ocaml/libswigocaml.h
deleted file mode 100644
index e752540fe..000000000
--- a/Lib/ocaml/libswigocaml.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* Ocaml runtime support */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- typedef int oc_bool;
- extern void *nullptr;
-
- extern oc_bool isnull( void *v );
-
- extern void *get_char_ptr( char *str );
- extern void *make_ptr_array( int size );
- extern void *get_ptr( void *arrayptr, int elt );
- extern void set_ptr( void *arrayptr, int elt, void *elt_v );
- extern void *offset_ptr( void *ptr, int n );
-
-#ifdef __cplusplus
-};
-#endif
diff --git a/Lib/ocaml/ocaml.i b/Lib/ocaml/ocaml.i
deleted file mode 100644
index a46e239d1..000000000
--- a/Lib/ocaml/ocaml.i
+++ /dev/null
@@ -1,61 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * ocaml.i
- *
- * SWIG Configuration File for Ocaml
- * ----------------------------------------------------------------------------- */
-
-%runtime %{
-#define SWIGSTATIC static
-%}
-
-/* Insert common stuff */
-%insert(runtime) "swigrun.swg"
-
-/* Include headers */
-%insert(runtime) "ocamldec.swg"
-
-/* Type registration */
-%insert(init) "swiginit.swg"
-%insert(init) "typeregister.swg"
-
-%insert(mlitail) %{
- val swig_val : c_enum_type -> c_obj -> Swig.c_obj
-%}
-
-%insert(mltail) %{
- let rec swig_val t v =
- match v with
- C_enum e -> enum_to_int t v
- | C_list l -> Swig.C_list (List.map (swig_val t) l)
- | C_array a -> Swig.C_array (Array.map (swig_val t) a)
- | _ -> Obj.magic v
-%}
-
-/*#ifndef SWIG_NOINCLUDE*/
-%insert(runtime) "ocaml.swg"
-/*#endif*/
-
-%insert(classtemplate) "class.swg"
-
-/* Definitions */
-#define SWIG_malloc(size) swig_malloc(size, FUNC_NAME)
-#define SWIG_free(mem) free(mem)
-
-/* Read in standard typemaps. */
-%include <swig.swg>
-%include <typemaps.i>
-%include <typecheck.i>
-%include <exception.i>
-%include <preamble.swg>
-
-/* ocaml keywords */
-/* There's no need to use this, because of my rewriting machinery. C++
- * words never collide with ocaml keywords */
-
-/* still we include the file, but the warning says that the offending
- name will be properly renamed. Just to let the user to know about
- it. */
-%include <ocamlkw.swg>
diff --git a/Lib/ocaml/ocaml.swg b/Lib/ocaml/ocaml.swg
index 5f8f929e2..983e4a6fe 100644
--- a/Lib/ocaml/ocaml.swg
+++ b/Lib/ocaml/ocaml.swg
@@ -1,602 +1,6 @@
-/* -*-c-*- */
-
-/* SWIG pointer structure */
-
-#include <string.h>
-#include <assert.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define C_bool 0
-#define C_char 1
-#define C_uchar 2
-#define C_short 3
-#define C_ushort 4
-#define C_int 5
-#define C_uint 6
-#define C_int32 7
-#define C_int64 8
-#define C_float 9
-#define C_double 10
-#define C_ptr 11
-#define C_array 12
-#define C_list 13
-#define C_obj 14
-#define C_string 15
-#define C_enum 16
-#define C_director_core 17
-
-
-/* Cast a pointer if possible; returns 1 if successful */
-
- SWIGSTATIC int
- SWIG_Cast (void *source, swig_type_info *source_type,
- void **ptr, swig_type_info *dest_type)
- {
- if( !source ) { // Special case for NULL. This is a popular question
- // for other modules on the list, so I want an easy way out...
- *ptr = 0;
- return 0;
- }
-
-#ifdef TYPE_CAST_VERBOSE
- fprintf( stderr, "Trying to cast %s to %s\n",
- source_type ? source_type->str : "<none>",
- dest_type ? dest_type->str : "<none>" );
-#endif
- if (dest_type != source_type) {
- /* We have a type mismatch. Will have to look through our type
- mapping table to figure out whether or not we can accept this
- datatype.
- --
- Ignore typechecks for void *. Allow any conversion. */
- if( !dest_type || !source_type ||
- !strcmp(dest_type->name,"_p_void") ||
- !strcmp(source_type->name,"_p_void") ) {
- *ptr = source;
- return 0;
- } else {
- swig_cast_info *tc =
- SWIG_TypeCheckStruct(source_type, dest_type );
-#ifdef TYPE_CAST_VERBOSE
- fprintf( stderr, "Typecheck -> %s\n",
- tc ? tc->str : "<none>" );
-#endif
- if( tc ) {
- int newmemory = 0;
- *ptr = SWIG_TypeCast(tc, source, &newmemory);
- assert(!newmemory); /* newmemory handling not yet implemented */
- return 0;
- } else
- return -1;
- }
- } else {
- *ptr = source;
- return 0;
- }
- }
-
-/* Return 0 if successful. */
- SWIGSTATIC int
- SWIG_GetPtr(void *inptr, void **outptr,
- swig_type_info *intype, swig_type_info *outtype) {
- if (intype) {
- return SWIG_Cast(inptr, intype,
- outptr, outtype) == -1;
- } else {
- *outptr = inptr;
- return 0;
- }
- }
-
- SWIGSTATIC void caml_print_list( CAML_VALUE v );
-
- SWIGSTATIC void caml_print_val( CAML_VALUE v ) {
- switch( SWIG_Tag_val(v) ) {
- case C_bool:
- if( Bool_val(SWIG_Field(v,0)) ) fprintf( stderr, "true " );
- else fprintf( stderr, "false " );
- break;
- case C_char:
- case C_uchar:
- fprintf( stderr, "'%c' (\\%03d) ",
- (Int_val(SWIG_Field(v,0)) >= ' ' &&
- Int_val(SWIG_Field(v,0)) < 127) ? Int_val(SWIG_Field(v,0)) : '.',
- Int_val(SWIG_Field(v,0)) );
- break;
- case C_short:
- case C_ushort:
- case C_int:
- fprintf( stderr, "%d ", (int)caml_long_val(v) );
- break;
-
- case C_uint:
- case C_int32:
- fprintf( stderr, "%ud ", (unsigned int)caml_long_val(v) );
- break;
- case C_int64:
- fprintf( stderr, "%ld ", caml_long_val(v) );
- break;
- case C_float:
- case C_double:
- fprintf( stderr, "%f ", caml_double_val(v) );
- break;
-
- case C_ptr:
- {
- void *vout = 0;
- swig_type_info *ty = (swig_type_info *)(long)SWIG_Int64_val(SWIG_Field(v,1));
- caml_ptr_val_internal(v,&vout,0);
- fprintf( stderr, "PTR(%p,%s) ",
- vout,
- ty ? ty->name : "(null)" );
- }
- break;
- case C_array:
- {
- unsigned int i;
- for( i = 0; i < Wosize_val( SWIG_Field(v,0) ); i++ )
- caml_print_val( SWIG_Field(SWIG_Field(v,0),i) );
- }
- break;
- case C_list:
- caml_print_list( SWIG_Field(v,0) );
- break;
- case C_obj:
- fprintf( stderr, "OBJ(%p) ", (void *)SWIG_Field(v,0) );
- break;
- case C_string:
- {
- void *cout;
- caml_ptr_val_internal(v,&cout,0);
- fprintf( stderr, "'%s' ", (char *)cout );
- }
- break;
- }
- }
-
- SWIGSTATIC void caml_print_list( CAML_VALUE v ) {
- CAMLparam1(v);
- while( v && Is_block(v) ) {
- fprintf( stderr, "[ " );
- caml_print_val( SWIG_Field(v,0) );
- fprintf( stderr, "]\n" );
- v = SWIG_Field(v,1);
- }
- CAMLreturn0;
- }
-
- SWIGSTATIC CAML_VALUE caml_list_nth( CAML_VALUE lst, int n ) {
- CAMLparam1(lst);
- int i = 0;
- while( i < n && lst && Is_block(lst) ) {
- i++; lst = SWIG_Field(lst,1);
- }
- if( lst == Val_unit ) CAMLreturn(Val_unit);
- else CAMLreturn(SWIG_Field(lst,0));
- }
-
- SWIGSTATIC CAML_VALUE caml_list_append( CAML_VALUE lst, CAML_VALUE elt ) {
- CAMLparam2(lst,elt);
- SWIG_CAMLlocal3(v,vt,lh);
- lh = Val_unit;
- v = Val_unit;
-
- /* Appending C_void should have no effect */
- if( !Is_block(elt) ) return lst;
-
- while( lst && Is_block(lst) ) {
- if( v && v != Val_unit ) {
- vt = alloc_tuple(2);
- SWIG_Store_field(v,1,vt);
- v = vt;
- } else {
- v = lh = alloc_tuple(2);
- }
- SWIG_Store_field(v,0,SWIG_Field(lst,0));
- lst = SWIG_Field(lst,1);
- }
-
- if( v && Is_block(v) ) {
- vt = alloc_tuple(2);
- SWIG_Store_field(v,1,vt);
- v = vt;
- } else {
- v = lh = alloc_tuple(2);
- }
- SWIG_Store_field(v,0,elt);
- SWIG_Store_field(v,1,Val_unit);
-
- CAMLreturn(lh);
- }
-
- SWIGSTATIC int caml_list_length( CAML_VALUE lst ) {
- CAMLparam1(lst);
- int i = 0;
- while( lst && Is_block(lst) ) { i++; lst = SWIG_Field(lst,1); }
- CAMLreturn(i);
- }
-
- SWIGSTATIC void caml_array_set( CAML_VALUE arr, int n, CAML_VALUE item ) {
- CAMLparam2(arr,item);
- SWIG_Store_field(SWIG_Field(arr,0),n,item);
- CAMLreturn0;
- }
-
- SWIGSTATIC value caml_array_nth( CAML_VALUE arr, int n ) {
- CAMLparam1(arr);
- if( SWIG_Tag_val(arr) == C_array )
- CAMLreturn(SWIG_Field(SWIG_Field(arr,0),n));
- else if( SWIG_Tag_val(arr) == C_list )
- CAMLreturn(caml_list_nth(arr,0));
- else
- failwith("Need array or list");
- }
-
- SWIGSTATIC int caml_array_len( CAML_VALUE arr ) {
- CAMLparam1(arr);
- if( SWIG_Tag_val(arr) == C_array )
- CAMLreturn(Wosize_val(SWIG_Field(arr,0)));
- else if( SWIG_Tag_val(arr) == C_list )
- CAMLreturn(caml_list_length(arr));
- else
- failwith("Need array or list");
- }
-
- SWIGSTATIC CAML_VALUE caml_swig_alloc(int x,int y) {
- return caml_alloc(x,y);
- }
-
- SWIGSTATIC value caml_array_new( int n ) {
- CAMLparam0();
- SWIG_CAMLlocal1(vv);
- vv = caml_swig_alloc(1,C_array);
- SWIG_Store_field(vv,0,alloc_tuple(n));
- CAMLreturn(vv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_bool( int b ) {
- CAMLparam0();
- SWIG_CAMLlocal1(bv);
- bv = caml_swig_alloc(1,C_bool);
- SWIG_Store_field(bv,0,Val_bool(b));
- CAMLreturn(bv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_char( char c ) {
- CAMLparam0();
- SWIG_CAMLlocal1(cv);
- cv = caml_swig_alloc(1,C_char);
- SWIG_Store_field(cv,0,Val_int(c));
- CAMLreturn(cv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_uchar( unsigned char uc ) {
- CAMLparam0();
- SWIG_CAMLlocal1(ucv);
- ucv = caml_swig_alloc(1,C_uchar);
- SWIG_Store_field(ucv,0,Val_int(uc));
- CAMLreturn(ucv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_short( short s ) {
- CAMLparam0();
- SWIG_CAMLlocal1(sv);
- sv = caml_swig_alloc(1,C_short);
- SWIG_Store_field(sv,0,Val_int(s));
- CAMLreturn(sv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_ushort( unsigned short us ) {
- CAMLparam0();
- SWIG_CAMLlocal1(usv);
- usv = caml_swig_alloc(1,C_ushort);
- SWIG_Store_field(usv,0,Val_int(us));
- CAMLreturn(usv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_int( int i ) {
- CAMLparam0();
- SWIG_CAMLlocal1(iv);
- iv = caml_swig_alloc(1,C_int);
- SWIG_Store_field(iv,0,Val_int(i));
- CAMLreturn(iv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_uint( unsigned int ui ) {
- CAMLparam0();
- SWIG_CAMLlocal1(uiv);
- uiv = caml_swig_alloc(1,C_int);
- SWIG_Store_field(uiv,0,Val_int(ui));
- CAMLreturn(uiv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_long( long l ) {
- CAMLparam0();
- SWIG_CAMLlocal1(lv);
- lv = caml_swig_alloc(1,C_int64);
- SWIG_Store_field(lv,0,copy_int64(l));
- CAMLreturn(lv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_ulong( unsigned long ul ) {
- CAMLparam0();
- SWIG_CAMLlocal1(ulv);
- ulv = caml_swig_alloc(1,C_int64);
- SWIG_Store_field(ulv,0,copy_int64(ul));
- CAMLreturn(ulv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_float( float f ) {
- CAMLparam0();
- SWIG_CAMLlocal1(fv);
- fv = caml_swig_alloc(1,C_float);
- SWIG_Store_field(fv,0,copy_double((double)f));
- CAMLreturn(fv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_double( double d ) {
- CAMLparam0();
- SWIG_CAMLlocal1(fv);
- fv = caml_swig_alloc(1,C_double);
- SWIG_Store_field(fv,0,copy_double(d));
- CAMLreturn(fv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_ptr( void *p, swig_type_info *info ) {
- CAMLparam0();
- SWIG_CAMLlocal1(vv);
- vv = caml_swig_alloc(2,C_ptr);
- SWIG_Store_field(vv,0,copy_int64((long)p));
- SWIG_Store_field(vv,1,copy_int64((long)info));
- CAMLreturn(vv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_string( const char *p ) {
- CAMLparam0();
- SWIG_CAMLlocal1(vv);
- if( !p ) CAMLreturn(caml_val_ptr( (void *)p, 0 ));
- vv = caml_swig_alloc(1,C_string);
- SWIG_Store_field(vv,0,copy_string(p));
- CAMLreturn(vv);
- }
-
- SWIGSTATIC CAML_VALUE caml_val_string_len( const char *p, int len ) {
- CAMLparam0();
- SWIG_CAMLlocal1(vv);
- if( !p || len < 0 ) CAMLreturn(caml_val_ptr( (void *)p, 0 ));
- vv = caml_swig_alloc(1,C_string);
- SWIG_Store_field(vv,0,alloc_string(len));
- memcpy(String_val(SWIG_Field(vv,0)),p,len);
- CAMLreturn(vv);
- }
-
- #define caml_val_obj(v, name) caml_val_obj_helper(v, SWIG_TypeQuery((name)), name)
- SWIGSTATIC CAML_VALUE caml_val_obj_helper( void *v, swig_type_info *type, char *name) {
- CAMLparam0();
- CAMLreturn(callback2(*caml_named_value("caml_create_object_fn"),
- caml_val_ptr(v,type),
- copy_string(name)));
- }
-
- SWIGSTATIC long caml_long_val_full( CAML_VALUE v, char *name ) {
- CAMLparam1(v);
- if( !Is_block(v) ) return 0;
-
- switch( SWIG_Tag_val(v) ) {
- case C_bool:
- case C_char:
- case C_uchar:
- case C_short:
- case C_ushort:
- case C_int:
- CAMLreturn(Int_val(SWIG_Field(v,0)));
- case C_uint:
- case C_int32:
- CAMLreturn(Int32_val(SWIG_Field(v,0)));
- case C_int64:
- CAMLreturn((long)SWIG_Int64_val(SWIG_Field(v,0)));
- case C_float:
- case C_double:
- CAMLreturn((long)Double_val(SWIG_Field(v,0)));
- case C_string:
- CAMLreturn((long)String_val(SWIG_Field(v,0)));
- case C_ptr:
- CAMLreturn((long)SWIG_Int64_val(SWIG_Field(SWIG_Field(v,0),0)));
- case C_enum: {
- SWIG_CAMLlocal1(ret);
- CAML_VALUE *enum_to_int = caml_named_value(SWIG_MODULE "_enum_to_int");
- if( !name ) failwith( "Not an enum conversion" );
- ret = callback2(*enum_to_int,*caml_named_value(name),v);
- CAMLreturn(caml_long_val(ret));
- }
- default:
- failwith("No conversion to int");
- }
- }
-
- SWIGSTATIC long caml_long_val( CAML_VALUE v ) {
- return caml_long_val_full(v,0);
- }
-
- SWIGSTATIC double caml_double_val( CAML_VALUE v ) {
- CAMLparam1(v);
- if( !Is_block(v) ) return 0.0;
- switch( SWIG_Tag_val(v) ) {
- case C_bool:
- case C_char:
- case C_uchar:
- case C_short:
- case C_ushort:
- case C_int:
- CAMLreturn_type(Int_val(SWIG_Field(v,0)));
- case C_uint:
- case C_int32:
- CAMLreturn_type(Int32_val(SWIG_Field(v,0)));
- case C_int64:
- CAMLreturn_type(SWIG_Int64_val(SWIG_Field(v,0)));
- case C_float:
- case C_double:
- CAMLreturn_type(Double_val(SWIG_Field(v,0)));
- default:
- fprintf( stderr, "Unknown block tag %d\n", SWIG_Tag_val(v) );
- failwith("No conversion to double");
- }
- }
-
- SWIGSTATIC int caml_ptr_val_internal( CAML_VALUE v, void **out,
- swig_type_info *descriptor ) {
- CAMLparam1(v);
- void *outptr = NULL;
- swig_type_info *outdescr = NULL;
-
- if( v == Val_unit ) {
- *out = 0;
- CAMLreturn(0);
- }
- if( !Is_block(v) ) return -1;
- switch( SWIG_Tag_val(v) ) {
- case C_int:
- if( !caml_long_val( v ) ) {
- *out = 0;
- CAMLreturn(0);
- } else {
- *out = 0;
- CAMLreturn(1);
- }
- break;
- case C_obj:
- CAMLreturn
- (caml_ptr_val_internal
- (callback(*caml_named_value("caml_obj_ptr"),v),
- out,descriptor));
- case C_string:
- outptr = (void *)String_val(SWIG_Field(v,0));
- break;
- case C_ptr:
- outptr = (void *)(long)SWIG_Int64_val(SWIG_Field(v,0));
- outdescr = (swig_type_info *)(long)SWIG_Int64_val(SWIG_Field(v,1));
- break;
- default:
- *out = 0;
- CAMLreturn(1);
- break;
- }
-
- CAMLreturn(SWIG_GetPtr(outptr,out,outdescr,descriptor));
- }
-
- SWIGSTATIC void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor ) {
- CAMLparam0();
-#ifdef TYPE_CAST_VERBOSE
- caml_print_val( v );
-#endif
- void *out = NULL;
- if( !caml_ptr_val_internal( v, &out, descriptor ) )
- CAMLreturn_type(out);
- else
- failwith( "No appropriate conversion found." );
- }
-
- SWIGSTATIC char *caml_string_val( CAML_VALUE v ) {
- return (char *)caml_ptr_val( v, 0 );
- }
-
- SWIGSTATIC int caml_string_len( CAML_VALUE v ) {
- switch( SWIG_Tag_val(v) ) {
- case C_string:
- return string_length(SWIG_Field(v,0));
- default:
- return strlen((char *)caml_ptr_val(v,0));
- }
- }
-
- SWIGSTATIC int caml_bool_check( CAML_VALUE v ) {
- CAMLparam1(v);
-
- if( !Is_block(v) ) return 0;
-
- switch( SWIG_Tag_val(v) ) {
- case C_bool:
- case C_ptr:
- case C_string:
- CAMLreturn(1);
- default:
- CAMLreturn(0);
- }
- }
-
- SWIGSTATIC int caml_int_check( CAML_VALUE v ) {
- CAMLparam1(v);
-
- if( !Is_block(v) ) return 0;
-
- switch( SWIG_Tag_val(v) ) {
- case C_char:
- case C_uchar:
- case C_short:
- case C_ushort:
- case C_int:
- case C_uint:
- case C_int32:
- case C_int64:
- CAMLreturn(1);
-
- default:
- CAMLreturn(0);
- }
- }
-
- SWIGSTATIC int caml_float_check( CAML_VALUE v ) {
- CAMLparam1(v);
- if( !Is_block(v) ) return 0;
-
- switch( SWIG_Tag_val(v) ) {
- case C_float:
- case C_double:
- CAMLreturn(1);
-
- default:
- CAMLreturn(0);
- }
- }
-
- SWIGSTATIC int caml_ptr_check( CAML_VALUE v ) {
- CAMLparam1(v);
- if( !Is_block(v) ) return 0;
-
- switch( SWIG_Tag_val(v) ) {
- case C_string:
- case C_ptr:
- case C_int64:
- CAMLreturn(1);
-
- default:
- CAMLreturn(0);
- }
- }
-
- static swig_module_info *SWIG_Ocaml_GetModule() {
- CAML_VALUE pointer;
-
- pointer = callback(*caml_named_value("swig_find_type_info"), caml_val_int(0));
- if (Is_block(pointer) && SWIG_Tag_val(pointer) == C_ptr) {
- return (swig_module_info *)(void *)(long)SWIG_Int64_val(SWIG_Field(pointer,0));
- }
- return 0;
- }
-
- static void SWIG_Ocaml_SetModule(swig_module_info *pointer) {
- CAML_VALUE mod_pointer;
-
- mod_pointer = caml_val_ptr(pointer, NULL);
- callback(*caml_named_value("swig_set_type_info"), mod_pointer);
- }
-
-#ifdef __cplusplus
-}
-#endif
-#undef value
+%include <ocamlhead.swg>
+%typemap(out) SWIGTYPE *
+ { $result = caml_alloc_custom(&custom_swigtype_ocaml_operations, sizeof (void *), 0, 1);
+ *((void **) Data_custom_val($result)) = (void *)$1;
+ }
diff --git a/Lib/ocaml/ocamldec.swg b/Lib/ocaml/ocamldec.swg
deleted file mode 100644
index 3b5290fa1..000000000
--- a/Lib/ocaml/ocamldec.swg
+++ /dev/null
@@ -1,172 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * ocamldec.swg
- *
- * Ocaml runtime code -- declarations
- * ----------------------------------------------------------------------------- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#ifdef __cplusplus
-#define SWIGEXT extern "C"
-SWIGEXT {
-#else
-#define SWIGEXT
-#endif
-#define value caml_value_t
-#define CAML_VALUE caml_value_t
-#include <caml/alloc.h>
-#include <caml/custom.h>
-#include <caml/mlvalues.h>
-#include <caml/memory.h>
-#include <caml/callback.h>
-#include <caml/fail.h>
-#include <caml/misc.h>
-
-#define caml_array_set swig_caml_array_set
-
-// Adapted from memory.h and mlvalues.h
-
-#define SWIG_CAMLlocal1(x) \
- caml_value_t x = 0; \
- CAMLxparam1 (x)
-
-#define SWIG_CAMLlocal2(x, y) \
- caml_value_t x = 0, y = 0; \
- CAMLxparam2 (x, y)
-
-#define SWIG_CAMLlocal3(x, y, z) \
- caml_value_t x = 0, y = 0, z = 0; \
- CAMLxparam3 (x, y, z)
-
-#define SWIG_CAMLlocal4(x, y, z, t) \
- caml_value_t x = 0, y = 0, z = 0, t = 0; \
- CAMLxparam4 (x, y, z, t)
-
-#define SWIG_CAMLlocal5(x, y, z, t, u) \
- caml_value_t x = 0, y = 0, z = 0, t = 0, u = 0; \
- CAMLxparam5 (x, y, z, t, u)
-
-#define SWIG_CAMLlocalN(x, size) \
- caml_value_t x [(size)] = { 0, /* 0, 0, ... */ }; \
- CAMLxparamN (x, (size))
-
-#define SWIG_Field(x, i) (((caml_value_t *)(x)) [i]) /* Also an l-value. */
-#define SWIG_Store_field(block, offset, val) do{ \
- mlsize_t caml__temp_offset = (offset); \
- caml_value_t caml__temp_val = (val); \
- modify (&SWIG_Field ((block), caml__temp_offset), caml__temp_val); \
-}while(0)
-
-#define SWIG_Data_custom_val(v) ((void *) &SWIG_Field((v), 1))
-#ifdef ARCH_BIG_ENDIAN
-#define SWIG_Tag_val(val) (((unsigned char *) (val)) [-1])
- /* Also an l-value. */
-#define SWIG_Tag_hp(hp) (((unsigned char *) (hp)) [sizeof(caml_value_t)-1])
- /* Also an l-value. */
-#else
-#define SWIG_Tag_val(val) (((unsigned char *) (val)) [-sizeof(caml_value_t)])
- /* Also an l-value. */
-#define SWIG_Tag_hp(hp) (((unsigned char *) (hp)) [0])
- /* Also an l-value. */
-#endif
-
-#ifdef CAMLreturn0
-#undef CAMLreturn0
-#endif
-#define CAMLreturn0 do{ \
- caml_local_roots = caml__frame; \
- return; \
-}while (0)
-
-#ifdef CAMLreturn
-#undef CAMLreturn
-#endif
-#define CAMLreturn(result) do{ \
- caml_value_t caml__temp_result = (result); \
- caml_local_roots = caml__frame; \
- return (caml__temp_result); \
-}while(0)
-
-#define CAMLreturn_type(result) do{ \
- caml_local_roots = caml__frame; \
- return result; \
-}while(0)
-
-#ifdef CAMLnoreturn
-#undef CAMLnoreturn
-#endif
-#define CAMLnoreturn ((void) caml__frame)
-
-
-#ifndef ARCH_ALIGN_INT64
-#define SWIG_Int64_val(v) (*((int64 *) SWIG_Data_custom_val(v)))
-#else
-CAMLextern int64 Int64_val(caml_value_t v);
-#define SWIG_Int64_val(v) Int64_val(v)
-#endif
-
-#define SWIG_NewPointerObj(p,type,flags) caml_val_ptr(p,type)
-#define SWIG_GetModule(clientdata) SWIG_Ocaml_GetModule()
-#define SWIG_SetModule(clientdata, pointer) SWIG_Ocaml_SetModule(pointer)
-
-#define SWIG_contract_assert(expr, msg) if(!(expr)) {failwith(msg);} else
-
- SWIGSTATIC int
- SWIG_GetPtr(void *source, void **result, swig_type_info *type, swig_type_info *result_type);
-
- SWIGSTATIC void *
- SWIG_MustGetPtr (CAML_VALUE v, swig_type_info *type);
-
- SWIGSTATIC CAML_VALUE _wrap_delete_void( CAML_VALUE );
-
- SWIGSTATIC int enum_to_int( char *name, CAML_VALUE v );
- SWIGSTATIC CAML_VALUE int_to_enum( char *name, int v );
-
- SWIGSTATIC CAML_VALUE caml_list_nth( CAML_VALUE lst, int n );
- SWIGSTATIC CAML_VALUE caml_list_append( CAML_VALUE lst, CAML_VALUE elt );
- SWIGSTATIC int caml_list_length( CAML_VALUE lst );
- SWIGSTATIC CAML_VALUE caml_array_new( int n );
- SWIGSTATIC void caml_array_set( CAML_VALUE arr, int n, CAML_VALUE item );
- SWIGSTATIC CAML_VALUE caml_array_nth( CAML_VALUE arr, int n );
- SWIGSTATIC int caml_array_length( CAML_VALUE arr );
-
- SWIGSTATIC CAML_VALUE caml_val_char( char c );
- SWIGSTATIC CAML_VALUE caml_val_uchar( unsigned char c );
-
- SWIGSTATIC CAML_VALUE caml_val_short( short s );
- SWIGSTATIC CAML_VALUE caml_val_ushort( unsigned short s );
-
- SWIGSTATIC CAML_VALUE caml_val_int( int x );
- SWIGSTATIC CAML_VALUE caml_val_uint( unsigned int x );
-
- SWIGSTATIC CAML_VALUE caml_val_long( long x );
- SWIGSTATIC CAML_VALUE caml_val_ulong( unsigned long x );
-
- SWIGSTATIC CAML_VALUE caml_val_float( float f );
- SWIGSTATIC CAML_VALUE caml_val_double( double d );
-
- SWIGSTATIC CAML_VALUE caml_val_ptr( void *p, swig_type_info *descriptor );
-
- SWIGSTATIC CAML_VALUE caml_val_string( const char *str );
- SWIGSTATIC CAML_VALUE caml_val_string_len( const char *str, int len );
-
- SWIGSTATIC long caml_long_val( CAML_VALUE v );
- SWIGSTATIC double caml_double_val( CAML_VALUE v );
-
- SWIGSTATIC int caml_ptr_val_internal( CAML_VALUE v, void **out,
- swig_type_info *descriptor );
- SWIGSTATIC void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor );
-
- SWIGSTATIC char *caml_string_val( CAML_VALUE v );
- SWIGSTATIC int caml_string_len( CAML_VALUE v );
-
-#ifdef __cplusplus
-}
-#endif
-
-/* mzschemedec.swg ends here */
diff --git a/Lib/ocaml/ocamlhead.swg b/Lib/ocaml/ocamlhead.swg
new file mode 100644
index 000000000..a9624b747
--- /dev/null
+++ b/Lib/ocaml/ocamlhead.swg
@@ -0,0 +1,57 @@
+%insert(runtime) %{
+ #include <stdlib.h>
+ #include <string.h>
+ #include <stdio.h>
+
+ /* Including OCaml system. */
+ #define CAML_VALUE value
+ #include <caml/alloc.h>
+ #include <caml/custom.h>
+ #include <caml/mlvalues.h>
+ #include <caml/memory.h>
+ #include <caml/callback.h>
+ #include <caml/fail.h>
+ #include <caml/misc.h>
+
+ #define SWIG_CAMLlocal1(x) \
+ CAML_VALUE x = 0; \
+ CAMLxparam1 (x)
+
+ #define SWIG_CAMLlocal2(x, y) \
+ CAML_VALUE x = 0, y = 0; \
+ CAMLxparam2 (x, y)
+
+ #define SWIG_CAMLlocal3(x, y, z) \
+ CAML_VALUE x = 0, y = 0, z = 0; \
+ CAMLxparam3 (x, y, z)
+
+ #define SWIG_CAMLlocal4(x, y, z, t) \
+ CAML_VALUE x = 0, y = 0, z = 0, t = 0; \
+ CAMLxparam4 (x, y, z, t)
+
+ #define SWIG_CAMLlocal5(x, y, z, t, u) \
+ CAML_VALUE x = 0, y = 0, z = 0, t = 0, u = 0; \
+ CAMLxparam5 (x, y, z, t, u)
+
+ #define SWIG_CAMLlocalN(x, size) \
+ CAML_VALUE x [(size)] = { 0, /* 0, 0, ... */ }; \
+ CAMLxparamN (x, (size))
+%}
+
+%insert(runtime) %{
+
+ /* Declarations for custom block operations. */
+
+ /* For more information of Objective Caml custom blocks,
+ * consult the Objective Caml manual, section 18.9. */
+
+ static struct custom_operations custom_swigtype_ocaml_operations = {
+ "org.homelinux.yziquel.ocaml.swig",
+ custom_finalize_default,
+ custom_compare_default,
+ custom_hash_default,
+ custom_serialize_default,
+ custom_deserialize_default
+ };
+
+%}
diff --git a/Lib/ocaml/ocamlkw.swg b/Lib/ocaml/ocamlkw.swg
deleted file mode 100644
index 9b9096e2b..000000000
--- a/Lib/ocaml/ocamlkw.swg
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef OCAML_OCAMLKW_SWG_
-#define OCAML_OCAMLKW_SWG_
-
-/* Warnings for Ocaml keywords */
-#define OCAMLKW(x) %namewarn("314: '" #x "' is a ocaml keyword and it will properly renamed") #x
-
-/*
- from
- http://caml.inria.fr/ocaml/htmlman/manual044.html
-*/
-
-
-OCAMLKW(and);
-OCAMLKW(as);
-OCAMLKW(assert);
-OCAMLKW(begin);
-OCAMLKW(class);
-OCAMLKW(constraint);
-OCAMLKW(do);
-OCAMLKW(done);
-OCAMLKW(downto);
-OCAMLKW(else);
-OCAMLKW(end);
-OCAMLKW(exception);
-OCAMLKW(external);
-OCAMLKW(false);
-OCAMLKW(for);
-OCAMLKW(fun);
-OCAMLKW(function);
-OCAMLKW(functor);
-OCAMLKW(if);
-OCAMLKW(in);
-OCAMLKW(include);
-OCAMLKW(inherit);
-OCAMLKW(initializer);
-OCAMLKW(lazy);
-OCAMLKW(let);
-OCAMLKW(match);
-OCAMLKW(method);
-OCAMLKW(module);
-OCAMLKW(mutable);
-OCAMLKW(new);
-OCAMLKW(object);
-OCAMLKW(of);
-OCAMLKW(open);
-OCAMLKW(or);
-OCAMLKW(private);
-OCAMLKW(rec);
-OCAMLKW(sig);
-OCAMLKW(struct);
-OCAMLKW(then);
-OCAMLKW(to);
-OCAMLKW(true);
-OCAMLKW(try);
-OCAMLKW(type);
-OCAMLKW(val);
-OCAMLKW(virtual);
-OCAMLKW(when);
-OCAMLKW(while);
-OCAMLKW(with);
-
-#undef OCAMLKW
-
-#endif //OCAML_OCAMLKW_SWG_
diff --git a/Lib/ocaml/preamble.swg b/Lib/ocaml/preamble.swg
deleted file mode 100644
index 39374ce4b..000000000
--- a/Lib/ocaml/preamble.swg
+++ /dev/null
@@ -1,17 +0,0 @@
-%insert(mli) %{
-exception BadArgs of string
-exception BadMethodName of c_obj * string * string
-exception NotObject of c_obj
-exception NotEnumType of c_obj
-exception LabelNotFromThisEnum of c_obj
-exception InvalidDirectorCall of c_obj
-%}
-
-%insert(ml) %{
-exception BadArgs of string
-exception BadMethodName of c_obj * string * string
-exception NotObject of c_obj
-exception NotEnumType of c_obj
-exception LabelNotFromThisEnum of c_obj
-exception InvalidDirectorCall of c_obj
-%} \ No newline at end of file
diff --git a/Lib/ocaml/std_common.i b/Lib/ocaml/std_common.i
deleted file mode 100644
index b2dff61d2..000000000
--- a/Lib/ocaml/std_common.i
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * std_common.i
- *
- * SWIG typemaps for STL - common utilities
- * ----------------------------------------------------------------------------- */
-
-%include <std/std_except.i>
-
-%apply size_t { std::size_t };
-
-%{
-#include <string>
- CAML_VALUE SwigString_FromString(const std::string& s) {
- return caml_val_string((char *)s.c_str());
- }
- std::string SwigString_AsString(CAML_VALUE o) {
- return std::string((char *)caml_ptr_val(o,0));
- }
-%}
diff --git a/Lib/ocaml/std_complex.i b/Lib/ocaml/std_complex.i
deleted file mode 100644
index 5192261aa..000000000
--- a/Lib/ocaml/std_complex.i
+++ /dev/null
@@ -1,65 +0,0 @@
-// -*- C++ -*-
-#ifndef SWIG_STD_COMPLEX_I_
-#define SWIG_STD_COMPLEX_I_
-
-#ifdef SWIG
-
-%{
-#include <complex>
-%}
-
-namespace std
-{
- template <class T> class complex;
-
- %define specialize_std_complex(T)
-
- %typemap(in) complex<T> {
- if (PyComplex_Check($input)) {
- $1 = std::complex<T>(PyComplex_RealAsDouble($input),
- PyComplex_ImagAsDouble($input));
- } else if (PyFloat_Check($input)) {
- $1 = std::complex<T>(PyFloat_AsDouble($input), 0);
- } else if (PyInt_Check($input)) {
- $1 = std::complex<T>(PyInt_AsLong($input), 0);
- }
- else {
- PyErr_SetString(PyExc_TypeError,"Expected a complex");
- SWIG_fail;
- }
- }
-
- %typemap(in) const complex<T>& (std::complex<T> temp) {
- if (PyComplex_Check($input)) {
- temp = std::complex<T>(PyComplex_RealAsDouble($input),
- PyComplex_ImagAsDouble($input));
- $1 = &temp;
- } else if (PyFloat_Check($input)) {
- temp = std::complex<T>(PyFloat_AsDouble($input), 0);
- $1 = &temp;
- } else if (PyInt_Check($input)) {
- temp = std::complex<T>(PyInt_AsLong($input), 0);
- $1 = &temp;
- } else {
- PyErr_SetString(PyExc_TypeError,"Expected a complex");
- SWIG_fail;
- }
- }
-
- %typemap(out) complex<T> {
- $result = PyComplex_FromDoubles($1.real(), $1.imag());
- }
-
- %typemap(out) const complex<T> & {
- $result = PyComplex_FromDoubles($1->real(), $1->imag());
- }
-
- %enddef
-
- specialize_std_complex(double);
- specialize_std_complex(float);
-}
-
-#endif // SWIG
-
-#endif //SWIG_STD_COMPLEX_I_
diff --git a/Lib/ocaml/std_deque.i b/Lib/ocaml/std_deque.i
deleted file mode 100644
index baadb4e53..000000000
--- a/Lib/ocaml/std_deque.i
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * std_deque.i
- *
- * Default std_deque wrapper
- * ----------------------------------------------------------------------------- */
-
-%module std_deque
-
-%rename(__getitem__) std::deque::getitem;
-%rename(__setitem__) std::deque::setitem;
-%rename(__delitem__) std::deque::delitem;
-%rename(__getslice__) std::deque::getslice;
-%rename(__setslice__) std::deque::setslice;
-%rename(__delslice__) std::deque::delslice;
-
-%extend std::deque {
- int __len__() {
- return (int) self->size();
- }
- int __nonzero__() {
- return ! self->empty();
- }
- void append(const T &x) {
- self->push_back(x);
- }
-};
-
-%include <std/_std_deque.i>
diff --git a/Lib/ocaml/std_list.i b/Lib/ocaml/std_list.i
deleted file mode 100644
index 0aea90767..000000000
--- a/Lib/ocaml/std_list.i
+++ /dev/null
@@ -1,222 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * std_list.i
- *
- * SWIG typemaps for std::list types
- * ----------------------------------------------------------------------------- */
-
-%include <std_common.i>
-
-%module std_list
-%{
-#include <list>
-#include <stdexcept>
-%}
-
-
-namespace std{
- template<class T> class list
- {
- public:
-
- typedef T &reference;
- typedef const T& const_reference;
- typedef T &iterator;
- typedef const T& const_iterator;
-
- list();
- list(unsigned int size, const T& value = T());
- list(const list<T> &);
-
- ~list();
- void assign(unsigned int n, const T& value);
- void swap(list<T> &x);
-
- const_reference front();
- const_reference back();
- const_iterator begin();
- const_iterator end();
-
- void resize(unsigned int n, T c = T());
- bool empty() const;
-
- void push_front(const T& x);
- void push_back(const T& x);
-
-
- void pop_front();
- void pop_back();
- void clear();
- unsigned int size() const;
- unsigned int max_size() const;
- void resize(unsigned int n, const T& value);
-
- void remove(const T& value);
- void unique();
- void reverse();
- void sort();
-
-
-
- %extend
- {
- const_reference __getitem__(int i) throw (std::out_of_range)
- {
- std::list<T>::iterator first = self->begin();
- int size = int(self->size());
- if (i<0) i += size;
- if (i>=0 && i<size)
- {
- for (int k=0;k<i;k++)
- {
- first++;
- }
- return *first;
- }
- else throw std::out_of_range("list index out of range");
- }
- void __setitem__(int i, const T& x) throw (std::out_of_range)
- {
- std::list<T>::iterator first = self->begin();
- int size = int(self->size());
- if (i<0) i += size;
- if (i>=0 && i<size)
- {
- for (int k=0;k<i;k++)
- {
- first++;
- }
- *first = x;
- }
- else throw std::out_of_range("list index out of range");
- }
- void __delitem__(int i) throw (std::out_of_range)
- {
- std::list<T>::iterator first = self->begin();
- int size = int(self->size());
- if (i<0) i += size;
- if (i>=0 && i<size)
- {
- for (int k=0;k<i;k++)
- {
- first++;
- }
- self->erase(first);
- }
- else throw std::out_of_range("list index out of range");
- }
- std::list<T> __getslice__(int i,int j)
- {
- std::list<T>::iterator first = self->begin();
- std::list<T>::iterator end = self->end();
-
- int size = int(self->size());
- if (i<0) i += size;
- if (j<0) j += size;
- if (i<0) i = 0;
- if (j>size) j = size;
- if (i>=j) i=j;
- if (i>=0 && i<size && j>=0)
- {
- for (int k=0;k<i;k++)
- {
- first++;
- }
- for (int m=0;m<j;m++)
- {
- end++;
- }
- std::list<T> tmp(j-i);
- if (j>i) std::copy(first,end,tmp.begin());
- return tmp;
- }
- else throw std::out_of_range("list index out of range");
- }
- void __delslice__(int i,int j)
- {
- std::list<T>::iterator first = self->begin();
- std::list<T>::iterator end = self->end();
-
- int size = int(self->size());
- if (i<0) i += size;
- if (j<0) j += size;
- if (i<0) i = 0;
- if (j>size) j = size;
-
- for (int k=0;k<i;k++)
- {
- first++;
- }
- for (int m=0;m<=j;m++)
- {
- end++;
- }
- self->erase(first,end);
- }
- void __setslice__(int i,int j, const std::list<T>& v)
- {
- std::list<T>::iterator first = self->begin();
- std::list<T>::iterator end = self->end();
-
- int size = int(self->size());
- if (i<0) i += size;
- if (j<0) j += size;
- if (i<0) i = 0;
- if (j>size) j = size;
-
- for (int k=0;k<i;k++)
- {
- first++;
- }
- for (int m=0;m<=j;m++)
- {
- end++;
- }
- if (int(v.size()) == j-i)
- {
- std::copy(v.begin(),v.end(),first);
- }
- else {
- self->erase(first,end);
- if (i+1 <= int(self->size()))
- {
- first = self->begin();
- for (int k=0;k<i;k++)
- {
- first++;
- }
- self->insert(first,v.begin(),v.end());
- }
- else self->insert(self->end(),v.begin(),v.end());
- }
-
- }
- unsigned int __len__()
- {
- return self->size();
- }
- bool __nonzero__()
- {
- return !(self->empty());
- }
- void append(const T& x)
- {
- self->push_back(x);
- }
- void pop()
- {
- self->pop_back();
- }
-
- };
-
- };
-}
-
-
-
-
-
-
diff --git a/Lib/ocaml/std_map.i b/Lib/ocaml/std_map.i
deleted file mode 100644
index f174f2872..000000000
--- a/Lib/ocaml/std_map.i
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * std_map.i
- *
- * SWIG typemaps for std::map
- * ----------------------------------------------------------------------------- */
-
-%include <std_common.i>
-
-// ------------------------------------------------------------------------
-// std::map
-// ------------------------------------------------------------------------
-
-%{
-#include <map>
-#include <algorithm>
-#include <stdexcept>
-%}
-
-// exported class
-
-namespace std {
- template<class K, class T> class map {
- // add typemaps here
- public:
- map();
- map(const map<K,T> &);
-
- unsigned int size() const;
- bool empty() const;
- void clear();
- %extend {
- T& get(const K& key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- return i->second;
- else
- throw std::out_of_range("key not found");
- }
- void set(const K& key, const T& x) {
- (*self)[key] = x;
- }
- void del(const K& key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- self->erase(i);
- else
- throw std::out_of_range("key not found");
- }
- bool has_key(const K& key) {
- std::map<K,T >::iterator i = self->find(key);
- return i != self->end();
- }
- }
- };
-
-
- // specializations for built-ins
-
- %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
-
- template<class T> class map<K,T> {
- // add typemaps here
- public:
- map();
- map(const map<K,T> &);
-
- unsigned int size() const;
- bool empty() const;
- void clear();
- %extend {
- T& get(K key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- return i->second;
- else
- throw std::out_of_range("key not found");
- }
- void set(K key, const T& x) {
- (*self)[key] = x;
- }
- void del(K key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- self->erase(i);
- else
- throw std::out_of_range("key not found");
- }
- bool has_key(K key) {
- std::map<K,T >::iterator i = self->find(key);
- return i != self->end();
- }
- }
- };
- %enddef
-
- %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
- template<class K> class map<K,T> {
- // add typemaps here
- public:
- map();
- map(const map<K,T> &);
-
- unsigned int size() const;
- bool empty() const;
- void clear();
- %extend {
- T get(const K& key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- return i->second;
- else
- throw std::out_of_range("key not found");
- }
- void set(const K& key, T x) {
- (*self)[key] = x;
- }
- void del(const K& key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- self->erase(i);
- else
- throw std::out_of_range("key not found");
- }
- bool has_key(const K& key) {
- std::map<K,T >::iterator i = self->find(key);
- return i != self->end();
- }
- }
- };
- %enddef
-
- %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
- T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
- template<> class map<K,T> {
- // add typemaps here
- public:
- map();
- map(const map<K,T> &);
-
- unsigned int size() const;
- bool empty() const;
- void clear();
- %extend {
- T get(K key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- return i->second;
- else
- throw std::out_of_range("key not found");
- }
- void set(K key, T x) {
- (*self)[key] = x;
- }
- void del(K key) throw (std::out_of_range) {
- std::map<K,T >::iterator i = self->find(key);
- if (i != self->end())
- self->erase(i);
- else
- throw std::out_of_range("key not found");
- }
- bool has_key(K key) {
- std::map<K,T >::iterator i = self->find(key);
- return i != self->end();
- }
- }
- };
- %enddef
-
- // add specializations here
-}
diff --git a/Lib/ocaml/std_pair.i b/Lib/ocaml/std_pair.i
deleted file mode 100644
index dc0604dc5..000000000
--- a/Lib/ocaml/std_pair.i
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * std_pair.i
- *
- * SWIG typemaps for std::pair
- * ----------------------------------------------------------------------------- */
-
-%include <std_common.i>
-%include <exception.i>
-
-// ------------------------------------------------------------------------
-// std::pair
-// ------------------------------------------------------------------------
-
-%{
-#include <utility>
-%}
-
-namespace std {
-
- template<class T, class U> struct pair {
-
- pair();
- pair(T first, U second);
- pair(const pair& p);
-
- template <class U1, class U2> pair(const pair<U1, U2> &p);
-
- T first;
- U second;
- };
-
- // add specializations here
-
-}
diff --git a/Lib/ocaml/std_string.i b/Lib/ocaml/std_string.i
index 7add3a070..0a8417973 100644
--- a/Lib/ocaml/std_string.i
+++ b/Lib/ocaml/std_string.i
@@ -1,179 +1,30 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * std_string.i
- *
- * SWIG typemaps for std::string
- * ----------------------------------------------------------------------------- */
-
-// ------------------------------------------------------------------------
-// std::string is typemapped by value
-// This can prevent exporting methods which return a string
-// in order for the user to modify it.
-// However, I think I'll wait until someone asks for it...
-// ------------------------------------------------------------------------
-
-%include <exception.i>
-
%{
-#include <string>
-#include <vector>
- using std::string;
- using std::vector;
+ #include <string>
%}
-%include <std_vector.i>
-
-%naturalvar std::string;
-%naturalvar std::wstring;
-
namespace std {
- template <class charT> class basic_string {
- public:
- typedef charT *pointer;
- typedef charT &reference;
- typedef const charT &const_reference;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- basic_string();
- basic_string( charT *str );
- size_t size();
- charT operator []( int pos ) const;
- charT *c_str() const;
- basic_string<charT> &operator = ( const basic_string &ws );
- basic_string<charT> &operator = ( const charT *str );
- basic_string<charT> &append( const basic_string<charT> &other );
- basic_string<charT> &append( const charT *str );
- void push_back( charT c );
- void clear();
- void reserve( size_type t );
- void resize( size_type n, charT c = charT() );
- int compare( const basic_string<charT> &other ) const;
- int compare( const charT *str ) const;
- basic_string<charT> &insert( size_type pos,
- const basic_string<charT> &str );
- size_type find( const basic_string<charT> &other, int pos = 0 ) const;
- size_type find( charT c, int pos = 0 ) const;
- %extend {
- bool operator == ( const basic_string<charT> &other ) const {
- return self->compare( other ) == 0;
- }
- bool operator != ( const basic_string<charT> &other ) const {
- return self->compare( other ) != 0;
- }
- bool operator < ( const basic_string<charT> &other ) const {
- return self->compare( other ) == -1;
- }
- bool operator > ( const basic_string<charT> &other ) const {
- return self->compare( other ) == 1;
- }
- bool operator <= ( const basic_string<charT> &other ) const {
- return self->compare( other ) != 1;
- }
- bool operator >= ( const basic_string<charT> &other ) const {
- return self->compare( other ) != -1;
- }
- }
- };
-
- %template(string) basic_string<char>;
- %template(wstring) basic_string<wchar_t>;
- typedef basic_string<char> string;
- typedef basic_string<wchar_t> wstring;
-
- /* Overloading check */
- %typemap(in) string {
- if (caml_ptr_check($input))
- $1.assign((char *)caml_ptr_val($input,0),
- caml_string_len($input));
- else
- SWIG_exception(SWIG_TypeError, "string expected");
- }
-
- %typemap(in) const string & (std::string temp) {
- if (caml_ptr_check($input)) {
- temp.assign((char *)caml_ptr_val($input,0),
- caml_string_len($input));
- $1 = &temp;
- } else {
- SWIG_exception(SWIG_TypeError, "string expected");
- }
- }
-
- %typemap(in) string & (std::string temp) {
- if (caml_ptr_check($input)) {
- temp.assign((char *)caml_ptr_val($input,0),
- caml_string_len($input));
- $1 = &temp;
- } else {
- SWIG_exception(SWIG_TypeError, "string expected");
- }
- }
-
- %typemap(in) string * (std::string *temp) {
- if (caml_ptr_check($input)) {
- temp = new std::string((char *)caml_ptr_val($input,0),
- caml_string_len($input));
- $1 = temp;
- } else {
- SWIG_exception(SWIG_TypeError, "string expected");
- }
- }
-
- %typemap(free) string * (std::string *temp) {
- delete temp;
- }
-
- %typemap(argout) string & {
- caml_list_append(swig_result,caml_val_string_len((*$1).c_str(),
- (*$1).size()));
- }
-
- %typemap(directorout) string {
- $result.assign((char *)caml_ptr_val($input,0),
- caml_string_len($input));
- }
- %typemap(out) string {
- $result = caml_val_string_len($1.c_str(),$1.size());
- }
-
- %typemap(out) string * {
- $result = caml_val_string_len((*$1).c_str(),(*$1).size());
- }
-}
-
-#ifdef ENABLE_CHARPTR_ARRAY
-char **c_charptr_array( const std::vector <string > &str_v );
-
-%{
- SWIGEXT char **c_charptr_array( const std::vector <string > &str_v ) {
- char **out = new char *[str_v.size() + 1];
- out[str_v.size()] = 0;
- for( int i = 0; i < str_v.size(); i++ ) {
- out[i] = (char *)str_v[i].c_str();
- }
- return out;
+ class string;
+
+ /* Reference documentation: Section 18.4.3 of
+ * http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html
+ *
+ * String_val(v) returns a pointer to the first byte of the string v,
+ * with type char *. This pointer is a valid C string: there is a null
+ * character after the last character in the string. However, Caml
+ * strings can contain embedded null characters, that will confuse the
+ * usual C functions over strings.
+ */
+
+ %typemap(ocamlin) string "string"
+ %typemap(in) string
+ %{$1.assign(String_val($input), caml_string_length($input));%}
+
+ %typemap(ocamlin) const string & "string"
+ %typemap(in) const string &
+ {
+ std::string $1_str(String_val($input), caml_string_length($input));
+ $1 = &$1_str;
}
-%}
-#endif
-#ifdef ENABLE_STRING_VECTOR
-%template (StringVector) std::vector<string >;
-
-%insert(ml) %{
- (* Some STL convenience items *)
-
- let string_array_to_vector sa =
- let nv = _new_StringVector C_void in
- array_to_vector nv (fun x -> C_string x) sa ; nv
-
- let c_string_array ar =
- _c_charptr_array (string_array_to_vector ar)
-%}
-
-%insert(mli) %{
- val c_string_array: string array -> c_obj
-%}
-#endif
+}
diff --git a/Lib/ocaml/std_vector.i b/Lib/ocaml/std_vector.i
deleted file mode 100644
index 91c335562..000000000
--- a/Lib/ocaml/std_vector.i
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * std_vector.i
- *
- * SWIG typemaps for std::vector types
- * ----------------------------------------------------------------------------- */
-
-%include <std_common.i>
-
-// ------------------------------------------------------------------------
-// std::vector
-//
-// The aim of all that follows would be to integrate std::vector with
-// Python as much as possible, namely, to allow the user to pass and
-// be returned Python tuples or lists.
-// const declarations are used to guess the intent of the function being
-// exported; therefore, the following rationale is applied:
-//
-// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
-// the parameter being read-only, either a Python sequence or a
-// previously wrapped std::vector<T> can be passed.
-// -- f(std::vector<T>&), f(std::vector<T>*):
-// the parameter must be modified; therefore, only a wrapped std::vector
-// can be passed.
-// -- std::vector<T> f():
-// the vector is returned by copy; therefore, a Python sequence of T:s
-// is returned which is most easily used in other Python functions
-// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
-// const std::vector<T>* f():
-// the vector is returned by reference; therefore, a wrapped std::vector
-// is returned
-// ------------------------------------------------------------------------
-
-%{
-#include <vector>
-#include <algorithm>
-#include <stdexcept>
-%}
-
-// exported class
-
-namespace std {
- template <class T> class vector {
- public:
- vector(unsigned int size = 0);
- vector(unsigned int size, const T& value);
- vector(const vector<T>&);
- unsigned int size() const;
- bool empty() const;
- void clear();
- void push_back(const T& x);
- T operator [] ( int f );
- vector <T> &operator = ( vector <T> &other );
- %extend {
- void set( int i, const T &x ) {
- self->resize(i+1);
- (*self)[i] = x;
- }
- };
- %extend {
- T *to_array() {
- T *array = new T[self->size() + 1];
- for( int i = 0; i < self->size(); i++ )
- array[i] = (*self)[i];
- return array;
- }
- };
- };
-};
-
-%insert(ml) %{
-
- let array_to_vector v argcons array =
- for i = 0 to (Array.length array) - 1 do
- (invoke v) "set" (C_list [ C_int i ; (argcons array.(i)) ])
- done ;
- v
-
- let vector_to_array v argcons array =
- for i = 0; to (get_int ((invoke v) "size" C_void)) - 1 do
- array.(i) <- argcons ((invoke v) "[]" (C_int i))
- done ;
- v
-
-%}
-
-%insert(mli) %{
- val array_to_vector : c_obj -> ('a -> c_obj) -> 'a array -> c_obj
- val vector_to_array : c_obj -> (c_obj -> 'a) -> 'a array -> c_obj
-%}
diff --git a/Lib/ocaml/stl.i b/Lib/ocaml/stl.i
deleted file mode 100644
index 66b72e073..000000000
--- a/Lib/ocaml/stl.i
+++ /dev/null
@@ -1,15 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * stl.i
- *
- * Initial STL definition. extended as needed in each language
- * ----------------------------------------------------------------------------- */
-
-%include <std_common.i>
-%include <std_string.i>
-%include <std_vector.i>
-%include <std_map.i>
-%include <std_pair.i>
-
diff --git a/Lib/ocaml/swig.ml b/Lib/ocaml/swig.ml
deleted file mode 100644
index 5dc2de7be..000000000
--- a/Lib/ocaml/swig.ml
+++ /dev/null
@@ -1,159 +0,0 @@
-(* -*- tuareg -*- *)
-open Int32
-open Int64
-
-type enum = [ `Int of int ]
-
-type 'a c_obj_t =
- C_void
- | C_bool of bool
- | C_char of char
- | C_uchar of char
- | C_short of int
- | C_ushort of int
- | C_int of int
- | C_uint of int32
- | C_int32 of int32
- | C_int64 of int64
- | C_float of float
- | C_double of float
- | C_ptr of int64 * int64
- | C_array of 'a c_obj_t array
- | C_list of 'a c_obj_t list
- | C_obj of (string -> 'a c_obj_t -> 'a c_obj_t)
- | C_string of string
- | C_enum of 'a
- | C_director_core of 'a c_obj_t * 'a c_obj_t option ref
-
-type c_obj = enum c_obj_t
-
-exception BadArgs of string
-exception BadMethodName of string * string
-exception NotObject of c_obj
-exception NotEnumType of c_obj
-exception LabelNotFromThisEnum of c_obj
-exception InvalidDirectorCall of c_obj
-exception NoSuchClass of string
-let rec invoke obj =
- match obj with
- C_obj o -> o
- | C_director_core (o,r) -> invoke o
- | _ -> raise (NotObject (Obj.magic obj))
-let _ = Callback.register "swig_runmethod" invoke
-
-let fnhelper arg =
- match arg with C_list l -> l | C_void -> [] | _ -> [ arg ]
-
-let rec get_int x =
- match x with
- C_bool b -> if b then 1 else 0
- | C_char c
- | C_uchar c -> (int_of_char c)
- | C_short s
- | C_ushort s
- | C_int s -> s
- | C_uint u
- | C_int32 u -> (Int32.to_int u)
- | C_int64 u -> (Int64.to_int u)
- | C_float f -> (int_of_float f)
- | C_double d -> (int_of_float d)
- | C_ptr (p,q) -> (Int64.to_int p)
- | C_obj o -> (try (get_int (o "int" C_void))
- with _ -> (get_int (o "&" C_void)))
- | _ -> raise (Failure "Can't convert to int")
-
-let rec get_float x =
- match x with
- C_char c
- | C_uchar c -> (float_of_int (int_of_char c))
- | C_short s -> (float_of_int s)
- | C_ushort s -> (float_of_int s)
- | C_int s -> (float_of_int s)
- | C_uint u
- | C_int32 u -> (float_of_int (Int32.to_int u))
- | C_int64 u -> (float_of_int (Int64.to_int u))
- | C_float f -> f
- | C_double d -> d
- | C_obj o -> (try (get_float (o "float" C_void))
- with _ -> (get_float (o "double" C_void)))
- | _ -> raise (Failure "Can't convert to float")
-
-let rec get_char x =
- (char_of_int (get_int x))
-
-let rec get_string x =
- match x with
- C_string str -> str
- | _ -> raise (Failure "Can't convert to string")
-
-let rec get_bool x =
- match x with
- C_bool b -> b
- | _ ->
- (try if get_int x != 0 then true else false
- with _ -> raise (Failure "Can't convert to bool"))
-
-let disown_object obj =
- match obj with
- C_director_core (o,r) -> r := None
- | _ -> raise (Failure "Not a director core object")
-let _ = Callback.register "caml_obj_disown" disown_object
-let addr_of obj =
- match obj with
- C_obj _ -> (invoke obj) "&" C_void
- | C_director_core (self,r) -> (invoke self) "&" C_void
- | C_ptr _ -> obj
- | _ -> raise (Failure "Not a pointer.")
-let _ = Callback.register "caml_obj_ptr" addr_of
-
-let make_float f = C_float f
-let make_double f = C_double f
-let make_string s = C_string s
-let make_bool b = C_bool b
-let make_char c = C_char c
-let make_char_i c = C_char (char_of_int c)
-let make_uchar c = C_uchar c
-let make_uchar_i c = C_uchar (char_of_int c)
-let make_short i = C_short i
-let make_ushort i = C_ushort i
-let make_int i = C_int i
-let make_uint i = C_uint (Int32.of_int i)
-let make_int32 i = C_int32 (Int32.of_int i)
-let make_int64 i = C_int64 (Int64.of_int i)
-
-let new_derived_object cfun x_class args =
- begin
- let get_object ob =
- match !ob with
- None ->
- raise (NotObject C_void)
- | Some o -> o in
- let ob_ref = ref None in
- let class_fun class_f ob_r =
- (fun meth args -> class_f (get_object ob_r) meth args) in
- let new_class = class_fun x_class ob_ref in
- let dircore = C_director_core (C_obj new_class,ob_ref) in
- let obj =
- cfun (match args with
- C_list argl -> (C_list ((dircore :: argl)))
- | C_void -> (C_list [ dircore ])
- | a -> (C_list [ dircore ; a ])) in
- ob_ref := Some obj ;
- obj
- end
-
-let swig_current_type_info = ref C_void
-let find_type_info obj = !swig_current_type_info
-let _ = Callback.register "swig_find_type_info" find_type_info
-let set_type_info obj =
- match obj with
- C_ptr _ -> swig_current_type_info := obj ;
- obj
- | _ -> raise (Failure "Internal error: passed non pointer to set_type_info")
-let _ = Callback.register "swig_set_type_info" set_type_info
-
-let class_master_list = Hashtbl.create 20
-let register_class_byname nm co =
- Hashtbl.replace class_master_list nm (Obj.magic co)
-let create_class nm arg =
- try (Obj.magic (Hashtbl.find class_master_list nm)) arg with _ -> raise (NoSuchClass nm)
diff --git a/Lib/ocaml/swig.mli b/Lib/ocaml/swig.mli
deleted file mode 100644
index 3207b9e73..000000000
--- a/Lib/ocaml/swig.mli
+++ /dev/null
@@ -1,61 +0,0 @@
-(* -*- tuareg -*- *)
-
-type enum = [ `Int of int ]
-
-type 'a c_obj_t =
- C_void
- | C_bool of bool
- | C_char of char
- | C_uchar of char
- | C_short of int
- | C_ushort of int
- | C_int of int
- | C_uint of int32
- | C_int32 of int32
- | C_int64 of int64
- | C_float of float
- | C_double of float
- | C_ptr of int64 * int64
- | C_array of 'a c_obj_t array
- | C_list of 'a c_obj_t list
- | C_obj of (string -> 'a c_obj_t -> 'a c_obj_t)
- | C_string of string
- | C_enum of 'a
- | C_director_core of 'a c_obj_t * 'a c_obj_t option ref
-
-type c_obj = enum c_obj_t
-
-exception InvalidDirectorCall of c_obj
-exception NoSuchClass of string
-
-val invoke : ('a c_obj_t) -> (string -> 'a c_obj_t -> 'a c_obj_t)
-val fnhelper : 'a c_obj_t -> 'a c_obj_t list
-
-val get_int : 'a c_obj_t -> int
-val get_float : 'a c_obj_t -> float
-val get_string : 'a c_obj_t -> string
-val get_char : 'a c_obj_t -> char
-val get_bool : 'a c_obj_t -> bool
-
-val make_float : float -> 'a c_obj_t
-val make_double : float -> 'a c_obj_t
-val make_string : string -> 'a c_obj_t
-val make_bool : bool -> 'a c_obj_t
-val make_char : char -> 'a c_obj_t
-val make_char_i : int -> 'a c_obj_t
-val make_uchar : char -> 'a c_obj_t
-val make_uchar_i : int -> 'a c_obj_t
-val make_short : int -> 'a c_obj_t
-val make_ushort : int -> 'a c_obj_t
-val make_int : int -> 'a c_obj_t
-val make_uint : int -> 'a c_obj_t
-val make_int32 : int -> 'a c_obj_t
-val make_int64 : int -> 'a c_obj_t
-
-val new_derived_object:
- ('a c_obj_t -> 'a c_obj_t) ->
- ('a c_obj_t -> string -> 'a c_obj_t -> 'a c_obj_t) ->
- 'a c_obj_t -> 'a c_obj_t
-
-val register_class_byname : string -> ('a c_obj_t -> 'a c_obj_t) -> unit
-val create_class : string -> 'a c_obj_t -> 'a c_obj_t
diff --git a/Lib/ocaml/swigp4.ml.in b/Lib/ocaml/swigp4.ml.in
deleted file mode 100644
index 0387c0a47..000000000
--- a/Lib/ocaml/swigp4.ml.in
+++ /dev/null
@@ -1,118 +0,0 @@
-open Pcaml ;;
-
-let lap x y = x :: y
-let c_ify e @OCAMLLOC@ =
- match e with
- <:expr< $int:_$ >> -> <:expr< (C_int $e$) >>
- | <:expr< $str:_$ >> -> <:expr< (C_string $e$) >>
- | <:expr< $chr:_$ >> -> <:expr< (C_char $e$) >>
- | <:expr< $flo:_$ >> -> <:expr< (C_double $e$) >>
- | <:expr< True >> -> <:expr< (C_bool $e$) >>
- | <:expr< False >> -> <:expr< (C_bool $e$) >>
- | _ -> <:expr< $e$ >>
-let mk_list args @OCAMLLOC@ f =
- let rec mk_list_inner args @OCAMLLOC@ f =
- match args with
- [] -> <:expr< [] >>
- | x :: xs ->
- (let @OCAMLLOC@ = MLast.loc_of_expr x in
- <:expr< [ ($f x @OCAMLLOC@$) ] @ ($mk_list_inner xs @OCAMLLOC@ f$) >>) in
- match args with
- [] -> <:expr< (Obj.magic C_void) >>
- | [ a ] -> <:expr< (Obj.magic $f a @OCAMLLOC@$) >>
- | _ -> <:expr< (Obj.magic (C_list ($mk_list_inner args @OCAMLLOC@ f$))) >>
-
-EXTEND
- expr:
- [ [ e1 = expr ; "'" ; "[" ; e2 = expr ; "]" ->
- <:expr< (invoke $e1$) "[]" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< (invoke $e1$) $str:l$ ($mk_list args @OCAMLLOC@ c_ify$) >>
- | e1 = expr ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< (invoke $e1$) $str:u$ ($mk_list args @OCAMLLOC@ c_ify$) >>
- | e1 = expr ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< (invoke $e1$) $s$ ($mk_list args @OCAMLLOC@ c_ify$) >>
- | e1 = expr ; "'" ; "." ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< (invoke $e1$) "()" ($mk_list args @OCAMLLOC@ c_ify$) >>
- | e1 = expr ; "'" ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ ($mk_list args @OCAMLLOC@ c_ify$) >>
- | e1 = expr ; "'" ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ ($mk_list args @OCAMLLOC@ c_ify$) >>
- | e1 = expr ; "'" ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< (invoke ((invoke $e1$) "->" C_void)) $s$ ($mk_list args @OCAMLLOC@ c_ify$) >>
- | e1 = expr ; "'" ; "++" ->
- <:expr< (invoke $e1$) "++" C_void >>
- | e1 = expr ; "'" ; "--" ->
- <:expr< (invoke $e1$) "--" C_void >>
- | e1 = expr ; "'" ; "-" ; e2 = expr ->
- <:expr< (invoke $e1$) "-" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "+" ; e2 = expr -> <:expr< (invoke $e1$) "+" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "*" ; e2 = expr -> <:expr< (invoke $e1$) "*" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | "'" ; "&" ; e1 = expr ->
- <:expr< (invoke $e1$) "&" C_void >>
- | "'" ; "!" ; e1 = expr ->
- <:expr< (invoke $e1$) "!" C_void >>
- | "'" ; "~" ; e1 = expr ->
- <:expr< (invoke $e1$) "~" C_void >>
- | e1 = expr ; "'" ; "/" ; e2 = expr ->
- <:expr< (invoke $e1$) "/" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "%" ; e2 = expr ->
- <:expr< (invoke $e1$) "%" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "lsl" ; e2 = expr ->
- <:expr< (invoke $e1$) ("<" ^ "<") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "lsr" ; e2 = expr ->
- <:expr< (invoke $e1$) (">" ^ ">") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "<" ; e2 = expr ->
- <:expr< (invoke $e1$) "<" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "<=" ; e2 = expr ->
- <:expr< (invoke $e1$) "<=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; ">" ; e2 = expr ->
- <:expr< (invoke $e1$) ">" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; ">=" ; e2 = expr ->
- <:expr< (invoke $e1$) ">=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "==" ; e2 = expr ->
- <:expr< (invoke $e1$) "==" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "!=" ; e2 = expr ->
- <:expr< (invoke $e1$) "!=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "&" ; e2 = expr ->
- <:expr< (invoke $e1$) "&" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "^" ; e2 = expr ->
- <:expr< (invoke $e1$) "^" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "|" ; e2 = expr ->
- <:expr< (invoke $e1$) "|" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "&&" ; e2 = expr ->
- <:expr< (invoke $e1$) "&&" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "||" ; e2 = expr ->
- <:expr< (invoke $e1$) "||" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "=" ; e2 = expr ->
- <:expr< (invoke $e1$) "=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "+=" ; e2 = expr ->
- <:expr< (invoke $e1$) "+=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "-=" ; e2 = expr ->
- <:expr< (invoke $e1$) "-=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "*=" ; e2 = expr ->
- <:expr< (invoke $e1$) "*=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "/=" ; e2 = expr ->
- <:expr< (invoke $e1$) "/=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "%=" ; e2 = expr ->
- <:expr< (invoke $e1$) "%=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "lsl" ; "=" ; e2 = expr ->
- <:expr< (invoke $e1$) ("<" ^ "<=") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "lsr" ; "=" ; e2 = expr ->
- <:expr< (invoke $e1$) (">" ^ ">=") (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "&=" ; e2 = expr ->
- <:expr< (invoke $e1$) "&=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "^=" ; e2 = expr ->
- <:expr< (invoke $e1$) "^=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | e1 = expr ; "'" ; "|=" ; e2 = expr ->
- <:expr< (invoke $e1$) "|=" (C_list [ $c_ify e2 @OCAMLLOC@$ ]) >>
- | "'" ; e = expr -> c_ify e @OCAMLLOC@
- | c = expr ; "as" ; id = LIDENT -> <:expr< $lid:"get_" ^ id$ $c$ >>
- | c = expr ; "to" ; id = LIDENT -> <:expr< $uid:"C_" ^ id$ $c$ >>
- | "`" ; "`" ; l = LIDENT -> <:expr< C_enum `$lid:l$ >>
- | "`" ; "`" ; u = UIDENT -> <:expr< C_enum `$uid:u$ >>
- | f = expr ; "'" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
- <:expr< $f$ ($mk_list args @OCAMLLOC@ c_ify$) >>
- ] ] ;
-END ;;
-
diff --git a/Lib/ocaml/typecheck.i b/Lib/ocaml/typecheck.i
deleted file mode 100644
index 51e66061b..000000000
--- a/Lib/ocaml/typecheck.i
+++ /dev/null
@@ -1,179 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * typecheck.i
- *
- * Typechecking rules
- * ----------------------------------------------------------------------------- */
-
-%typecheck(SWIG_TYPECHECK_INTEGER) char, signed char, const char &, const signed char & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_char: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_INTEGER) unsigned char, const unsigned char & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_uchar: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_INTEGER) short, signed short, const short &, const signed short &, wchar_t {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_short: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_INTEGER) unsigned short, const unsigned short & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_ushort: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-// XXX arty
-// Will move enum SWIGTYPE later when I figure out what to do with it...
-
-%typecheck(SWIG_TYPECHECK_INTEGER) int, signed int, const int &, const signed int &, enum SWIGTYPE {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_int: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_INTEGER) unsigned int, const unsigned int & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_uint: $1 = 1; break;
- case C_int32: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_INTEGER) long, signed long, unsigned long, long long, signed long long, unsigned long long, const long &, const signed long &, const unsigned long &, const long long &, const signed long long &, const unsigned long long & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_int64: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_INTEGER) bool, oc_bool, BOOL, const bool &, const oc_bool &, const BOOL & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_bool: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_DOUBLE) float, const float & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_float: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_DOUBLE) double, const double & {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_double: $1 = 1; break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_STRING) char * {
- if( !Is_block($input) ) $1 = 0;
- else {
- switch( SWIG_Tag_val($input) ) {
- case C_string: $1 = 1; break;
- case C_ptr: {
- swig_type_info *typeinfo =
- (swig_type_info *)(long)SWIG_Int64_val(SWIG_Field($input,1));
- $1 = SWIG_TypeCheck("char *",typeinfo) ||
- SWIG_TypeCheck("signed char *",typeinfo) ||
- SWIG_TypeCheck("unsigned char *",typeinfo) ||
- SWIG_TypeCheck("const char *",typeinfo) ||
- SWIG_TypeCheck("const signed char *",typeinfo) ||
- SWIG_TypeCheck("const unsigned char *",typeinfo) ||
- SWIG_TypeCheck("std::string",typeinfo);
- } break;
- default: $1 = 0; break;
- }
- }
-}
-
-%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
- void *ptr;
- $1 = !caml_ptr_val_internal($input, &ptr,$descriptor);
-}
-
-#if 0
-
-%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
- void *ptr;
- $1 = !caml_ptr_val_internal($input, &ptr, $&1_descriptor);
-}
-
-#endif
-
-%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
- void *ptr;
- $1 = !caml_ptr_val_internal($input, &ptr, 0);
-}
-
-/* ------------------------------------------------------------
- * Exception handling
- * ------------------------------------------------------------ */
-
-%typemap(throws) int,
- long,
- short,
- unsigned int,
- unsigned long,
- unsigned short {
- SWIG_exception($1,"Thrown exception from C++ (int)");
-}
-
-%typemap(throws) SWIGTYPE CLASS {
- $&1_ltype temp = new $1_ltype($1);
- SWIG_exception((int)temp,"Thrown exception from C++ (object)");
-}
-
-%typemap(throws) SWIGTYPE {
- (void)$1;
- SWIG_exception(0,"Thrown exception from C++ (unknown)");
-}
-
-%typemap(throws) char * {
- SWIG_exception(0,$1);
-}
diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i
deleted file mode 100644
index 7f978bf7f..000000000
--- a/Lib/ocaml/typemaps.i
+++ /dev/null
@@ -1,319 +0,0 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * typemaps.i
- *
- * The Ocaml module handles all types uniformly via typemaps. Here
- * are the definitions.
- * ----------------------------------------------------------------------------- */
-
-/* Pointers */
-
-%typemap(in) void ""
-
-%typemap(out) void "$result = Val_int(0);"
-
-%typemap(in) void * {
- $1 = caml_ptr_val($input,$descriptor);
-}
-
-%typemap(varin) void * {
- $1 = ($ltype)caml_ptr_val($input,$descriptor);
-}
-
-%typemap(out) void * {
- $result = caml_val_ptr($1,$descriptor);
-}
-
-%typemap(varout) void * {
- $result = caml_val_ptr($1,$descriptor);
-}
-
-#ifdef __cplusplus
-
-%typemap(in) SWIGTYPE & {
- /* %typemap(in) SWIGTYPE & */
- $1 = ($ltype) caml_ptr_val($input,$1_descriptor);
-}
-
-%typemap(varin) SWIGTYPE & {
- /* %typemap(varin) SWIGTYPE & */
- $1 = *(($ltype) caml_ptr_val($input,$1_descriptor));
-}
-
-%typemap(out) SWIGTYPE & {
- /* %typemap(out) SWIGTYPE & */
- CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
- if( fromval ) {
- $result = callback(*fromval,caml_val_ptr((void *) &$1,$1_descriptor));
- } else {
- $result = caml_val_ptr ((void *) &$1,$1_descriptor);
- }
-}
-
-#if 0
-%typemap(argout) SWIGTYPE & {
- CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
- if( fromval ) {
- swig_result =
- caml_list_append(swig_result,
- callback(*fromval,caml_val_ptr((void *) $1,
- $1_descriptor)));
- } else {
- swig_result =
- caml_list_append(swig_result,
- caml_val_ptr ((void *) $1,$1_descriptor));
- }
-}
-#endif
-
-%typemap(argout) const SWIGTYPE & { }
-
-%typemap(in) SWIGTYPE {
- $1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
-}
-
-%typemap(out) SWIGTYPE {
- /* %typemap(out) SWIGTYPE */
- $&1_ltype temp = new $ltype((const $1_ltype &) $1);
- CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
- if( fromval ) {
- $result = callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
- } else {
- $result = caml_val_ptr ((void *)temp,$&1_descriptor);
- }
-}
-
-#else
-
-%typemap(in) SWIGTYPE {
- $1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
-}
-
-%typemap(out) SWIGTYPE {
- /* %typemap(out) SWIGTYPE */
- void *temp = calloc(1,sizeof($ltype));
- CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
- memmove( temp, &$1, sizeof( $1_type ) );
- if( fromval ) {
- $result = callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
- } else {
- $result = caml_val_ptr ((void *)temp,$&1_descriptor);
- }
-}
-
-%apply SWIGTYPE { const SWIGTYPE & };
-
-#endif
-
-/* The SIMPLE_MAP macro below defines the whole set of typemaps needed
- for simple types. */
-
-%define SIMPLE_MAP(C_NAME, C_TO_MZ, MZ_TO_C)
-/* In */
-%typemap(in) C_NAME {
- $1 = MZ_TO_C($input);
-}
-%typemap(varin) C_NAME {
- $1 = MZ_TO_C($input);
-}
-%typemap(in) C_NAME & ($*1_ltype temp) {
- temp = ($*1_ltype) MZ_TO_C($input);
- $1 = &temp;
-}
-%typemap(varin) C_NAME & {
- $1 = MZ_TO_C($input);
-}
-%typemap(directorout) C_NAME {
- $1 = MZ_TO_C($input);
-}
-%typemap(in) C_NAME *INPUT ($*1_ltype temp) {
- temp = ($*1_ltype) MZ_TO_C($input);
- $1 = &temp;
-}
-%typemap(in,numinputs=0) C_NAME *OUTPUT ($*1_ltype temp) {
- $1 = &temp;
-}
-/* Out */
-%typemap(out) C_NAME {
- $result = C_TO_MZ($1);
-}
-%typemap(varout) C_NAME {
- $result = C_TO_MZ($1);
-}
-%typemap(varout) C_NAME & {
- /* %typemap(varout) C_NAME & (generic) */
- $result = C_TO_MZ($1);
-}
-%typemap(argout) C_NAME *OUTPUT {
- swig_result = caml_list_append(swig_result,C_TO_MZ((long)*$1));
-}
-%typemap(out) C_NAME & {
- /* %typemap(out) C_NAME & (generic) */
- $result = C_TO_MZ(*$1);
-}
-%typemap(argout) C_NAME & {
- swig_result = caml_list_append(swig_result,C_TO_MZ((long)*$1));
-}
-%typemap(directorin) C_NAME {
- args = caml_list_append(args,C_TO_MZ($1_name));
-}
-%enddef
-
-SIMPLE_MAP(bool, caml_val_bool, caml_long_val);
-SIMPLE_MAP(oc_bool, caml_val_bool, caml_long_val);
-SIMPLE_MAP(char, caml_val_char, caml_long_val);
-SIMPLE_MAP(signed char, caml_val_char, caml_long_val);
-SIMPLE_MAP(unsigned char, caml_val_uchar, caml_long_val);
-SIMPLE_MAP(int, caml_val_int, caml_long_val);
-SIMPLE_MAP(short, caml_val_short, caml_long_val);
-SIMPLE_MAP(wchar_t, caml_val_short, caml_long_val);
-SIMPLE_MAP(long, caml_val_long, caml_long_val);
-SIMPLE_MAP(ptrdiff_t, caml_val_int, caml_long_val);
-SIMPLE_MAP(unsigned int, caml_val_uint, caml_long_val);
-SIMPLE_MAP(unsigned short, caml_val_ushort, caml_long_val);
-SIMPLE_MAP(unsigned long, caml_val_ulong, caml_long_val);
-SIMPLE_MAP(size_t, caml_val_int, caml_long_val);
-SIMPLE_MAP(float, caml_val_float, caml_double_val);
-SIMPLE_MAP(double, caml_val_double, caml_double_val);
-SIMPLE_MAP(long long,caml_val_ulong,caml_long_val);
-SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
-
-/* Void */
-
-%typemap(out) void "$result = Val_unit;";
-
-/* Pass through value */
-
-%typemap (in) value,caml::value,CAML_VALUE "$1=$input;";
-%typemap (out) value,caml::value,CAML_VALUE "$result=$1;";
-
-/* Arrays */
-
-%typemap(in) ArrayCarrier * {
- $1 = ($ltype)caml_ptr_val($input,$1_descriptor);
-}
-
-%typemap(out) ArrayCarrier * {
- CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
- if( fromval ) {
- $result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
- } else {
- $result = caml_val_ptr ((void *)$1,$1_descriptor);
- }
-}
-
-#if 0
-%include <carray.i>
-#endif
-
-/* Handle char arrays as strings */
-
-%define %char_ptr_in(how)
-%typemap(how) char *, signed char *, unsigned char * {
- /* %typemap(how) char * ... */
- $1 = ($ltype)caml_string_val($input);
-}
-/* Again work around the empty array bound bug */
-%typemap(how) char [ANY], signed char [ANY], unsigned char [ANY] {
- /* %typemap(how) char [ANY] ... */
- char *temp = caml_string_val($input);
- strcpy((char *)$1,temp);
- /* strncpy would be better but we might not have an array size */
-}
-%enddef
-
-%char_ptr_in(in);
-%char_ptr_in(varin);
-%char_ptr_in(directorout);
-
-%define %char_ptr_out(how)
-%typemap(how)
- char *, signed char *, unsigned char *,
- const char *, const signed char *, const unsigned char * {
- $result = caml_val_string((char *)$1);
-}
-/* I'd like to use the length here but can't because it might be empty */
-%typemap(how)
- char [ANY], signed char [ANY], unsigned char [ANY],
- const char [ANY], const signed char [ANY], const unsigned char [ANY] {
- $result = caml_val_string((char *)$1);
-}
-%enddef
-
-%char_ptr_out(out);
-%char_ptr_out(varout);
-%char_ptr_out(directorin);
-
-%define %swigtype_ptr_in(how)
-%typemap(how) SWIGTYPE * {
- /* %typemap(how) SWIGTYPE * */
- $1 = ($ltype)caml_ptr_val($input,$1_descriptor);
-}
-%typemap(how) SWIGTYPE (CLASS::*) {
- /* %typemap(how) SWIGTYPE (CLASS::*) */
- void *v = caml_ptr_val($input,$1_descriptor);
- memcpy(& $1, &v, sizeof(v));
-}
-%enddef
-
-%define %swigtype_ptr_out(how)
-%typemap(out) SWIGTYPE * {
- /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */
- CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
- if( fromval ) {
- $result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
- } else {
- $result = caml_val_ptr ((void *)$1,$1_descriptor);
- }
-}
-%typemap(how) SWIGTYPE (CLASS::*) {
- /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */
- void *v;
- memcpy(&v,& $1, sizeof(void *));
- $result = caml_val_ptr (v,$1_descriptor);
-}
-%enddef
-
-%swigtype_ptr_in(in);
-%swigtype_ptr_in(varin);
-%swigtype_ptr_in(directorout);
-%swigtype_ptr_out(out);
-%swigtype_ptr_out(varout);
-%swigtype_ptr_out(directorin);
-
-%define %swigtype_array_fail(how,msg)
-%typemap(how) SWIGTYPE [] {
- failwith(msg);
-}
-%enddef
-
-%swigtype_array_fail(in,"Array arguments for arbitrary types need a typemap");
-%swigtype_array_fail(varin,"Assignment to global arrays for arbitrary types need a typemap");
-%swigtype_array_fail(out,"Array arguments for arbitrary types need a typemap");
-%swigtype_array_fail(varout,"Array variables need a typemap");
-%swigtype_array_fail(directorin,"Array results with arbitrary types need a typemap");
-%swigtype_array_fail(directorout,"Array arguments with arbitrary types need a typemap");
-
-/* C++ References */
-
-/* Enums */
-%define %swig_enum_in(how)
-%typemap(how) enum SWIGTYPE {
- $1 = ($type)caml_long_val_full($input,"$type_marker");
-}
-%enddef
-
-%define %swig_enum_out(how)
-%typemap(how) enum SWIGTYPE {
- $result = callback2(*caml_named_value(SWIG_MODULE "_int_to_enum"),*caml_named_value("$type_marker"),Val_int((int)$1));
-}
-%enddef
-
-%swig_enum_in(in)
-%swig_enum_in(varin)
-%swig_enum_in(directorout)
-%swig_enum_out(out)
-%swig_enum_out(varout)
-%swig_enum_out(directorin)
diff --git a/Lib/ocaml/typeregister.swg b/Lib/ocaml/typeregister.swg
deleted file mode 100644
index c3ba904ab..000000000
--- a/Lib/ocaml/typeregister.swg
+++ /dev/null
@@ -1,2 +0,0 @@
-SWIGEXT void SWIG_init() {
- SWIG_InitializeModule(0);
diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx
index 8a797759c..576ed3f07 100644
--- a/Source/Modules/ocaml.cxx
+++ b/Source/Modules/ocaml.cxx
@@ -1,1866 +1,375 @@
-/* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
+/*
*
- * ocaml.cxx
+ * Swig Module for the Objective Caml language.
*
- * Ocaml language module for SWIG.
- * ----------------------------------------------------------------------------- */
-
-char cvsroot_ocaml_cxx[] = "$Id$";
+ */
#include "swigmod.h"
-#include <ctype.h>
-
-static const char *usage = (char *)
- ("Ocaml Options (available with -ocaml)\n"
- "-prefix <name> - Set a prefix <name> to be prepended to all names\n"
- "-where - Emit library location\n"
- "-suffix <name> - Change .cxx to something else\n" "-oldvarnames - old intermediary method names for variable wrappers\n" "\n");
-
-static int classmode = 0;
-static int in_constructor = 0, in_destructor = 0, in_copyconst = 0;
-static int const_enum = 0;
-static int static_member_function = 0;
-static int generate_sizeof = 0;
-static char *prefix = 0;
-static char *ocaml_path = (char *) "ocaml";
-static bool old_variable_names = false;
-static String *classname = 0;
-static String *module = 0;
-static String *init_func_def = 0;
-static String *f_classtemplate = 0;
-static String *name_qualifier = 0;
-
-static Hash *seen_enums = 0;
-static Hash *seen_enumvalues = 0;
-static Hash *seen_constructors = 0;
-
-static File *f_header = 0;
-static File *f_begin = 0;
-static File *f_runtime = 0;
-static File *f_wrappers = 0;
-static File *f_directors = 0;
-static File *f_directors_h = 0;
-static File *f_init = 0;
-static File *f_mlout = 0;
-static File *f_mliout = 0;
-static File *f_mlbody = 0;
-static File *f_mlibody = 0;
-static File *f_mltail = 0;
-static File *f_mlitail = 0;
-static File *f_enumtypes_type = 0;
-static File *f_enumtypes_value = 0;
-static File *f_class_ctors = 0;
-static File *f_class_ctors_end = 0;
-static File *f_enum_to_int = 0;
-static File *f_int_to_enum = 0;
-
-class OCAML:public Language {
-public:
-
- OCAML() {
- director_prot_ctor_code = NewString("");
- Printv(director_prot_ctor_code,
- "if ( $comparison ) { /* subclassed */\n",
- " $director_new \n", "} else {\n", " failwith(\"accessing abstract class or protected constructor\"); \n", "}\n", NIL);
- director_multiple_inheritance = 1;
- director_language = 1;
- }
-
- String *Swig_class_name(Node *n) {
- String *name;
- name = Copy(Getattr(n, "sym:name"));
- return name;
- }
+class OCAML : public Language {
- void PrintIncludeArg() {
- Printv(stdout, SWIG_LIB, SWIG_FILE_DELIMITER, ocaml_path, "\n", NIL);
- }
+ public:
+ virtual void main(int argc, char * argv[]);
+ virtual int top(Node * n);
- /* ------------------------------------------------------------
- * main()
- * ------------------------------------------------------------ */
-
- virtual void main(int argc, char *argv[]) {
- int i;
-
- prefix = 0;
-
- SWIG_library_directory(ocaml_path);
-
- // Look for certain command line options
- for (i = 1; i < argc; i++) {
- if (argv[i]) {
- if (strcmp(argv[i], "-help") == 0) {
- fputs(usage, stdout);
- SWIG_exit(0);
- } else if (strcmp(argv[i], "-where") == 0) {
- PrintIncludeArg();
- SWIG_exit(0);
- } else if (strcmp(argv[i], "-prefix") == 0) {
- if (argv[i + 1]) {
- prefix = new char[strlen(argv[i + 1]) + 2];
- strcpy(prefix, argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- } else {
- Swig_arg_error();
- }
- } else if (strcmp(argv[i], "-suffix") == 0) {
- if (argv[i + 1]) {
- SWIG_config_cppext(argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- } else
- Swig_arg_error();
- } else if (strcmp(argv[i], "-oldvarnames") == 0) {
- Swig_mark_arg(i);
- old_variable_names = true;
- }
- }
- }
+ // The following functions are used while passing through the
+ // parse tree. They are responsible for doing the actual wrapping
+ // to the target language.
- // If a prefix has been specified make sure it ends in a '_'
+ virtual int functionWrapper (Node * n);
+ virtual int classHandler (Node * n);
+ virtual int constructorHandler (Node * n);
- if (prefix) {
- if (prefix[strlen(prefix)] != '_') {
- prefix[strlen(prefix) + 1] = 0;
- prefix[strlen(prefix)] = '_';
- }
- } else
- prefix = (char *) "swig_";
- // Add a symbol for this module
+ protected:
+ // General DOH objects used for holding the strings
+ // These strings are used for the C/C++ stub code.
+ File * f_runtime;
+ File * f_header;
+ File * f_wrappers;
+ File * f_init;
- Preprocessor_define("SWIGOCAML 1", 0);
- // Set name of typemaps
+ // DOH objects for output to OCaml code
+ File * f_mlcdecl; // File object for the import of the C declaration in the .ml module
+ File * f_mlbody; // File object for the .ml code that will be exported
+ File * f_mlout;
- SWIG_typemap_lang("ocaml");
+ String * f_mlbody_virtualclass; // String object containing the OCaml virtual class declarations.
+ String * f_mlbody_concreteclass; // String object containing the OCaml "concrete" class declarations.
- // Read in default typemaps */
- SWIG_config_file("ocaml.i");
- allow_overloading();
+ // Objects used while delving into the parse tree.
+ String * proxy_class_name;
- }
+ // Variables specifying the state of the parse tree parsing.
+ int classmode; // classmode will determine whether or not
+ // the code we are wrapping is relevant to a class
+ int in_constructor; // in_constructor will determine whether or
+ // not we're dealing with a constructor...
- /* Swig_director_declaration()
- *
- * Generate the full director class declaration, complete with base classes.
- * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {"
- *
- */
-
- String *Swig_director_declaration(Node *n) {
- String *classname = Swig_class_name(n);
- String *directorname = NewStringf("SwigDirector_%s", classname);
- String *base = Getattr(n, "classtype");
- String *declaration = Swig_class_declaration(n, directorname);
- Printf(declaration, " : public %s, public Swig::Director {\n", base);
- Delete(classname);
- Delete(directorname);
- return declaration;
- }
+};
- /* ------------------------------------------------------------
- * top()
- *
- * Recognize the %module, and capture the module name.
- * Create the default enum cases.
- * Set up the named outputs:
- *
- * init
- * ml
- * mli
- * wrapper
- * header
- * runtime
- * directors
- * directors_h
- * ------------------------------------------------------------ */
-
- virtual int top(Node *n) {
- /* Set comparison with none for ConstructorToFunction */
- setSubclassInstanceCheck(NewString("caml_list_nth(args,0) != Val_unit"));
-
- /* check if directors are enabled for this module. note: this
- * is a "master" switch, without which no director code will be
- * emitted. %feature("director") statements are also required
- * to enable directors for individual classes or methods.
- *
- * use %module(directors="1") modulename at the start of the
- * interface file to enable director generation.
- */
- {
- Node *module = Getattr(n, "module");
- if (module) {
- Node *options = Getattr(module, "options");
- if (options) {
- if (Getattr(options, "directors")) {
- allow_directors();
- }
- if (Getattr(options, "dirprot")) {
- allow_dirprot();
- }
- if (Getattr(options, "sizeof")) {
- generate_sizeof = 1;
- }
- }
- }
- }
+extern "C" Language *
+swig_ocaml(void) {
+ return new OCAML();
+}
- /* Initialize all of the output files */
- String *outfile = Getattr(n, "outfile");
+void OCAML::main(int argc, char * argv[]) {
- f_begin = NewFile(outfile, "w", SWIG_output_files());
- if (!f_begin) {
- FileErrorDisplay(outfile);
- SWIG_exit(EXIT_FAILURE);
- }
- f_runtime = NewString("");
- f_init = NewString("");
- f_header = NewString("");
- f_wrappers = NewString("");
- f_directors = NewString("");
- f_directors_h = NewString("");
- f_enumtypes_type = NewString("");
- f_enumtypes_value = NewString("");
- init_func_def = NewString("");
- f_mlbody = NewString("");
- f_mlibody = NewString("");
- f_mltail = NewString("");
- f_mlitail = NewString("");
- f_class_ctors = NewString("");
- f_class_ctors_end = NewString("");
- f_enum_to_int = NewString("");
- f_int_to_enum = NewString("");
- f_classtemplate = NewString("");
-
- module = Getattr(n, "name");
-
- seen_constructors = NewHash();
- seen_enums = NewHash();
- seen_enumvalues = NewHash();
-
- /* Register file targets with the SWIG file handler */
- Swig_register_filebyname("init", init_func_def);
- Swig_register_filebyname("header", f_header);
- Swig_register_filebyname("wrapper", f_wrappers);
- Swig_register_filebyname("begin", f_begin);
- Swig_register_filebyname("runtime", f_runtime);
- Swig_register_filebyname("mli", f_mlibody);
- Swig_register_filebyname("ml", f_mlbody);
- Swig_register_filebyname("mlitail", f_mlitail);
- Swig_register_filebyname("mltail", f_mltail);
- Swig_register_filebyname("director", f_directors);
- Swig_register_filebyname("director_h", f_directors_h);
- Swig_register_filebyname("classtemplate", f_classtemplate);
- Swig_register_filebyname("class_ctors", f_class_ctors);
-
- if (old_variable_names) {
- Swig_name_register("set", "%v__set__");
- Swig_name_register("get", "%v__get__");
- }
+ // Sets the name of the swig subfolder where swig will
- Swig_banner(f_begin);
-
- Printf(f_runtime, "\n");
- Printf(f_runtime, "#define SWIGOCAML\n");
- Printf(f_runtime, "#define SWIG_MODULE \"%s\"\n", module);
- /* Module name */
- Printf(f_mlbody, "let module_name = \"%s\"\n", module);
- Printf(f_mlibody, "val module_name : string\n");
- Printf(f_enum_to_int,
- "let enum_to_int x (v : c_obj) =\n"
- " match v with\n"
- " C_enum _y ->\n"
- " (let y = _y in match (x : c_enum_type) with\n"
- " `unknown -> " " (match y with\n" " `Int x -> (Swig.C_int x)\n" " | _ -> raise (LabelNotFromThisEnum v))\n");
-
- Printf(f_int_to_enum, "let int_to_enum x y =\n" " match (x : c_enum_type) with\n" " `unknown -> C_enum (`Int y)\n");
-
- if (directorsEnabled()) {
- Printf(f_runtime, "#define SWIG_DIRECTORS\n");
- }
+ SWIG_library_directory("ocaml");
- Printf(f_runtime, "\n");
+ // No command line options are yet implemented.
+ // TODO: -noproxy and -help
- /* Produce the enum_to_int and int_to_enum functions */
+ // Add a symbol to the parser for conditional compilation
+ Preprocessor_define("SWIGOCAML 1", 0);
- Printf(f_enumtypes_type, "open Swig\n" "type c_enum_type = [ \n `unknown\n");
- Printf(f_enumtypes_value, "type c_enum_value = [ \n `Int of int\n");
- String *mlfile = NewString("");
- String *mlifile = NewString("");
+ // Add typemap definitions
+ SWIG_typemap_lang("ocaml");
+ SWIG_config_file("ocaml.swg");
- Printv(mlfile, module, ".ml", NIL);
- Printv(mlifile, module, ".mli", NIL);
+ // TODO: We need to allow overloading at a later point in development.
+ // allow_overloading();
+}
- String *mlfilen = NewStringf("%s%s", SWIG_output_directory(), mlfile);
- if ((f_mlout = NewFile(mlfilen, "w", SWIG_output_files())) == 0) {
- FileErrorDisplay(mlfilen);
- SWIG_exit(EXIT_FAILURE);
- }
- String *mlifilen = NewStringf("%s%s", SWIG_output_directory(), mlifile);
- if ((f_mliout = NewFile(mlifilen, "w", SWIG_output_files())) == 0) {
- FileErrorDisplay(mlifilen);
- SWIG_exit(EXIT_FAILURE);
- }
+int OCAML::top(Node * n) {
+
+ // Initialisation of variables describing the status of the parse tree parsing.
+ classmode = 0;
+ in_constructor = 0;
+
+ // Get the module name
+ String * modulename = Getattr(n, "name");
+
+ // Get the output filename
+ String * outfile = Getattr(n, "outfile");
+
+ // Initialise I/O - Initialise the all the output files.
+ f_runtime = NewFile(outfile, "w", SWIG_output_files());
+ if (!f_runtime) {
+ FileErrorDisplay(outfile);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ f_init = NewString("");
+ f_header = NewString("");
+ f_wrappers = NewString("");
+ f_mlcdecl = NewString("");
+ f_mlbody = NewString("");
+
+ // Register file targets with the SWIG file handler
+ Swig_register_filebyname("header" , f_header );
+ Swig_register_filebyname("wrapper", f_wrappers);
+ Swig_register_filebyname("runtime", f_runtime );
+ Swig_register_filebyname("init" , f_init );
+ // OCaml-specific output file.
+ Swig_register_filebyname("ml" , f_mlbody );
+ Swig_register_filebyname("mlcdecl", f_mlcdecl );
+
+ // Initialising OCaml-specific files
+ String * mlfile = NewString("");
+ Printv(mlfile, modulename, ".ml", NIL);
+ String * ml_filename = NewStringf("%s%s", SWIG_output_directory(), mlfile);
+ if (0 == (f_mlout = NewFile(ml_filename, "w", SWIG_output_files()))) {
+ FileErrorDisplay(ml_filename);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ // Initialising the OCaml submodule containing low-level access
+ // to C wrapper functions and to low-level OCaml type declarations.
+ // This OCaml submodule will be opaque to the end user.
+ Printf(f_mlcdecl, "module Swig = struct\n");
+
+ // n contains the whole parse tree. This instruction is
+ // the code iterating over the whole parse tree. Code for
+ // Language::top is in the lang.cxx file. Flow of execution
+ // goes from Language::top to Language::emit_children, and
+ // then to Language::emit_one, where handlers are executed
+ // for different elements of the parse tree... functions,
+ // constants, classes, et ceterae.
+ //
+ // swig -c++ -ocaml -debug-module 4 myinterface.i
+ //
+ // is a command that outputs the parse tree.
+
+ Language::top(n);
+
+ // Closing the OCaml submodule containing low-level C accessors
+ // and low-level OCaml type declarations.
+
+ Printf(f_mlcdecl, "end;;\n");
+
+ // Write all to the file
+ Dump (f_header , f_runtime);
+ Dump (f_wrappers, f_runtime);
+ Wrapper_pretty_print(f_init , f_runtime);
+
+ // Cleanup files
+ Delete(f_header );
+ Delete(f_wrappers);
+ Delete(f_init );
+ Close (f_runtime );
+ Delete(f_runtime );
+
+ // Write and dump OCaml-specific files, cleanup.
+ Dump (f_mlcdecl, f_mlout);
+ Dump (f_mlbody, f_mlout);
+ Close (f_mlout);
+ Delete (f_mlout);
+
+ return SWIG_OK;
+}
- Language::top(n);
+///////////////////////////////////
+// IMPLEMENTING FUNCTION WRAPPER //
+///////////////////////////////////
- Printf(f_enum_to_int, ") | _ -> (C_int (get_int v))\n" "let _ = Callback.register \"%s_enum_to_int\" enum_to_int\n", module);
- Printf(f_mlibody, "val enum_to_int : c_enum_type -> c_obj -> Swig.c_obj\n");
+int OCAML::functionWrapper (Node * n) {
- Printf(f_int_to_enum, "let _ = Callback.register \"%s_int_to_enum\" int_to_enum\n", module);
- Printf(f_mlibody, "val int_to_enum : c_enum_type -> int -> c_obj\n");
- Printf(f_init, "#define SWIG_init f_%s_init\n" "%s" "}\n", module, init_func_def);
- Printf(f_mlbody, "external f_init : unit -> unit = \"f_%s_init\" ;;\n" "let _ = f_init ()\n", module);
- Printf(f_enumtypes_type, "]\n");
- Printf(f_enumtypes_value, "]\n\n" "type c_obj = c_enum_value c_obj_t\n");
+ // Get some useful attributes of this function
+ String * name = Getattr(n, "sym:name" );
+ String * type = Getattr(n, "type" );
+ ParmList * parms = Getattr(n, "parms" );
- if (directorsEnabled()) {
- // Insert director runtime into the f_runtime file (make it occur before %header section)
- Swig_insert_file("director.swg", f_runtime);
- }
+ // Conversion of parms to the string parmstr
+ String * parmstr = ParmList_str_defaultargs(parms);
+ String * func = SwigType_str(type, NewStringf("%s(%s)", name, parmstr));
+ String * action = Getattr(n, "wrap:action");
- SwigType_emit_type_table(f_runtime, f_wrappers);
- /* Close all of the files */
- Dump(f_runtime, f_begin);
- Dump(f_directors_h, f_header);
- Dump(f_header, f_begin);
- Dump(f_directors, f_wrappers);
- Dump(f_wrappers, f_begin);
- Wrapper_pretty_print(f_init, f_begin);
- Delete(f_header);
- Delete(f_wrappers);
- Delete(f_init);
- Close(f_begin);
- Delete(f_runtime);
- Delete(f_begin);
-
- Dump(f_enumtypes_type, f_mlout);
- Dump(f_enumtypes_value, f_mlout);
- Dump(f_mlbody, f_mlout);
- Dump(f_enum_to_int, f_mlout);
- Dump(f_int_to_enum, f_mlout);
- Delete(f_int_to_enum);
- Delete(f_enum_to_int);
- Dump(f_class_ctors, f_mlout);
- Dump(f_class_ctors_end, f_mlout);
- Dump(f_mltail, f_mlout);
- Close(f_mlout);
- Delete(f_mlout);
-
- Dump(f_enumtypes_type, f_mliout);
- Dump(f_enumtypes_value, f_mliout);
- Dump(f_mlibody, f_mliout);
- Dump(f_mlitail, f_mliout);
- Close(f_mliout);
- Delete(f_mliout);
-
- return SWIG_OK;
- }
+ // Declaration of the wrapper.
+ Wrapper * f = NewWrapper();
- /* Produce an error for the given type */
- void throw_unhandled_ocaml_type_error(SwigType *d, const char *types) {
- Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number, "Unable to handle type %s (%s).\n", SwigType_str(d, 0), types);
- }
+ // Construction of the wrapper name.
+ String * wrapper_name = Swig_name_wrapper(name);
- /* Return true iff T is a pointer type */
- int
- is_a_pointer(SwigType *t) {
- return SwigType_ispointer(SwigType_typedef_resolve_all(t));
+ // Checking that the wrapper name doesn't conflict with another symbol.
+ if (!addSymbol(name, n)) {
+ DelWrapper(f);
+ return SWIG_ERROR;
}
- /*
- * Delete one reference from a given type.
- */
+ // Registering the wrapper name.
+ Setattr(n, "wrap:name", wrapper_name);
- void oc_SwigType_del_reference(SwigType *t) {
- char *c = Char(t);
- if (strncmp(c, "q(", 2) == 0) {
- Delete(SwigType_pop(t));
- c = Char(t);
- }
- if (strncmp(c, "r.", 2)) {
- printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n");
- abort();
- }
- Replace(t, "r.", "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
- }
+ // Attach the non-standard typemaps to the parameter list.
+ Swig_typemap_attach_parms("ocamlin", parms, f);
- void oc_SwigType_del_array(SwigType *t) {
- char *c = Char(t);
- if (strncmp(c, "q(", 2) == 0) {
- Delete(SwigType_pop(t));
- c = Char(t);
- }
- if (strncmp(c, "a(", 2) == 0) {
- Delete(SwigType_pop(t));
- }
- }
+ // This switch is where we choose the OCaml-side wrapping behaviour, depending on
+ // whether we are wrapping a raw C function, or a C++ function of a class.
+ //
+ // TODO: Make this switch exhaustive.
- /*
- * Return true iff T is a reference type
- */
+ String * f_mlbody_concreteclass_1 = NewString("");
+ String * f_mlbody_concreteclass_2 = NewString("");
- int
- is_a_reference(SwigType *t) {
- return SwigType_isreference(SwigType_typedef_resolve_all(t));
+ if (classmode && in_constructor) {
+ Printf(f_mlcdecl, " external %s : ", wrapper_name);
+ Printf(f_mlbody_concreteclass, "class %s = object(self)\n", proxy_class_name);
+ Printf(f_mlbody_concreteclass, " inherit %s\n", proxy_class_name);
+ Printf(f_mlbody_concreteclass, " val underlying_cpp_object = Swig.%s constructing_argument\n", wrapper_name);
+ Printf(f_mlbody_concreteclass, "end;;\n");
+ } else if (classmode) {
+ Printf(f_mlcdecl, "external %s : Obj.t * Obj.t -> Obj.t = \"%s\"\n", wrapper_name, wrapper_name);
+ Printf(f_mlbody_virtualclass, "method %s x = Swig.%s (underlying_cpp_object, x)\n", name, wrapper_name);
}
- int
- is_an_array(SwigType *t) {
- return SwigType_isarray(SwigType_typedef_resolve_all(t));
- }
- /* ------------------------------------------------------------
- * functionWrapper()
- * Create a function declaration and register it with the interpreter.
- * ------------------------------------------------------------ */
-
- virtual int functionWrapper(Node *n) {
- char *iname = GetChar(n, "sym:name");
- SwigType *d = Getattr(n, "type");
- String *return_type_normalized = normalizeTemplatedClassName(d);
- ParmList *l = Getattr(n, "parms");
- int director_method = 0;
- Parm *p;
-
- Wrapper *f = NewWrapper();
- String *proc_name = NewString("");
- String *source = NewString("");
- String *target = NewString("");
- String *arg = NewString("");
- String *cleanup = NewString("");
- String *outarg = NewString("");
- String *build = NewString("");
- String *tm;
- int argout_set = 0;
- int i = 0;
- int numargs;
- int numreq;
- int newobj = GetFlag(n, "feature:new");
- String *nodeType = Getattr(n, "nodeType");
- int destructor = (!Cmp(nodeType, "destructor"));
- String *overname = 0;
- bool isOverloaded = Getattr(n, "sym:overloaded") ? true : false;
-
- // Make a wrapper name for this
- String *wname = Swig_name_wrapper(iname);
- if (isOverloaded) {
- overname = Getattr(n, "sym:overname");
- } else {
- if (!addSymbol(iname, n)) {
- DelWrapper(f);
- return SWIG_ERROR;
- }
- }
- if (overname) {
- Append(wname, overname);
- }
- /* Do this to disambiguate functions emitted from different modules */
- Append(wname, module);
-
- Setattr(n, "wrap:name", wname);
-
- // Build the name for Scheme.
- Printv(proc_name, "_", iname, NIL);
- String *mangled_name = mangleNameForCaml(proc_name);
-
- if (classmode && in_constructor) { // Emit constructor for object
- String *mangled_name_nounder = NewString((char *) (Char(mangled_name)) + 1);
- Printf(f_class_ctors_end, "let %s clst = _%s clst\n", mangled_name_nounder, mangled_name_nounder);
- Printf(f_mlibody, "val %s : c_obj -> c_obj\n", mangled_name_nounder);
- Delete(mangled_name_nounder);
- } else if (classmode && in_destructor) {
- Printf(f_class_ctors, " \"~\", %s ;\n", mangled_name);
- } else if (classmode && !in_constructor && !in_destructor && !static_member_function) {
- String *opname = Copy(Getattr(n, "memberfunctionHandler:sym:name"));
-
- Replaceall(opname, "operator ", "");
-
- if (strstr(Char(mangled_name), "__get__")) {
- String *set_name = Copy(mangled_name);
- if (!GetFlag(n, "feature:immutable")) {
- Replaceall(set_name, "__get__", "__set__");
- Printf(f_class_ctors, " \"%s\", (fun args -> " "if args = (C_list [ raw_ptr ]) then %s args else %s args) ;\n", opname, mangled_name, set_name);
- Delete(set_name);
- } else {
- Printf(f_class_ctors, " \"%s\", (fun args -> " "if args = (C_list [ raw_ptr ]) then %s args else C_void) ;\n", opname, mangled_name);
- }
- } else if (strstr(Char(mangled_name), "__set__")) {
- ; /* Nothing ... handled by the case above */
- } else {
- Printf(f_class_ctors, " \"%s\", %s ;\n", opname, mangled_name);
- }
-
- Delete(opname);
- }
+ // Trying to generate wrapper code.... No promise yet!
- if (classmode && in_constructor) {
- Setattr(seen_constructors, mangled_name, "true");
- }
- // writing the function wrapper function
- Printv(f->def, "SWIGEXT CAML_VALUE ", wname, " (", NIL);
- Printv(f->def, "CAML_VALUE args", NIL);
- Printv(f->def, ")\n{", NIL);
-
- /* Define the scheme name in C. This define is used by several
- macros. */
- //Printv(f->def, "#define FUNC_NAME \"", mangled_name, "\"", NIL);
-
- // adds local variables
- Wrapper_add_local(f, "args", "CAMLparam1(args)");
- Wrapper_add_local(f, "ret", "SWIG_CAMLlocal2(swig_result,rv)");
- Wrapper_add_local(f, "_v", "int _v = 0");
- if (isOverloaded) {
- Wrapper_add_local(f, "i", "int i");
- Wrapper_add_local(f, "argc", "int argc = caml_list_length(args)");
- Wrapper_add_local(f, "argv", "CAML_VALUE *argv");
-
- Printv(f->code,
- "argv = (CAML_VALUE *)malloc( argc * sizeof( CAML_VALUE ) );\n"
- "for( i = 0; i < argc; i++ ) {\n" " argv[i] = caml_list_nth(args,i);\n" "}\n", NIL);
- }
- d = SwigType_typedef_qualified(d);
- emit_parameter_variables(l, f);
-
- /* Attach the standard typemaps */
- emit_attach_parmmaps(l, f);
- Setattr(n, "wrap:parms", l);
-
- numargs = emit_num_arguments(l);
- numreq = emit_num_required(l);
-
- Printf(f->code, "swig_result = Val_unit;\n");
-
- // Now write code to extract the parameters (this is super ugly)
-
- for (i = 0, p = l; i < numargs; i++) {
- /* Skip ignored arguments */
- while (checkAttribute(p, "tmap:in:numinputs", "0")) {
- p = Getattr(p, "tmap:in:next");
- }
-
- SwigType *pt = Getattr(p, "type");
- String *ln = Getattr(p, "lname");
- pt = SwigType_typedef_qualified(pt);
-
- // Produce names of source and target
- Clear(source);
- Clear(target);
- Clear(arg);
- Printf(source, "caml_list_nth(args,%d)", i);
- Printf(target, "%s", ln);
- Printv(arg, Getattr(p, "name"), NIL);
-
- if (i >= numreq) {
- Printf(f->code, "if (caml_list_length(args) > %d) {\n", i);
- }
- // Handle parameter types.
- if ((tm = Getattr(p, "tmap:in"))) {
- Replaceall(tm, "$source", source);
- Replaceall(tm, "$target", target);
- Replaceall(tm, "$input", source);
- Setattr(p, "emit:input", source);
- Printv(f->code, tm, "\n", NIL);
- p = Getattr(p, "tmap:in:next");
- } else {
- // no typemap found
- // check if typedef and resolve
- throw_unhandled_ocaml_type_error(pt, "in");
- p = nextSibling(p);
- }
- if (i >= numreq) {
- Printf(f->code, "}\n");
- }
- }
+ // Documentation on wrapper objects can be found in
+ // /usr/share/doc/swig-doc/Devel/wrapobj.html
- /* Insert constraint checking code */
- for (p = l; p;) {
- if ((tm = Getattr(p, "tmap:check"))) {
- Replaceall(tm, "$target", Getattr(p, "lname"));
- Printv(f->code, tm, "\n", NIL);
- p = Getattr(p, "tmap:check:next");
- } else {
- p = nextSibling(p);
- }
- }
+ // Generating wrapper C declaration, without arguments...
+ Printv(f->def, "CAML_VALUE ", wrapper_name, " (", NIL);
- // Pass output arguments back to the caller.
-
- for (p = l; p;) {
- if ((tm = Getattr(p, "tmap:argout"))) {
- Replaceall(tm, "$source", Getattr(p, "emit:input")); /* Deprecated */
- Replaceall(tm, "$target", Getattr(p, "lname")); /* Deprecated */
- Replaceall(tm, "$arg", Getattr(p, "emit:input"));
- Replaceall(tm, "$input", Getattr(p, "emit:input"));
- Replaceall(tm, "$ntype", normalizeTemplatedClassName(Getattr(p, "type")));
- Printv(outarg, tm, "\n", NIL);
- p = Getattr(p, "tmap:argout:next");
- argout_set = 1;
- } else {
- p = nextSibling(p);
- }
- }
+ // Declaring the output return variable.
+ Wrapper_add_local(f, "caml_result", "SWIG_CAMLlocal1(caml_result)");
- // Free up any memory allocated for the arguments.
-
- /* Insert cleanup code */
- for (p = l; p;) {
- if ((tm = Getattr(p, "tmap:freearg"))) {
- Replaceall(tm, "$target", Getattr(p, "lname"));
- Printv(cleanup, tm, "\n", NIL);
- p = Getattr(p, "tmap:freearg:next");
- } else {
- p = nextSibling(p);
- }
- }
+ type = SwigType_typedef_qualified(type);
- /* if the object is a director, and the method call originated from its
- * underlying python object, resolve the call by going up the c++
- * inheritance chain. otherwise try to resolve the method in python.
- * without this check an infinite loop is set up between the director and
- * shadow class method calls.
- */
-
- // NOTE: this code should only be inserted if this class is the
- // base class of a director class. however, in general we haven't
- // yet analyzed all classes derived from this one to see if they are
- // directors. furthermore, this class may be used as the base of
- // a director class defined in a completely different module at a
- // later time, so this test must be included whether or not directorbase
- // is true. we do skip this code if directors have not been enabled
- // at the command line to preserve source-level compatibility with
- // non-polymorphic swig. also, if this wrapper is for a smart-pointer
- // method, there is no need to perform the test since the calling object
- // (the smart-pointer) and the director object (the "pointee") are
- // distinct.
-
- director_method = is_member_director(n) && !is_smart_pointer() && !destructor;
- if (director_method) {
- Wrapper_add_local(f, "director", "Swig::Director *director = 0");
- Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
- Wrapper_add_local(f, "upcall", "bool upcall = false");
- Append(f->code, "upcall = (director);\n");
- }
+ // Emit all of the local variables for holding arguments.
+ emit_parameter_variables(parms, f);
- // Now write code to make the function call
- Swig_director_emit_dynamic_cast(n, f);
- String *actioncode = emit_action(n);
+ // Attach the standard typemaps.
+ emit_attach_parmmaps(parms, f);
- if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
- Replaceall(tm, "$source", "swig_result");
- Replaceall(tm, "$target", "rv");
- Replaceall(tm, "$result", "rv");
- Replaceall(tm, "$ntype", return_type_normalized);
- Printv(f->code, tm, "\n", NIL);
- } else {
- throw_unhandled_ocaml_type_error(d, "out");
- }
- emit_return_variable(n, d, f);
+ // Parameter overloading.
+ Setattr(n, "wrap:parms", parms );
+ Setattr(n, "wrap:name" , wrapper_name);
- // Dump the argument output code
- Printv(f->code, Char(outarg), NIL);
+ // Get the number of required and total arguments.
+ int num_arguments = emit_num_arguments(parms);
+ int num_required = emit_num_required(parms);
- // Dump the argument cleanup code
- Printv(f->code, Char(cleanup), NIL);
+ // Now walk the function parameter list and generate code to get arguments.
+ int gencomma = 0;
+ Parm * p;
+ int i;
+ for (i = 0, p = parms; i < num_arguments; i++) {
- // Look for any remaining cleanup
-
- if (GetFlag(n, "feature:new")) {
- if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) {
- Replaceall(tm, "$source", "swig_result");
- Printv(f->code, tm, "\n", NIL);
- }
+ while (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
}
- // Free any memory allocated by the function being wrapped..
- if ((tm = Swig_typemap_lookup("swig_result", n, "result", 0))) {
- Replaceall(tm, "$source", "result");
- Printv(f->code, tm, "\n", NIL);
- }
- // Wrap things up (in a manner of speaking)
-
- Printv(f->code, tab4, "swig_result = caml_list_append(swig_result,rv);\n", NIL);
- if (isOverloaded)
- Printv(f->code, "free(argv);\n", NIL);
- Printv(f->code, tab4, "CAMLreturn(swig_result);\n", NIL);
- Printv(f->code, "}\n", NIL);
-
- /* Substitute the function name */
- Replaceall(f->code, "$symname", iname);
-
- Wrapper_print(f, f_wrappers);
-
- if (isOverloaded) {
- if (!Getattr(n, "sym:nextSibling")) {
- int maxargs;
- Wrapper *df = NewWrapper();
- String *dispatch = Swig_overload_dispatch(n,
- "free(argv);\n" "CAMLreturn(%s(args));\n",
- &maxargs);
-
- Wrapper_add_local(df, "_v", "int _v = 0");
- Wrapper_add_local(df, "argv", "CAML_VALUE *argv");
-
- /* Undifferentiate name .. this is the dispatch function */
- wname = Swig_name_wrapper(iname);
- /* Do this to disambiguate functions emitted from different
- * modules */
- Append(wname, module);
-
- Printv(df->def,
- "SWIGEXT CAML_VALUE ", wname, "(CAML_VALUE args) {\n" " CAMLparam1(args);\n" " int i;\n" " int argc = caml_list_length(args);\n", NIL);
- Printv(df->code,
- "argv = (CAML_VALUE *)malloc( argc * sizeof( CAML_VALUE ) );\n"
- "for( i = 0; i < argc; i++ ) {\n" " argv[i] = caml_list_nth(args,i);\n" "}\n", NIL);
- Printv(df->code, dispatch, "\n", NIL);
- Printf(df->code, "failwith(\"No matching function for overloaded '%s'\");\n", iname);
- Printv(df->code, "}\n", NIL);
- Wrapper_print(df, f_wrappers);
-
- DelWrapper(df);
- Delete(dispatch);
- }
- }
+ SwigType * pt = Getattr(p, "type" );
+ String * ln = Getattr(p, "lname");
+ String * arg = NewString("");
- Printf(f_mlbody,
- "external %s_f : c_obj list -> c_obj list = \"%s\" ;;\n"
- "let %s arg = match %s_f (fnhelper arg) with\n"
- " [] -> C_void\n"
- "| [x] -> (if %s then Gc.finalise \n"
- " (fun x -> ignore ((invoke x) \"~\" C_void)) x) ; x\n"
- "| lst -> C_list lst ;;\n", mangled_name, wname, mangled_name, mangled_name, newobj ? "true" : "false");
+ Printf(arg, "ocaml_%s", ln);
- if (!classmode || in_constructor || in_destructor || static_member_function)
- Printf(f_mlibody, "val %s : c_obj -> c_obj\n", mangled_name);
+ // Writing the current argument in the wrapper function header.
+ Printv(f->def, gencomma ? ", " : "", "CAML_VALUE ", arg, NIL);
+ gencomma = 1;
- Delete(proc_name);
- Delete(source);
- Delete(target);
- Delete(arg);
- Delete(outarg);
- Delete(cleanup);
- Delete(build);
- DelWrapper(f);
- return SWIG_OK;
- }
+ Printv(f_mlcdecl, Getattr(p, "tmap:ocamlin"), " -> ", NIL);
- /* ------------------------------------------------------------
- * variableWrapper()
- *
- * Create a link to a C variable.
- * This creates a single function _wrap_swig_var_varname().
- * This function takes a single optional argument. If supplied, it means
- * we are setting this variable to some value. If omitted, it means we are
- * simply evaluating this variable. In the set case we return C_void.
- *
- * symname is the name of the variable with respect to C. This
- * may need to differ from the original name in the case of enums.
- * enumvname is the name of the variable with respect to ocaml. This
- * will vary if the variable has been renamed.
- * ------------------------------------------------------------ */
-
- virtual int variableWrapper(Node *n) {
- char *name = GetChar(n, "feature:symname");
- String *iname = Getattr(n, "feature:enumvname");
- String *mname = mangleNameForCaml(iname);
- SwigType *t = Getattr(n, "type");
-
- String *proc_name = NewString("");
- String *tm;
- String *tm2 = NewString("");;
- String *argnum = NewString("0");
- String *arg = NewString("SWIG_Field(args,0)");
- Wrapper *f;
-
- if (!name) {
- name = GetChar(n, "name");
- }
-
- if (!iname) {
- iname = Getattr(n, "sym:name");
- mname = mangleNameForCaml(NewString(iname));
- }
+ // Declaring the input ocaml_arg_n, i.e. arg, value in the wrapper.
+ String * caml_parameter_declaration = NewString("");
+ Printf(caml_parameter_declaration, "CAMLparam1(%s)", arg);
+ Wrapper_add_local(f, arg, caml_parameter_declaration);
+ Delete(caml_parameter_declaration);
- if (!iname || !addSymbol(iname, n))
- return SWIG_ERROR;
-
- f = NewWrapper();
-
- // evaluation function names
- String *var_name = Swig_name_wrapper(iname);
-
- // Build the name for scheme.
- Printv(proc_name, iname, NIL);
- Setattr(n, "wrap:name", proc_name);
-
- Printf(f->def, "SWIGEXT CAML_VALUE %s(CAML_VALUE args) {\n", var_name);
- // Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL);
-
- Wrapper_add_local(f, "swig_result", "CAML_VALUE swig_result");
-
- if (!GetFlag(n, "feature:immutable")) {
- /* Check for a setting of the variable value */
- Printf(f->code, "if (args != Val_int(0)) {\n");
- if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
- Replaceall(tm, "$source", "args");
- Replaceall(tm, "$target", name);
- Replaceall(tm, "$input", "args");
- /* Printv(f->code, tm, "\n",NIL); */
- emit_action_code(n, f->code, tm);
- } else if ((tm = Swig_typemap_lookup("in", n, name, 0))) {
- Replaceall(tm, "$source", "args");
- Replaceall(tm, "$target", name);
- Replaceall(tm, "$input", "args");
- Printv(f->code, tm, "\n", NIL);
- } else {
- throw_unhandled_ocaml_type_error(t, "varin/in");
- }
- Printf(f->code, "}\n");
- }
- // Now return the value of the variable (regardless
- // of evaluating or setting)
-
- if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
- Replaceall(tm, "$source", name);
- Replaceall(tm, "$target", "swig_result");
- Replaceall(tm, "$result", "swig_result");
- emit_action_code(n, f->code, tm);
- } else if ((tm = Swig_typemap_lookup("out", n, name, 0))) {
- Replaceall(tm, "$source", name);
- Replaceall(tm, "$target", "swig_result");
- Replaceall(tm, "$result", "swig_result");
+ String * tm;
+ // Get the standard typemap for this argument
+ if ((tm = Getattr(p, "tmap:in"))) {
+ // Replaceall(tm, "$source", arg); /* deprecated */
+ // Replaceall(tm, "$target", ln ); /* deprecated */
+ // Replaceall(tm, "$arg" , arg); /* deprecated ? */
+ Replaceall(tm, "$input", arg);
+ Setattr(p, "emit:input", arg);
Printf(f->code, "%s\n", tm);
+ p = Getattr(p, "tmap:in:next");
} else {
- throw_unhandled_ocaml_type_error(t, "varout/out");
+ Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number,
+ "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
+ p = nextSibling(p);
}
- Printf(f->code, "\nreturn swig_result;\n");
- Printf(f->code, "}\n");
-
- Wrapper_print(f, f_wrappers);
-
- // Now add symbol to the Ocaml interpreter
-
- if (GetFlag(n, "feature:immutable")) {
- Printf(f_mlbody, "external _%s : c_obj -> Swig.c_obj = \"%s\" \n", mname, var_name);
- Printf(f_mlibody, "val _%s : c_obj -> Swig.c_obj\n", iname);
- if (const_enum) {
- Printf(f_enum_to_int, " | `%s -> _%s C_void\n", mname, mname);
- Printf(f_int_to_enum, " if y = (get_int (_%s C_void)) then `%s else\n", mname, mname);
- }
- } else {
- Printf(f_mlbody, "external _%s : c_obj -> c_obj = \"%s\"\n", mname, var_name);
- Printf(f_mlibody, "external _%s : c_obj -> c_obj = \"%s\"\n", mname, var_name);
- }
-
- Delete(var_name);
- Delete(proc_name);
- Delete(argnum);
Delete(arg);
- Delete(tm2);
- DelWrapper(f);
- return SWIG_OK;
- }
- /* ------------------------------------------------------------
- * staticmemberfunctionHandler --
- * Overridden to set static_member_function
- * ------------------------------------------------------------ */
-
- virtual int staticmemberfunctionHandler(Node *n) {
- int rv;
- static_member_function = 1;
- rv = Language::staticmemberfunctionHandler(n);
- static_member_function = 0;
- return SWIG_OK;
}
+ Printf(f->def, ")\n{\n");
- /* ------------------------------------------------------------
- * constantWrapper()
- *
- * The one trick here is that we have to make sure we rename the
- * constant to something useful that doesn't collide with the
- * original if any exists.
- * ------------------------------------------------------------ */
-
- virtual int constantWrapper(Node *n) {
- String *name = Getattr(n, "feature:symname");
- SwigType *type = Getattr(n, "type");
- String *value = Getattr(n, "value");
- String *qvalue = Getattr(n, "qualified:value");
- String *rvalue = NewString("");
- String *temp = 0;
-
- if (qvalue)
- value = qvalue;
-
- if (!name) {
- name = mangleNameForCaml(Getattr(n, "name"));
- Insert(name, 0, "_swig_wrap_");
- Setattr(n, "feature:symname", name);
- }
- // See if there's a typemap
-
- Printv(rvalue, value, NIL);
- if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 1)) {
- temp = Copy(rvalue);
- Clear(rvalue);
- Printv(rvalue, "\"", temp, "\"", NIL);
- Delete(temp);
- }
- if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 0)) {
- temp = Copy(rvalue);
- Clear(rvalue);
- Printv(rvalue, "'", temp, "'", NIL);
- Delete(temp);
- }
- // Create variable and assign it a value
+ // Now write code to make the function call.
+ String * action_code = emit_action(n);
- Printf(f_header, "static %s = ", SwigType_lstr(type, name));
- if ((SwigType_type(type) == T_STRING)) {
- Printf(f_header, "\"%s\";\n", value);
- } else if (SwigType_type(type) == T_CHAR) {
- Printf(f_header, "\'%s\';\n", value);
- } else {
- Printf(f_header, "%s;\n", value);
- }
-
- SetFlag(n, "feature:immutable");
- variableWrapper(n);
- return SWIG_OK;
- }
-
- int constructorHandler(Node *n) {
- int ret;
-
- in_constructor = 1;
- ret = Language::constructorHandler(n);
- in_constructor = 0;
-
- return ret;
- }
-
- /* destructorHandler:
- * Turn on destructor flag to inform decisions in functionWrapper
- */
-
- int destructorHandler(Node *n) {
- int ret;
+ // Return value if necessary.
+ String * tm;
+ if ((tm = Swig_typemap_lookup_out("out", n, "result", f, action_code)))
+ {
+ //Replaceall(tm, "$source", "result"); /* deprecated */
+ //Replaceall(tm, "$target", "caml_result"); /* deprecated */
+ Replaceall(tm, "$result", "caml_result");
- in_destructor = 1;
- ret = Language::destructorHandler(n);
- in_destructor = 0;
+ // The following line might be completely unnecessary, depending on
+ // how garbage-collection is done...
+ //Replaceall(tm, "$owner", (GetFlag(n, "feature:new")) ? "1" : "0");
- return ret;
+ Printf(f->code, "%s", tm);
+ } else {
+ Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number,
+ "Unable to use return type %s in function %s.\n",
+ SwigType_str(type, 0), Getattr(n, "name"));
}
+ emit_return_variable(n, type, f);
- /* copyconstructorHandler:
- * Turn on constructor and copyconstructor flags for functionWrapper
- */
+ Printf(f->code, "\nCAMLreturn(caml_result);\n}");
+ Wrapper_print(f, f_wrappers);
- int copyconstructorHandler(Node *n) {
- int ret;
+ Printf(f_mlcdecl, "%s = \"%s\"\n", proxy_class_name, wrapper_name);
- in_copyconst = 1;
- in_constructor = 1;
- ret = Language::copyconstructorHandler(n);
- in_constructor = 0;
- in_copyconst = 0;
-
- return ret;
- }
-
- /**
- * A simple, somewhat general purpose function for writing to multiple
- * streams from a source template. This allows the user to define the
- * class definition in ways different from the one I have here if they
- * want to. It will also make the class definition system easier to
- * fiddle with when I want to change methods, etc.
- */
-
- void Multiwrite(String *s) {
- char *find_marker = strstr(Char(s), "(*Stream:");
- while (find_marker) {
- char *next = strstr(find_marker, "*)");
- find_marker += strlen("(*Stream:");
-
- if (next) {
- int num_chars = next - find_marker;
- String *stream_name = NewString(find_marker);
- Delslice(stream_name, num_chars, Len(stream_name));
- File *fout = Swig_filebyname(stream_name);
- if (fout) {
- next += strlen("*)");
- char *following = strstr(next, "(*Stream:");
- find_marker = following;
- if (!following)
- following = next + strlen(next);
- String *chunk = NewString(next);
- Delslice(chunk, following - next, Len(chunk));
- Printv(fout, chunk, NIL);
- }
- }
- }
- }
-
- bool isSimpleType(String *name) {
- char *ch = Char(name);
-
- return !(strchr(ch, '(') || strchr(ch, '<') || strchr(ch, ')') || strchr(ch, '>'));
- }
-
- /* We accept all chars in identifiers because we use strings to index
- * them. */
- int validIdentifier(String *name) {
- return Len(name) > 0 ? 1 : 0;
- }
-
- /* classHandler
- *
- * Create a "class" definition for ocaml. I thought quite a bit about
- * how I should do this part of it, and arrived here, using a function
- * invocation to select a method, and dispatch. This can obviously be
- * done better, but I can't see how, given that I want to support
- * overloaded methods, out parameters, and operators.
- *
- * I needed a system that would do this:
- *
- * a Be able to call these methods:
- * int foo( int x );
- * float foo( int x, int &out );
- *
- * b Be typeable, even in the presence of mutually dependent classes.
- *
- * c Support some form of operator invocation.
- *
- * (c) I chose strings for the method names so that "+=" would be a
- * valid method name, and the somewhat natural << (invoke x) "+=" y >>
- * would work.
- *
- * (a) (b) Since the c_obj type exists, it's easy to return C_int in one
- * case and C_list [ C_float ; C_int ] in the other. This makes tricky
- * problems with out parameters disappear; they're simply appended to the
- * return list.
- *
- * (b) Since every item that comes from C++ is the same type, there is no
- * problem with the following:
- *
- * class Foo;
- * class Bar { Foo *toFoo(); }
- * class Foo { Bar *toBar(); }
- *
- * Since the Objective caml types of Foo and Bar are the same. Now that
- * I correctly incorporate SWIG's typechecking, this isn't a big deal.
- *
- * The class is in the form of a function returning a c_obj. The c_obj
- * is a C_obj containing a function which invokes a method on the
- * underlying object given its type.
- *
- * The name emitted here is normalized before being sent to
- * Callback.register, because we need this string to look up properly
- * when the typemap passes the descriptor string. I've been considering
- * some, possibly more forgiving method that would do some transformations
- * on the $descriptor in order to find a potential match. This is for
- * later.
- *
- * Important things to note:
- *
- * We rely on exception handling (BadMethodName) in order to call an
- * ancestor. This can be improved.
- *
- * The method used to get :classof could be improved to look at the type
- * info that the base pointer contains. It's really an error to have a
- * SWIG-generated object that does not contain type info, since the
- * existence of the object means that SWIG knows the type.
- *
- * :parents could use :classof to tell what class it is and make a better
- * decision. This could be nice, (i.e. provide a run-time graph of C++
- * classes represented);.
- *
- * I can't think of a more elegant way of converting a C_obj fun to a
- * pointer than "operator &"...
- *
- * Added a 'sizeof' that will allow you to do the expected thing.
- * This should help users to fill buffer structs and the like (as is
- * typical in windows-styled code). It's only enabled if you give
- * %feature(sizeof) and then, only for simple types.
- *
- * Overall, carrying the list of methods and base classes has worked well.
- * It allows me to give the Ocaml user introspection over their objects.
- */
-
- int classHandler(Node *n) {
- String *name = Getattr(n, "name");
-
- if (!name)
- return SWIG_OK;
-
- String *mangled_sym_name = mangleNameForCaml(name);
- String *this_class_def = NewString(f_classtemplate);
- String *name_normalized = normalizeTemplatedClassName(name);
- String *old_class_ctors = f_class_ctors;
- String *base_classes = NewString("");
- f_class_ctors = NewString("");
- bool sizeof_feature = generate_sizeof && isSimpleType(name);
-
-
- classname = mangled_sym_name;
- classmode = true;
- int rv = Language::classHandler(n);
- classmode = false;
-
- if (sizeof_feature) {
- Printf(f_wrappers,
- "SWIGEXT CAML_VALUE _wrap_%s_sizeof( CAML_VALUE args ) {\n"
- " CAMLparam1(args);\n" " CAMLreturn(Val_int(sizeof(%s)));\n" "}\n", mangled_sym_name, name_normalized);
-
- Printf(f_mlbody, "external __%s_sizeof : unit -> int = " "\"_wrap_%s_sizeof\"\n", classname, mangled_sym_name);
- }
-
-
- /* Insert sizeof operator for concrete classes */
- if (sizeof_feature) {
- Printv(f_class_ctors, "\"sizeof\" , (fun args -> C_int (__", classname, "_sizeof ())) ;\n", NIL);
- }
- /* Handle up-casts in a nice way */
- List *baselist = Getattr(n, "bases");
- if (baselist && Len(baselist)) {
- Iterator b;
- b = First(baselist);
- while (b.item) {
- String *bname = Getattr(b.item, "name");
- if (bname) {
- String *base_create = NewString("");
- Printv(base_create, "(create_class \"", bname, "\")", NIL);
- Printv(f_class_ctors, " \"::", bname, "\", (fun args -> ", base_create, " args) ;\n", NIL);
- Printv(base_classes, base_create, " ;\n", NIL);
- }
- b = Next(b);
- }
- }
-
- Replaceall(this_class_def, "$classname", classname);
- Replaceall(this_class_def, "$normalized", name_normalized);
- Replaceall(this_class_def, "$realname", name);
- Replaceall(this_class_def, "$baselist", base_classes);
- Replaceall(this_class_def, "$classbody", f_class_ctors);
-
- Delete(f_class_ctors);
- f_class_ctors = old_class_ctors;
-
- // Actually write out the class definition
-
- Multiwrite(this_class_def);
-
- Setattr(n, "ocaml:ctor", classname);
-
- return rv;
- }
-
- String *normalizeTemplatedClassName(String *name) {
- String *name_normalized = SwigType_typedef_resolve_all(name);
- bool took_action;
-
- do {
- took_action = false;
-
- if (is_a_pointer(name_normalized)) {
- SwigType_del_pointer(name_normalized);
- took_action = true;
- }
-
- if (is_a_reference(name_normalized)) {
- oc_SwigType_del_reference(name_normalized);
- took_action = true;
- }
-
- if (is_an_array(name_normalized)) {
- oc_SwigType_del_array(name_normalized);
- took_action = true;
- }
- } while (took_action);
-
- return SwigType_str(name_normalized, 0);
- }
-
- /*
- * Produce the symbol name that ocaml will use when referring to the
- * target item. I wonder if there's a better way to do this:
- *
- * I shudder to think about doing it with a hash lookup, but that would
- * make a couple of things easier:
- */
-
- String *mangleNameForCaml(String *s) {
- String *out = Copy(s);
- Replaceall(out, " ", "_xx");
- Replaceall(out, "::", "_xx");
- Replaceall(out, ",", "_x");
- Replaceall(out, "+", "_xx_plus");
- Replaceall(out, "-", "_xx_minus");
- Replaceall(out, "<", "_xx_ldbrace");
- Replaceall(out, ">", "_xx_rdbrace");
- Replaceall(out, "!", "_xx_not");
- Replaceall(out, "%", "_xx_mod");
- Replaceall(out, "^", "_xx_xor");
- Replaceall(out, "*", "_xx_star");
- Replaceall(out, "&", "_xx_amp");
- Replaceall(out, "|", "_xx_or");
- Replaceall(out, "(", "_xx_lparen");
- Replaceall(out, ")", "_xx_rparen");
- Replaceall(out, "[", "_xx_lbrace");
- Replaceall(out, "]", "_xx_rbrace");
- Replaceall(out, "~", "_xx_bnot");
- Replaceall(out, "=", "_xx_equals");
- Replaceall(out, "/", "_xx_slash");
- Replaceall(out, ".", "_xx_dot");
- return out;
- }
-
- String *fully_qualify_enum_name(Node *n, String *name) {
- Node *parent = 0;
- String *qualification = NewString("");
- String *fully_qualified_name = NewString("");
- String *parent_type = 0;
- String *normalized_name;
-
- parent = parentNode(n);
- while (parent) {
- parent_type = nodeType(parent);
- if (Getattr(parent, "name")) {
- String *parent_copy = NewStringf("%s::", Getattr(parent, "name"));
- if (!Cmp(parent_type, "class") || !Cmp(parent_type, "namespace"))
- Insert(qualification, 0, parent_copy);
- Delete(parent_copy);
- }
- if (!Cmp(parent_type, "class"))
- break;
- parent = parentNode(parent);
- }
-
- Printf(fully_qualified_name, "%s%s", qualification, name);
-
- normalized_name = normalizeTemplatedClassName(fully_qualified_name);
- if (!strncmp(Char(normalized_name), "enum ", 5)) {
- Insert(normalized_name, 5, qualification);
- }
-
- return normalized_name;
- }
-
- /* Benedikt Grundmann inspired --> Enum wrap styles */
-
- int enumvalueDeclaration(Node *n) {
- String *name = Getattr(n, "name");
- String *qvalue = 0;
-
- if (name_qualifier) {
- qvalue = Copy(name_qualifier);
- Printv(qvalue, name, NIL);
- }
-
- if (const_enum && name && !Getattr(seen_enumvalues, name)) {
- Setattr(seen_enumvalues, name, "true");
- SetFlag(n, "feature:immutable");
- Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used
-
- if (qvalue)
- Setattr(n, "qualified:value", qvalue);
-
- String *evname = SwigType_manglestr(qvalue);
- Insert(evname, 0, "SWIG_ENUM_");
-
- Setattr(n, "feature:enumvname", name);
- Setattr(n, "feature:symname", evname);
- Delete(evname);
- Printf(f_enumtypes_value, "| `%s\n", name);
-
- return Language::enumvalueDeclaration(n);
- } else
- return SWIG_OK;
- }
-
- /* -------------------------------------------------------------------
- * This function is a bit uglier than it deserves.
- *
- * I used to direct lookup the name of the enum. Now that certain fixes
- * have been made in other places, the names of enums are now fully
- * qualified, which is a good thing, overall, but requires me to do
- * some legwork.
- *
- * The other thing that uglifies this function is the varying way that
- * typedef enum and enum are handled. I need to produce consistent names,
- * which means looking up and registering by typedef and enum name. */
- int enumDeclaration(Node *n) {
- String *name = Getattr(n, "name");
- if (name) {
- String *oname = NewString(name);
- /* name is now fully qualified */
- String *fully_qualified_name = NewString(name);
- bool seen_enum = false;
- if (name_qualifier)
- Delete(name_qualifier);
- char *strip_position;
- name_qualifier = fully_qualify_enum_name(n, NewString(""));
-
- strip_position = strstr(Char(oname), "::");
-
- while (strip_position) {
- strip_position += 2;
- oname = NewString(strip_position);
- strip_position = strstr(Char(oname), "::");
- }
-
- seen_enum = (Getattr(seen_enums, fully_qualified_name) ? true : false);
-
- if (!seen_enum) {
- const_enum = true;
- Printf(f_enum_to_int, "| `%s -> (match y with\n", oname);
- Printf(f_int_to_enum, "| `%s -> C_enum (\n", oname);
- /* * * * A note about enum name resolution * * * *
- * This code should now work, but I think we can do a bit better.
- * The problem I'm having is that swig isn't very precise about
- * typedef name resolution. My opinion is that SwigType_typedef
- * resolve_all should *always* return the enum tag if one exists,
- * rather than the admittedly friendlier enclosing typedef.
- *
- * This would make one of the cases below unnecessary.
- * * * */
- Printf(f_mlbody, "let _ = Callback.register \"%s_marker\" (`%s)\n", fully_qualified_name, oname);
- if (!strncmp(Char(fully_qualified_name), "enum ", 5)) {
- String *fq_noenum = NewString(Char(fully_qualified_name) + 5);
- Printf(f_mlbody,
- "let _ = Callback.register \"%s_marker\" (`%s)\n" "let _ = Callback.register \"%s_marker\" (`%s)\n", fq_noenum, oname, fq_noenum, name);
- }
-
- Printf(f_enumtypes_type, "| `%s\n", oname);
- Insert(fully_qualified_name, 0, "enum ");
- Setattr(seen_enums, fully_qualified_name, n);
- }
- }
-
- int ret = Language::enumDeclaration(n);
-
- if (const_enum) {
- Printf(f_int_to_enum, "`Int y)\n");
- Printf(f_enum_to_int, "| `Int x -> Swig.C_int x\n" "| _ -> raise (LabelNotFromThisEnum v))\n");
- }
-
- const_enum = false;
-
- return ret;
- }
-
- /* ----------------------------------------------------------------------------
- * BEGIN C++ Director Class modifications
- * ------------------------------------------------------------------------- */
-
- /*
- * Modified polymorphism code for Ocaml language module.
- * Original:
- * C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose
- * <mrose@stm.lbl.gov>
- *
- * TODO
- *
- * Move some boilerplate code generation to Swig_...() functions.
- *
- */
-
- /* ---------------------------------------------------------------
- * classDirectorMethod()
- *
- * Emit a virtual director method to pass a method call on to the
- * underlying Python object.
- *
- * --------------------------------------------------------------- */
-
- int classDirectorMethod(Node *n, Node *parent, String *super) {
- int is_void = 0;
- int is_pointer = 0;
- String *storage;
- String *value;
- String *decl;
- String *type;
- String *name;
- String *classname;
- String *c_classname = Getattr(parent, "name");
- String *declaration;
- ParmList *l;
- Wrapper *w;
- String *tm;
- String *wrap_args = NewString("");
- String *return_type;
- int status = SWIG_OK;
- int idx;
- bool pure_virtual = false;
- bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
-
- storage = Getattr(n, "storage");
- value = Getattr(n, "value");
- classname = Getattr(parent, "sym:name");
- type = Getattr(n, "type");
- name = Getattr(n, "name");
-
- if (Cmp(storage, "virtual") == 0) {
- if (Cmp(value, "0") == 0) {
- pure_virtual = true;
- }
- }
-
- w = NewWrapper();
- declaration = NewString("");
- Wrapper_add_local(w, "swig_result", "CAMLparam0();\n" "SWIG_CAMLlocal2(swig_result,args)");
-
- /* determine if the method returns a pointer */
- decl = Getattr(n, "decl");
- is_pointer = SwigType_ispointer_return(decl);
- is_void = (!Cmp(type, "void") && !is_pointer);
-
- /* form complete return type */
- return_type = Copy(type);
- {
- SwigType *t = Copy(decl);
- SwigType *f = 0;
- f = SwigType_pop_function(t);
- SwigType_push(return_type, t);
- Delete(f);
- Delete(t);
- }
-
- /* virtual method definition */
- l = Getattr(n, "parms");
- String *target;
- String *pclassname = NewStringf("SwigDirector_%s", classname);
- String *qualified_name = NewStringf("%s::%s", pclassname, name);
- SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
- target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
- Printf(w->def, "%s {", target);
- Delete(qualified_name);
- Delete(target);
- /* header declaration */
- target = Swig_method_decl(rtype, decl, name, l, 0, 1);
- Printf(declaration, " virtual %s;", target);
- Delete(target);
-
- /* declare method return value
- * if the return value is a reference or const reference, a specialized typemap must
- * handle it, including declaration of c_result ($result).
- */
- if (!is_void) {
- if (!(ignored_method && !pure_virtual)) {
- Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL);
- }
- }
-
- if (ignored_method) {
- if (!pure_virtual) {
- if (!is_void)
- Printf(w->code, "return ");
- String *super_call = Swig_method_call(super, l);
- Printf(w->code, "%s;\n", super_call);
- Delete(super_call);
- } else {
- Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
- SwigType_namestr(name));
- }
- } else {
- /* attach typemaps to arguments (C/C++ -> Ocaml) */
- String *arglist = NewString("");
-
- Swig_typemap_attach_parms("in", l, 0);
- Swig_typemap_attach_parms("directorin", l, 0);
- Swig_typemap_attach_parms("directorargout", l, w);
-
- Parm *p;
- int num_arguments = emit_num_arguments(l);
- int i;
- char source[256];
-
- int outputs = 0;
- if (!is_void)
- outputs++;
-
- /* build argument list and type conversion string */
- for (i = 0, idx = 0, p = l; i < num_arguments; i++) {
-
- while (Getattr(p, "tmap:ignore")) {
- p = Getattr(p, "tmap:ignore:next");
- }
-
- if (Getattr(p, "tmap:directorargout") != 0)
- outputs++;
-
- String *pname = Getattr(p, "name");
- String *ptype = Getattr(p, "type");
-
- Putc(',', arglist);
- if ((tm = Getattr(p, "tmap:directorin")) != 0) {
- Replaceall(tm, "$input", pname);
- Replaceall(tm, "$owner", "0");
- if (Len(tm) == 0)
- Append(tm, pname);
- Printv(wrap_args, tm, "\n", NIL);
- p = Getattr(p, "tmap:directorin:next");
- continue;
- } else if (Cmp(ptype, "void")) {
- /* special handling for pointers to other C++ director classes.
- * ideally this would be left to a typemap, but there is currently no
- * way to selectively apply the dynamic_cast<> to classes that have
- * directors. in other words, the type "SwigDirector_$1_lname" only exists
- * for classes with directors. we avoid the problem here by checking
- * module.wrap::directormap, but it's not clear how to get a typemap to
- * do something similar. perhaps a new default typemap (in addition
- * to SWIGTYPE) called DIRECTORTYPE?
- */
- if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
- Node *module = Getattr(parent, "module");
- Node *target = Swig_directormap(module, ptype);
- sprintf(source, "obj%d", idx++);
- String *nonconst = 0;
- /* strip pointer/reference --- should move to Swig/stype.c */
- String *nptype = NewString(Char(ptype) + 2);
- /* name as pointer */
- String *ppname = Copy(pname);
- if (SwigType_isreference(ptype)) {
- Insert(ppname, 0, "&");
- }
- /* if necessary, cast away const since Python doesn't support it! */
- if (SwigType_isconst(nptype)) {
- nonconst = NewStringf("nc_tmp_%s", pname);
- String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
- Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
- Delete(nonconst_i);
- Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
- "Target language argument '%s' discards const in director method %s::%s.\n", SwigType_str(ptype, pname),
- SwigType_namestr(c_classname), SwigType_namestr(name));
- } else {
- nonconst = Copy(ppname);
- }
- Delete(nptype);
- Delete(ppname);
- String *mangle = SwigType_manglestr(ptype);
- if (target) {
- String *director = NewStringf("director_%s", mangle);
- Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
- Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL);
- Printf(wrap_args, "%s = dynamic_cast<Swig::Director *>(%s);\n", director, nonconst);
- Printf(wrap_args, "if (!%s) {\n", director);
- Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- Printf(wrap_args, "} else {\n");
- Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
- Printf(wrap_args, "}\n");
- Delete(director);
- Printv(arglist, source, NIL);
- } else {
- Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL);
- Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
- // source, nonconst, base);
- Printv(arglist, source, NIL);
- }
- Delete(mangle);
- Delete(nonconst);
- } else {
- Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
- "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
- SwigType_namestr(c_classname), SwigType_namestr(name));
- status = SWIG_NOWRAP;
- break;
- }
- }
- p = nextSibling(p);
- }
-
- Printv(w->code, "swig_result = Val_unit;\n", 0);
- Printf(w->code, "args = Val_unit;\n");
-
- /* wrap complex arguments to values */
- Printv(w->code, wrap_args, NIL);
-
- /* pass the method call on to the Python object */
- Printv(w->code,
- "swig_result = caml_swig_alloc(1,C_list);\n" "SWIG_Store_field(swig_result,0,args);\n" "args = swig_result;\n" "swig_result = Val_unit;\n", 0);
- Printf(w->code, "swig_result = " "callback3(*caml_named_value(\"swig_runmethod\")," "swig_get_self(),copy_string(\"%s\"),args);\n", Getattr(n, "name"));
- /* exception handling */
- tm = Swig_typemap_lookup("director:except", n, "result", 0);
- if (!tm) {
- tm = Getattr(n, "feature:director:except");
- }
- if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
- Printf(w->code, "if (result == NULL) {\n");
- Printf(w->code, " CAML_VALUE error = *caml_named_value(\"director_except\");\n");
- Replaceall(tm, "$error", "error");
- Printv(w->code, Str(tm), "\n", NIL);
- Printf(w->code, "}\n");
- }
-
- /*
- * Python method may return a simple object, or a tuple.
- * for in/out aruments, we have to extract the appropriate values from the
- * argument list, then marshal everything back to C/C++ (return value and
- * output arguments).
- */
-
- /* marshal return value and other outputs (if any) from value to C/C++
- * type */
-
- String *cleanup = NewString("");
- String *outarg = NewString("");
-
- idx = 0;
-
- /* this seems really silly. the node's type excludes
- * qualifier/pointer/reference markers, which have to be retrieved
- * from the decl field to construct return_type. but the typemap
- * lookup routine uses the node's type, so we have to swap in and
- * out the correct type. it's not just me, similar silliness also
- * occurs in Language::cDeclaration().
- */
- Setattr(n, "type", return_type);
- tm = Swig_typemap_lookup("directorout", n, "c_result", w);
- Setattr(n, "type", type);
- if (tm != 0) {
- Replaceall(tm, "$input", "swig_result");
- /* TODO check this */
- if (Getattr(n, "wrap:disown")) {
- Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
- } else {
- Replaceall(tm, "$disown", "0");
- }
- Replaceall(tm, "$result", "c_result");
- Printv(w->code, tm, "\n", NIL);
- }
-
- /* marshal outputs */
- for (p = l; p;) {
- if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
- Replaceall(tm, "$input", "swig_result");
- Replaceall(tm, "$result", Getattr(p, "name"));
- Printv(w->code, tm, "\n", NIL);
- p = Getattr(p, "tmap:directorargout:next");
- } else {
- p = nextSibling(p);
- }
- }
-
- Delete(arglist);
- Delete(cleanup);
- Delete(outarg);
- }
-
- /* any existing helper functions to handle this? */
- if (!is_void) {
- if (!(ignored_method && !pure_virtual)) {
- /* A little explanation:
- * The director_enum test case makes a method whose return type
- * is an enum type. return_type here is "int". gcc complains
- * about an implicit enum conversion, and although i don't strictly
- * agree with it, I'm working on fixing the error:
- *
- * Below is what I came up with. It's not great but it should
- * always essentially work.
- */
- if (!SwigType_isreference(return_type)) {
- Printf(w->code, "CAMLreturn_type((%s)c_result);\n", SwigType_lstr(return_type, ""));
- } else {
- Printf(w->code, "CAMLreturn_type(*c_result);\n");
- }
- }
- }
-
- Printf(w->code, "}\n");
-
- // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
- String *inline_extra_method = NewString("");
- if (dirprot_mode() && !is_public(n) && !pure_virtual) {
- Printv(inline_extra_method, declaration, NIL);
- String *extra_method_name = NewStringf("%sSwigPublic", name);
- Replaceall(inline_extra_method, name, extra_method_name);
- Replaceall(inline_extra_method, ";\n", " {\n ");
- if (!is_void)
- Printf(inline_extra_method, "return ");
- String *methodcall = Swig_method_call(super, l);
- Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
- Delete(methodcall);
- Delete(extra_method_name);
- }
-
- /* emit the director method */
- if (status == SWIG_OK) {
- if (!Getattr(n, "defaultargs")) {
- Wrapper_print(w, f_directors);
- Printv(f_directors_h, declaration, NIL);
- Printv(f_directors_h, inline_extra_method, NIL);
- }
- }
-
- /* clean up */
- Delete(wrap_args);
- Delete(return_type);
- Delete(pclassname);
- DelWrapper(w);
- return status;
- }
-
- /* ------------------------------------------------------------
- * classDirectorConstructor()
- * ------------------------------------------------------------ */
-
- int classDirectorConstructor(Node *n) {
- Node *parent = Getattr(n, "parentNode");
- String *sub = NewString("");
- String *decl = Getattr(n, "decl");
- String *supername = Swig_class_name(parent);
- String *classname = NewString("");
- Printf(classname, "SwigDirector_%s", supername);
-
- /* insert self parameter */
- Parm *p, *q;
- ParmList *superparms = Getattr(n, "parms");
- ParmList *parms = CopyParmList(superparms);
- String *type = NewString("CAML_VALUE");
- p = NewParm(type, NewString("self"));
- q = Copy(p);
- set_nextSibling(q, superparms);
- set_nextSibling(p, parms);
- parms = p;
-
- if (!Getattr(n, "defaultargs")) {
- /* constructor */
- {
- Wrapper *w = NewWrapper();
- String *call;
- String *basetype = Getattr(parent, "classtype");
- String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
- call = Swig_csuperclass_call(0, basetype, superparms);
- Printf(w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call);
- Delete(target);
- Wrapper_print(w, f_directors);
- Delete(call);
- DelWrapper(w);
- }
-
- /* constructor header */
- {
- String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
- Printf(f_directors_h, " %s;\n", target);
- Delete(target);
- }
- }
-
- Setattr(n, "parms", q);
- Language::classDirectorConstructor(n);
-
- Delete(sub);
- Delete(classname);
- Delete(supername);
- //Delete(parms);
+ return SWIG_OK;
+}
- return SWIG_OK;
- }
+////////////////////////////////
+// IMPLEMENTING CLASS WRAPPER //
+////////////////////////////////
- /* ------------------------------------------------------------
- * classDirectorDefaultConstructor()
- * ------------------------------------------------------------ */
-
- int classDirectorDefaultConstructor(Node *n) {
- String *classname;
- classname = Swig_class_name(n);
-
- /* insert self parameter */
- Parm *p, *q;
- ParmList *superparms = Getattr(n, "parms");
- ParmList *parms = CopyParmList(superparms);
- String *type = NewString("CAML_VALUE");
- p = NewParm(type, NewString("self"));
- q = Copy(p);
- set_nextSibling(p, parms);
- parms = p;
-
- {
- Wrapper *w = NewWrapper();
- Printf(w->def, "SwigDirector_%s::SwigDirector_%s(CAML_VALUE self) : Swig::Director(self) { }", classname, classname);
- Wrapper_print(w, f_directors);
- DelWrapper(w);
- }
- Printf(f_directors_h, " SwigDirector_%s(CAML_VALUE self);\n", classname);
- Delete(classname);
- Setattr(n, "parms", q);
- return Language::classDirectorDefaultConstructor(n);
- }
+int OCAML::classHandler (Node * n) {
- int classDirectorInit(Node *n) {
- String *declaration = Swig_director_declaration(n);
- Printf(f_directors_h, "\n" "%s\n" "public:\n", declaration);
- Delete(declaration);
- return Language::classDirectorInit(n);
- }
+ // Error handling if symbols/names collide.
+ proxy_class_name = NewString(Getattr(n, "sym:name"));
+ if (!addSymbol(proxy_class_name, n))
+ return SWIG_ERROR;
- int classDirectorEnd(Node *n) {
- Printf(f_directors_h, "};\n\n");
- return Language::classDirectorEnd(n);
- }
+ // OCaml submodule: low-level type declaration.
+ // This declares the type of an OCaml-wrapped pointer
+ // to a C++ object instantiated from this class.
+ Printf(f_mlcdecl, " type %s\n", proxy_class_name);
- /* ---------------------------------------------------------------------
- * typedefHandler
- *
- * This is here in order to maintain the correct association between
- * typedef names and enum names.
- *
- * Since I implement enums as polymorphic variant tags, I need to call
- * back into ocaml to evaluate them. This requires a string that can
- * be generated in the typemaps, and also at SWIG time to be the same
- * string. The problem that arises is that SWIG variously generates
- * enum e_name_tag
- * e_name_tag
- * e_typedef_name
- * for
- * typedef enum e_name_tag { ... } e_typedef_name;
- *
- * Since I need these strings to be consistent, I must maintain a correct
- * association list between typedef and enum names.
- * --------------------------------------------------------------------- */
- int typedefHandler(Node *n) {
- String *type = Getattr(n, "type");
- Node *enum_node = type ? Getattr(seen_enums, type) : 0;
- if (enum_node) {
- String *name = Getattr(enum_node, "name");
-
- Printf(f_mlbody, "let _ = Callback.register \"%s_marker\" (`%s)\n", Getattr(n, "name"), name);
+ // Initialisation of the String containing the virtual
+ // and concrete class declarations.
+ f_mlbody_virtualclass = NewString("");
+ f_mlbody_concreteclass = NewString("");
+ Printf(f_mlbody_virtualclass, "class virtual %s = object(self)\n", proxy_class_name);
+ Printf(f_mlbody_virtualclass, " val virtual underlying_cpp_object : Swig.%s\n", proxy_class_name);
- }
- return SWIG_OK;
- }
+ // We are wrapping a class. Set classmode to true.
+ classmode = true;
- String *runtimeCode() {
- String *s = Swig_include_sys("ocaml.swg");
- if (!s) {
- Printf(stderr, "*** Unable to open 'ocaml.swg'\n");
- s = NewString("");
- }
- return s;
- }
+ // Recursing throughout the node's children.
+ Language::classHandler(n);
- String *defaultExternalRuntimeFilename() {
- return NewString("swigocamlrun.h");
- }
-};
+ // We are not wrapping a class anymore. Set classmode
+ // to false.
+ classmode = false;
-/* -------------------------------------------------------------------------
- * swig_ocaml() - Instantiate module
- * ------------------------------------------------------------------------- */
+ // Finishing the virtual class declaration, and dumping
+ // everything to f_mlbody.
+ Printf(f_mlbody_virtualclass, "end;;\n");
+ Printv(f_mlbody, f_mlbody_virtualclass, f_mlbody_concreteclass, NIL);
+ Delete(f_mlbody_virtualclass);
+ Delete(f_mlbody_concreteclass);
-static Language *new_swig_ocaml() {
- return new OCAML();
+ return SWIG_OK;
}
-extern "C" Language *swig_ocaml(void) {
- return new_swig_ocaml();
+
+// Basically, this handler's purpose is to toggle the
+// in_constructor value on/off...
+int OCAML::constructorHandler (Node * n) {
+ int ret;
+ in_constructor = true;
+ ret = Language::constructorHandler(n);
+ in_constructor = false;
+ return ret;
}