PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-26/SWIG/Lib/pike/pike.swg

#
Unknown | 340 lines | 282 code | 58 blank | 0 comment | 0 complexity | e7be5ad73024e51e8ab7b363291cbdef 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. /************************ Output Typemaps *****************************/
  83. %typemap(out, pikedesc="tInt")
  84. int, unsigned int,
  85. short, unsigned short,
  86. long, unsigned long,
  87. char, signed char, unsigned char,
  88. bool, enum SWIGTYPE
  89. "push_int($1);";
  90. %typemap(out, pikedesc="tInt") long long "push_int64($1);";
  91. %typemap(out, pikedesc="tInt") unsigned long long "push_int64($1);";
  92. %typemap(out, pikedesc="tFloat") float, double "push_float($1);";
  93. %typemap(out, pikedesc="tStr") char * "push_text($1);";
  94. /* Pointers, references, and arrays */
  95. %typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));";
  96. /* Void return value; don't push anything */
  97. %typemap(out, pikedesc="tVoid") void "";
  98. /* Dynamic casts */
  99. %typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC "/* FIXME */";
  100. /* Member pointer */
  101. %typemap(out) SWIGTYPE (CLASS::*) "/* FIXME */";
  102. /* Special typemap for character array return values */
  103. %typemap(out, pikedesc="tStr") char [ANY], const char [ANY] "push_text($1);";
  104. /* Primitive types--return by value */
  105. %typemap(out, "tObj") SWIGTYPE
  106. #ifdef __cplusplus
  107. {
  108. $&1_ltype resultptr;
  109. resultptr = new $1_ltype(($1_ltype &) $1);
  110. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  111. }
  112. #else
  113. {
  114. $&1_ltype resultptr;
  115. resultptr = ($&1_ltype) malloc(sizeof($1_type));
  116. memmove(resultptr, &$1, sizeof($1_type));
  117. push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1));
  118. }
  119. #endif
  120. /* References to primitive types. Return by value */
  121. %typemap(out, pikedesc="tInt") const int &, const unsigned int &,
  122. const short &, const unsigned short &,
  123. const long &, const unsigned long &,
  124. const char &, const signed char &, const unsigned char &,
  125. const bool &,
  126. const long long &, const unsigned long long &,
  127. const enum SWIGTYPE & ($*1_ltype temp)
  128. "push_int(*($1));";
  129. %typemap(out, pikedesc="tFloat") const float &, const double & "push_float(*($1));";
  130. /************************ Constant Typemaps *****************************/
  131. %typemap(constant)
  132. int, unsigned int,
  133. short, unsigned short,
  134. long, unsigned long,
  135. signed char, unsigned char,
  136. bool, enum SWIGTYPE,
  137. long long, unsigned long long
  138. "add_integer_constant(\"$symname\", $1, 0);";
  139. %typemap(constant) char
  140. "add_integer_constant(\"$symname\", '$1', 0);";
  141. %typemap(constant) long long, unsigned long long
  142. "add_integer_constant(\"$symname\", $1, 0);";
  143. %typemap(constant) float, double
  144. "add_float_constant(\"$symname\", $1, 0);";
  145. %typemap(constant) char *
  146. "add_string_constant(\"$symname\", \"$1\", 0);";
  147. /* ------------------------------------------------------------
  148. * String & length
  149. * ------------------------------------------------------------ */
  150. %typemap(in, pikedesc="tStr") (char *STRING, int LENGTH) {
  151. if ($input.type != T_STRING)
  152. Pike_error("Bad argument: Expected a string.\n");
  153. $1 = ($1_ltype) STR0($input.u.string);
  154. $2 = ($2_ltype) $input.u.string->length;
  155. }
  156. /* ------------------------------------------------------------
  157. * ANSI C typemaps
  158. * ------------------------------------------------------------ */
  159. %typemap(in, pikedesc="tInt") size_t {
  160. if ($input.type != T_INT)
  161. Pike_error("Bad argument: Expected an integer.\n");
  162. $1 = ($1_ltype) $input.u.integer;
  163. }
  164. %typemap(out) size_t = long;
  165. /* ------------------------------------------------------------
  166. * Typechecking rules
  167. * ------------------------------------------------------------ */
  168. %typecheck(SWIG_TYPECHECK_INTEGER)
  169. int, short, long,
  170. unsigned int, unsigned short, unsigned long,
  171. signed char, unsigned char,
  172. long long, unsigned long long,
  173. const int &, const short &, const long &,
  174. const unsigned int &, const unsigned short &, const unsigned long &,
  175. const long long &, const unsigned long long &,
  176. enum SWIGTYPE, enum SWIGTYPE &,
  177. bool, const bool &
  178. {
  179. $1 = ($input.type == T_INT) ? 1 : 0;
  180. }
  181. %typecheck(SWIG_TYPECHECK_DOUBLE)
  182. float, double,
  183. const float &, const double &
  184. {
  185. $1 = (($input.type == T_FLOAT) || ($input.type == T_INT)) ? 1 : 0;
  186. }
  187. %typecheck(SWIG_TYPECHECK_CHAR) char {
  188. $1 = ($input.type == T_INT) ? 1 : 0;
  189. }
  190. %typecheck(SWIG_TYPECHECK_STRING) char * {
  191. $1 = ($input.type == T_STRING) ? 1 : 0;
  192. }
  193. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
  194. void *ptr;
  195. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $1_descriptor, 0) == -1) {
  196. $1 = 0;
  197. } else {
  198. $1 = 1;
  199. }
  200. }
  201. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
  202. void *ptr;
  203. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $&1_descriptor, 0) == -1) {
  204. $1 = 0;
  205. } else {
  206. $1 = 1;
  207. }
  208. }
  209. %typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
  210. void *ptr;
  211. if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, 0, 0) == -1) {
  212. $1 = 0;
  213. } else {
  214. $1 = 1;
  215. }
  216. }
  217. /* ------------------------------------------------------------
  218. * Overloaded operator support
  219. * ------------------------------------------------------------ */
  220. #ifdef __cplusplus
  221. %rename("`+") *::operator+;
  222. %rename("`-") *::operator-;
  223. %rename("`*") *::operator*;
  224. %rename("`/") *::operator/;
  225. %rename("`%") *::operator%;
  226. %rename("`<<") *::operator<<;
  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. /* Special cases */
  236. %rename("`()") *::operator();
  237. /* Ignored operators */
  238. %ignorewarn("362:operator= ignored") operator=;
  239. %ignorewarn("365:operator+= ignored") operator+=;
  240. %ignorewarn("366:operator-= ignored") operator-=;
  241. %ignorewarn("367:operator*= ignored") operator*=;
  242. %ignorewarn("368:operator/= ignored") operator/=;
  243. %ignorewarn("369:operator%= ignored") operator%=;
  244. %ignorewarn("370:operator^= ignored") operator^=;
  245. %ignorewarn("371:operator&= ignored") operator&=;
  246. %ignorewarn("372:operator|= ignored") operator|=;
  247. %ignorewarn("375:operator<<= ignored") operator<<=;
  248. %ignorewarn("376:operator>>= ignored") operator>>=;
  249. %ignorewarn("378:operator!= ignored") operator!=;
  250. %ignorewarn("379:operator<= ignored") operator<=;
  251. %ignorewarn("380:operator>= ignored") operator>=;
  252. %ignorewarn("381:operator&& ignored") operator&&;
  253. %ignorewarn("382:operator|| ignored") operator||;
  254. %ignorewarn("383:operator++ ignored") operator++;
  255. %ignorewarn("384:operator-- ignored") operator--;
  256. %ignorewarn("386:operator->* ignored") operator->*;
  257. %ignorewarn("389:operator[] ignored (consider using %extend)") operator[];
  258. %ignorewarn("390:operator+() ignored") operator+();
  259. %ignorewarn("390:operator+() const ignored") operator+() const;
  260. %ignorewarn("391:operator-() ignored") operator-();
  261. %ignorewarn("391:operator-() const ignored") operator-() const;
  262. #endif
  263. /* ------------------------------------------------------------
  264. * The start of the Pike initialization function
  265. * ------------------------------------------------------------ */
  266. %init "swiginit.swg"
  267. %init %{
  268. #ifdef __cplusplus
  269. extern "C"
  270. #endif
  271. PIKE_MODULE_EXIT {}
  272. #ifdef __cplusplus
  273. extern "C"
  274. #endif
  275. PIKE_MODULE_INIT
  276. {
  277. struct program *pr;
  278. SWIG_InitializeModule(0);
  279. %}
  280. /* pike keywords */
  281. /* please test and activate */
  282. //%include "pikekw.swg"