| 1 | /* ----------------------------------------------------------------------------- |
| 2 | * pike.swg |
| 3 | * |
| 4 | * Pike configuration module. |
| 5 | * ----------------------------------------------------------------------------- */ |
| 6 | |
| 7 | %insert(runtime) "swigrun.swg"; // Common C API type-checking code |
| 8 | %insert(runtime) "pikerun.swg"; // Pike run-time code |
| 9 | |
| 10 | %insert(runtime) %{ |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | #include "global.h" |
| 15 | #include "module.h" |
| 16 | #include "interpret.h" |
| 17 | #ifdef __cplusplus |
| 18 | } |
| 19 | #endif |
| 20 | %} |
| 21 | |
| 22 | /* ----------------------------------------------------------------------------- |
| 23 | * standard typemaps |
| 24 | * ----------------------------------------------------------------------------- */ |
| 25 | |
| 26 | /* --- Input arguments --- */ |
| 27 | |
| 28 | /* Primitive datatypes. */ |
| 29 | |
| 30 | %typemap(in, pikedesc="tInt") |
| 31 | int, unsigned int, short, unsigned short, |
| 32 | long, unsigned long, char, signed char, unsigned char, |
| 33 | bool, enum SWIGTYPE, long long, unsigned long long |
| 34 | { |
| 35 | if ($input.type != T_INT) |
| 36 | Pike_error("Bad argument: Expected an integer.\n"); |
| 37 | $1 = ($1_ltype) $input.u.integer; |
| 38 | } |
| 39 | |
| 40 | %typemap(in, pikedesc="tFloat") float, double { |
| 41 | if ($input.type != T_FLOAT) |
| 42 | Pike_error("Bad argument: Expected a float.\n"); |
| 43 | $1 = ($1_ltype) $input.u.float_number; |
| 44 | } |
| 45 | |
| 46 | %typemap(in, pikedesc="tStr") char *, char [ANY] { |
| 47 | if ($input.type != T_STRING) |
| 48 | Pike_error("Bad argument: Expected a string.\n"); |
| 49 | $1 = ($1_ltype) STR0($input.u.string); |
| 50 | } |
| 51 | |
| 52 | /* Pointers, references and arrays */ |
| 53 | |
| 54 | %typemap(in) SWIGTYPE *, |
| 55 | SWIGTYPE &, |
| 56 | SWIGTYPE [] |
| 57 | "SWIG_ConvertPtr($input.u.object, (void **) &$1, $1_descriptor, 1);" |
| 58 | |
| 59 | /* Void pointer. Accepts any kind of pointer */ |
| 60 | %typemap(in) void * "/* FIXME */"; |
| 61 | |
| 62 | /* Object passed by value. Convert to a pointer */ |
| 63 | %typemap(in) SWIGTYPE ($&1_ltype argp) "/* FIXME */"; |
| 64 | |
| 65 | /* Pointer to a class member */ |
| 66 | %typemap(in) SWIGTYPE (CLASS::*) "/* FIXME */"; |
| 67 | |
| 68 | /* Const primitive references. Passed by value */ |
| 69 | |
| 70 | %typemap(in, pikedesc="tInt") const int & (int temp), |
| 71 | const short & (short temp), |
| 72 | const long & (long temp), |
| 73 | const unsigned int & (unsigned int temp), |
| 74 | const unsigned short & (unsigned short temp), |
| 75 | const unsigned long & (unsigned long temp), |
| 76 | const char & (char temp), |
| 77 | const signed char & (signed char temp), |
| 78 | const unsigned char & (unsigned char temp), |
| 79 | const bool & (bool temp), |
| 80 | const long long & ($*1_ltype temp), |
| 81 | const unsigned long long & ($*1_ltype temp), |
| 82 | const enum SWIGTYPE & ($*1_ltype temp) |
| 83 | { |
| 84 | if ($input.type != T_INT) |
| 85 | Pike_error("Bad argument: Expected an integer.\n"); |
| 86 | temp = ($*1_ltype) $input.u.integer; |
| 87 | $1 = &temp; |
| 88 | } |
| 89 | |
| 90 | %typemap(in, pikedesc="tFloat") const float & (float temp), |
| 91 | const double & (double temp) |
| 92 | { |
| 93 | if ($input.type != T_FLOAT) |
| 94 | Pike_error("Bad argument: Expected a float.\n"); |
| 95 | temp = ($*1_ltype) $input.u.float_number; |
| 96 | $1 = &temp; |
| 97 | } |
| 98 | |
| 99 | /************************ Output Typemaps *****************************/ |
| 100 | |
| 101 | %typemap(out, pikedesc="tInt") |
| 102 | int, unsigned int, |
| 103 | short, unsigned short, |
| 104 | long, unsigned long, |
| 105 | char, signed char, unsigned char, |
| 106 | bool, enum SWIGTYPE |
| 107 | "push_int($1);"; |
| 108 | |
| 109 | %typemap(out, pikedesc="tInt") long long "push_int64($1);"; |
| 110 | %typemap(out, pikedesc="tInt") unsigned long long "push_int64($1);"; |
| 111 | %typemap(out, pikedesc="tFloat") float, double "push_float($1);"; |
| 112 | %typemap(out, pikedesc="tStr") char * "push_text($1);"; |
| 113 | |
| 114 | /* Pointers, references, and arrays */ |
| 115 | %typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));"; |
| 116 | |
| 117 | /* Void return value; don't push anything */ |
| 118 | %typemap(out, pikedesc="tVoid") void ""; |
| 119 | |
| 120 | /* Dynamic casts */ |
| 121 | |
| 122 | %typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC "/* FIXME */"; |
| 123 | |
| 124 | /* Member pointer */ |
| 125 | %typemap(out) SWIGTYPE (CLASS::*) "/* FIXME */"; |
| 126 | |
| 127 | /* Special typemap for character array return values */ |
| 128 | %typemap(out, pikedesc="tStr") char [ANY], const char [ANY] "push_text($1);"; |
| 129 | |
| 130 | /* Primitive types--return by value */ |
| 131 | %typemap(out, "tObj") SWIGTYPE |
| 132 | #ifdef __cplusplus |
| 133 | { |
| 134 | $&1_ltype resultptr; |
| 135 | resultptr = new $1_ltype(($1_ltype &) $1); |
| 136 | push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1)); |
| 137 | } |
| 138 | #else |
| 139 | { |
| 140 | $&1_ltype resultptr; |
| 141 | resultptr = ($&1_ltype) malloc(sizeof($1_type)); |
| 142 | memmove(resultptr, &$1, sizeof($1_type)); |
| 143 | push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1)); |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | /* References to primitive types. Return by value */ |
| 148 | |
| 149 | %typemap(out, pikedesc="tInt") const int &, const unsigned int &, |
| 150 | const short &, const unsigned short &, |
| 151 | const long &, const unsigned long &, |
| 152 | const char &, const signed char &, const unsigned char &, |
| 153 | const bool &, |
| 154 | const long long &, const unsigned long long &, |
| 155 | const enum SWIGTYPE & ($*1_ltype temp) |
| 156 | "push_int(*($1));"; |
| 157 | |
| 158 | %typemap(out, pikedesc="tFloat") const float &, const double & "push_float(*($1));"; |
| 159 | |
| 160 | /************************ Constant Typemaps *****************************/ |
| 161 | |
| 162 | %typemap(constant) |
| 163 | int, unsigned int, |
| 164 | short, unsigned short, |
| 165 | long, unsigned long, |
| 166 | signed char, unsigned char, |
| 167 | bool, enum SWIGTYPE, |
| 168 | long long, unsigned long long |
| 169 | "add_integer_constant(\"$symname\", $1, 0);"; |
| 170 | |
| 171 | %typemap(constant) char |
| 172 | "add_integer_constant(\"$symname\", '$1', 0);"; |
| 173 | |
| 174 | %typemap(constant) long long, unsigned long long |
| 175 | "add_integer_constant(\"$symname\", $1, 0);"; |
| 176 | |
| 177 | %typemap(constant) float, double |
| 178 | "add_float_constant(\"$symname\", $1, 0);"; |
| 179 | |
| 180 | %typemap(constant) char * |
| 181 | "add_string_constant(\"$symname\", \"$1\", 0);"; |
| 182 | |
| 183 | /* ------------------------------------------------------------ |
| 184 | * String & length |
| 185 | * ------------------------------------------------------------ */ |
| 186 | |
| 187 | %typemap(in, pikedesc="tStr") (char *STRING, int LENGTH) { |
| 188 | if ($input.type != T_STRING) |
| 189 | Pike_error("Bad argument: Expected a string.\n"); |
| 190 | $1 = ($1_ltype) STR0($input.u.string); |
| 191 | $2 = ($2_ltype) $input.u.string->length; |
| 192 | } |
| 193 | |
| 194 | /* ------------------------------------------------------------ |
| 195 | * ANSI C typemaps |
| 196 | * ------------------------------------------------------------ */ |
| 197 | |
| 198 | %typemap(in, pikedesc="tInt") size_t { |
| 199 | if ($input.type != T_INT) |
| 200 | Pike_error("Bad argument: Expected an integer.\n"); |
| 201 | $1 = ($1_ltype) $input.u.integer; |
| 202 | } |
| 203 | |
| 204 | %typemap(out) size_t = long; |
| 205 | |
| 206 | /* ------------------------------------------------------------ |
| 207 | * Typechecking rules |
| 208 | * ------------------------------------------------------------ */ |
| 209 | |
| 210 | %typecheck(SWIG_TYPECHECK_INTEGER) |
| 211 | int, short, long, |
| 212 | unsigned int, unsigned short, unsigned long, |
| 213 | signed char, unsigned char, |
| 214 | long long, unsigned long long, |
| 215 | const int &, const short &, const long &, |
| 216 | const unsigned int &, const unsigned short &, const unsigned long &, |
| 217 | const long long &, const unsigned long long &, |
| 218 | enum SWIGTYPE, enum SWIGTYPE &, |
| 219 | bool, const bool & |
| 220 | { |
| 221 | $1 = ($input.type == T_INT) ? 1 : 0; |
| 222 | } |
| 223 | |
| 224 | %typecheck(SWIG_TYPECHECK_DOUBLE) |
| 225 | float, double, |
| 226 | const float &, const double & |
| 227 | { |
| 228 | $1 = (($input.type == T_FLOAT) || ($input.type == T_INT)) ? 1 : 0; |
| 229 | } |
| 230 | |
| 231 | %typecheck(SWIG_TYPECHECK_CHAR) char { |
| 232 | $1 = ($input.type == T_INT) ? 1 : 0; |
| 233 | } |
| 234 | |
| 235 | %typecheck(SWIG_TYPECHECK_STRING) char * { |
| 236 | $1 = ($input.type == T_STRING) ? 1 : 0; |
| 237 | } |
| 238 | |
| 239 | %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { |
| 240 | void *ptr; |
| 241 | if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $1_descriptor, 0) == -1) { |
| 242 | $1 = 0; |
| 243 | } else { |
| 244 | $1 = 1; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { |
| 249 | void *ptr; |
| 250 | if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $&1_descriptor, 0) == -1) { |
| 251 | $1 = 0; |
| 252 | } else { |
| 253 | $1 = 1; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | %typecheck(SWIG_TYPECHECK_VOIDPTR) void * { |
| 258 | void *ptr; |
| 259 | if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, 0, 0) == -1) { |
| 260 | $1 = 0; |
| 261 | } else { |
| 262 | $1 = 1; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /* ------------------------------------------------------------ |
| 267 | * Overloaded operator support |
| 268 | * ------------------------------------------------------------ */ |
| 269 | |
| 270 | #ifdef __cplusplus |
| 271 | %rename("`+") *::operator+; |
| 272 | %rename("`-") *::operator-; |
| 273 | %rename("`*") *::operator*; |
| 274 | %rename("`/") *::operator/; |
| 275 | %rename("`%") *::operator%; |
| 276 | %rename("`<<") *::operator<<; |
| 277 | %rename("`>>") *::operator>>; |
| 278 | %rename("`&") *::operator&; |
| 279 | %rename("`|") *::operator|; |
| 280 | %rename("`^") *::operator^; |
| 281 | %rename("`~") *::operator~; |
| 282 | %rename("`<") *::operator<; |
| 283 | %rename("`>") *::operator>; |
| 284 | %rename("`==") *::operator==; |
| 285 | |
| 286 | /* Special cases */ |
| 287 | %rename("`()") *::operator(); |
| 288 | |
| 289 | /* Ignored operators */ |
| 290 | %ignorewarn("362:operator= ignored") operator=; |
| 291 | %ignorewarn("365:operator+= ignored") operator+=; |
| 292 | %ignorewarn("366:operator-= ignored") operator-=; |
| 293 | %ignorewarn("367:operator*= ignored") operator*=; |
| 294 | %ignorewarn("368:operator/= ignored") operator/=; |
| 295 | %ignorewarn("369:operator%= ignored") operator%=; |
| 296 | %ignorewarn("370:operator^= ignored") operator^=; |
| 297 | %ignorewarn("371:operator&= ignored") operator&=; |
| 298 | %ignorewarn("372:operator|= ignored") operator|=; |
| 299 | %ignorewarn("375:operator<<= ignored") operator<<=; |
| 300 | %ignorewarn("376:operator>>= ignored") operator>>=; |
| 301 | %ignorewarn("378:operator!= ignored") operator!=; |
| 302 | %ignorewarn("379:operator<= ignored") operator<=; |
| 303 | %ignorewarn("380:operator>= ignored") operator>=; |
| 304 | %ignorewarn("381:operator&& ignored") operator&&; |
| 305 | %ignorewarn("382:operator|| ignored") operator||; |
| 306 | %ignorewarn("383:operator++ ignored") operator++; |
| 307 | %ignorewarn("384:operator-- ignored") operator--; |
| 308 | %ignorewarn("386:operator->* ignored") operator->*; |
| 309 | %ignorewarn("389:operator[] ignored (consider using %extend)") operator[]; |
| 310 | %ignorewarn("390:operator+() ignored") operator+(); |
| 311 | %ignorewarn("390:operator+() const ignored") operator+() const; |
| 312 | %ignorewarn("391:operator-() ignored") operator-(); |
| 313 | %ignorewarn("391:operator-() const ignored") operator-() const; |
| 314 | |
| 315 | #endif |
| 316 | |
| 317 | /* ------------------------------------------------------------ |
| 318 | * The start of the Pike initialization function |
| 319 | * ------------------------------------------------------------ */ |
| 320 | |
| 321 | %init "swiginit.swg" |
| 322 | |
| 323 | %init %{ |
| 324 | #ifdef __cplusplus |
| 325 | extern "C" |
| 326 | #endif |
| 327 | PIKE_MODULE_EXIT {} |
| 328 | |
| 329 | #ifdef __cplusplus |
| 330 | extern "C" |
| 331 | #endif |
| 332 | PIKE_MODULE_INIT |
| 333 | { |
| 334 | struct program *pr; |
| 335 | SWIG_InitializeModule(0); |
| 336 | %} |
| 337 | |
| 338 | /* pike keywords */ |
| 339 | /* please test and activate */ |
| 340 | //%include "pikekw.swg" |