PageRenderTime 102ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/pike/pike.swg

#
Unknown | 320 lines | 262 code | 58 blank | 0 comment | 0 complexity | 2498203f3b38c552b2ae357aae40af53 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * pike.swg
  3. *
  4. * Pike configuration module.
  5. * ----------------------------------------------------------------------------- */
  6. %insert(runtime) "swigrun.swg"; // Common C API type-checking code
  7. %insert(runtime) "pikerun.swg"; // Pike run-time code
  8. %insert(runtime) %{
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <global.h>
  13. #include <module.h>
  14. #include <interpret.h>
  15. #ifdef __cplusplus
  16. }
  17. #endif
  18. %}
  19. /* -----------------------------------------------------------------------------
  20. * standard typemaps
  21. * ----------------------------------------------------------------------------- */
  22. /* --- Input arguments --- */
  23. /* Primitive datatypes. */
  24. %typemap(in, pikedesc="tInt")
  25. int, unsigned int, short, unsigned short,
  26. long, unsigned long, char, signed char, unsigned char,
  27. bool, enum SWIGTYPE, long long, unsigned long long
  28. {
  29. if ($input.type != T_INT)
  30. Pike_error("Bad argument: Expected an integer.\n");
  31. $1 = ($1_ltype) $input.u.integer;
  32. }
  33. %typemap(in, pikedesc="tFloat") float, double {
  34. if ($input.type != T_FLOAT)
  35. Pike_error("Bad argument: Expected a float.\n");
  36. $1 = ($1_ltype) $input.u.float_number;
  37. }
  38. %typemap(in, pikedesc="tStr") char *, char [ANY] {
  39. if ($input.type != T_STRING)
  40. Pike_error("Bad argument: Expected a string.\n");
  41. $1 = ($1_ltype) STR0($input.u.string);
  42. }
  43. /* Pointers, references and arrays */
  44. %typemap(in) SWIGTYPE *,
  45. SWIGTYPE &,
  46. SWIGTYPE []
  47. "SWIG_ConvertPtr($input.u.object, (void **) &$1, $1_descriptor, 1);"
  48. /* Void pointer. Accepts any kind of pointer */
  49. %typemap(in) void * "/* FIXME */";
  50. /* Object passed by value. Convert to a pointer */
  51. %typemap(in) SWIGTYPE ($&1_ltype argp) "/* FIXME */";
  52. /* Pointer to a class member */
  53. %typemap(in) SWIGTYPE (CLASS::*) "/* FIXME */";
  54. /* Const primitive references. Passed by value */
  55. %typemap(in, pikedesc="tInt") const int & (int temp),
  56. const short & (short temp),
  57. const long & (long temp),
  58. const unsigned int & (unsigned int temp),
  59. const unsigned short & (unsigned short temp),
  60. const unsigned long & (unsigned long temp),
  61. const char & (char temp),
  62. const signed char & (signed char temp),
  63. const unsigned char & (unsigned char temp),
  64. const bool & (bool temp),
  65. const long long & ($*1_ltype temp),
  66. const unsigned long long & ($*1_ltype temp),
  67. const enum SWIGTYPE & ($*1_ltype temp)
  68. {
  69. if ($input.type != T_INT)
  70. Pike_error("Bad argument: Expected an integer.\n");
  71. temp = ($*1_ltype) $input.u.integer;
  72. $1 = &temp;
  73. }
  74. %typemap(in, pikedesc="tFloat") const float & (float temp),
  75. const double & (double temp)
  76. {
  77. if ($input.type != T_FLOAT)
  78. Pike_error("Bad argument: Expected a float.\n");
  79. temp = ($*1_ltype) $input.u.float_number;
  80. $1 = &temp;
  81. }
  82. /* -----------------------------------------------------------------------------
  83. * Output Typemaps
  84. * ----------------------------------------------------------------------------- */
  85. %typemap(out, pikedesc="tInt")
  86. int, unsigned int,
  87. short, unsigned short,
  88. long, unsigned long,
  89. char, signed char, unsigned char,
  90. bool, enum SWIGTYPE
  91. "push_int($1);";
  92. %typemap(out, pikedesc="tInt") long long "push_int64($1);";
  93. %typemap(out, pikedesc="tInt") unsigned long long "push_int64($1);";
  94. %typemap(out, pikedesc="tFloat") float, double "push_float($1);";
  95. %typemap(out, pikedesc="tStr") char * "push_text($1);";
  96. /* Pointers, references, and arrays */
  97. %typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));";
  98. /* Void return value; don't push anything */
  99. %typemap(out, pikedesc="tVoid") void "";
  100. /* Dynamic casts */
  101. %typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC "/* FIXME */";
  102. /* Member pointer */
  103. %typemap(out) SWIGTYPE (CLASS::*) "/* FIXME */";
  104. /* Special typemap for character array return values */
  105. %typemap(out, pikedesc="tStr") char [ANY], const char [ANY] "push_text($1);";
  106. /* Primitive types--return by value */
  107. %typemap(out, pikedesc="tObj") SWIGTYPE
  108. #ifdef __cplusplus
  109. {
  110. $&1_ltype resultptr;
  111. resultptr = new $1_ltype((const $1_ltype &) $1);
  112. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  113. }
  114. #else
  115. {
  116. $&1_ltype resultptr;
  117. resultptr = ($&1_ltype) malloc(sizeof($1_type));
  118. memmove(resultptr, &$1, sizeof($1_type));
  119. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  120. }
  121. #endif
  122. /* References to primitive types. Return by value */
  123. %typemap(out, pikedesc="tInt") const int &, const unsigned int &,
  124. const short &, const unsigned short &,
  125. const long &, const unsigned long &,
  126. const char &, const signed char &, const unsigned char &,
  127. const bool &,
  128. const long long &, const unsigned long long &,
  129. const enum SWIGTYPE & ($*1_ltype temp)
  130. "push_int(*($1));";
  131. %typemap(out, pikedesc="tFloat") const float &, const double & "push_float(*($1));";
  132. /************************ Constant Typemaps *****************************/
  133. %typemap(constant)
  134. int, unsigned int,
  135. short, unsigned short,
  136. long, unsigned long,
  137. signed char, unsigned char,
  138. bool, enum SWIGTYPE,
  139. long long, unsigned long long
  140. "add_integer_constant(\"$symname\", $1, 0);";
  141. %typemap(constant) char
  142. "add_integer_constant(\"$symname\", '$1', 0);";
  143. %typemap(constant) long long, unsigned long long
  144. "add_integer_constant(\"$symname\", $1, 0);";
  145. %typemap(constant) float, double
  146. "add_float_constant(\"$symname\", $1, 0);";
  147. %typemap(constant) char *
  148. "add_string_constant(\"$symname\", \"$1\", 0);";
  149. /* ------------------------------------------------------------
  150. * String & length
  151. * ------------------------------------------------------------ */
  152. %typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) {
  153. if ($input.type != T_STRING)
  154. Pike_error("Bad argument: Expected a string.\n");
  155. $1 = ($1_ltype) STR0($input.u.string);
  156. $2 = ($2_ltype) $input.u.string->length;
  157. }
  158. /* ------------------------------------------------------------
  159. * ANSI C typemaps
  160. * ------------------------------------------------------------ */
  161. %typemap(in, pikedesc="tInt") size_t {
  162. if ($input.type != T_INT)
  163. Pike_error("Bad argument: Expected an integer.\n");
  164. $1 = ($1_ltype) $input.u.integer;
  165. }
  166. %typemap(out) size_t = long;
  167. /* ------------------------------------------------------------
  168. * Typechecking rules
  169. * ------------------------------------------------------------ */
  170. %typecheck(SWIG_TYPECHECK_INTEGER)
  171. int, short, long,
  172. unsigned int, unsigned short, unsigned long,
  173. signed char, unsigned char,
  174. long long, unsigned long long,
  175. const int &, const short &, const long &,
  176. const unsigned int &, const unsigned short &, const unsigned long &,
  177. const long long &, const unsigned long long &,
  178. enum SWIGTYPE, enum SWIGTYPE &,
  179. bool, const bool &
  180. {
  181. $1 = ($input.type == T_INT) ? 1 : 0;
  182. }
  183. %typecheck(SWIG_TYPECHECK_DOUBLE)
  184. float, double,
  185. const float &, const double &
  186. {
  187. $1 = (($input.type == T_FLOAT) || ($input.type == T_INT)) ? 1 : 0;
  188. }
  189. %typecheck(SWIG_TYPECHECK_CHAR) char {
  190. $1 = ($input.type == T_INT) ? 1 : 0;
  191. }
  192. %typecheck(SWIG_TYPECHECK_STRING) char * {
  193. $1 = ($input.type == T_STRING) ? 1 : 0;
  194. }
  195. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
  196. void *ptr;
  197. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $1_descriptor, 0) == -1) {
  198. $1 = 0;
  199. } else {
  200. $1 = 1;
  201. }
  202. }
  203. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
  204. void *ptr;
  205. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $&1_descriptor, 0) == -1) {
  206. $1 = 0;
  207. } else {
  208. $1 = 1;
  209. }
  210. }
  211. %typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
  212. void *ptr;
  213. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, 0, 0) == -1) {
  214. $1 = 0;
  215. } else {
  216. $1 = 1;
  217. }
  218. }
  219. /* Array reference typemaps */
  220. %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
  221. /* const pointers */
  222. %apply SWIGTYPE * { SWIGTYPE *const }
  223. /* ------------------------------------------------------------
  224. * Overloaded operator support
  225. * ------------------------------------------------------------ */
  226. #ifdef __cplusplus
  227. %rename("`+") *::operator+;
  228. %rename("`-") *::operator-;
  229. %rename("`*") *::operator*;
  230. %rename("`/") *::operator/;
  231. %rename("`%") *::operator%;
  232. %rename("`<<") *::operator<<;
  233. %rename("`>>") *::operator>>;
  234. %rename("`&") *::operator&;
  235. %rename("`|") *::operator|;
  236. %rename("`^") *::operator^;
  237. %rename("`~") *::operator~;
  238. %rename("`<") *::operator<;
  239. %rename("`>") *::operator>;
  240. %rename("`==") *::operator==;
  241. /* Special cases */
  242. %rename("`()") *::operator();
  243. #endif
  244. /* ------------------------------------------------------------
  245. * The start of the Pike initialization function
  246. * ------------------------------------------------------------ */
  247. %init "swiginit.swg"
  248. %init %{
  249. #ifdef __cplusplus
  250. extern "C"
  251. #endif
  252. PIKE_MODULE_EXIT {}
  253. #ifdef __cplusplus
  254. extern "C"
  255. #endif
  256. PIKE_MODULE_INIT
  257. {
  258. struct program *pr;
  259. SWIG_InitializeModule(0);
  260. %}
  261. /* pike keywords */
  262. %include <pikekw.swg>