PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/go/go.swg

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