File: preproc.i

package info (click to toggle)
swig1.3 1.3.24-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,336 kB
  • ctags: 10,604
  • sloc: cpp: 27,917; ansic: 24,160; yacc: 4,412; python: 4,255; java: 4,156; makefile: 3,735; sh: 3,552; cs: 2,250; ruby: 2,150; lisp: 1,605; tcl: 1,136; perl: 980; php: 879; ml: 825
file content (294 lines) | stat: -rw-r--r-- 5,391 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
%module preproc

%warnfilter(801) one; /* Ruby, wrong constant name */
%warnfilter(801) two; /* Ruby, wrong constant name */
%warnfilter(801) three; /* Ruby, wrong constant name */
%warnfilter(801) __GMP_HAVE_CONST; /* Ruby, wrong constant name */
%warnfilter(801) __GMP_HAVE_PROTOTYPES; /* Ruby, wrong constant name */
%warnfilter(801) __GMP_HAVE_TOKEN_PASTE; /* Ruby, wrong constant name */

/* check __cplusplus case */
%header
%{
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
  /* C code */
#ifdef __cplusplus
}
#endif /* __cplusplus */

%}


/* This interface file tests whether SWIG's extended C
   preprocessor is working right. 

   In this example, SWIG 1.3.6 chokes on "//" in a #define with a
   syntax error.
*/

#define SLASHSLASH "//"

/* This SWIG -*- c -*- interface is to test for some strange
   preprocessor bug.

   I get syntax errors unless I remove the apostrophe in the comment
   or the sharp-sign substitution.  (The apostrophe seems to disable
   sharp-sign substitution.)
*/


%define TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(SCM_TYPE)

     /* Don't check for NULL pointers (override checks). */

     %typemap(argout, doc="($arg <vector of <" #SCM_TYPE ">>)") 
          int *VECTORLENOUTPUT
     {
     }

%enddef

TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(boolean)

// preproc_3

#define Sum( A, B, \
             C)    \
        A + B + C 


// preproc_4
%{
  int hello0()
  {
    return 0;
  }

  int hello1()
  {
    return 1;
  }

  int hello2()
  {
    return 2;
  }  
  int f(int min) { return min; }
%}

#define ARITH_RTYPE(A1, A2) A2

#define HELLO_TYPE(A, B) ARITH_RTYPE(A, ARITH_RTYPE(A,B))

//
// These two work fine
//
int hello0();
ARITH_RTYPE(double,int) hello1();


//
// This doesn't work with 1.3.17+ ( but it was ok in 1.3.16 )
// it gets expanded as (using -E)
// 
//   ARITH_RTYPE(double,int) hello2();
//
HELLO_TYPE(double,int) hello2();

#define min(x,y) ((x) < (y)) ? (x) : (y) 
int f(int min);

// preproc_5

%warnfilter(801) a5;	// Ruby, wrong constant name
%warnfilter(801) b5;	// Ruby, wrong constant name
%warnfilter(801) c5;	// Ruby, wrong constant name
%warnfilter(801) d5;	// Ruby, wrong constant name

// Various preprocessor bits of nastiness.


/* Test argument name substitution */
#define foo(x,xx) #x #xx
#define bar(x,xx) x + xx

%constant char *a5 = foo(hello,world);
%constant int   b5 = bar(3,4);

// Wrap your brain around this one ;-)

%{
#define cat(x,y) x ## y
%}

#define cat(x,y) x ## y

/* This should expand to cat(1,2);  
   See K&R, p. 231 */

%constant int c5 = cat(cat(1,2),;)

#define xcat(x,y) cat(x,y)

/* This expands to 123.  See K&R, p. 231 */
%constant int d5 = xcat(xcat(1,2),3);


#define C1\
"hello"

#define C2
#define C3 C2

#define ALONG_\
NAME 42

#define C4"Hello"

// preproc_6

%warnfilter(801) a6; /* Ruby, wrong constant name */
%warnfilter(801) b6; /* Ruby, wrong constant name */
%warnfilter(801) c6; /* Ruby, wrong constant name */
%warnfilter(801) d6; /* Ruby, wrong constant name */

#define add(a, b) (a + b)
#define times(a, b) (a * b)
#define op(x) x(1, 5)
 
/* expand to (1 + 5) */
%constant int a6 = op(add);
/* expand to (1 * 5) */
%constant int b6 = op(times);
/* expand to ((1 + 5) * 5) */
%constant int c6 = times(add(1, 5), 5);
/* expand to ((1 + 5) * 5) */
%constant int d6 = times(op(add), 5);                 

/* This interface file tests whether SWIG's extended C
   preprocessor is working right. 

   In this example, SWIG 1.3a5 reports missing macro arguments, which
   is bogus.
*/

%define MACRO1(C_TYPE, GETLENGTH)
     /* nothing */
%enddef

%define MACRO2(XYZZY)
  MACRO1(XYZZY, 1)
%enddef

MACRO2(int)

// cpp_macro_noarg.  Tests to make sure macros with no arguments work right.
#define MACROWITHARG(x) something(x) 

typedef int MACROWITHARG; 

/* 
This testcase tests for embedded defines and embedded %constants
*/

%inline %{

typedef struct EmbeddedDefines {
  int dummy;
#define  EMBEDDED_DEFINE 44
#ifdef SWIG
%constant EMBEDDED_SWIG_CONSTANT = 55;
#endif
} EmbeddedDefines;

%}

/* 
This testcase tests operators for defines
*/

#define A1   1 + 2
#define A2   3 - 4
#define A3   5 * 6
#define A4   7 / 8
#define A5   9 >> 10
#define A6   11 << 12
#define A7   13 & 14
#define A8   15 | 16
#define A9   17 ^ 18
#define A10  19 && 20
#define A11  21 || 21
#define A12  ~22
#define A13  !23



#ifdef __cplusplus
		   
#define %mangle(...) #@__VA_ARGS__
#define %mangle_str(...) ##@__VA_ARGS__

%define my_func(...)
inline const char* mangle ## #@__VA_ARGS__ () {
  return %mangle_str(__VA_ARGS__);
}
%enddef

%inline {
  my_func(class Int) ;
  my_func(std::pair<double, std::complex< double > >*) ;
}

#endif


#if defined (__cplusplus) \
|| defined (_AIX) \
|| defined (__DECC) \
|| (defined (__mips) && defined (_SYSTYPE_SVR4)) \
|| defined (_MSC_VER) \
|| defined (_WIN32)
#define __GMP_HAVE_CONST 1
#define __GMP_HAVE_PROTOTYPES 1
#define __GMP_HAVE_TOKEN_PASTE 1
#else
#define __GMP_HAVE_CONST 0
#define __GMP_HAVE_PROTOTYPES 0
#define __GMP_HAVE_TOKEN_PASTE 0
#endif


/* empty TWO() macro is broken */
#define ONE 1
#define TWO() 2
#define THREE(FOO) 3

#define one ONE
#define two TWO()
#define three THREE(42)


#if defined(one)
/* hello */
#else
/* chiao */
#endif;

#ifdef SWIGRUBY
%rename(ddefined) defined;
#endif
%inline %{
const int endif = 1;
const int define = 1;
const int defined = 1; 
int test(int defined)
{
  return defined;
}
 
%}