diff options
Diffstat (limited to 'share/swig/2.0.11/go')
-rw-r--r-- | share/swig/2.0.11/go/cdata.i | 64 | ||||
-rw-r--r-- | share/swig/2.0.11/go/exception.i | 7 | ||||
-rw-r--r-- | share/swig/2.0.11/go/go.swg | 541 | ||||
-rw-r--r-- | share/swig/2.0.11/go/gokw.swg | 33 | ||||
-rw-r--r-- | share/swig/2.0.11/go/goruntime.swg | 218 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_common.i | 4 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_deque.i | 1 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_except.i | 29 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_list.i | 40 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_map.i | 60 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_pair.i | 34 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_string.i | 55 | ||||
-rw-r--r-- | share/swig/2.0.11/go/std_vector.i | 78 | ||||
-rw-r--r-- | share/swig/2.0.11/go/stl.i | 9 | ||||
-rw-r--r-- | share/swig/2.0.11/go/typemaps.i | 292 |
15 files changed, 1465 insertions, 0 deletions
diff --git a/share/swig/2.0.11/go/cdata.i b/share/swig/2.0.11/go/cdata.i new file mode 100644 index 0000000..0dac642 --- /dev/null +++ b/share/swig/2.0.11/go/cdata.i @@ -0,0 +1,64 @@ +/* ----------------------------------------------------------------------------- + * cdata.i + * + * SWIG library file containing macros for manipulating raw C data as strings. + * ----------------------------------------------------------------------------- */ + +%{ +typedef struct SWIGCDATA { + char *data; + int len; +} SWIGCDATA; +%} + +%typemap(gotype) SWIGCDATA %{ []byte %} +%typemap(out) SWIGCDATA %{ + $result.data = (char*)_swig_goallocate($1.len); + memcpy($result.data, $1.data, $1.len); + $result.len = (int)$1.len; +%} + +/* ----------------------------------------------------------------------------- + * %cdata(TYPE [, NAME]) + * + * Convert raw C data to a binary string. + * ----------------------------------------------------------------------------- */ + +%define %cdata(TYPE,NAME...) + +%insert("header") { +#if #NAME == "" +static SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements) { +#else +static SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements) { +#endif + SWIGCDATA d; + d.data = (char *) ptr; +#if #TYPE != "void" + d.len = nelements*sizeof(TYPE); +#else + d.len = nelements; +#endif + return d; +} +} + +%typemap(default) int nelements "$1 = 1;" + +#if #NAME == "" +SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements); +#else +SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements); +#endif +%enddef + +%typemap(default) int nelements; + +%rename(cdata) ::cdata_void(void *ptr, int nelements); + +%cdata(void); + +/* Memory move function. Due to multi-argument typemaps this appears + to be wrapped as + void memmove(void *data, const char *s); */ +void memmove(void *data, char *indata, int inlen); diff --git a/share/swig/2.0.11/go/exception.i b/share/swig/2.0.11/go/exception.i new file mode 100644 index 0000000..5abd306 --- /dev/null +++ b/share/swig/2.0.11/go/exception.i @@ -0,0 +1,7 @@ +%typemap(throws,noblock=1) (...) { + SWIG_exception(SWIG_RuntimeError,"unknown exception"); +} + +%insert("runtime") %{ +#define SWIG_exception(code, msg) _swig_gopanic(msg) +%} diff --git a/share/swig/2.0.11/go/go.swg b/share/swig/2.0.11/go/go.swg new file mode 100644 index 0000000..cc3beef --- /dev/null +++ b/share/swig/2.0.11/go/go.swg @@ -0,0 +1,541 @@ +/* ------------------------------------------------------------ + * go.swg + * + * Go configuration module. + * ------------------------------------------------------------ */ + +/* Basic types */ + +%typemap(gotype) bool, const bool & "bool" +%typemap(gotype) char, const char & "byte" +%typemap(gotype) signed char, const signed char & "int8" +%typemap(gotype) unsigned char, const unsigned char & "byte" +%typemap(gotype) short, const short & "int16" +%typemap(gotype) unsigned short, const unsigned short & "uint16" +%typemap(gotype) int, const int & "int" +%typemap(gotype) unsigned int, const unsigned int & "uint" +#if SWIGGO_LONG_TYPE_SIZE == 32 +%typemap(gotype) long, const long & "int32" +%typemap(gotype) unsigned long, const unsigned long & "uint32" +#elif SWIGGO_LONG_TYPE_SIZE == 64 +%typemap(gotype) long, const long & "int64" +%typemap(gotype) unsigned long, const unsigned long & "uint64" +#else +#error "SWIGGO_LONG_TYPE_SIZE not 32 or 64" +#endif +%typemap(gotype) long long, const long long & "int64" +%typemap(gotype) unsigned long long, const unsigned long long & "uint64" +%typemap(gotype) float, const float & "float32" +%typemap(gotype) double, const double & "float64" + +%typemap(in) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $1 = ($1_ltype)$input; %} + +%typemap(in) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ $1 = ($1_ltype)&$input; %} + +%typemap(out) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $result = $1; %} + +%typemap(out) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ $result = ($*1_ltype)*$1; %} + +%typemap(out) void "" + +%typemap(directorin) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $input = ($1_ltype)$1; %} + +%typemap(directorin) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ $input = ($*1_ltype)$1; %} + +%typemap(directorout) bool, + char, + signed char, + unsigned char, + short, + unsigned short, + int, + unsigned int, + long, + unsigned long, + long long, + unsigned long long, + float, + double +%{ $result = ($1_ltype)$input; %} + +%typemap(directorout) const bool &, + const char &, + const signed char &, + const unsigned char &, + const short &, + const unsigned short &, + const int &, + const unsigned int &, + const long &, + const unsigned long &, + const long long &, + const unsigned long long &, + const float &, + const double & +%{ + $result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype)); + *$result = *($1_ltype)&$input; +%} + +/* The size_t type. */ + +#if SWIGGO_LONG_TYPE_SIZE == 32 +%typemap(gotype) size_t, const size_t & %{int%} +#else +%typemap(gotype) size_t, const size_t & %{int64%} +#endif + +%typemap(in) size_t +%{ $1 = (size_t)$input; %} + +%typemap(in) const size_t & +%{ $1 = ($1_ltype)&$input; %} + +%typemap(out) size_t +%{ $result = $1; %} + +%typemap(out) const size_t & +%{ $result = ($*1_ltype)*$1; %} + +%typemap(directorin) size_t +%{ $input = (size_t)$1; %} + +%typemap(directorin) const size_t & +%{ $input = ($*1_ltype)$1; %} + +%typemap(directorout) size_t +%{ $result = ($1_ltype)$input; %} + +%typemap(directorout) const size_t & +%{ + $result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype)); + *$result = *($1_ltype)$input; +%} + +/* Member pointers. */ + +%typemap(gotype) SWIGTYPE (CLASS::*) +%{$gotypename%} + +%typemap(in) SWIGTYPE (CLASS::*) +%{ $1 = *($&1_ltype)$input; %} + +%typemap(out) SWIGTYPE (CLASS::*) +%{ + $result = _swig_goallocate(sizeof($1_ltype)); + *($&1_ltype)$result = $1; +%} + +%typemap(directorin) SWIGTYPE (CLASS::*) +%{ $input = *($&1_ltype)$1; %} + +%typemap(directorout) SWIGTYPE (CLASS::*) +%{ + $result = _swig_goallocate(sizeof($1_ltype)); + *($&1_ltype)$result = $input; +%} + +/* Pointers. */ + +/* We can't translate pointers using a typemap, so that is handled in + the C++ code. */ +%typemap(gotype) SWIGTYPE * +%{$gotypename%} + +%typemap(in) SWIGTYPE * +%{ $1 = *($&1_ltype)&$input; %} + +%typemap(out) SWIGTYPE * +%{ *($&1_ltype)&$result = $1; %} + +%typemap(directorin) SWIGTYPE * +%{ $input = ($1_ltype)$1; %} + +%typemap(directorout) SWIGTYPE * +%{ $result = ($1_ltype)$input; %} + +%apply SWIGTYPE * { SWIGTYPE *const } + +/* Pointer references. */ + +%typemap(gotype) SWIGTYPE *const& +%{$gotypename%} + +%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) +%{ + temp = *($1_ltype)&$input; + $1 = ($1_ltype)&temp; +%} + +%typemap(out) SWIGTYPE *const& +%{ *($1_ltype)&$result = *$1; %} + +/* References. */ + +/* Converting a C++ reference to Go has to be handled in the C++ + code. */ +%typemap(gotype) SWIGTYPE & +%{$gotypename%} + +%typemap(in) SWIGTYPE & +%{ $1 = *($&1_ltype)&$input; %} + +%typemap(out) SWIGTYPE & +%{ *($&1_ltype)&$result = $1; %} + +%typemap(directorin) SWIGTYPE & +%{ $input = ($1_ltype)&$1; %} + +%typemap(directorout) SWIGTYPE & +%{ *($&1_ltype)&$result = $input; %} + +/* C arrays turn into Go pointers. If we know the length we can use a + slice. */ + +%typemap(gotype) SWIGTYPE [] +%{$gotypename%} + +%typemap(in) SWIGTYPE [] +%{ $1 = *($&1_ltype)&$input; %} + +%typemap(out) SWIGTYPE [] +%{ *($&1_ltype)&$result = $1; %} + +%typemap(directorin) SWIGTYPE [] +%{ $input = *($1_ltype)&$1; %} + +%typemap(directorout) SWIGTYPE [] +%{ *($&1_ltype)&$result = $input; %} + +/* Strings. */ + +%typemap(gotype) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +"string" + +/* Needed to avoid confusion with the way the go module handles + references. */ +%typemap(gotype) char&, unsigned char& "*byte" +%typemap(gotype) signed char& "*int8" + +%typemap(in) + char *, char[ANY], char[], + signed char *, signed char[ANY], signed char[], + unsigned char *, unsigned char[ANY], unsigned char[] +%{ $1 = ($1_ltype)$input.p; %} + +%typemap(in) char *&, signed char *&, unsigned char *& +%{ $1 = ($1_ltype)$input.p; %} + +%typemap(out) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +%{ $result = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0); %} + +%typemap(directorin) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +%{ + $input = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0); +%} + +%typemap(directorout) + char *, char *&, char[ANY], char[], + signed char *, signed char *&, signed char[ANY], signed char[], + unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[] +%{ $result = ($1_ltype)$input.p; %} + +/* String & length */ + +%typemap(gotype) (char *STRING, size_t LENGTH) "string" + +%typemap(in) (char *STRING, size_t LENGTH) +%{ + $1 = ($1_ltype)$input.p; + $2 = ($2_ltype)$input.n; +%} + +%typemap(out) (char *STRING, size_t LENGTH) +%{ $result = _swig_makegostring((char*)$1, (size_t)$2); %} + +%typemap(directorin) (char *STRING, size_t LENGTH) +%{ $input = _swig_makegostring((char*)$1, $2); %} + +%typemap(directorout) (char *STRING, size_t LENGTH) +%{ + $1 = ($1_ltype)$input.p; + $2 = ($2_ltype)$input.n; +%} + +/* Enums. We can't do the right thing for enums in typemap(gotype) so + we deliberately don't define them. The right thing would be to + capitalize the name. This is instead done in go.cxx. */ + +%typemap(gotype) enum SWIGTYPE +%{$gotypename%} + +%typemap(in) enum SWIGTYPE +%{ $1 = ($1_ltype)$input; %} + +%typemap(out) enum SWIGTYPE +%{ $result = (intgo)$1; %} + +%typemap(directorin) enum SWIGTYPE +%{ $input = ($1_ltype)$1; %} + +%typemap(directorout) enum SWIGTYPE +%{ $result = ($1_ltype)$input; %} + +%typemap(directorin) enum SWIGTYPE & (intgo e) +%{ + e = (intgo)$1; + $input = &e; +%} + +%typemap(directorout) enum SWIGTYPE & +%{ + $*1_ltype f = ($*1_ltype)*$input; + $result = ($1_ltype)&f; +%} + +/* Arbitrary type. This is a type passed by value in the C/C++ code. + We convert it to a pointer for the Go code. Note that all basic + types are explicitly handled above. */ + +%typemap(gotype) SWIGTYPE +%{$gotypename%} + +%typemap(in) SWIGTYPE ($&1_type argp) +%{ + argp = ($&1_ltype)$input; + if (argp == NULL) { + _swig_gopanic("Attempt to dereference null $1_type"); + } + $1 = ($1_ltype)*argp; +%} + +%typemap(out) SWIGTYPE +#ifdef __cplusplus +%{ *($&1_ltype*)&$result = new $1_ltype($1); %} +#else +{ + $&1_ltype $1ptr = ($&1_ltype)malloc(sizeof($1_ltype)); + memmove($1ptr, &$1, sizeof($1_type)); + *($&1_ltype*)&$result = $1ptr; +} +#endif + +%typemap(directorin) SWIGTYPE +%{ $input = ($&1_ltype)&$1; %} + +%typemap(directorout) SWIGTYPE +%{ $result = *($&1_ltype)$input; %} + +/* Exception handling */ + +%typemap(throws) char * +%{ _swig_gopanic($1); %} + +%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] +%{ + (void)$1; + _swig_gopanic("C++ $1_type exception thrown"); +%} + +/* Typecheck typemaps. The purpose of these is merely to issue a + warning for overloaded C++ functions * that cannot be overloaded in + Go as more than one C++ type maps to a single Go type. */ + +%typecheck(SWIG_TYPECHECK_BOOL) /* Go bool */ + bool, + const bool & + "" + +%typecheck(SWIG_TYPECHECK_CHAR) /* Go byte */ + char, + const char &, + unsigned char, + const unsigned char & + "" + +%typecheck(SWIG_TYPECHECK_INT8) /* Go int8 */ + signed char, + const signed char & + "" + +%typecheck(SWIG_TYPECHECK_INT16) /* Go int16 */ + short, + const short & + "" + +%typecheck(SWIG_TYPECHECK_INT16) /* Go uint16 */ + unsigned short, + const unsigned short & + "" + +%typecheck(SWIG_TYPECHECK_INT32) /* Go int */ + int, + const int & + "" + +%typecheck(SWIG_TYPECHECK_INT32) /* Go uint */ + unsigned int, + const unsigned int & + "" + +#if SWIGGO_LONG_TYPE_SIZE == 32 +%typecheck(SWIG_TYPECHECK_INT32) /* Go int32 */ + long, + const long & + "" + +%typecheck(SWIG_TYPECHECK_INT32) /* Go uint32 */ + unsigned long, + const unsigned long & + "" +#endif + +%typecheck(SWIG_TYPECHECK_INT64) /* Go int64 */ +#if SWIGGO_LONG_TYPE_SIZE == 64 + long, + const long &, +#endif + long long, + const long long & + "" + +%typecheck(SWIG_TYPECHECK_INT64) /* Go uint64 */ +#if SWIGGO_LONG_TYPE_SIZE == 64 + unsigned long, + const unsigned long &, +#endif + unsigned long long, + const unsigned long long & + "" + +%typecheck(SWIG_TYPECHECK_FLOAT) /* Go float32 */ + float, + const float & + "" + +%typecheck(SWIG_TYPECHECK_DOUBLE) /* Go float64 */ + double, + const double & + "" + +%typecheck(SWIG_TYPECHECK_STRING) /* Go string */ + char *, + char *&, + char[ANY], + char [], + signed char *, + signed char *&, + signed char[ANY], + signed char [], + unsigned char *, + unsigned char *&, + unsigned char[ANY], + unsigned char [] + "" + +%typecheck(SWIG_TYPECHECK_POINTER) + SWIGTYPE, + SWIGTYPE *, + SWIGTYPE &, + SWIGTYPE *const&, + SWIGTYPE [], + SWIGTYPE (CLASS::*) + "" + +/* Go keywords. */ +%include <gokw.swg> + +%include <goruntime.swg> diff --git a/share/swig/2.0.11/go/gokw.swg b/share/swig/2.0.11/go/gokw.swg new file mode 100644 index 0000000..dd9f35a --- /dev/null +++ b/share/swig/2.0.11/go/gokw.swg @@ -0,0 +1,33 @@ +/* Rename keywords. */ + +#define GOKW(x) %keywordwarn("'" `x` "' is a Go keyword, renaming to 'X"`x`"'",rename="X%s") `x` +#define GOBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in Go") "::"`x` + +GOKW(break); +GOKW(case); +GOKW(chan); +GOKW(const); +GOKW(continue); +GOKW(default); +GOKW(defer); +GOKW(else); +GOKW(fallthrough); +GOKW(for); +GOKW(func); +GOKW(go); +GOKW(goto); +GOKW(if); +GOKW(import); +GOKW(interface); +GOKW(package); +GOKW(range); +GOKW(return); +GOKW(select); +GOKW(struct); +GOKW(switch); +GOKW(type); +GOKW(var); + +GOBN(map); + +#undef GOKW diff --git a/share/swig/2.0.11/go/goruntime.swg b/share/swig/2.0.11/go/goruntime.swg new file mode 100644 index 0000000..4b7daf4 --- /dev/null +++ b/share/swig/2.0.11/go/goruntime.swg @@ -0,0 +1,218 @@ +/* ------------------------------------------------------------ + * goruntime.swg + * + * Go runtime code for the various generated files. + * ------------------------------------------------------------ */ + +%insert(runtime) %{ +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> + +%} + +#if SWIGGO_INTGO_SIZE == 32 +%insert(runtime) %{ +typedef int intgo; +typedef unsigned int uintgo; +%} +#elif SWIGGO_INTGO_SIZE == 64 +%insert(runtime) %{ +typedef long long intgo; +typedef unsigned long long uintgo; +%} +#else +%insert(runtime) %{ +typedef ptrdiff_t intgo; +typedef size_t uintgo; +%} +#endif + +%insert(runtime) %{ + +typedef struct { char *p; intgo n; } _gostring_; +typedef struct { void* array; intgo len; intgo cap; } _goslice_; + +%} + +#ifndef SWIGGO_GCCGO +/* Boilerplate for C/C++ code when using 6g/8g. This code is compiled + with gcc. */ +%insert(runtime) %{ + +#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; +#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n) + +swiggo_size_assert(char, 1) +swiggo_size_assert(short, 2) +swiggo_size_assert(int, 4) +typedef long long swiggo_long_long; +swiggo_size_assert(swiggo_long_long, 8) +swiggo_size_assert(float, 4) +swiggo_size_assert(double, 8) + +#ifdef __cplusplus +extern "C" { +#endif +extern void crosscall2(void (*fn)(void *, int), void *, int); +extern void _cgo_allocate(void *, int); +extern void _cgo_panic(void *, int); +#ifdef __cplusplus +} +#endif + +static void *_swig_goallocate(size_t len) { + struct { + size_t len; + void *ret; + } a; + a.len = len; + crosscall2(_cgo_allocate, &a, (int) sizeof a); + return a.ret; +} + +static void _swig_gopanic(const char *p) { + struct { + const char *p; + } a; + a.p = p; + crosscall2(_cgo_panic, &a, (int) sizeof a); +} + +%} + +/* Boilerplate for C code when using 6g/8g. This code is compiled + with 6c/8c. */ +%insert(gc_header) %{ +#include "runtime.h" +#include "cgocall.h" + +#ifdef _64BIT +#define SWIG_PARM_SIZE 8 +#else +#define SWIG_PARM_SIZE 4 +#endif +%} + +#else + +/* Boilerplate for C/C++ code when using gccgo. */ +%insert(runtime) %{ +#define SWIGGO_GCCGO + +#ifdef __cplusplus +extern "C" { +#endif +extern void *_cgo_allocate(size_t); +extern void _cgo_panic(const char *); + +/* Implementations of SwigCgocall and friends for different versions + of gccgo. The Go code will call these functions using C names with + a prefix of the module name. The implementations here call the + routine in libgo. The routines to call vary depending on the gccgo + version. We assume that the version of gcc used to compile this + file is the same as the version of gccgo. */ + +#define SWIGCONCAT2(s1, s2) s1 ## s2 +#define SWIGCONCAT1(s1, s2) SWIGCONCAT2(s1, s2) +#define SwigCgocall SWIGCONCAT1(SWIGMODULE, SwigCgocall) +#define SwigCgocallDone SWIGCONCAT1(SWIGMODULE, SwigCgocallDone) +#define SwigCgocallBack SWIGCONCAT1(SWIGMODULE, SwigCgocallBack) +#define SwigCgocallBackDone SWIGCONCAT1(SWIGMODULE, SwigCgocallBackDone) + +#define SWIG_GCC_VERSION \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC__PATH_LEVEL__) + +#if SWIG_GCC_VERSION < 40700 +#define SwigDoCgocall() +#define SwigDoCgocallDone() +#define SwigDoCgocallBack() +#define SwigDoCgocallBackDone() +#elif SWIG_GCC_VERSION == 40700 +void SwigDoCgocall(void) __asm__("libgo_syscall.syscall.Entersyscall"); +void SwigDoCgocallDone(void) __asm__("libgo_syscall.syscall.Exitsyscall"); +void SwigDoCgocallBack(void) __asm__("libgo_syscall.syscall.Exitsyscall"); +void SwigDoCgocallBackDone(void) __asm__("libgo_syscall.syscall.Entersyscall"); +#else +void SwigDoCgocall(void) __asm__("syscall.Cgocall"); +void SwigDoCgocallDone(void) __asm__("syscall.CgocallDone"); +void SwigDoCgocallBack(void) __asm__("syscall.CgocallBack"); +void SwigDoCgocallBackDone(void) __asm__("syscall.CgocallBackDone"); +#endif + +void SwigCgocall() { + SwigDoCgocall(); +} + +void SwigCgocallDone() { + SwigDoCgocallDone(); +} + +void SwigCgocallBack() { + SwigDoCgocallBack(); +} + +void SwigCgocallBackDone() { + SwigDoCgocallBackDone(); +} + +#ifdef __cplusplus +} +#endif + +#define _swig_goallocate _cgo_allocate +#define _swig_gopanic _cgo_panic + +%} + +#endif + +%insert(runtime) %{ + +static _gostring_ _swig_makegostring(const char *p, size_t l) { + _gostring_ ret; + ret.p = (char*)_swig_goallocate(l + 1); + memcpy(ret.p, p, l); + ret.n = l; + return ret; +} + +#define SWIG_contract_assert(expr, msg) \ + if (!(expr)) { _swig_gopanic(msg); } else +%} + +#ifndef SWIGGO_GCCGO + +%insert(go_header) %{ + +import _ "runtime/cgo" +import "unsafe" + +type _ unsafe.Pointer + +%} + +#else + +%insert(go_header) %{ + +import "syscall" +import "unsafe" + +type _ syscall.Sockaddr + +type _ unsafe.Pointer + +%} + +#endif + +/* Function pointers are translated by the code in go.cxx into + _swig_fnptr. Member pointers are translated to _swig_memberptr. */ + +%insert(go_header) %{ +type _swig_fnptr *byte +type _swig_memberptr *byte +%} diff --git a/share/swig/2.0.11/go/std_common.i b/share/swig/2.0.11/go/std_common.i new file mode 100644 index 0000000..c010fac --- /dev/null +++ b/share/swig/2.0.11/go/std_common.i @@ -0,0 +1,4 @@ +%include <std_except.i> + +%apply size_t { std::size_t }; +%apply const size_t& { const std::size_t& }; diff --git a/share/swig/2.0.11/go/std_deque.i b/share/swig/2.0.11/go/std_deque.i new file mode 100644 index 0000000..cb98f6c --- /dev/null +++ b/share/swig/2.0.11/go/std_deque.i @@ -0,0 +1 @@ +%include <std/_std_deque.i> diff --git a/share/swig/2.0.11/go/std_except.i b/share/swig/2.0.11/go/std_except.i new file mode 100644 index 0000000..789a335 --- /dev/null +++ b/share/swig/2.0.11/go/std_except.i @@ -0,0 +1,29 @@ +/* ----------------------------------------------------------------------------- + * std_except.i + * + * Typemaps used by the STL wrappers that throw exceptions. + * These typemaps are used when methods are declared with an STL exception specification, such as + * size_t at() const throw (std::out_of_range); + * ----------------------------------------------------------------------------- */ + +%{ +#include <stdexcept> +%} + +namespace std +{ + %ignore exception; + struct exception {}; +} + +%typemap(throws) std::bad_exception %{_swig_gopanic($1.what());%} +%typemap(throws) std::domain_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::exception %{_swig_gopanic($1.what());%} +%typemap(throws) std::invalid_argument %{_swig_gopanic($1.what());%} +%typemap(throws) std::length_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::logic_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::out_of_range %{_swig_gopanic($1.what());%} +%typemap(throws) std::overflow_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::range_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::runtime_error %{_swig_gopanic($1.what());%} +%typemap(throws) std::underflow_error %{_swig_gopanic($1.what());%} diff --git a/share/swig/2.0.11/go/std_list.i b/share/swig/2.0.11/go/std_list.i new file mode 100644 index 0000000..e026233 --- /dev/null +++ b/share/swig/2.0.11/go/std_list.i @@ -0,0 +1,40 @@ +/* ----------------------------------------------------------------------------- + * std_vector.i + * ----------------------------------------------------------------------------- */ + +%{ +#include <list> +#include <stdexcept> +%} + +namespace std { + + template<class T, class Alloc = allocator<T> > + class list { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef Alloc allocator_type; + + list(); + size_type size() const; + bool empty() const; + %rename(isEmpty) empty; + void clear(); + void push_front(const value_type& x); + void pop_front(); + void push_back(const value_type& x); + void pop_back(); + void remove(value_type x); + void reverse(); + void unique(); + void sort(); + void merge(list& x); + }; + +} diff --git a/share/swig/2.0.11/go/std_map.i b/share/swig/2.0.11/go/std_map.i new file mode 100644 index 0000000..84b0c74 --- /dev/null +++ b/share/swig/2.0.11/go/std_map.i @@ -0,0 +1,60 @@ +/* ----------------------------------------------------------------------------- + * 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: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef K key_type; + typedef T mapped_type; + map(); + map(const map<K,T> &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + const 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(); + } + } + }; +} diff --git a/share/swig/2.0.11/go/std_pair.i b/share/swig/2.0.11/go/std_pair.i new file mode 100644 index 0000000..fe45ee6 --- /dev/null +++ b/share/swig/2.0.11/go/std_pair.i @@ -0,0 +1,34 @@ +/* ----------------------------------------------------------------------------- + * 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/share/swig/2.0.11/go/std_string.i b/share/swig/2.0.11/go/std_string.i new file mode 100644 index 0000000..9922fbe --- /dev/null +++ b/share/swig/2.0.11/go/std_string.i @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------------------- + * std_string.i + * + * Typemaps for std::string and const std::string& + * These are mapped to a Go string and are passed around by value. + * + * To use non-const std::string references use the following %apply. Note + * that they are passed by value. + * %apply const std::string & {std::string &}; + * ----------------------------------------------------------------------------- */ + +%{ +#include <string> +%} + +namespace std { + +%naturalvar string; + +class string; + +%typemap(gotype) string, const string & "string" + +%typemap(in) string +%{ $1.assign($input.p, $input.n); %} + +%typemap(directorout) string +%{ $result.assign($input.p, $input.n); %} + +%typemap(out) string +%{ $result = _swig_makegostring($1.data(), $1.length()); %} + +%typemap(directorin) string +%{ $input = _swig_makegostring($1.data(), $1.length()); %} + +%typemap(in) const string & +%{ + $*1_ltype $1_str($input.p, $input.n); + $1 = &$1_str; +%} + +%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string & +%{ + static $*1_ltype $1_str; + $1_str.assign($input.p, $input.n); + $result = &$1_str; +%} + +%typemap(out) const string & +%{ $result = _swig_makegostring((*$1).data(), (*$1).length()); %} + +%typemap(directorin) const string & +%{ $input = _swig_makegostring($1.data(), $1.length()); %} + +} diff --git a/share/swig/2.0.11/go/std_vector.i b/share/swig/2.0.11/go/std_vector.i new file mode 100644 index 0000000..f4ce843 --- /dev/null +++ b/share/swig/2.0.11/go/std_vector.i @@ -0,0 +1,78 @@ +/* ----------------------------------------------------------------------------- + * std_vector.i + * ----------------------------------------------------------------------------- */ + +%{ +#include <vector> +#include <stdexcept> +%} + +namespace std { + + template<class T> class vector { + public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; + vector(); + vector(size_type n); + size_type size() const; + size_type capacity() const; + void reserve(size_type n); + %rename(isEmpty) empty; + bool empty() const; + void clear(); + %rename(add) push_back; + void push_back(const value_type& x); + %extend { + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && i<size) + return (*self)[i]; + else + throw std::out_of_range("vector index out of range"); + } + void set(int i, const value_type& val) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && i<size) + (*self)[i] = val; + else + throw std::out_of_range("vector index out of range"); + } + } + }; + + // bool specialization + template<> class vector<bool> { + public: + typedef size_t size_type; + typedef bool value_type; + typedef bool const_reference; + vector(); + vector(size_type n); + size_type size() const; + size_type capacity() const; + void reserve(size_type n); + %rename(isEmpty) empty; + bool empty() const; + void clear(); + %rename(add) push_back; + void push_back(const value_type& x); + %extend { + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && i<size) + return (*self)[i]; + else + throw std::out_of_range("vector index out of range"); + } + void set(int i, const value_type& val) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && i<size) + (*self)[i] = val; + else + throw std::out_of_range("vector index out of range"); + } + } + }; +} diff --git a/share/swig/2.0.11/go/stl.i b/share/swig/2.0.11/go/stl.i new file mode 100644 index 0000000..38aba67 --- /dev/null +++ b/share/swig/2.0.11/go/stl.i @@ -0,0 +1,9 @@ +/* ----------------------------------------------------------------------------- + * stl.i + * ----------------------------------------------------------------------------- */ + +%include <std_common.i> +%include <std_string.i> +%include <std_vector.i> +%include <std_map.i> +%include <std_pair.i> diff --git a/share/swig/2.0.11/go/typemaps.i b/share/swig/2.0.11/go/typemaps.i new file mode 100644 index 0000000..c339fb3 --- /dev/null +++ b/share/swig/2.0.11/go/typemaps.i @@ -0,0 +1,292 @@ +/* ----------------------------------------------------------------------------- + * typemaps.i + * + * Pointer and reference handling typemap library + * + * These mappings provide support for input/output arguments and common + * uses for C/C++ pointers and C++ references. + * ----------------------------------------------------------------------------- */ + +/* +INPUT typemaps +-------------- + +These typemaps remap a C pointer or C++ reference to be an "INPUT" value which is +passed by value instead of reference. + +The following typemaps can be applied to turn a pointer or reference into a simple +input value. That is, instead of passing a pointer or reference to an object, +you would use a real value instead. + + bool *INPUT, bool &INPUT + signed char *INPUT, signed char &INPUT + unsigned char *INPUT, unsigned char &INPUT + short *INPUT, short &INPUT + unsigned short *INPUT, unsigned short &INPUT + int *INPUT, int &INPUT + unsigned int *INPUT, unsigned int &INPUT + long *INPUT, long &INPUT + unsigned long *INPUT, unsigned long &INPUT + long long *INPUT, long long &INPUT + unsigned long long *INPUT, unsigned long long &INPUT + float *INPUT, float &INPUT + double *INPUT, double &INPUT + +To use these, suppose you had a C function like this : + + double fadd(double *a, double *b) { + return *a+*b; + } + +You could wrap it with SWIG as follows : + + %include <typemaps.i> + double fadd(double *INPUT, double *INPUT); + +or you can use the %apply directive : + + %include <typemaps.i> + %apply double *INPUT { double *a, double *b }; + double fadd(double *a, double *b); + +In Go you could then use it like this: + answer := modulename.Fadd(10.0, 20.0) + +There are no char *INPUT typemaps, however you can apply the signed +char * typemaps instead: + %include <typemaps.i> + %apply signed char *INPUT {char *input}; + void f(char *input); +*/ + +%define INPUT_TYPEMAP(TYPE, GOTYPE) +%typemap(gotype) TYPE *INPUT, TYPE &INPUT "GOTYPE" + + %typemap(in) TYPE *INPUT, TYPE &INPUT +%{ $1 = ($1_ltype)&$input; %} + +%typemap(out) TYPE *INPUT, TYPE &INPUT "" + +%typemap(freearg) TYPE *INPUT, TYPE &INPUT "" + +%typemap(argout) TYPE *INPUT, TYPE &INPUT "" + +// %typemap(typecheck) TYPE *INPUT = TYPE; +// %typemap(typecheck) TYPE &INPUT = TYPE; +%enddef + +INPUT_TYPEMAP(bool, bool); +INPUT_TYPEMAP(signed char, int8); +INPUT_TYPEMAP(char, byte); +INPUT_TYPEMAP(unsigned char, byte); +INPUT_TYPEMAP(short, int16); +INPUT_TYPEMAP(unsigned short, uint16); +INPUT_TYPEMAP(int, int); +INPUT_TYPEMAP(unsigned int, uint); +INPUT_TYPEMAP(long, int64); +INPUT_TYPEMAP(unsigned long, uint64); +INPUT_TYPEMAP(long long, int64); +INPUT_TYPEMAP(unsigned long long, uint64); +INPUT_TYPEMAP(float, float32); +INPUT_TYPEMAP(double, float64); + +#undef INPUT_TYPEMAP + +// OUTPUT typemaps. These typemaps are used for parameters that +// are output only. An array replaces the c pointer or reference parameter. +// The output value is returned in this array passed in. + +/* +OUTPUT typemaps +--------------- + +The following typemaps can be applied to turn a pointer or reference +into an "output" value. When calling a function, no input value would +be given for a parameter, but an output value would be returned. This +works by a Go slice being passed as a parameter where a c pointer or +reference is required. As with any Go function, the array is passed +by reference so that any modifications to the array will be picked up +in the calling function. Note that the array passed in MUST have at +least one element, but as the c function does not require any input, +the value can be set to anything. + + bool *OUTPUT, bool &OUTPUT + signed char *OUTPUT, signed char &OUTPUT + unsigned char *OUTPUT, unsigned char &OUTPUT + short *OUTPUT, short &OUTPUT + unsigned short *OUTPUT, unsigned short &OUTPUT + int *OUTPUT, int &OUTPUT + unsigned int *OUTPUT, unsigned int &OUTPUT + long *OUTPUT, long &OUTPUT + unsigned long *OUTPUT, unsigned long &OUTPUT + long long *OUTPUT, long long &OUTPUT + unsigned long long *OUTPUT, unsigned long long &OUTPUT + float *OUTPUT, float &OUTPUT + double *OUTPUT, double &OUTPUT + +For example, suppose you were trying to wrap the modf() function in the +C math library which splits x into integral and fractional parts (and +returns the integer part in one of its parameters): + + double modf(double x, double *ip); + +You could wrap it with SWIG as follows : + + %include <typemaps.i> + double modf(double x, double *OUTPUT); + +or you can use the %apply directive : + + %include <typemaps.i> + %apply double *OUTPUT { double *ip }; + double modf(double x, double *ip); + +The Go output of the function would be the function return value and the +value in the single element array. In Go you would use it like this: + + ptr := []float64{0.0} + fraction := modulename.Modf(5.0,ptr) + +There are no char *OUTPUT typemaps, however you can apply the signed +char * typemaps instead: + %include <typemaps.i> + %apply signed char *OUTPUT {char *output}; + void f(char *output); +*/ + +%define OUTPUT_TYPEMAP(TYPE, GOTYPE) +%typemap(gotype) TYPE *OUTPUT, TYPE &OUTPUT %{[]GOTYPE%} + +%typemap(in) TYPE *OUTPUT($*1_ltype temp), TYPE &OUTPUT($*1_ltype temp) +{ + if ($input.len == 0) { + _swig_gopanic("array must contain at least 1 element"); + } + $1 = &temp; +} + +%typemap(out) TYPE *OUTPUT, TYPE &OUTPUT "" + +%typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT "" + +%typemap(argout) TYPE *OUTPUT, TYPE &OUTPUT +{ + TYPE* a = (TYPE *) $input.array; + a[0] = temp$argnum; +} + +%enddef + +OUTPUT_TYPEMAP(bool, bool); +OUTPUT_TYPEMAP(signed char, int8); +OUTPUT_TYPEMAP(char, byte); +OUTPUT_TYPEMAP(unsigned char, byte); +OUTPUT_TYPEMAP(short, int16); +OUTPUT_TYPEMAP(unsigned short, uint16); +OUTPUT_TYPEMAP(int, int); +OUTPUT_TYPEMAP(unsigned int, uint); +OUTPUT_TYPEMAP(long, int64); +OUTPUT_TYPEMAP(unsigned long, uint64); +OUTPUT_TYPEMAP(long long, int64); +OUTPUT_TYPEMAP(unsigned long long, uint64); +OUTPUT_TYPEMAP(float, float32); +OUTPUT_TYPEMAP(double, float64); + +#undef OUTPUT_TYPEMAP + +/* +INOUT typemaps +-------------- + +Mappings for a parameter that is both an input and an output parameter + +The following typemaps can be applied to make a function parameter both +an input and output value. This combines the behavior of both the +"INPUT" and "OUTPUT" typemaps described earlier. Output values are +returned as an element in a Go slice. + + bool *INOUT, bool &INOUT + signed char *INOUT, signed char &INOUT + unsigned char *INOUT, unsigned char &INOUT + short *INOUT, short &INOUT + unsigned short *INOUT, unsigned short &INOUT + int *INOUT, int &INOUT + unsigned int *INOUT, unsigned int &INOUT + long *INOUT, long &INOUT + unsigned long *INOUT, unsigned long &INOUT + long long *INOUT, long long &INOUT + unsigned long long *INOUT, unsigned long long &INOUT + float *INOUT, float &INOUT + double *INOUT, double &INOUT + +For example, suppose you were trying to wrap the following function : + + void neg(double *x) { + *x = -(*x); + } + +You could wrap it with SWIG as follows : + + %include <typemaps.i> + void neg(double *INOUT); + +or you can use the %apply directive : + + %include <typemaps.i> + %apply double *INOUT { double *x }; + void neg(double *x); + +This works similarly to C in that the mapping directly modifies the +input value - the input must be an array with a minimum of one element. +The element in the array is the input and the output is the element in +the array. + + x := []float64{5.0} + Neg(x); + +The implementation of the OUTPUT and INOUT typemaps is different to +other languages in that other languages will return the output value +as part of the function return value. This difference is due to Go +being a typed language. + +There are no char *INOUT typemaps, however you can apply the signed +char * typemaps instead: + %include <typemaps.i> + %apply signed char *INOUT {char *inout}; + void f(char *inout); +*/ + +%define INOUT_TYPEMAP(TYPE, GOTYPE) +%typemap(gotype) TYPE *INOUT, TYPE &INOUT %{[]GOTYPE%} + +%typemap(in) TYPE *INOUT, TYPE &INOUT { + if ($input.len == 0) { + _swig_gopanic("array must contain at least 1 element"); + } + $1 = ($1_ltype) $input.array; +} + +%typemap(out) TYPE *INOUT, TYPE &INOUT "" + +%typemap(freearg) TYPE *INOUT, TYPE &INOUT "" + +%typemap(argout) TYPE *INOUT, TYPE &INOUT "" + +%enddef + +INOUT_TYPEMAP(bool, bool); +INOUT_TYPEMAP(signed char, int8); +INOUT_TYPEMAP(char, byte); +INOUT_TYPEMAP(unsigned char, byte); +INOUT_TYPEMAP(short, int16); +INOUT_TYPEMAP(unsigned short, uint16); +INOUT_TYPEMAP(int, int); +INOUT_TYPEMAP(unsigned int, uint); +INOUT_TYPEMAP(long, int64); +INOUT_TYPEMAP(unsigned long, uint64); +INOUT_TYPEMAP(long long, int64); +INOUT_TYPEMAP(unsigned long long, uint64); +INOUT_TYPEMAP(float, float32); +INOUT_TYPEMAP(double, float64); + +#undef INOUT_TYPEMAP |