Home | History | Annotate | Download | only in go
      1 /* ------------------------------------------------------------
      2  * go.swg
      3  *
      4  * Go configuration module.
      5  * ------------------------------------------------------------ */
      6 
      7 /* Basic types */
      8 
      9 %typemap(gotype) bool,               const bool &               "bool"
     10 %typemap(gotype) char,               const char &               "byte"
     11 %typemap(gotype) signed char,        const signed char &        "int8"
     12 %typemap(gotype) unsigned char,      const unsigned char &      "byte"
     13 %typemap(gotype) short,              const short &              "int16"
     14 %typemap(gotype) unsigned short,     const unsigned short &     "uint16"
     15 %typemap(gotype) int,                const int &                "int"
     16 %typemap(gotype) unsigned int,       const unsigned int &       "uint"
     17 #if SWIGGO_LONG_TYPE_SIZE == 32
     18 %typemap(gotype) long,               const long &               "int32"
     19 %typemap(gotype) unsigned long,      const unsigned long &      "uint32"
     20 #elif SWIGGO_LONG_TYPE_SIZE == 64
     21 %typemap(gotype) long,               const long &               "int64"
     22 %typemap(gotype) unsigned long,      const unsigned long &      "uint64"
     23 #else
     24 #error "SWIGGO_LONG_TYPE_SIZE not 32 or 64"
     25 #endif
     26 %typemap(gotype) long long,          const long long &          "int64"
     27 %typemap(gotype) unsigned long long, const unsigned long long & "uint64"
     28 %typemap(gotype) float,              const float &              "float32"
     29 %typemap(gotype) double,             const double &             "float64"
     30 
     31 %typemap(in) bool,
     32 	     char,
     33 	     signed char,
     34 	     unsigned char,
     35 	     short,
     36 	     unsigned short,
     37 	     int,
     38 	     unsigned int,
     39 	     long,
     40 	     unsigned long,
     41 	     long long,
     42 	     unsigned long long,
     43 	     float,
     44 	     double
     45 %{ $1 = ($1_ltype)$input; %}
     46 
     47 %typemap(in) const bool &,
     48 	     const char &,
     49 	     const signed char &,
     50 	     const unsigned char &,
     51 	     const short &,
     52 	     const unsigned short &,
     53 	     const int &,
     54 	     const unsigned int &,
     55 	     const long &,
     56 	     const unsigned long &,
     57 	     const long long &,
     58 	     const unsigned long long &,
     59 	     const float &,
     60 	     const double &
     61 %{ $1 = ($1_ltype)&$input; %}
     62 
     63 %typemap(out) bool,
     64 	      char,
     65 	      signed char,
     66 	      unsigned char,
     67 	      short,
     68 	      unsigned short,
     69 	      int,
     70 	      unsigned int,
     71 	      long,
     72 	      unsigned long,
     73 	      long long,
     74 	      unsigned long long,
     75 	      float,
     76 	      double
     77 %{ $result = $1; %}
     78 
     79 %typemap(out) const bool &,
     80 	      const char &,
     81 	      const signed char &,
     82 	      const unsigned char &,
     83 	      const short &,
     84 	      const unsigned short &,
     85 	      const int &,
     86 	      const unsigned int &,
     87 	      const long &,
     88 	      const unsigned long &,
     89 	      const long long &,
     90 	      const unsigned long long &,
     91 	      const float &,
     92 	      const double &
     93 %{ $result = ($*1_ltype)*$1; %}
     94 
     95 %typemap(out) void ""
     96 
     97 %typemap(directorin) bool,
     98 		     char,
     99 		     signed char,
    100 		     unsigned char,
    101 		     short,
    102 		     unsigned short,
    103 		     int,
    104 		     unsigned int,
    105 		     long,
    106 		     unsigned long,
    107 		     long long,
    108 		     unsigned long long,
    109 		     float,
    110 		     double
    111 %{ $input = ($1_ltype)$1; %}
    112 
    113 %typemap(directorin) const bool &,
    114 		     const char &,
    115 		     const signed char &,
    116 		     const unsigned char &,
    117 		     const short &,
    118 		     const unsigned short &,
    119 		     const int &,
    120 		     const unsigned int &,
    121 		     const long &,
    122 		     const unsigned long &,
    123 		     const long long &,
    124 		     const unsigned long long &,
    125 		     const float &,
    126 		     const double &
    127 %{ $input = ($*1_ltype)$1; %}
    128 
    129 %typemap(directorout) bool,
    130 		      char,
    131 		      signed char,
    132 		      unsigned char,
    133 		      short,
    134 		      unsigned short,
    135 		      int,
    136 		      unsigned int,
    137 		      long,
    138 		      unsigned long,
    139 		      long long,
    140 		      unsigned long long,
    141 		      float,
    142 		      double
    143 %{ $result = ($1_ltype)$input; %}
    144 
    145 %typemap(directorout) const bool &,
    146 		      const char &,
    147 		      const signed char &,
    148 		      const unsigned char &,
    149 		      const short &,
    150 		      const unsigned short &,
    151 		      const int &,
    152 		      const unsigned int &,
    153 		      const long &,
    154 		      const unsigned long &,
    155 		      const long long &,
    156 		      const unsigned long long &,
    157 		      const float &,
    158 		      const double &
    159 %{
    160   $result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype));
    161   *$result = *($1_ltype)&$input;
    162 %}
    163 
    164 /* The size_t type.  */
    165 
    166 #if SWIGGO_LONG_TYPE_SIZE == 32
    167 %typemap(gotype) size_t, const size_t & %{int%}
    168 #else
    169 %typemap(gotype) size_t, const size_t & %{int64%}
    170 #endif
    171 
    172 %typemap(in) size_t
    173 %{ $1 = (size_t)$input; %}
    174 
    175 %typemap(in) const size_t &
    176 %{ $1 = ($1_ltype)&$input; %}
    177 
    178 %typemap(out) size_t
    179 %{ $result = $1; %}
    180 
    181 %typemap(out) const size_t &
    182 %{ $result = ($*1_ltype)*$1; %}
    183 
    184 %typemap(directorin) size_t
    185 %{ $input = (size_t)$1; %}
    186 
    187 %typemap(directorin) const size_t &
    188 %{ $input = ($*1_ltype)$1; %}
    189 
    190 %typemap(directorout) size_t
    191 %{ $result = ($1_ltype)$input; %}
    192 
    193 %typemap(directorout) const size_t &
    194 %{
    195   $result = ($1_ltype)_swig_goallocate(sizeof($*1_ltype));
    196   *$result = *($1_ltype)$input;
    197 %}
    198 
    199 /* Member pointers.  */
    200 
    201 %typemap(gotype) SWIGTYPE (CLASS::*)
    202 %{$gotypename%}
    203 
    204 %typemap(in) SWIGTYPE (CLASS::*)
    205 %{ $1 = *($&1_ltype)$input; %}
    206 
    207 %typemap(out) SWIGTYPE (CLASS::*)
    208 %{
    209   $result = _swig_goallocate(sizeof($1_ltype));
    210   *($&1_ltype)$result = $1;
    211 %}
    212 
    213 %typemap(directorin) SWIGTYPE (CLASS::*)
    214 %{ $input = *($&1_ltype)$1; %}
    215 
    216 %typemap(directorout) SWIGTYPE (CLASS::*)
    217 %{
    218   $result = _swig_goallocate(sizeof($1_ltype));
    219   *($&1_ltype)$result = $input;
    220 %}
    221 
    222 /* Pointers.  */
    223 
    224 /* We can't translate pointers using a typemap, so that is handled in
    225    the C++ code.  */
    226 %typemap(gotype) SWIGTYPE *
    227 %{$gotypename%}
    228 
    229 %typemap(in) SWIGTYPE *
    230 %{ $1 = *($&1_ltype)&$input; %}
    231 
    232 %typemap(out) SWIGTYPE *
    233 %{ *($&1_ltype)&$result = $1; %}
    234 
    235 %typemap(directorin) SWIGTYPE *
    236 %{ $input = ($1_ltype)$1; %}
    237 
    238 %typemap(directorout) SWIGTYPE *
    239 %{ $result = ($1_ltype)$input; %}
    240 
    241 %apply SWIGTYPE * { SWIGTYPE *const }
    242 
    243 /* Pointer references.  */
    244 
    245 %typemap(gotype) SWIGTYPE *const&
    246 %{$gotypename%}
    247 
    248 %typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
    249 %{
    250   temp = *($1_ltype)&$input;
    251   $1 = ($1_ltype)&temp;
    252 %}
    253 
    254 %typemap(out) SWIGTYPE *const&
    255 %{ *($1_ltype)&$result = *$1; %}
    256 
    257 /* References.  */
    258 
    259 /* Converting a C++ reference to Go has to be handled in the C++
    260    code.  */
    261 %typemap(gotype) SWIGTYPE &
    262 %{$gotypename%}
    263 
    264 %typemap(in) SWIGTYPE &
    265 %{ $1 = *($&1_ltype)&$input; %}
    266 
    267 %typemap(out) SWIGTYPE &
    268 %{ *($&1_ltype)&$result = $1; %}
    269 
    270 %typemap(directorin) SWIGTYPE &
    271 %{ $input = ($1_ltype)&$1; %}
    272 
    273 %typemap(directorout) SWIGTYPE &
    274 %{ *($&1_ltype)&$result = $input; %}
    275 
    276 /* C arrays turn into Go pointers.  If we know the length we can use a
    277    slice.  */
    278 
    279 %typemap(gotype) SWIGTYPE []
    280 %{$gotypename%}
    281 
    282 %typemap(in) SWIGTYPE []
    283 %{ $1 = *($&1_ltype)&$input; %}
    284 
    285 %typemap(out) SWIGTYPE []
    286 %{ *($&1_ltype)&$result = $1; %}
    287 
    288 %typemap(directorin) SWIGTYPE []
    289 %{ $input = *($1_ltype)&$1; %}
    290 
    291 %typemap(directorout) SWIGTYPE []
    292 %{ *($&1_ltype)&$result = $input; %}
    293 
    294 /* Strings.  */
    295 
    296 %typemap(gotype)
    297 	char *, char *&, char[ANY], char[],
    298 	signed char *, signed char *&, signed char[ANY], signed char[],
    299 	unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
    300 "string"
    301 
    302 /* Needed to avoid confusion with the way the go module handles
    303    references.  */
    304 %typemap(gotype) char&, unsigned char& "*byte"
    305 %typemap(gotype) signed char& "*int8"
    306 
    307 %typemap(in)
    308 	char *, char[ANY], char[],
    309 	signed char *, signed char[ANY], signed char[],
    310 	unsigned char *, unsigned char[ANY], unsigned char[]
    311 %{ $1 = ($1_ltype)$input.p; %}
    312 
    313 %typemap(in) char *&, signed char *&, unsigned char *&
    314 %{ $1 = ($1_ltype)$input.p; %}
    315 
    316 %typemap(out)
    317 	char *, char *&, char[ANY], char[],
    318 	signed char *, signed char *&, signed char[ANY], signed char[],
    319 	unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
    320 %{ $result = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0); %}
    321 
    322 %typemap(directorin)
    323 	char *, char *&, char[ANY], char[],
    324 	signed char *, signed char *&, signed char[ANY], signed char[],
    325 	unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
    326 %{
    327   $input = _swig_makegostring((char*)$1, $1 ? strlen((char*)$1) : 0);
    328 %}
    329 
    330 %typemap(directorout)
    331 	char *, char *&, char[ANY], char[],
    332 	signed char *, signed char *&, signed char[ANY], signed char[],
    333 	unsigned char *, unsigned char *&, unsigned char[ANY], unsigned char[]
    334 %{ $result = ($1_ltype)$input.p; %}
    335 
    336 /* String & length */
    337 
    338 %typemap(gotype) (char *STRING, size_t LENGTH) "string"
    339 
    340 %typemap(in) (char *STRING, size_t LENGTH)
    341 %{
    342   $1 = ($1_ltype)$input.p;
    343   $2 = ($2_ltype)$input.n;
    344 %}
    345 
    346 %typemap(out) (char *STRING, size_t LENGTH)
    347 %{ $result = _swig_makegostring((char*)$1, (size_t)$2); %}
    348 
    349 %typemap(directorin) (char *STRING, size_t LENGTH)
    350 %{ $input = _swig_makegostring((char*)$1, $2); %}
    351 
    352 %typemap(directorout) (char *STRING, size_t LENGTH)
    353 %{
    354   $1 = ($1_ltype)$input.p;
    355   $2 = ($2_ltype)$input.n;
    356 %}
    357 
    358 /* Enums.  We can't do the right thing for enums in typemap(gotype) so
    359    we deliberately don't define them.  The right thing would be to
    360    capitalize the name.  This is instead done in go.cxx.  */
    361 
    362 %typemap(gotype) enum SWIGTYPE
    363 %{$gotypename%}
    364 
    365 %typemap(in) enum SWIGTYPE
    366 %{ $1 = ($1_ltype)$input; %}
    367 
    368 %typemap(out) enum SWIGTYPE
    369 %{ $result = (intgo)$1; %}
    370 
    371 %typemap(directorin) enum SWIGTYPE
    372 %{ $input = ($1_ltype)$1; %}
    373 
    374 %typemap(directorout) enum SWIGTYPE
    375 %{ $result = ($1_ltype)$input; %}
    376 
    377 %typemap(directorin) enum SWIGTYPE & (intgo e)
    378 %{
    379   e = (intgo)$1;
    380   $input = &e;
    381 %}
    382 
    383 %typemap(directorout) enum SWIGTYPE &
    384 %{
    385   $*1_ltype f = ($*1_ltype)*$input;
    386   $result = ($1_ltype)&f;
    387 %}
    388 
    389 /* Arbitrary type.  This is a type passed by value in the C/C++ code.
    390    We convert it to a pointer for the Go code.  Note that all basic
    391    types are explicitly handled above.  */
    392 
    393 %typemap(gotype) SWIGTYPE
    394 %{$gotypename%}
    395 
    396 %typemap(in) SWIGTYPE ($&1_type argp)
    397 %{
    398   argp = ($&1_ltype)$input;
    399   if (argp == NULL) {
    400     _swig_gopanic("Attempt to dereference null $1_type");
    401   }
    402   $1 = ($1_ltype)*argp;
    403 %}
    404 
    405 %typemap(out) SWIGTYPE
    406 #ifdef __cplusplus
    407 %{ *($&1_ltype*)&$result = new $1_ltype($1); %}
    408 #else
    409 {
    410   $&1_ltype $1ptr = ($&1_ltype)malloc(sizeof($1_ltype));
    411   memmove($1ptr, &$1, sizeof($1_type));
    412   *($&1_ltype*)&$result = $1ptr;
    413 }
    414 #endif
    415 
    416 %typemap(directorin) SWIGTYPE
    417 %{ $input = ($&1_ltype)&$1; %}
    418 
    419 %typemap(directorout) SWIGTYPE
    420 %{ $result = *($&1_ltype)$input; %}
    421 
    422 /* Exception handling */
    423 
    424 %typemap(throws) char *
    425 %{ _swig_gopanic($1); %}
    426 
    427 %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY]
    428 %{
    429   (void)$1;
    430   _swig_gopanic("C++ $1_type exception thrown");
    431 %}
    432 
    433 /* Typecheck typemaps.  The purpose of these is merely to issue a
    434    warning for overloaded C++ functions * that cannot be overloaded in
    435    Go as more than one C++ type maps to a single Go type.  */
    436 
    437 %typecheck(SWIG_TYPECHECK_BOOL) /* Go bool */
    438     bool,
    439     const bool &
    440     ""
    441 
    442 %typecheck(SWIG_TYPECHECK_CHAR) /* Go byte */
    443     char,
    444     const char &,
    445     unsigned char,
    446     const unsigned char &
    447     ""
    448 
    449 %typecheck(SWIG_TYPECHECK_INT8) /* Go int8 */
    450     signed char,
    451     const signed char &
    452     ""
    453 
    454 %typecheck(SWIG_TYPECHECK_INT16) /* Go int16 */
    455     short,
    456     const short &
    457     ""
    458 
    459 %typecheck(SWIG_TYPECHECK_INT16) /* Go uint16 */
    460     unsigned short,
    461     const unsigned short &
    462     ""
    463 
    464 %typecheck(SWIG_TYPECHECK_INT32) /* Go int */
    465     int,
    466     const int &
    467     ""
    468 
    469 %typecheck(SWIG_TYPECHECK_INT32) /* Go uint */
    470     unsigned int,
    471     const unsigned int &
    472     ""
    473 
    474 #if SWIGGO_LONG_TYPE_SIZE == 32
    475 %typecheck(SWIG_TYPECHECK_INT32) /* Go int32 */
    476     long,
    477     const long &
    478     ""
    479 
    480 %typecheck(SWIG_TYPECHECK_INT32) /* Go uint32 */
    481     unsigned long,
    482     const unsigned long &
    483     ""
    484 #endif
    485 
    486 %typecheck(SWIG_TYPECHECK_INT64) /* Go int64 */
    487 #if SWIGGO_LONG_TYPE_SIZE == 64
    488     long,
    489     const long &,
    490 #endif
    491     long long,
    492     const long long &
    493     ""
    494 
    495 %typecheck(SWIG_TYPECHECK_INT64) /* Go uint64 */
    496 #if SWIGGO_LONG_TYPE_SIZE == 64
    497     unsigned long,
    498     const unsigned long &,
    499 #endif
    500     unsigned long long,
    501     const unsigned long long &
    502     ""
    503 
    504 %typecheck(SWIG_TYPECHECK_FLOAT) /* Go float32 */
    505     float,
    506     const float &
    507     ""
    508 
    509 %typecheck(SWIG_TYPECHECK_DOUBLE) /* Go float64 */
    510     double,
    511     const double &
    512     ""
    513 
    514 %typecheck(SWIG_TYPECHECK_STRING) /* Go string */
    515     char *,
    516     char *&,
    517     char[ANY],
    518     char [],
    519     signed char *,
    520     signed char *&,
    521     signed char[ANY],
    522     signed char [],
    523     unsigned char *,
    524     unsigned char *&,
    525     unsigned char[ANY],
    526     unsigned char []
    527     ""
    528 
    529 %typecheck(SWIG_TYPECHECK_POINTER)
    530     SWIGTYPE,
    531     SWIGTYPE *,
    532     SWIGTYPE &,
    533     SWIGTYPE *const&,
    534     SWIGTYPE [],
    535     SWIGTYPE (CLASS::*)
    536     ""
    537 
    538 /* Go keywords.  */
    539 %include <gokw.swg>
    540 
    541 %include <goruntime.swg>
    542