Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / share / swig / 1.3.26 / python / pyvaltypes.swg
CommitLineData
920dae64
AT
1/*---------------------------------------------------------------------
2 * Value typemaps (Type, const Type&) for value types, such as
3 * fundamental types (int, double), that define the As/AsVal/From
4 * methods.
5 *---------------------------------------------------------------------*/
6
7
8/* in */
9
10%define PYVAL_IN_TYPEMAP(as_meth,pyfrag,Type...)
11 %typemap(in,fragment=pyfrag) Type {
12 $1 = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
13 if (SWIG_arg_fail($argnum)) SWIG_fail;
14 }
15 %typemap(in,fragment=pyfrag) const Type & ($*ltype temp) {
16 temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
17 if (SWIG_arg_fail($argnum)) SWIG_fail;
18 $1 = &temp;
19 }
20%enddef
21
22/* out */
23
24%define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,Type...)
25 %typemap(out,fragment=pyfrag) Type, const Type
26 { $result = from_meth(SWIG_static_cast($1,Type)); }
27
28 %typemap(out,fragment=pyfrag) const Type&
29 { $result = from_meth(SWIG_static_cast(*$1,Type)); }
30%enddef
31
32/* varin */
33
34%define PYVAL_VARIN_TYPEMAP(as_meth,pyfrag,Type...)
35 %typemap(varin,fragment=pyfrag) Type {
36 $1_type temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$1_type);
37 if (PyErr_Occurred()) {
38 SWIG_append_errmsg("C/C++ variable '$name ($1_ltype)'");
39 return 1;
40 }
41 $1 = temp;
42 }
43%enddef
44
45/* varout */
46
47%define PYVAL_VAROUT_TYPEMAP(from_meth,pyfrag,Type...)
48 %typemap(varout,fragment=pyfrag) Type, const Type&
49 { $result = from_meth(SWIG_static_cast($1,$basetype)); }
50%enddef
51
52/* constant installation code */
53
54%define PYVAL_CONSTCODE_TYPEMAP(from_meth,pyfrag,Type...)
55 %typemap(constcode,fragment=pyfrag) Type
56 { PyDict_SetItemString(d,"$symname", from_meth(SWIG_static_cast($value,$basetype))); }
57%enddef
58
59/* directorin */
60
61%define PYVAL_DIRECTORIN_TYPEMAP(from_meth,pyfrag,Type...)
62 %typemap(directorin,fragment=pyfrag) Type *DIRECTORIN
63 { $input = from_meth(SWIG_static_cast(*$1_name,$basetype)); }
64 %typemap(directorin,fragment=pyfrag) Type, const Type&
65 { $input = from_meth(SWIG_static_cast($1_name,$basetype)); }
66%enddef
67
68/* directorout */
69
70%define PYVAL_DIRECTOROUT_TYPEMAP(as_meth,pyfrag,Type...)
71 %typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT {
72 if ($input) *$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
73 if (!$input || PyErr_Occurred())
74 Swig::DirectorTypeMismatchException::raise("Error converting Python object when using as_meth.");
75 }
76 %typemap(directorout,fragment=pyfrag) Type {
77 if ($input) $result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
78 if (!$input || PyErr_Occurred())
79 Swig::DirectorTypeMismatchException::raise("Error converting Python object when using as_meth.");
80 }
81 %typemap(directorout,fragment=pyfrag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
82 if ($input) {
83 static $basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
84 $result = &temp;
85 }
86 if (!$input || PyErr_Occurred())
87 Swig::DirectorTypeMismatchException::raise("Error converting Python object when using as_meth.");
88 }
89 %typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
90%enddef
91
92/* throws */
93
94%define PYVAL_THROWS_TYPEMAP(from_meth,pyfrag,Type...)
95 %typemap(throws,fragment=pyfrag) Type {
96 PyErr_SetObject(PyExc_RuntimeError, from_meth(SWIG_static_cast($1,$basetype)));
97 SWIG_fail;
98 }
99%enddef
100
101/* typecheck */
102
103%define PYVAL_TYPECHECK_TYPEMAP(check,pyobj_check,pyfrag,Type...)
104%typemap(typecheck,precedence=check,fragment=pyfrag)
105 Type, const Type&
106 "$1 = pyobj_check($input);";
107%enddef
108
109/*---------------------------------------------------------------------
110 * typemap definition for types with As/Check methods
111 *---------------------------------------------------------------------*/
112%define %typemap_ascheck(CheckCode, AsMeth, CheckMeth,
113 AsFrag, CheckFrag, Type...)
114 PYVAL_IN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
115 PYVAL_VARIN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
116 PYVAL_DIRECTOROUT_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
117 PYVAL_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(CheckMeth),
118 SWIG_arg(CheckFrag), Type);
119
120 PYVAL_INPUT_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsMeth), SWIG_arg(CheckMeth),
121 SWIG_arg(AsFrag), SWIG_arg(CheckFrag), Type);
122%enddef
123
124/*---------------------------------------------------------------------
125 * typemap definition for types with AsVal method
126 *---------------------------------------------------------------------*/
127%define %typemap_asvaln(CheckCode, Type...)
128%fragment(SWIG_As_frag(Type),"header",
129 fragment=SWIG_AsVal_frag(Type)) %{
130SWIGINTERNINLINE Type
131SWIG_As(Type)(PyObject* obj)
132{
133 Type v;
134 if (!SWIG_AsVal(Type)(obj, &v)) {
135 /*
136 this is needed to make valgrind/purify happier.
137 */
138 memset((void*)&v, 0, sizeof(Type));
139 }
140 return v;
141}
142%}
143%fragment(SWIG_Check_frag(Type),"header",
144 fragment=SWIG_AsVal_frag(Type)) %{
145SWIGINTERNINLINE int
146SWIG_Check(Type)(PyObject* obj)
147{
148 return SWIG_AsVal(Type)(obj, (Type*)0);
149}
150%}
151%typemap_ascheck(SWIG_arg(CheckCode),
152 SWIG_As(Type),
153 SWIG_Check(Type),
154 SWIG_arg(SWIG_As_frag(Type)),
155 SWIG_arg(SWIG_Check_frag(Type)),
156 Type);
157%enddef
158
159/*---------------------------------------------------------------------
160 * typemap definition for types with from method
161 *---------------------------------------------------------------------*/
162%define %typemap_from(FromMeth, FromFrag, Type...)
163 PYVAL_OUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
164 PYVAL_VAROUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
165 PYVAL_CONSTCODE_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
166 PYVAL_DIRECTORIN_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
167 PYVAL_THROWS_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
168 PYVAL_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
169
170%enddef
171
172
173%define %typemap_ascheckfrom(CheckCode, AsMeth, CheckMeth, FromMeth,
174 AsFrag, CheckFrag, FromFrag, Type...)
175 %typemap_ascheck(SWIG_arg(CheckCode), SWIG_arg(AsMeth), SWIG_arg(CheckMeth),
176 SWIG_arg(AsFrag), SWIG_arg(CheckFrag), Type);
177 %typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
178
179 PYVAL_INOUT_TYPEMAP(Type);
180
181%enddef
182
183/*---------------------------------------------------------------------
184 * typemap definition for types with asval/from method
185 *---------------------------------------------------------------------*/
186%define %typemap_asvalfromn(CheckCode, Type...)
187 %typemap_asvaln(SWIG_arg(CheckCode), Type);
188 %typemap_from(SWIG_arg(SWIG_From(Type)),
189 SWIG_arg(SWIG_From_frag(Type)),
190 Type);
191
192 PYVAL_INOUT_TYPEMAP(Type);
193
194%enddef
195
196/*---------------------------------------------------------------------
197 * typemap definition for types with as/check/from method
198 *---------------------------------------------------------------------*/
199%define %typemap_ascheckfromn(CheckCode, Type...)
200 %typemap_ascheckfrom(SWIG_arg(CheckCode),
201 SWIG_As(Type),
202 SWIG_From(Type),
203 SWIG_Check(Type),
204 SWIG_arg(SWIG_As_frag(Type)),
205 SWIG_arg(SWIG_From_frag(Type)),
206 SWIG_arg(SWIG_Check_frag(Type)),
207 Type);
208%enddef