PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/cffi/cffi.swg

#
Unknown | 291 lines | 237 code | 54 blank | 0 comment | 0 complexity | a9a2819fd01fba90e60dbbdf4ff0c5ef 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) void "";
  64. %typemap(out) bool "$result = (int)$1;";
  65. %typemap(out) char, unsigned char, signed char,
  66. short, signed short, unsigned short,
  67. int, signed int, unsigned int,
  68. long, signed long, unsigned long,
  69. float, double, long double, char *, void *,
  70. enum SWIGTYPE, SWIGTYPE *,
  71. SWIGTYPE[ANY], SWIGTYPE & "$result = $1;";
  72. #ifdef __cplusplus
  73. %typemap(out) SWIGTYPE "$result = new $1_type($1);";
  74. #else
  75. %typemap(out) SWIGTYPE {
  76. $result = ($&1_ltype) malloc(sizeof($1_type));
  77. memmove($result, &$1, sizeof($1_type));
  78. }
  79. #endif
  80. %typecheck(SWIG_TYPECHECK_BOOL) bool { $1 = 1; };
  81. %typecheck(SWIG_TYPECHECK_CHAR) char { $1 = 1; };
  82. %typecheck(SWIG_TYPECHECK_FLOAT) float { $1 = 1; };
  83. %typecheck(SWIG_TYPECHECK_DOUBLE) double { $1 = 1; };
  84. %typecheck(SWIG_TYPECHECK_STRING) char * { $1 = 1; };
  85. %typecheck(SWIG_TYPECHECK_INTEGER)
  86. unsigned char, signed char,
  87. short, signed short, unsigned short,
  88. int, signed int, unsigned int,
  89. long, signed long, unsigned long,
  90. enum SWIGTYPE { $1 = 1; };
  91. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &,
  92. SWIGTYPE[ANY], SWIGTYPE { $1 = 1; };
  93. /* This maps C/C++ types to Lisp classes for overload dispatch */
  94. %typemap(lisptype) bool "cl:boolean";
  95. %typemap(lisptype) char "cl:character";
  96. %typemap(lisptype) unsigned char "cl:integer";
  97. %typemap(lisptype) signed char "cl:integer";
  98. %typemap(lispclass) bool "t";
  99. %typemap(lispclass) char "cl:character";
  100. %typemap(lispclass) unsigned char, signed char,
  101. short, signed short, unsigned short,
  102. int, signed int, unsigned int,
  103. long, signed long, unsigned long,
  104. enum SWIGTYPE "cl:integer";
  105. /* CLOS methods can't be specialized on single-float or double-float */
  106. %typemap(lispclass) float "cl:number";
  107. %typemap(lispclass) double "cl:number";
  108. %typemap(lispclass) char * "cl:string";
  109. /* Array reference typemaps */
  110. %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
  111. /* const pointers */
  112. %apply SWIGTYPE * { SWIGTYPE *const }
  113. %{
  114. #ifdef __cplusplus
  115. # define EXTERN extern "C"
  116. #else
  117. # define EXTERN extern
  118. #endif
  119. #define EXPORT EXTERN SWIGEXPORT
  120. #include <string.h>
  121. %}
  122. %insert("swiglisp") %{
  123. ;;;SWIG wrapper code starts here
  124. (cl:defmacro defanonenum (&body enums)
  125. "Converts anonymous enums to defconstants."
  126. `(cl:progn ,@(cl:loop for value in enums
  127. for index = 0 then (cl:1+ index)
  128. when (cl:listp value) do (cl:setf index (cl:second value)
  129. value (cl:first value))
  130. collect `(cl:defconstant ,value ,index))))
  131. (cl:eval-when (:compile-toplevel :load-toplevel)
  132. (cl:unless (cl:fboundp 'swig-lispify)
  133. (cl:defun swig-lispify (name flag cl:&optional (package cl:*package*))
  134. (cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst)))
  135. (cl:cond
  136. ((cl:null lst)
  137. rest)
  138. ((cl:upper-case-p c)
  139. (helper (cl:cdr lst) 'upper
  140. (cl:case last
  141. ((lower digit) (cl:list* c #\- rest))
  142. (cl:t (cl:cons c rest)))))
  143. ((cl:lower-case-p c)
  144. (helper (cl:cdr lst) 'lower (cl:cons (cl:char-upcase c) rest)))
  145. ((cl:digit-char-p c)
  146. (helper (cl:cdr lst) 'digit
  147. (cl:case last
  148. ((upper lower) (cl:list* c #\- rest))
  149. (cl:t (cl:cons c rest)))))
  150. ((cl:char-equal c #\_)
  151. (helper (cl:cdr lst) '_ (cl:cons #\- rest)))
  152. (cl:t
  153. (cl:error "Invalid character: ~A" c)))))
  154. (cl:let ((fix (cl:case flag
  155. ((constant enumvalue) "+")
  156. (variable "*")
  157. (cl:t ""))))
  158. (cl:intern
  159. (cl:concatenate
  160. 'cl:string
  161. fix
  162. (cl:nreverse (helper (cl:concatenate 'cl:list name) cl:nil cl:nil))
  163. fix)
  164. package))))))
  165. ;;;SWIG wrapper code ends here
  166. %}
  167. #ifdef __cplusplus
  168. %typemap(out) SWIGTYPE "$result = new $1_type($1);";
  169. #else
  170. %typemap(out) SWIGTYPE {
  171. $result = ($&1_ltype) malloc(sizeof($1_type));
  172. memmove($result, &$1, sizeof($1_type));
  173. }
  174. #endif
  175. //////////////////////////////////////////////////////////////
  176. /* name conversion for overloaded operators. */
  177. #ifdef __cplusplus
  178. %rename(__add__) *::operator+;
  179. %rename(__pos__) *::operator+();
  180. %rename(__pos__) *::operator+() const;
  181. %rename(__sub__) *::operator-;
  182. %rename(__neg__) *::operator-() const;
  183. %rename(__neg__) *::operator-();
  184. %rename(__mul__) *::operator*;
  185. %rename(__deref__) *::operator*();
  186. %rename(__deref__) *::operator*() const;
  187. %rename(__div__) *::operator/;
  188. %rename(__mod__) *::operator%;
  189. %rename(__logxor__) *::operator^;
  190. %rename(__logand__) *::operator&;
  191. %rename(__logior__) *::operator|;
  192. %rename(__lognot__) *::operator~();
  193. %rename(__lognot__) *::operator~() const;
  194. %rename(__not__) *::operator!();
  195. %rename(__not__) *::operator!() const;
  196. %rename(__assign__) *::operator=;
  197. %rename(__add_assign__) *::operator+=;
  198. %rename(__sub_assign__) *::operator-=;
  199. %rename(__mul_assign__) *::operator*=;
  200. %rename(__div_assign__) *::operator/=;
  201. %rename(__mod_assign__) *::operator%=;
  202. %rename(__logxor_assign__) *::operator^=;
  203. %rename(__logand_assign__) *::operator&=;
  204. %rename(__logior_assign__) *::operator|=;
  205. %rename(__lshift__) *::operator<<;
  206. %rename(__lshift_assign__) *::operator<<=;
  207. %rename(__rshift__) *::operator>>;
  208. %rename(__rshift_assign__) *::operator>>=;
  209. %rename(__eq__) *::operator==;
  210. %rename(__ne__) *::operator!=;
  211. %rename(__lt__) *::operator<;
  212. %rename(__gt__) *::operator>;
  213. %rename(__lte__) *::operator<=;
  214. %rename(__gte__) *::operator>=;
  215. %rename(__and__) *::operator&&;
  216. %rename(__or__) *::operator||;
  217. %rename(__preincr__) *::operator++();
  218. %rename(__postincr__) *::operator++(int);
  219. %rename(__predecr__) *::operator--();
  220. %rename(__postdecr__) *::operator--(int);
  221. %rename(__comma__) *::operator,();
  222. %rename(__comma__) *::operator,() const;
  223. %rename(__member_ref__) *::operator->;
  224. %rename(__member_func_ref__) *::operator->*;
  225. %rename(__funcall__) *::operator();
  226. %rename(__aref__) *::operator[];
  227. #endif
  228. %{
  229. #ifdef __cplusplus
  230. # define EXTERN extern "C"
  231. #else
  232. # define EXTERN extern
  233. #endif
  234. #define EXPORT EXTERN SWIGEXPORT
  235. #include <string.h>
  236. #include <stdlib.h>
  237. %}