PageRenderTime 21ms CodeModel.GetById 17ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

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