123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- /* ------------------------------------------------------------
- * go.swg
- *
- * Go configuration module.
- * ------------------------------------------------------------ */
- %include <gostring.swg>
- /* Code insertion directives */
- #define %go_import(...) %insert(go_imports) %{__VA_ARGS__%}
- /* 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"
- %typemap(gotype) long, const long & "int64"
- %typemap(gotype) unsigned long, const unsigned long & "uint64"
- %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 long &,
- const unsigned long long &,
- const float &,
- const double &
- %{ $1 = ($1_ltype)&$input; %}
- %typemap(in) const long & ($*1_ltype temp),
- const unsigned long & ($*1_ltype temp)
- %{ temp = ($*1_ltype)$input;
- $1 = ($1_ltype)&temp; %}
- %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(goout) bool,
- char,
- signed char,
- unsigned char,
- short,
- unsigned short,
- int,
- unsigned int,
- long,
- unsigned long,
- long long,
- unsigned long long,
- float,
- double
- ""
- %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(goout) 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 &
- ""
- %typemap(out) void ""
- %typemap(goout) 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(godirectorin) bool,
- char,
- signed char,
- unsigned char,
- short,
- unsigned short,
- int,
- unsigned int,
- long,
- unsigned long,
- long long,
- unsigned long long,
- float,
- double
- ""
- %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(godirectorin) 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 &
- ""
- %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,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) 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 = new $*1_ltype($input);
- swig_acquire_pointer(&swig_mem, $result);
- %}
- /* The size_t type. */
- %typemap(gotype) size_t, const size_t & %{int64%}
- %typemap(in) size_t
- %{ $1 = (size_t)$input; %}
- %typemap(in) const size_t &
- %{ $1 = ($1_ltype)&$input; %}
- %typemap(out) size_t
- %{ $result = $1; %}
- %typemap(goout) size_t ""
- %typemap(out) const size_t &
- %{ $result = ($*1_ltype)*$1; %}
- %typemap(goout) const size_t & ""
- %typemap(directorin) size_t
- %{ $input = (size_t)$1; %}
- %typemap(godirectorin) size_t ""
- %typemap(directorin) const size_t &
- %{ $input = ($*1_ltype)$1; %}
- %typemap(godirectorin) const size_t & ""
- %typemap(directorout) size_t
- %{ $result = ($1_ltype)$input; %}
- %typemap(directorout,warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) const size_t &
- %{
- $result = new $*1_ltype($input);
- swig_acquire_pointer(&swig_mem, $result);
- %}
- /* Member pointers. */
- %typemap(gotype) SWIGTYPE (CLASS::*)
- %{$gotypename%}
- %typemap(in) SWIGTYPE (CLASS::*)
- %{ $1 = *($&1_ltype)$input; %}
- %typemap(out) SWIGTYPE (CLASS::*)
- %{
- struct swig_out_type { intgo size; void* val; } *swig_out;
- swig_out = (struct swig_out_type*)malloc(sizeof(*swig_out));
- if (swig_out) {
- swig_out->size = sizeof($1_ltype);
- swig_out->val = malloc(swig_out->size);
- if (swig_out->val) {
- *($&1_ltype)(swig_out->val) = $1;
- }
- }
- $result = swig_out;
- %}
- %typemap(goout) SWIGTYPE (CLASS::*)
- %{
- {
- type swig_out_type struct { size int; val uintptr }
- p := (*swig_out_type)(unsafe.Pointer($1))
- if p == nil || p.val == 0 {
- $result = nil
- } else {
- m := make([]byte, p.size)
- a := (*[1024]byte)(unsafe.Pointer(p.val))[:p.size]
- copy(m, a)
- Swig_free(p.val)
- Swig_free(uintptr(unsafe.Pointer(p)))
- $result = &m[0]
- }
- }
- %}
- %typemap(directorin) SWIGTYPE (CLASS::*)
- %{ $input = *($&1_ltype)$1; %}
- %typemap(godirectorin) SWIGTYPE (CLASS::*) ""
- %typemap(directorout) SWIGTYPE (CLASS::*)
- %{
- $result = new $1_ltype($input);
- swig_acquire_pointer(&swig_mem, $result);
- %}
- /* 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_ltype)$1; %}
- %typemap(goout) SWIGTYPE * ""
- %typemap(directorin) SWIGTYPE *
- %{ *($&1_ltype)&$input = ($1_ltype)$1; %}
- %typemap(godirectorin) SWIGTYPE * ""
- %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; %}
- %typemap(goout) SWIGTYPE *const& ""
- /* 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(goout) SWIGTYPE & ""
- %typemap(directorin) SWIGTYPE &
- %{ $input = ($1_ltype)&$1; %}
- %typemap(godirectorin) SWIGTYPE & ""
- %typemap(directorout) SWIGTYPE &
- %{ *($&1_ltype)&$result = $input; %}
- %typemap(gotype) SWIGTYPE &&
- %{$gotypename%}
- %typemap(in) SWIGTYPE &&
- %{ $1 = *($&1_ltype)&$input; %}
- %typemap(out) SWIGTYPE &&
- %{ *($&1_ltype)&$result = $1; %}
- %typemap(goout) SWIGTYPE && ""
- %typemap(directorin) SWIGTYPE &&
- %{ $input = ($1_ltype)&$1_name; %}
- %typemap(godirectorin) SWIGTYPE && ""
- %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(goout) SWIGTYPE [] ""
- %typemap(directorin) SWIGTYPE []
- %{ $input = *($1_ltype)&$1; %}
- %typemap(godirectorin) SWIGTYPE [] ""
- %typemap(directorout) SWIGTYPE []
- %{ *($&1_ltype)&$result = $input; %}
- /* Strings. */
- %typemap(gotype)
- char *, char *&, char[ANY], 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[]
- %{ $1 = ($1_ltype)$input.p; %}
- %typemap(in) char *&
- %{ $1 = ($1_ltype)$input.p; %}
- %typemap(out,fragment="AllocateString")
- char *, char *&, char[ANY], char[]
- %{ $result = Swig_AllocateString((char*)$1, $1 ? strlen((char*)$1) : 0); %}
- %typemap(goout,fragment="CopyString")
- char *, char *&, char[ANY], char[]
- %{ $result = swigCopyString($1) %}
- %typemap(directorin,fragment="AllocateString")
- char *, char *&, char[ANY], char[]
- %{
- $input = Swig_AllocateString((char*)$1, $1 ? strlen((char*)$1) : 0);
- %}
- %typemap(godirectorin,fragment="CopyString")
- char *, char *&, char[ANY], char[]
- %{
- $result = swigCopyString($input)
- %}
- %typemap(directorout)
- char *, char *&, char[ANY], 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,fragment="AllocateString") (char *STRING, size_t LENGTH)
- %{ $result = Swig_AllocateString((char*)$1, (size_t)$2); %}
- %typemap(goout,fragment="CopyString") (char *STRING, size_t LENGTH)
- %{ $result = swigCopyString($1) %}
- %typemap(directorin,fragment="AllocateString") (char *STRING, size_t LENGTH)
- %{ $input = Swig_AllocateString((char*)$1, $2); %}
- %typemap(godirectorin,fragment="CopyString") (char *STRING, size_t LENGTH)
- %{ $result = swigCopyString($input) %}
- %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(goout) enum SWIGTYPE ""
- %typemap(directorin) enum SWIGTYPE
- %{ $input = (intgo)$1; %}
- %typemap(godirectorin) enum SWIGTYPE ""
- %typemap(directorout) enum SWIGTYPE
- %{ $result = ($1_ltype)$input; %}
- %typemap(directorin) enum SWIGTYPE & (intgo e)
- %{
- e = (intgo)$1;
- $input = ($1_ltype)&e;
- %}
- %typemap(godirectorin) enum SWIGTYPE & ""
- %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(goout) SWIGTYPE ""
- %typemap(directorin) SWIGTYPE
- %{ $input = ($&1_ltype)&$1; %}
- %typemap(godirectorin) SWIGTYPE ""
- %typemap(directorout) SWIGTYPE
- %{ $result = *($&1_ltype)$input; %}
- /* Exception handling */
- %typemap(throws) char *
- %{ _swig_gopanic($1); %}
- %typemap(throws) SWIGTYPE, 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 &
- ""
- %typecheck(SWIG_TYPECHECK_INT64) /* Go int64 */
- long,
- const long &,
- long long,
- const long long &
- ""
- %typecheck(SWIG_TYPECHECK_INT64) /* Go uint64 */
- unsigned long,
- const unsigned long &,
- 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 &&,
- SWIGTYPE *const&,
- SWIGTYPE [],
- SWIGTYPE (CLASS::*)
- ""
- /* Go keywords. */
- %include <gokw.swg>
- %include <goruntime.swg>
|