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

/trunk/Examples/test-suite/preproc.i

#
Swig | 348 lines | 217 code | 88 blank | 43 comment | 0 complexity | f0fc87720ade9bd3ae5ecd7868d3b869 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module preproc
  2. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) one; /* Ruby, wrong constant name */
  3. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) two; /* Ruby, wrong constant name */
  4. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) three; /* Ruby, wrong constant name */
  5. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) __GMP_HAVE_CONST; /* Ruby, wrong constant name */
  6. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) __GMP_HAVE_PROTOTYPES; /* Ruby, wrong constant name */
  7. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) __GMP_HAVE_TOKEN_PASTE; /* Ruby, wrong constant name */
  8. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) __GMP_HAVE_TOKEN_PASTE; /* Ruby, wrong constant name */
  9. #pragma SWIG nowarn=890 /* lots of Go name conflicts */
  10. #pragma SWIG nowarn=206 /* Unexpected tokens after #endif directive. */
  11. /* check __cplusplus case */
  12. %header
  13. %{
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif /* __cplusplus */
  18. /* C code */
  19. #ifdef __cplusplus
  20. }
  21. #endif /* __cplusplus */
  22. %}
  23. /* This interface file tests whether SWIG's extended C
  24. preprocessor is working right.
  25. In this example, SWIG 1.3.6 chokes on "//" in a #define with a
  26. syntax error.
  27. */
  28. #define SLASHSLASH "//"
  29. /* This SWIG -*- c -*- interface is to test for some strange
  30. preprocessor bug.
  31. I get syntax errors unless I remove the apostrophe in the comment
  32. or the sharp-sign substitution. (The apostrophe seems to disable
  33. sharp-sign substitution.)
  34. */
  35. %define TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(SCM_TYPE)
  36. /* Don't check for NULL pointers (override checks). */
  37. %typemap(argout, doc="($arg <vector of <" #SCM_TYPE ">>)")
  38. int *VECTORLENOUTPUT
  39. {
  40. }
  41. %enddef
  42. TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(boolean)
  43. // preproc_3
  44. #define Sum( A, B, \
  45. C) \
  46. A + B + C
  47. // preproc_4
  48. %{
  49. int hello0()
  50. {
  51. return 0;
  52. }
  53. int hello1()
  54. {
  55. return 1;
  56. }
  57. int hello2()
  58. {
  59. return 2;
  60. }
  61. int f(int min) { return min; }
  62. %}
  63. #define ARITH_RTYPE(A1, A2) A2
  64. #define HELLO_TYPE(A, B) ARITH_RTYPE(A, ARITH_RTYPE(A,B))
  65. //
  66. // These two work fine
  67. //
  68. int hello0();
  69. ARITH_RTYPE(double,int) hello1();
  70. //
  71. // This doesn't work with 1.3.17+ ( but it was ok in 1.3.16 )
  72. // it gets expanded as (using -E)
  73. //
  74. // ARITH_RTYPE(double,int) hello2();
  75. //
  76. HELLO_TYPE(double,int) hello2();
  77. #define min(x,y) ((x) < (y)) ? (x) : (y)
  78. int f(int min);
  79. // preproc_5
  80. %warnfilter(SWIGWARN_PARSE_REDEFINED) A5; // Ruby, wrong constant name
  81. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) a5; // Ruby, wrong constant name
  82. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) b5; // Ruby, wrong constant name
  83. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) c5; // Ruby, wrong constant name
  84. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) d5; // Ruby, wrong constant name
  85. // Various preprocessor bits of nastiness.
  86. /* Test argument name substitution */
  87. #define foo(x,xx) #x #xx
  88. #define bar(x,xx) x + xx
  89. %constant char *a5 = foo(hello,world);
  90. %constant int b5 = bar(3,4);
  91. // Wrap your brain around this one ;-)
  92. %{
  93. #define cat(x,y) x ## y
  94. %}
  95. #define cat(x,y) x ## y
  96. /* This should expand to cat(1,2);
  97. See K&R, p. 231 */
  98. %constant int c5 = cat(cat(1,2),;)
  99. #define xcat(x,y) cat(x,y)
  100. /* This expands to 123. See K&R, p. 231 */
  101. %constant int d5 = xcat(xcat(1,2),3);
  102. #define C1\
  103. "hello"
  104. #define C2
  105. #define C3 C2
  106. #define ALONG_\
  107. NAME 42
  108. #define C4"Hello"
  109. // preproc_6
  110. %warnfilter(SWIGWARN_PARSE_REDEFINED) A6; /* Ruby, wrong constant name */
  111. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) a6; /* Ruby, wrong constant name */
  112. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) b6; /* Ruby, wrong constant name */
  113. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) c6; /* Ruby, wrong constant name */
  114. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) d6; /* Ruby, wrong constant name */
  115. #define add(a, b) (a + b)
  116. #define times(a, b) (a * b)
  117. #define op(x) x(1, 5)
  118. /* expand to (1 + 5) */
  119. %constant int a6 = op(add);
  120. /* expand to (1 * 5) */
  121. %constant int b6 = op(times);
  122. /* expand to ((1 + 5) * 5) */
  123. %constant int c6 = times(add(1, 5), 5);
  124. /* expand to ((1 + 5) * 5) */
  125. %constant int d6 = times(op(add), 5);
  126. /* This interface file tests whether SWIG's extended C
  127. preprocessor is working right.
  128. In this example, SWIG 1.3a5 reports missing macro arguments, which
  129. is bogus.
  130. */
  131. %define MACRO1(C_TYPE, GETLENGTH)
  132. /* nothing */
  133. %enddef
  134. %define MACRO2(XYZZY)
  135. MACRO1(XYZZY, 1)
  136. %enddef
  137. MACRO2(int)
  138. // cpp_macro_noarg. Tests to make sure macros with no arguments work right.
  139. #define MACROWITHARG(x) something(x)
  140. typedef int MACROWITHARG;
  141. /*
  142. This testcase tests for embedded defines and embedded %constants
  143. */
  144. %inline %{
  145. typedef struct EmbeddedDefines {
  146. int dummy;
  147. #define EMBEDDED_DEFINE 44
  148. #ifdef SWIG
  149. %constant EMBEDDED_SWIG_CONSTANT = 55;
  150. #endif
  151. } EmbeddedDefines;
  152. %}
  153. /*
  154. This testcase tests operators for defines
  155. */
  156. #define A1 1 + 2
  157. #define A2 3 - 4
  158. #define A3 5 * 6
  159. #define A4 7 / 8
  160. #define A5 9 >> 10
  161. #define A6 11 << 12
  162. #define A7 13 & 14
  163. #define A8 15 | 16
  164. #define A9 17 ^ 18
  165. #define A10 19 && 20
  166. #define A11 21 || 21
  167. #define A12 ~22
  168. #define A13 !23
  169. #ifdef __cplusplus
  170. #define %mangle_macro(...) #@__VA_ARGS__
  171. #define %mangle_macro_str(...) ##@__VA_ARGS__
  172. %define my_func(...)
  173. inline const char* mangle_macro ## #@__VA_ARGS__ () {
  174. return %mangle_macro_str(__VA_ARGS__);
  175. }
  176. %enddef
  177. %inline {
  178. my_func(class Int) ;
  179. my_func(std::pair<double, std::complex< double > >*) ;
  180. }
  181. #endif
  182. #if defined (__cplusplus) \
  183. || defined (_AIX) \
  184. || defined (__DECC) \
  185. || (defined (__mips) && defined (_SYSTYPE_SVR4)) \
  186. || defined (_MSC_VER) \
  187. || defined (_WIN32)
  188. #define __GMP_HAVE_CONST 1
  189. #define __GMP_HAVE_PROTOTYPES 1
  190. #define __GMP_HAVE_TOKEN_PASTE 1
  191. #else
  192. #define __GMP_HAVE_CONST 0
  193. #define __GMP_HAVE_PROTOTYPES 0
  194. #define __GMP_HAVE_TOKEN_PASTE 0
  195. #endif
  196. /* empty TWO() macro is broken */
  197. #define ONE 1
  198. #define TWO() 2
  199. #define THREE(FOO) 3
  200. #define one ONE
  201. #define two TWO()
  202. #define three THREE(42)
  203. #if defined(one)
  204. /* hello */
  205. #else
  206. /* chiao */
  207. #endif;
  208. #ifdef SWIGCHICKEN
  209. /* define is a scheme keyword (and thus an invalid variable name), so SWIG warns about it */
  210. %warnfilter(SWIGWARN_PARSE_KEYWORD) define;
  211. #endif
  212. #ifdef SWIGRUBY
  213. %rename(ddefined) defined;
  214. #endif
  215. #ifdef SWIGPHP
  216. %rename(endif_) endif;
  217. #endif
  218. %inline %{
  219. const int endif = 1;
  220. const int define = 1;
  221. const int defined = 1;
  222. int test(int defined)
  223. {
  224. return defined;
  225. }
  226. %}
  227. #pragma SWIG nowarn=SWIGWARN_PP_CPP_WARNING
  228. #warning "Some warning"
  229. /* check that #error can be turned into a warning, but suppress the warning message for the test-suite! */
  230. #pragma SWIG nowarn=SWIGWARN_PP_CPP_ERROR
  231. #pragma SWIG cpperraswarn=1
  232. #error "Some error"
  233. #define MASK(shift, size) (((1 << (size)) - 1) <<(shift))
  234. #define SOME_MASK_DEF (80*MASK(8, 10))
  235. /* some constants */
  236. #define BOLTZMANN (1.380658e-23)
  237. #define AVOGADRO (6.0221367e23)
  238. #define RGAS (BOLTZMANN*AVOGADRO)
  239. #define RGASX (BOLTZMANN*AVOGADRO*BOLTZMANN)
  240. %{
  241. #define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE) \
  242. struct TypeNameTraits { \
  243. int val; \
  244. } \
  245. %}
  246. #define TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(TYPE) \
  247. struct TypeNameTraits { \
  248. int val; \
  249. } \
  250. %inline %{
  251. TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(int);
  252. %}
  253. %inline %{
  254. int method(struct TypeNameTraits tnt) {
  255. return tnt.val;
  256. }
  257. %}