PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Lib/cffi/cffi.swg

#
Unknown | 284 lines | 231 code | 53 blank | 0 comment | 0 complexity | a2b21977c14cab0e41b5a1819acd2450 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* Define a C preprocessor symbol that can be used in interface files
  2. to distinguish between the SWIG language modules. */
  3. #define SWIG_CFFI
  4. /* Typespecs for basic types. */
  5. %typemap(cin) void ":void";
  6. %typemap(cin) char ":char";
  7. %typemap(cin) char * ":string";
  8. %typemap(cin) unsigned char ":unsigned-char";
  9. %typemap(cin) signed char ":char";
  10. %typemap(cin) short ":short";
  11. %typemap(cin) signed short ":short";
  12. %typemap(cin) unsigned short ":unsigned-short";
  13. %typemap(cin) int ":int";
  14. %typemap(cin) signed int ":int";
  15. %typemap(cin) unsigned int ":unsigned-int";
  16. %typemap(cin) long ":long";
  17. %typemap(cin) signed long ":long";
  18. %typemap(cin) unsigned long ":unsigned-long";
  19. %typemap(cin) long long ":long-long";
  20. %typemap(cin) signed long long ":long-long";
  21. %typemap(cin) unsigned long long ":unsigned-long-long";
  22. %typemap(cin) float ":float";
  23. %typemap(cin) double ":double";
  24. %typemap(cin) SWIGTYPE ":pointer";
  25. %typemap(cout) void ":void";
  26. %typemap(cout) char ":char";
  27. %typemap(cout) char * ":string";
  28. %typemap(cout) unsigned char ":unsigned-char";
  29. %typemap(cout) signed char ":char";
  30. %typemap(cout) short ":short";
  31. %typemap(cout) signed short ":short";
  32. %typemap(cout) unsigned short ":unsigned-short";
  33. %typemap(cout) int ":int";
  34. %typemap(cout) signed int ":int";
  35. %typemap(cout) unsigned int ":unsigned-int";
  36. %typemap(cout) long ":long";
  37. %typemap(cout) signed long ":long";
  38. %typemap(cout) unsigned long ":unsigned-long";
  39. %typemap(cout) long long ":long-long";
  40. %typemap(cout) signed long long ":long-long";
  41. %typemap(cout) unsigned long long ":unsigned-long-long";
  42. %typemap(cout) float ":float";
  43. %typemap(cout) double ":double";
  44. %typemap(cout) SWIGTYPE ":pointer";
  45. %typemap(ctype) bool "int";
  46. %typemap(ctype) char, unsigned char, signed char,
  47. short, signed short, unsigned short,
  48. int, signed int, unsigned int,
  49. long, signed long, unsigned long,
  50. float, double, long double, char *, void *, void,
  51. enum SWIGTYPE, SWIGTYPE *,
  52. SWIGTYPE[ANY], SWIGTYPE & "$1_ltype";
  53. %typemap(ctype) SWIGTYPE "$&1_type";
  54. %typemap(in) bool "$1 = (bool)$input;";
  55. %typemap(in) char, unsigned char, signed char,
  56. short, signed short, unsigned short,
  57. int, signed int, unsigned int,
  58. long, signed long, unsigned long,
  59. float, double, long double, char *, void *, void,
  60. enum SWIGTYPE, SWIGTYPE *,
  61. SWIGTYPE[ANY], SWIGTYPE & "$1 = $input;";
  62. %typemap(in) SWIGTYPE "$1 = *$input;";
  63. %typemap(out) bool "$result = (int)$1;";
  64. %typemap(out) char, unsigned char, signed char,
  65. short, signed short, unsigned short,
  66. int, signed int, unsigned int,
  67. long, signed long, unsigned long,
  68. float, double, long double, char *, void *, void,
  69. enum SWIGTYPE, SWIGTYPE *,
  70. SWIGTYPE[ANY], SWIGTYPE & "$result = $1;";
  71. #ifdef __cplusplus
  72. %typemap(out) SWIGTYPE "$result = new $1_type($1);";
  73. #else
  74. %typemap(out) SWIGTYPE {
  75. $result = ($&1_ltype) malloc(sizeof($1_type));
  76. memmove($result, &$1, sizeof($1_type));
  77. }
  78. #endif
  79. %typecheck(SWIG_TYPECHECK_BOOL) bool { $1 = 1; };
  80. %typecheck(SWIG_TYPECHECK_CHAR) char { $1 = 1; };
  81. %typecheck(SWIG_TYPECHECK_FLOAT) float { $1 = 1; };
  82. %typecheck(SWIG_TYPECHECK_DOUBLE) double { $1 = 1; };
  83. %typecheck(SWIG_TYPECHECK_STRING) char * { $1 = 1; };
  84. %typecheck(SWIG_TYPECHECK_INTEGER)
  85. unsigned char, signed char,
  86. short, signed short, unsigned short,
  87. int, signed int, unsigned int,
  88. long, signed long, unsigned long,
  89. enum SWIGTYPE { $1 = 1; };
  90. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &,
  91. SWIGTYPE[ANY], SWIGTYPE { $1 = 1; };
  92. /* This maps C/C++ types to Lisp classes for overload dispatch */
  93. %typemap(lisptype) bool "cl:boolean";
  94. %typemap(lisptype) char "cl:character";
  95. %typemap(lisptype) unsigned char "cl:integer";
  96. %typemap(lisptype) signed char "cl:integer";
  97. %typemap(lispclass) bool "t";
  98. %typemap(lispclass) char "cl:character";
  99. %typemap(lispclass) unsigned char, signed char,
  100. short, signed short, unsigned short,
  101. int, signed int, unsigned int,
  102. long, signed long, unsigned long,
  103. enum SWIGTYPE "cl:integer";
  104. %typemap(lispclass) float "cl:single-float";
  105. %typemap(lispclass) double "cl:double-float";
  106. %typemap(lispclass) char * "cl:string";
  107. %{
  108. #ifdef __cplusplus
  109. # define EXTERN extern "C"
  110. #else
  111. # define EXTERN extern
  112. #endif
  113. #define EXPORT EXTERN SWIGEXPORT
  114. #include <string.h>
  115. %}
  116. %insert("swiglisp") %{
  117. ;;;SWIG wrapper code starts here
  118. (cl:defmacro defanonenum (&body enums)
  119. "Converts anonymous enums to defconstants."
  120. `(cl:progn ,@(cl:loop for value in enums
  121. for index = 0 then (cl:1+ index)
  122. when (cl:listp value) do (cl:setf index (cl:second value)
  123. value (cl:first value))
  124. collect `(cl:defconstant ,value ,index))))
  125. (cl:eval-when (:compile-toplevel :load-toplevel)
  126. (cl:unless (cl:fboundp 'swig-lispify)
  127. (cl:defun swig-lispify (name flag cl:&optional (package cl:*package*))
  128. (cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst)))
  129. (cl:cond
  130. ((cl:null lst)
  131. rest)
  132. ((cl:upper-case-p c)
  133. (helper (cl:cdr lst) 'upper
  134. (cl:case last
  135. ((lower digit) (cl:list* c #\- rest))
  136. (cl:t (cl:cons c rest)))))
  137. ((cl:lower-case-p c)
  138. (helper (cl:cdr lst) 'lower (cl:cons (cl:char-upcase c) rest)))
  139. ((cl:digit-char-p c)
  140. (helper (cl:cdr lst) 'digit
  141. (cl:case last
  142. ((upper lower) (cl:list* c #\- rest))
  143. (cl:t (cl:cons c rest)))))
  144. ((cl:char-equal c #\_)
  145. (helper (cl:cdr lst) '_ (cl:cons #\- rest)))
  146. (cl:t
  147. (cl:error "Invalid character: ~A" c)))))
  148. (cl:let ((fix (cl:case flag
  149. ((constant enumvalue) "+")
  150. (variable "*")
  151. (cl:t ""))))
  152. (cl:intern
  153. (cl:concatenate
  154. 'cl:string
  155. fix
  156. (cl:nreverse (helper (cl:concatenate 'cl:list name) cl:nil cl:nil))
  157. fix)
  158. package))))))
  159. ;;;SWIG wrapper code ends here
  160. %}
  161. #ifdef __cplusplus
  162. %typemap(out) SWIGTYPE "$result = new $1_type($1);";
  163. #else
  164. %typemap(out) SWIGTYPE {
  165. $result = ($&1_ltype) malloc(sizeof($1_type));
  166. memmove($result, &$1, sizeof($1_type));
  167. }
  168. #endif
  169. //////////////////////////////////////////////////////////////
  170. /* name conversion for overloaded operators. */
  171. #ifdef __cplusplus
  172. %rename(__add__) *::operator+;
  173. %rename(__pos__) *::operator+();
  174. %rename(__pos__) *::operator+() const;
  175. %rename(__sub__) *::operator-;
  176. %rename(__neg__) *::operator-() const;
  177. %rename(__neg__) *::operator-();
  178. %rename(__mul__) *::operator*;
  179. %rename(__deref__) *::operator*();
  180. %rename(__deref__) *::operator*() const;
  181. %rename(__div__) *::operator/;
  182. %rename(__mod__) *::operator%;
  183. %rename(__logxor__) *::operator^;
  184. %rename(__logand__) *::operator&;
  185. %rename(__logior__) *::operator|;
  186. %rename(__lognot__) *::operator~();
  187. %rename(__lognot__) *::operator~() const;
  188. %rename(__not__) *::operator!();
  189. %rename(__not__) *::operator!() const;
  190. %rename(__assign__) *::operator=;
  191. %rename(__add_assign__) *::operator+=;
  192. %rename(__sub_assign__) *::operator-=;
  193. %rename(__mul_assign__) *::operator*=;
  194. %rename(__div_assign__) *::operator/=;
  195. %rename(__mod_assign__) *::operator%=;
  196. %rename(__logxor_assign__) *::operator^=;
  197. %rename(__logand_assign__) *::operator&=;
  198. %rename(__logior_assign__) *::operator|=;
  199. %rename(__lshift__) *::operator<<;
  200. %rename(__lshift_assign__) *::operator<<=;
  201. %rename(__rshift__) *::operator>>;
  202. %rename(__rshift_assign__) *::operator>>=;
  203. %rename(__eq__) *::operator==;
  204. %rename(__ne__) *::operator!=;
  205. %rename(__lt__) *::operator<;
  206. %rename(__gt__) *::operator>;
  207. %rename(__lte__) *::operator<=;
  208. %rename(__gte__) *::operator>=;
  209. %rename(__and__) *::operator&&;
  210. %rename(__or__) *::operator||;
  211. %rename(__preincr__) *::operator++();
  212. %rename(__postincr__) *::operator++(int);
  213. %rename(__predecr__) *::operator--();
  214. %rename(__postdecr__) *::operator--(int);
  215. %rename(__comma__) *::operator,();
  216. %rename(__comma__) *::operator,() const;
  217. %rename(__member_ref__) *::operator->;
  218. %rename(__member_func_ref__) *::operator->*;
  219. %rename(__funcall__) *::operator();
  220. %rename(__aref__) *::operator[];
  221. #endif
  222. %{
  223. #ifdef __cplusplus
  224. # define EXTERN extern "C"
  225. #else
  226. # define EXTERN extern
  227. #endif
  228. #define EXPORT EXTERN SWIGEXPORT
  229. #include <string.h>
  230. #include <stdlib.h>
  231. %}