PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/go/go.swg

#
Unknown | 529 lines | 432 code | 97 blank | 0 comment | 0 complexity | 068ca33f182f8f39e46af2853ec6d5c1 MD5 | raw file
  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 = $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/* Arbitrary type.  This is a type passed by value in the C/C++ code.
378   We convert it to a pointer for the Go code.  Note that all basic
379   types are explicitly handled above.  */
380
381%typemap(gotype) SWIGTYPE
382%{$gotypename%}
383
384%typemap(in) SWIGTYPE ($&1_type argp)
385%{
386  argp = ($&1_ltype)$input;
387  if (argp == NULL) {
388    _swig_gopanic("Attempt to dereference null $1_type");
389  }
390  $1 = ($1_ltype)*argp;
391%}
392
393%typemap(out) SWIGTYPE
394#ifdef __cplusplus
395%{ *($&1_ltype*)&$result = new $1_ltype($1); %}
396#else
397{
398  $&1_ltype $1ptr = ($&1_ltype)malloc(sizeof($1_ltype));
399  memmove($1ptr, &$1, sizeof($1_type));
400  *($&1_ltype*)&$result = $1ptr;
401}
402#endif
403
404%typemap(directorin) SWIGTYPE
405%{ $input = ($&1_ltype)&$1; %}
406
407%typemap(directorout) SWIGTYPE
408%{ $result = *($&1_ltype)$input; %}
409
410/* Exception handling */
411
412%typemap(throws) char *
413%{ _swig_gopanic($1); %}
414
415%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY]
416%{
417  (void)$1;
418  _swig_gopanic("C++ $1_type exception thrown");
419%}
420
421/* Typecheck typemaps.  The purpose of these is merely to issue a
422   warning for overloaded C++ functions * that cannot be overloaded in
423   Go as more than one C++ type maps to a single Go type.  */
424
425%typecheck(SWIG_TYPECHECK_BOOL) /* Go bool */
426    bool,
427    const bool &
428    ""
429
430%typecheck(SWIG_TYPECHECK_CHAR) /* Go byte */
431    char,
432    const char &,
433    unsigned char,
434    const unsigned char &
435    ""
436
437%typecheck(SWIG_TYPECHECK_INT8) /* Go int8 */
438    signed char,
439    const signed char &
440    ""
441
442%typecheck(SWIG_TYPECHECK_INT16) /* Go int16 */
443    short,
444    const short &
445    ""
446
447%typecheck(SWIG_TYPECHECK_INT16) /* Go uint16 */
448    unsigned short,
449    const unsigned short &
450    ""
451
452%typecheck(SWIG_TYPECHECK_INT32) /* Go int */
453    int,
454    const int &
455    ""
456
457%typecheck(SWIG_TYPECHECK_INT32) /* Go uint */
458    unsigned int,
459    const unsigned int &
460    ""
461
462#if SWIGGO_LONG_TYPE_SIZE == 32
463%typecheck(SWIG_TYPECHECK_INT32) /* Go int32 */
464    long,
465    const long &
466    ""
467
468%typecheck(SWIG_TYPECHECK_INT32) /* Go uint32 */
469    unsigned long,
470    const unsigned long &
471    ""
472#endif
473
474%typecheck(SWIG_TYPECHECK_INT64) /* Go int64 */
475#if SWIGGO_LONG_TYPE_SIZE == 64
476    long, 
477    const long &, 
478#endif
479    long long,
480    const long long &
481    ""
482
483%typecheck(SWIG_TYPECHECK_INT64) /* Go uint64 */
484#if SWIGGO_LONG_TYPE_SIZE == 64
485    unsigned long, 
486    const unsigned long &, 
487#endif
488    unsigned long long,
489    const unsigned long long &
490    ""
491
492%typecheck(SWIG_TYPECHECK_FLOAT) /* Go float32 */
493    float,
494    const float &
495    ""
496
497%typecheck(SWIG_TYPECHECK_DOUBLE) /* Go float64 */
498    double,
499    const double &
500    ""
501
502%typecheck(SWIG_TYPECHECK_STRING) /* Go string */
503    char *,
504    char *&,
505    char[ANY],
506    char [],
507    signed char *,
508    signed char *&,
509    signed char[ANY],
510    signed char [],
511    unsigned char *,
512    unsigned char *&,
513    unsigned char[ANY],
514    unsigned char []
515    ""
516
517%typecheck(SWIG_TYPECHECK_POINTER)
518    SWIGTYPE,
519    SWIGTYPE *,
520    SWIGTYPE &,
521    SWIGTYPE *const&,
522    SWIGTYPE [],
523    SWIGTYPE (CLASS::*)
524    ""
525
526/* Go keywords.  */
527%include <gokw.swg>
528
529%include <goruntime.swg>