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