Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / share / swig / 1.3.26 / php4 / typemaps.i
CommitLineData
920dae64
AT
1//
2// SWIG Typemap library
3// Richard Palmer
4// Oct 3, 2001
5//
6// PHP4 implementation
7//
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
14//
15// Define macros to define the following typemaps:
16//
17// TYPE *INPUT. Argument is passed in as native variable by value.
18// TYPE *OUTPUT. Argument is returned as an array from the function call.
19// TYPE *INOUT. Argument is passed in by value, and out as part of returned list
20// TYPE *REFERENCE. Argument is passed in as native variable with value
21// semantics. Variable value is changed with result.
22// Use like this:
23// int foo(int *REFERENCE);
24//
25// $a = 0;
26// $rc = foo($a);
27//
28// Even though $a looks like it's passed by value,
29// it's value can be changed by foo().
30//
31%define double_typemap(TYPE)
32%typemap(in) TYPE *INPUT(TYPE temp)
33{
34 convert_to_double_ex($input);
35 temp = (TYPE) Z_DVAL_PP($input);
36 $1 = &temp;
37}
38%typemap(argout) TYPE *INPUT "";
39%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp)
40{
41 $1 = &temp;
42}
43%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
44{
45 zval *o;
46 MAKE_STD_ZVAL(o);
47 ZVAL_DOUBLE(o,temp$argnum);
48 t_output_helper( &$result, o );
49}
50%typemap(in) TYPE *REFERENCE (TYPE dvalue)
51{
52 convert_to_double_ex($input);
53 dvalue = (TYPE) (*$input)->value.dval;
54 $1 = &dvalue;
55}
56%typemap(argout) TYPE *REFERENCE
57{
58 $1->value.dval = (double)(lvalue$argnum);
59 $1->type = IS_DOUBLE;
60}
61%enddef
62
63%define int_typemap(TYPE)
64%typemap(in) TYPE *INPUT(TYPE temp)
65{
66 convert_to_long_ex($input);
67 temp = (TYPE) Z_LVAL_PP($input);
68 $1 = &temp;
69}
70%typemap(argout) TYPE *INPUT "";
71%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp)
72{
73 $1 = &temp;
74}
75%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
76{
77 zval *o;
78 MAKE_STD_ZVAL(o);
79 ZVAL_LONG(o,temp$argnum);
80 t_output_helper( &$result, o );
81}
82%typemap(in) TYPE *REFERENCE (TYPE lvalue)
83{
84 convert_to_long_ex($input);
85 lvalue = (TYPE) (*$input)->value.lval;
86 $1 = &lvalue;
87}
88%typemap(argout) TYPE *REFERENCE
89{
90
91 (*$arg)->value.lval = (long)(lvalue$argnum);
92 (*$arg)->type = IS_LONG;
93}
94%enddef
95
96double_typemap(float);
97double_typemap(double);
98
99int_typemap(int);
100int_typemap(short);
101int_typemap(long);
102int_typemap(unsigned int);
103int_typemap(unsigned short);
104int_typemap(unsigned long);
105int_typemap(unsigned char);
106
107%typemap(in) float *INOUT = float *INPUT;
108%typemap(in) double *INOUT = double *INPUT;
109
110%typemap(in) int *INOUT = int *INPUT;
111%typemap(in) short *INOUT = short *INPUT;
112%typemap(in) long *INOUT = long *INPUT;
113%typemap(in) unsigned *INOUT = unsigned *INPUT;
114%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
115%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
116%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
117
118%typemap(argout) float *INOUT = float *OUTPUT;
119%typemap(argout) double *INOUT= double *OUTPUT;
120
121%typemap(argout) int *INOUT = int *OUTPUT;
122%typemap(argout) short *INOUT = short *OUTPUT;
123%typemap(argout) long *INOUT= long *OUTPUT;
124%typemap(argout) unsigned short *INOUT= unsigned short *OUTPUT;
125%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
126%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
127
128%typemap(in) char INPUT[ANY] ( char temp[$1_dim0] )
129{
130 convert_to_string_ex($input);
131 char *val = Z_LVAL_PP($input);
132 strncpy(temp,val,$1_dim0);
133 $1 = temp;
134}
135%typemap(in,numinputs=0) char OUTPUT[ANY] ( char temp[$1_dim0] )
136{
137 $1 = temp;
138}
139%typemap(argout) char OUTPUT[ANY]
140{
141 zval *o;
142 MAKE_STD_ZVAL(o);
143 ZVAL_STRINGL(o,temp$argnum,$1_dim0);
144 t_output_helper( &$result, o );
145}
146
147%typemap(in,numinputs=0) void **OUTPUT (int force),
148 void *&OUTPUT (int force)
149{
150 /* If they pass NULL by reference, make it into a void*
151 This bit should go in arginit if arginit support init-ing scripting args */
152 if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
153 /* So... we didn't get a ref or ptr, but we'll accept NULL by reference */
154 if ((*$input)->type==IS_NULL && PZVAL_IS_REF(*$input)) {
155#ifdef __cplusplus
156 ptr=new $*1_ltype;
157#else
158 ptr=($*1_ltype) calloc(1,sizeof($*1_ltype));
159#endif
160 $1=&ptr;
161 /* have to passback arg$arg too */
162 force=1;
163 } else { /* wasn't a pre/ref/thing, OR anything like an int thing */
164 force=0;
165 SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname.");
166 }
167 } else force=0;
168}
169
170%typemap(argout) void **OUTPUT,
171 void *&OUTPUT
172{
173 if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
174 if(! PZVAL_IS_REF(*$arg)) {
175 SWIG_PHP_Error(E_WARNING, "Parameter $argnum of $symname wasn't passed by reference");
176 } else {
177 SWIG_SetPointerZval(*$arg, (void *) ptr$argnum, $*1_descriptor, 1);
178 }
179 }
180}