PageRenderTime 68ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 109 lines | 88 code | 16 blank | 5 comment | 0 complexity | fc2b348e3b3d52b1025630adac45c321 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module preproc_defined
  2. // Check 'defined' passes through the preprocessor without being processed like '#if defined(ABC)' would be (SF bug #1940536)
  3. %define DEFINED_MACRO
  4. %{
  5. int defined(int b) {
  6. return b > 10;
  7. }
  8. int vvv = -1;
  9. void fn(int val) {
  10. if (defined(val))
  11. vvv = 1;
  12. else
  13. vvv = 0;
  14. }
  15. %}
  16. %enddef
  17. DEFINED_MACRO
  18. %{
  19. int checking(void) {
  20. int okay;
  21. fn(11);
  22. okay = (vvv == 1);
  23. fn(9);
  24. okay = okay && (vvv == 0);
  25. return okay; /* should be 1 */
  26. }
  27. %}
  28. %inline %{
  29. int call_checking(void) {
  30. return checking();
  31. }
  32. %}
  33. /*****************************************************************************/
  34. /* Check #if/#elif defined() macro expansions
  35. Also checks #if/#elif defined() works correctly within macros... this is not
  36. standard C, but is now relied on in the SWIG library. */
  37. /*****************************************************************************/
  38. #define AAA
  39. #define BBB
  40. #define CCC
  41. #if defined(AAA)\
  42. && defined(BBB) \
  43. && defined(CCC)
  44. %{
  45. void thing(int i) {}
  46. void stuff(int i) {}
  47. struct Defined {
  48. int defined;
  49. };
  50. void bumpf(int i) {}
  51. %}
  52. #else
  53. #endif
  54. %define ANOTHER_MACRO(TYPE)
  55. #if defined(AAA) && defined(BBB) && defined(CCC)
  56. void thing(TYPE) {}
  57. #else
  58. void thing_not(TYPE) {}
  59. #endif
  60. #if defined(AAA) &&\
  61. defined(BBB) \\
  62. && defined(CCC)
  63. void stuff(TYPE) {}
  64. #else
  65. void stuff_not(TYPE);
  66. #endif
  67. #if defined(0)
  68. void defined_not(TYPE);
  69. #elif defined(AAA) && defined( BBB ) && defined(CCC)
  70. struct Defined {
  71. int defined;
  72. };
  73. #else
  74. void defined_not(TYPE);
  75. #endif
  76. #if !( defined(AAA) \
  77. defined(BBB) \\
  78. && defined(CCC) )
  79. void bumpf_not(TYPE);
  80. #else
  81. void bumpf(TYPE) {}
  82. #endif
  83. %enddef
  84. ANOTHER_MACRO(int)
  85. %{
  86. void another_macro_checking(void) {
  87. struct Defined d;
  88. d.defined = 10;
  89. thing(10);
  90. stuff(10);
  91. bumpf(10);
  92. }
  93. %}