Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / share / swig / 1.3.26 / chicken / typemaps.i
CommitLineData
920dae64
AT
1//
2// SWIG Typemap library
3// Jonah Beckford
4// Nov 22, 2002
5// Derived: Dave Beazley (Author); Lib/python/typemaps.i; May 5, 1997
6//
7// CHICKEN implementation
8//
9// This library provides standard typemaps for modifying SWIG's behavior.
10// With enough entries in this file, I hope that very few people actually
11// ever need to write a typemap.
12//
13// Disclaimer : Unless you really understand how typemaps work, this file
14// probably isn't going to make much sense.
15//
16
17// ------------------------------------------------------------------------
18// Pointer handling
19//
20// These mappings provide support for input/output arguments and
21// common uses for C/C++ pointers. INOUT mappings allow for C/C++
22// pointer variables in addition to input/output arguments.
23// ------------------------------------------------------------------------
24
25// INPUT typemaps.
26// These remap a C pointer to be an "INPUT" value which is passed by value
27// instead of reference.
28
29/*
30The following methods can be applied to turn a pointer into a simple
31"input" value. That is, instead of passing a pointer to an object,
32you would use a real value instead.
33
34 int *INPUT
35 short *INPUT
36 long *INPUT
37 long long *INPUT
38 unsigned int *INPUT
39 unsigned short *INPUT
40 unsigned long *INPUT
41 unsigned long long *INPUT
42 unsigned char *INPUT
43 char *INPUT
44 bool *INPUT
45 float *INPUT
46 double *INPUT
47
48To use these, suppose you had a C function like this :
49
50 double fadd(double *a, double *b) {
51 return *a+*b;
52 }
53
54You could wrap it with SWIG as follows :
55
56 %include typemaps.i
57 double fadd(double *INPUT, double *INPUT);
58
59or you can use the %apply directive :
60
61 %include typemaps.i
62 %apply double *INPUT { double *a, double *b };
63 double fadd(double *a, double *b);
64
65*/
66
67// OUTPUT typemaps. These typemaps are used for parameters that
68// are output only. The output value is appended to the result as
69// a list element.
70
71/*
72The following methods can be applied to turn a pointer into an "output"
73value. When calling a function, no input value would be given for
74a parameter, but an output value would be returned. In the case of
75multiple output values, they are returned in the form of a Scheme list.
76
77 int *OUTPUT
78 short *OUTPUT
79 long *OUTPUT
80 long long *OUTPUT
81 unsigned int *OUTPUT
82 unsigned short *OUTPUT
83 unsigned long *OUTPUT
84 unsigned long long *OUTPUT
85 unsigned char *OUTPUT
86 char *OUTPUT
87 bool *OUTPUT
88 float *OUTPUT
89 double *OUTPUT
90
91For example, suppose you were trying to wrap the modf() function in the
92C math library which splits x into integral and fractional parts (and
93returns the integer part in one of its parameters).K:
94
95 double modf(double x, double *ip);
96
97You could wrap it with SWIG as follows :
98
99 %include typemaps.i
100 double modf(double x, double *OUTPUT);
101
102or you can use the %apply directive :
103
104 %include typemaps.i
105 %apply double *OUTPUT { double *ip };
106 double modf(double x, double *ip);
107
108The CHICKEN output of the function would be a list containing both
109output values, in reverse order.
110
111*/
112
113// These typemaps contributed by Robin Dunn
114//----------------------------------------------------------------------
115//
116// T_OUTPUT typemap (and helper function) to return multiple argouts as
117// a tuple instead of a list.
118//
119// Author: Robin Dunn
120//----------------------------------------------------------------------
121
122// Simple types
123
124%define INOUT_TYPEMAP(type_, from_scheme, to_scheme, checker, convtype, storage_)
125
126%typemap(in) type_ *INPUT($*1_ltype temp), type_ &INPUT($*1_ltype temp)
127%{ if (!checker ($input)) {
128 swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'");
129 }
130 temp = ($*1_ltype) from_scheme ($input);
131 $1 = &temp; %}
132
133%typemap(typecheck) type_ *INPUT = type_;
134%typemap(typecheck) type_ &INPUT = type_;
135
136%typemap(in, numinputs=0) type_ *OUTPUT($*1_ltype temp), type_ &OUTPUT($*1_ltype temp)
137" $1 = &temp;"
138
139#if "storage_" == "0"
140
141%typemap(argout) type_ *OUTPUT, type_ &OUTPUT
142%{
143 if ($1 == NULL) {
144 swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Argument #$argnum must be non-null");
145 }
146 SWIG_APPEND_VALUE(to_scheme (convtype (*$1)));
147%}
148
149#else
150
151%typemap(argout) type_ *OUTPUT, type_ &OUTPUT
152%{
153 {
154 C_word *known_space = C_alloc(storage_);
155 if ($1 == NULL) {
156 swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Variable '$1' must be non-null");
157 }
158 SWIG_APPEND_VALUE(to_scheme (&known_space, convtype (*$1)));
159 }
160%}
161
162#endif
163
164%enddef
165
166INOUT_TYPEMAP(int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
167INOUT_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
168INOUT_TYPEMAP(short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
169INOUT_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
170INOUT_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
171INOUT_TYPEMAP(unsigned int, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
172INOUT_TYPEMAP(unsigned short, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
173INOUT_TYPEMAP(unsigned long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
174INOUT_TYPEMAP(unsigned long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
175INOUT_TYPEMAP(unsigned char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
176INOUT_TYPEMAP(signed char, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
177INOUT_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
178INOUT_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0);
179INOUT_TYPEMAP(float, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
180INOUT_TYPEMAP(double, C_flonum_magnitude, C_flonum, C_swig_is_flonum, (double), C_SIZEOF_FLONUM);
181
182// INOUT
183// Mappings for an argument that is both an input and output
184// parameter
185
186/*
187The following methods can be applied to make a function parameter both
188an input and output value. This combines the behavior of both the
189"INPUT" and "OUTPUT" methods described earlier. Output values are
190returned in the form of a CHICKEN tuple.
191
192 int *INOUT
193 short *INOUT
194 long *INOUT
195 long long *INOUT
196 unsigned int *INOUT
197 unsigned short *INOUT
198 unsigned long *INOUT
199 unsigned long long *INOUT
200 unsigned char *INOUT
201 char *INOUT
202 bool *INOUT
203 float *INOUT
204 double *INOUT
205
206For example, suppose you were trying to wrap the following function :
207
208 void neg(double *x) {
209 *x = -(*x);
210 }
211
212You could wrap it with SWIG as follows :
213
214 %include typemaps.i
215 void neg(double *INOUT);
216
217or you can use the %apply directive :
218
219 %include typemaps.i
220 %apply double *INOUT { double *x };
221 void neg(double *x);
222
223As well, you can wrap variables with :
224
225 %include typemaps.i
226 %apply double *INOUT { double *y };
227 extern double *y;
228
229Unlike C, this mapping does not directly modify the input value (since
230this makes no sense in CHICKEN). Rather, the modified input value shows
231up as the return value of the function. Thus, to apply this function
232to a CHICKEN variable you might do this :
233
234 x = neg(x)
235
236Note : previous versions of SWIG used the symbol 'BOTH' to mark
237input/output arguments. This is still supported, but will be slowly
238phased out in future releases.
239
240*/
241
242%typemap(in) int *INOUT = int *INPUT;
243%typemap(in) enum SWIGTYPE *INOUT = enum SWIGTYPE *INPUT;
244%typemap(in) short *INOUT = short *INPUT;
245%typemap(in) long *INOUT = long *INPUT;
246%typemap(in) long long *INOUT = long long *INPUT;
247%typemap(in) unsigned *INOUT = unsigned *INPUT;
248%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
249%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
250%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
251%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
252%typemap(in) char *INOUT = char *INPUT;
253%typemap(in) bool *INOUT = bool *INPUT;
254%typemap(in) float *INOUT = float *INPUT;
255%typemap(in) double *INOUT = double *INPUT;
256
257%typemap(in) int &INOUT = int &INPUT;
258%typemap(in) enum SWIGTYPE &INOUT = enum SWIGTYPE &INPUT;
259%typemap(in) short &INOUT = short &INPUT;
260%typemap(in) long &INOUT = long &INPUT;
261%typemap(in) long long &INOUT = long long &INPUT;
262%typemap(in) unsigned &INOUT = unsigned &INPUT;
263%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
264%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
265%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
266%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
267%typemap(in) char &INOUT = char &INPUT;
268%typemap(in) bool &INOUT = bool &INPUT;
269%typemap(in) float &INOUT = float &INPUT;
270%typemap(in) double &INOUT = double &INPUT;
271
272%typemap(argout) int *INOUT = int *OUTPUT;
273%typemap(argout) enum SWIGTYPE *INOUT = enum SWIGTYPE *OUTPUT;
274%typemap(argout) short *INOUT = short *OUTPUT;
275%typemap(argout) long *INOUT = long *OUTPUT;
276%typemap(argout) long long *INOUT = long long *OUTPUT;
277%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
278%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
279%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
280%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
281%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
282%typemap(argout) bool *INOUT = bool *OUTPUT;
283%typemap(argout) float *INOUT = float *OUTPUT;
284%typemap(argout) double *INOUT = double *OUTPUT;
285
286%typemap(argout) int &INOUT = int &OUTPUT;
287%typemap(argout) enum SWIGTYPE &INOUT = enum SWIGTYPE &OUTPUT;
288%typemap(argout) short &INOUT = short &OUTPUT;
289%typemap(argout) long &INOUT = long &OUTPUT;
290%typemap(argout) long long &INOUT = long long &OUTPUT;
291%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
292%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
293%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
294%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
295%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
296%typemap(argout) char &INOUT = char &OUTPUT;
297%typemap(argout) bool &INOUT = bool &OUTPUT;
298%typemap(argout) float &INOUT = float &OUTPUT;
299%typemap(argout) double &INOUT = double &OUTPUT;
300
301/* Overloading information */
302
303%typemap(typecheck) double *INOUT = double;
304%typemap(typecheck) bool *INOUT = bool;
305%typemap(typecheck) char *INOUT = char;
306%typemap(typecheck) signed char *INOUT = signed char;
307%typemap(typecheck) unsigned char *INOUT = unsigned char;
308%typemap(typecheck) unsigned long *INOUT = unsigned long;
309%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
310%typemap(typecheck) unsigned short *INOUT = unsigned short;
311%typemap(typecheck) unsigned int *INOUT = unsigned int;
312%typemap(typecheck) long *INOUT = long;
313%typemap(typecheck) long long *INOUT = long long;
314%typemap(typecheck) short *INOUT = short;
315%typemap(typecheck) int *INOUT = int;
316%typemap(typecheck) enum SWIGTYPE *INOUT = enum SWIGTYPE;
317%typemap(typecheck) float *INOUT = float;
318
319%typemap(typecheck) double &INOUT = double;
320%typemap(typecheck) bool &INOUT = bool;
321%typemap(typecheck) char &INOUT = char;
322%typemap(typecheck) signed char &INOUT = signed char;
323%typemap(typecheck) unsigned char &INOUT = unsigned char;
324%typemap(typecheck) unsigned long &INOUT = unsigned long;
325%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
326%typemap(typecheck) unsigned short &INOUT = unsigned short;
327%typemap(typecheck) unsigned int &INOUT = unsigned int;
328%typemap(typecheck) long &INOUT = long;
329%typemap(typecheck) long long &INOUT = long long;
330%typemap(typecheck) short &INOUT = short;
331%typemap(typecheck) int &INOUT = int;
332%typemap(typecheck) enum SWIGTYPE &INOUT = enum SWIGTYPE;
333%typemap(typecheck) float &INOUT = float;