Skip to content

Instantly share code, notes, and snippets.

@joelreymont
Created January 5, 2011 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelreymont/766233 to your computer and use it in GitHub Desktop.
Save joelreymont/766233 to your computer and use it in GitHub Desktop.
This patch updates the OCaml portion of the SWIG trunk (2.0.2) to work with OCaml 3.12
From b44f800bb40aa94b1c013f32b629ba989dc52e4a Mon Sep 17 00:00:00 2001
From: wagerlabs <joelr1@gmail.com>
Date: Tue, 4 Jan 2011 17:57:36 +0000
Subject: [PATCH] update for ocaml 3.12
---
trunk/Examples/Makefile.in | 14 +-
trunk/Examples/ocaml/argout_ref/example.i | 4 +
trunk/Examples/ocaml/std_string/README | 6 +
trunk/Examples/ocaml/strings_test/example.h | 18 ++-
trunk/Examples/ocaml/strings_test/example.i | 4 +
trunk/Lib/ocaml/std_string.i | 182 ++++++++------------
trunk/Lib/ocaml/swigp4.ml.in | 249 ++++++++++++++-------------
trunk/Lib/ocaml/typemaps.i | 11 ++
8 files changed, 245 insertions(+), 243 deletions(-)
diff --git a/trunk/Examples/Makefile.in b/trunk/Examples/Makefile.in
index b23fcce..32eaecc 100644
--- a/trunk/Examples/Makefile.in
+++ b/trunk/Examples/Makefile.in
@@ -632,7 +632,7 @@ ocaml_static_cpp: $(SRCS)
$(OCAMLCORE)
$(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH)
cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
- $(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
+ $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
$(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS)
$(OCC) -g -c $(INTERFACE:%.i=%.mli)
$(OCC) -g -c $(INTERFACE:%.i=%.ml)
@@ -643,13 +643,13 @@ ocaml_static_cpp: $(SRCS)
$(INTERFACE:%.i=%.cmo) \
$(PROGFILE:%.ml=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
- -cclib "$(LIBS)" -cc '$(CXX)'
+ -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings'
ocaml_static_cpp_toplevel: $(SRCS)
$(OCAMLCORE)
$(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH)
cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
- $(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
+ $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
$(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS)
$(OCC) -g -c $(INTERFACE:%.i=%.mli)
$(OCC) -g -c $(INTERFACE:%.i=%.ml)
@@ -657,17 +657,17 @@ ocaml_static_cpp_toplevel: $(SRCS)
$(OCC) $(OCAMLPP) -c $(PROGFILE)
$(NOLINK) || $(OCAMLMKTOP) \
swig.cmo \
- -I $(OCAMLP4WHERE) camlp4o.cma swigp4.cmo \
+ -I $(OCAMLP4WHERE) dynlink.cma camlp4o.cma swigp4.cmo \
-g -ccopt -g -cclib -g -custom -o $(TARGET)_top \
$(INTERFACE:%.i=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
- -cclib "$(LIBS)" -cc '$(CXX)'
+ -cclib "$(LIBS)" -cc '$(CXX) -Wno-write-strings'
ocaml_dynamic_cpp: $(SRCS)
$(OCAMLCORE)
$(SWIG) -ocaml -c++ $(SWIGOPT) $(INTERFACEPATH)
cp $(ICXXSRCS) $(ICXXSRCS:%.cxx=%.c)
- $(OCC) -cc '$(CXX)' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
+ $(OCC) -cc '$(CXX) -Wno-write-strings' -g -c -ccopt -g -ccopt "-xc++ $(INCLUDES)" \
$(ICXXSRCS:%.cxx=%.c) $(SRCS) $(CXXSRCS) -ccopt -fPIC
$(CXXSHARED) $(CFLAGS) -o $(INTERFACE:%.i=%@SO@) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
@@ -684,7 +684,7 @@ ocaml_dynamic_cpp: $(SRCS)
$(OCC) -cclib -export-dynamic -g -ccopt -g -cclib -g -custom \
-o $(TARGET) \
-package dl -linkpkg \
- $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX)'
+ $(INTERFACE:%.i=%.cmo) $(PROGFILE:%.ml=%.cmo) -cc '$(CXX) -Wno-write-strings'
ocaml_clean:
rm -f *_wrap* *~ .~* *.cmo *.cmi $(MLFILE) $(MLFILE)i swig.mli swig.cmi swig.ml swig.cmo swigp4.ml swigp4.cmo
diff --git a/trunk/Examples/ocaml/argout_ref/example.i b/trunk/Examples/ocaml/argout_ref/example.i
index a0be05f..5ea6777 100644
--- a/trunk/Examples/ocaml/argout_ref/example.i
+++ b/trunk/Examples/ocaml/argout_ref/example.i
@@ -1,4 +1,8 @@
/* File : example.i */
%module example
+%{
+extern "C" void factor(int &x, int &y);
+%}
+
extern "C" void factor(int &x, int &y);
diff --git a/trunk/Examples/ocaml/std_string/README b/trunk/Examples/ocaml/std_string/README
index 5665530..ccebecb 100644
--- a/trunk/Examples/ocaml/std_string/README
+++ b/trunk/Examples/ocaml/std_string/README
@@ -1,3 +1,9 @@
+--- New ---
+
+It's not possible to access std::(w)string at the moment as it breaks other string examples.
+
+--- Old ---
+
This example shows how to use both std::string and std::wstring in Ocaml,
and also demonstrates that one might use this to make a locale-obedient
Ocaml program.
diff --git a/trunk/Examples/ocaml/strings_test/example.h b/trunk/Examples/ocaml/strings_test/example.h
index 3417981..959404b 100644
--- a/trunk/Examples/ocaml/strings_test/example.h
+++ b/trunk/Examples/ocaml/strings_test/example.h
@@ -1,14 +1,18 @@
/* -*- mode: c++ -*- */
/* File : example.h -- Tests all string typemaps */
+#include <sys/time.h>
+#include <time.h>
+
void takes_std_string( std::string in ) {
cout << "takes_std_string( \"" << in << "\" );" << endl;
}
std::string gives_std_string() {
- time_t t;
-
- return std::string( asctime( localtime( &t ) ) );
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ return std::string( asctime( localtime( &tv.tv_sec ) ) );
}
void takes_char_ptr( char *p ) {
@@ -24,10 +28,10 @@ void takes_and_gives_std_string( std::string &inout ) {
inout.insert( inout.end(), ']' );
}
-void takes_and_gives_char_ptr( char *&ptr ) {
- char *pout = strchr( ptr, '.' );
- if( pout ) ptr = pout + 1;
- else ptr = "foo";
+void takes_and_gives_char_ptr( char *&inout ) {
+ char *pout = strchr( inout, '.' );
+ if( pout ) inout = pout + 1;
+ else inout = "foo";
}
/*
diff --git a/trunk/Examples/ocaml/strings_test/example.i b/trunk/Examples/ocaml/strings_test/example.i
index be9eabf..31a4615 100644
--- a/trunk/Examples/ocaml/strings_test/example.i
+++ b/trunk/Examples/ocaml/strings_test/example.i
@@ -11,4 +11,8 @@ using std::string;
#include "example.h"
%}
+%include stl.i
+
+%feature("director");
+
%include example.h
diff --git a/trunk/Lib/ocaml/std_string.i b/trunk/Lib/ocaml/std_string.i
index e75e953..eeaf560 100644
--- a/trunk/Lib/ocaml/std_string.i
+++ b/trunk/Lib/ocaml/std_string.i
@@ -11,141 +11,97 @@
// 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 <exception.i>
%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");
- }
- }
+%naturalvar string;
+%naturalvar wstring;
+
+class string;
+class wstring;
+
+/* Overloading check */
+%typemap(in) string {
+ /* %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) 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) const string & (std::string temp) {
+ /* %typemap(in) const string & */
+ 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(in) string & (std::string temp) {
+ /* %typemap(in) string & */
+ 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(free) string * (std::string *temp) {
+%typemap(in) string * (std::string *temp) {
+ /* %typemap(in) string * */
+ 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(argout) string & {
+ /* %typemap(argout) string & */
+ swig_result = caml_list_append(swig_result,caml_val_string_len((*$1).c_str(),
+ (*$1).size()));
+}
- %typemap(directorout) string {
+%typemap(directorout) string {
+ /* %typemap(directorout) string */
$result.assign((char *)caml_ptr_val($input,0),
- caml_string_len($input));
- }
+ caml_string_len($input));
+}
- %typemap(out) string {
- $result = caml_val_string_len($1.c_str(),$1.size());
- }
+%typemap(out) string {
+ /* %typemap(out) string */
+ $result = caml_val_string_len($1.c_str(),$1.size());
+}
- %typemap(out) string * {
+%typemap(out) string * {
+ /* %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 );
+char **c_charptr_array( const std::vector <std::string > &str_v );
%{
- SWIGEXT char **c_charptr_array( const std::vector <string > &str_v ) {
+ SWIGEXT char **c_charptr_array( const std::vector <std::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++ ) {
@@ -157,7 +113,7 @@ char **c_charptr_array( const std::vector <string > &str_v );
#endif
#ifdef ENABLE_STRING_VECTOR
-%template (StringVector) std::vector<string >;
+%template (StringVector) std::vector<std::string >;
%insert(ml) %{
(* Some STL convenience items *)
diff --git a/trunk/Lib/ocaml/swigp4.ml.in b/trunk/Lib/ocaml/swigp4.ml.in
index 0387c0a..2f6074a 100644
--- a/trunk/Lib/ocaml/swigp4.ml.in
+++ b/trunk/Lib/ocaml/swigp4.ml.in
@@ -1,118 +1,135 @@
-open Pcaml ;;
+open Camlp4
+
+module Id : Sig.Id =
+struct
+ let name = "swigp4"
+ let version = "0.1"
+end
+
+module Make (Syntax : Sig.Camlp4Syntax) =
+struct
+ open Sig
+ include Syntax
-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$))) >>
+ let _loc = Loc.ghost
+ let lap x y = x :: y
+ let c_ify e loc =
+ 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 loc f =
+ let rec mk_list_inner args loc f =
+ match args with
+ [] -> <:expr< [] >>
+ | x :: xs ->
+ (let loc = Ast.loc_of_expr x in
+ <:expr< [ ($f x _loc$) ] @ ($mk_list_inner xs loc f$) >>) in
+ match args with
+ [] -> <:expr< (Obj.magic C_void) >>
+ | [ a ] -> <:expr< (Obj.magic $f a _loc$) >>
+ | _ -> <:expr< (Obj.magic (C_list ($mk_list_inner args loc f$))) >> ;;
+
+ EXTEND Gram
+ GLOBAL: expr;
-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 ;;
-
+ expr: LEVEL "top"
+ [ [ e1 = expr ; "'" ; "[" ; e2 = expr ; "]" ->
+ <:expr< (invoke $e1$) "[]" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
+ <:expr< (invoke $e1$) $str:l$ ($mk_list args _loc c_ify$) >>
+ | e1 = expr ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
+ <:expr< (invoke $e1$) $str:u$ ($mk_list args _loc c_ify$) >>
+ | e1 = expr ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
+ <:expr< (invoke $e1$) $s$ ($mk_list args _loc c_ify$) >>
+ | e1 = expr ; "'" ; "." ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
+ <:expr< (invoke $e1$) "()" ($mk_list args _loc c_ify$) >>
+ | e1 = expr ; "'" ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
+ <:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ ($mk_list args _loc c_ify$) >>
+ | e1 = expr ; "'" ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
+ <:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ ($mk_list args _loc c_ify$) >>
+ | e1 = expr ; "'" ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
+ <:expr< (invoke ((invoke $e1$) "->" C_void)) $s$ ($mk_list args _loc 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 _loc$ ]) >>
+ | e1 = expr ; "'" ; "+" ; e2 = expr -> <:expr< (invoke $e1$) "+" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "*" ; e2 = expr -> <:expr< (invoke $e1$) "*" (C_list [ $c_ify e2 _loc$ ]) >>
+ | "'" ; "&" ; 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 _loc$ ]) >>
+ | e1 = expr ; "'" ; "%" ; e2 = expr ->
+ <:expr< (invoke $e1$) "%" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "lsl" ; e2 = expr ->
+ <:expr< (invoke $e1$) ("<" ^ "<") (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "lsr" ; e2 = expr ->
+ <:expr< (invoke $e1$) (">" ^ ">") (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "<" ; e2 = expr ->
+ <:expr< (invoke $e1$) "<" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "<=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "<=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; ">" ; e2 = expr ->
+ <:expr< (invoke $e1$) ">" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; ">=" ; e2 = expr ->
+ <:expr< (invoke $e1$) ">=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "==" ; e2 = expr ->
+ <:expr< (invoke $e1$) "==" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "!=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "!=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "&" ; e2 = expr ->
+ <:expr< (invoke $e1$) "&" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "^" ; e2 = expr ->
+ <:expr< (invoke $e1$) "^" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "|" ; e2 = expr ->
+ <:expr< (invoke $e1$) "|" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "&&" ; e2 = expr ->
+ <:expr< (invoke $e1$) "&&" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "||" ; e2 = expr ->
+ <:expr< (invoke $e1$) "||" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "+=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "+=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "-=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "-=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "*=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "*=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "/=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "/=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "%=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "%=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "lsl" ; "=" ; e2 = expr ->
+ <:expr< (invoke $e1$) ("<" ^ "<=") (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "lsr" ; "=" ; e2 = expr ->
+ <:expr< (invoke $e1$) (">" ^ ">=") (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "&=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "&=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "^=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "^=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | e1 = expr ; "'" ; "|=" ; e2 = expr ->
+ <:expr< (invoke $e1$) "|=" (C_list [ $c_ify e2 _loc$ ]) >>
+ | "'" ; e = expr -> c_ify e _loc
+ | 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 _loc c_ify$) >>
+ ] ] ;
+ END ;;
+
+end
+
+module M = Register.OCamlSyntaxExtension(Id)(Make)
diff --git a/trunk/Lib/ocaml/typemaps.i b/trunk/Lib/ocaml/typemaps.i
index e5458a3..4365785 100644
--- a/trunk/Lib/ocaml/typemaps.i
+++ b/trunk/Lib/ocaml/typemaps.i
@@ -82,6 +82,17 @@
}
}
+%typemap(in) char * & (char* temp) {
+ /* %typemap(in) char * & */
+ temp = (char*)caml_val_ptr($1,$descriptor);
+ $1 = &temp;
+}
+
+%typemap(argout) char * & {
+ /* %typemap(argout) char * & */
+ swig_result = caml_list_append(swig_result,caml_val_string_len(*$1, strlen(*$1)));
+}
+
#else
%typemap(in) SWIGTYPE {
--
1.7.3.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment