2 # Add a pre-defined type to \$PSI_TYPES_H.
4 PSI_TYPES="\$PSI_TYPES
5 \$1,"
6 }
9 PSI_STDTYPES="\$PSI_STDTYPES
10 \$1,"
11 }
13 # psi_type_pair(type, size)
14 # Output a PSI_T_<TYPE>, \"<TYPENAME>\" tuple.
15 # Uses stdint types when possible.
16 psi_type_pair() {
17 local psi_type_name=`printf "%s" "\$1" | tr -cd A-Za-z0-9_`
18 local psi_type_lower=`printf "%s" "\$1" | tr A-Z a-z`
19 while expr "\$psi_type_lower" : const >/dev/null; do
20 psi_type_lower=`printf "%s" "\$psi_type_lower" | cut -d " " -f2-`
21 done
22 case \$psi_type_lower in
23 int*|uint*)
24 local psi_type_upper=`printf "%s" "\$psi_type_name" | tr a-z A-Z`
25 local psi_type_bits=`expr \$2 \* 8`
26 echo "PSI_T_\${psi_type_upper}\${psi_type_bits}, \"\${psi_type_lower}\${psi_type_bits}_t\""
27 ;;
28 struct*)
29 echo "PSI_T_STRUCT, \"\$2\""
30 ;;
31 union*)
32 echo "PSI_T_UNION, \"\$2\""
33 ;;
34 void)
35 echo "PSI_T_VOID, \"void\""
36 ;;
37 *)
38 echo "PSI_T_NAME, \"\$psi_type_name\""
39 ;;
40 esac
41 }
43 dnl PSI_TYPE(type name, basic type)
44 dnl Check for a specific type, optionally referring to a basic type.
45 dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
46 dnl If the basic type is just specified as "int" (in contrast to "sint" or
47 dnl "uint"), AX_CHECK_SIGN is used to discover signedness of the type.
48 dnl Defines a pre-defined type in \$PSI_TYPES_H.
49 AC_DEFUN(PSI_TYPE, [
50 ifdef(AS_TR_CPP(AC_TYPE_\$1), AS_TR_CPP(AC_TYPE_\$1))
51 PSI_CHECK_SIZEOF(\$1)
52 psi_basic_type=AS_TR_SH(\$2)
53 case \$psi_basic_type in
54 int)
55 AX_CHECK_SIGN(\$1, :, [psi_basic_type=uint], PSI_INCLUDES)
56 ;;
57 sint)
58 psi_basic_type=int
59 ;;
60 esac
61 if test "\$2" && PSI_SH_TEST_SIZEOF(\$1); then
62 AS_TR_SH(psi_basic_type_\$1)=\$psi_basic_type
63 psi_add_type "{`psi_type_pair \$psi_basic_type PSI_SH_SIZEOF(\$1)`, \"\$1\"}"
64 fi
65 ])
67 AC_DEFUN(PSI_STDTYPE, [
68 ifdef(AS_TR_CPP(AC_TYPE_\$1), AS_TR_CPP(AC_TYPE_\$1))
69 PSI_CHECK_SIZEOF(\$1)
70 if PSI_SH_TEST_SIZEOF(\$1); then
71 m4_case([\$1],
75 [long double],[psi_add_stdtype "{PSI_T_LONG_DOUBLE, \"long double\", NULL}"],
76 [
77 AX_CHECK_SIGN(\$1, psi_basic_type=int, psi_basic_type=uint, PSI_INCLUDES)
78 AS_TR_SH(psi_basic_type_\$1)=\$psi_basic_type
79 psi_add_stdtype "{`psi_type_pair \$psi_basic_type PSI_SH_SIZEOF(\$1)`, \"\$1\"}"
80 ])
81 fi
82 ])
84 dnl PSI_SH_BASIC_TYPE(type)
85 dnl Expand to the basic type (int/uint) of a distinct type
86 AC_DEFUN(PSI_SH_BASIC_TYPE, [\$AS_TR_SH([psi_basic_type_]\$1)])
88 dnl PSI_OPAQUE_TYPE(type name)
89 dnl Checks a type for being a scalar, a struct or a pointer type.
90 dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
91 dnl Defines a pre-defined type in \$PSI_TYPES_H and a pre-defined struct in
92 dnl \$PSI_STRUCTS if the type is a struct.
93 AC_DEFUN(PSI_OPAQUE_TYPE, [
94 ifdef(AS_TR_CPP(AC_TYPE_\$1), AS_TR_CPP(AC_TYPE_\$1))
95 PSI_CHECK_SIZEOF(\$1)
96 if PSI_SH_TEST_SIZEOF(\$1); then
97 psi_type_class=
98 AC_CACHE_CHECK(kind of \$1, AS_TR_SH([psi_cv_type_class_]\$1), [
99 AC_TRY_COMPILE(PSI_INCLUDES, [char test@<:@(\$1)1@:>@;], [
100 psi_type_class=scalar
101 ], [
102 AC_TRY_COMPILE(PSI_INCLUDES, [\$1 test = 0;], [
103 AC_TRY_COMPILE(PSI_INCLUDES, [\$1 test = ((\$1)0)+1;], [
104 psi_type_class="pointer of known type"
105 ], [
106 psi_type_class="pointer of opaque type"
107 ])
108 ], [
109 psi_type_class=struct
110 ])
111 ])
112 AS_TR_SH([psi_cv_type_class_]\$1)="\$psi_type_class"
113 ])
114 case "\$AS_TR_SH([psi_cv_type_class_]\$1)" in
115 scalar)
116 AX_CHECK_SIGN(\$1, [psi_basic_type=int], [psi_basic_type=uint], PSI_INCLUDES)
117 psi_add_type "{`psi_type_pair \$psi_basic_type PSI_SH_SIZEOF(\$1)`, \"\$1\"}"
118 ;;
119 struct)
120 PSI_STRUCT(\$1)
121 ;;
122 pointer*)
124 ;;
125 *)
126 AC_MSG_WARN(could not detect kind of \$1)
127 ;;
128 esac
129 fi
130 ])
132 dnl PSI_FUNCTOR_TYPE(type functor_name, args)
133 dnl Forwards to PSI_DECL_TYPE.
134 AC_DEFUN(PSI_FUNCTOR_TYPE, [
135 dnl psi_add_type "{PSI_T_POINTER, \"void\", \"PSI_VAR_NAME(\$1)\"}"
136 AS_TR_SH([ac_cv_sizeof_]PSI_VAR_NAME(\$1))=PSI_SH_SIZEOF(void *)
137 PSI_DECL_TYPE([\$1], [\$2])
138 if test "\$PHP_DEBUG" = "1"; then
139 AC_CHECK_TYPE(PSI_VAR_NAME(\$1), [], [
142 ])
143 fi
144 ])
146 dnl PSI_VAR_TYPE(decl arg)
147 dnl Extracts the type of a decl arg, e.g. dnl unsigned char* buf[16] -> unsigned char*.
148 AC_DEFUN(PSI_VAR_TYPE, [m4_bregexp([\$1], [^\(const \)?\(.*\) \([*]*\)[^ ]+\$], [\2\3])])
150 dnl PSI_VAR_TYPE_RETURN(decl arg)
151 dnl Extracts the type of a decl arg usable for return types, e.g. dnl unsigned char* buf[16] -> unsigned char**.
152 AC_DEFUN(PSI_VAR_TYPE_RETURN, [PSI_VAR_TYPE(m4_bpatsubst([\$1], [\([^ ]+\) *@<:@[0-9]+@:>@], [* \1]))])
154 dnl PSI_VAR_NAME(decl arg)
155 dnl Extracts the var name of a decl arg, e.g. unsigned char* buf[16] -> buf.
156 AC_DEFUN(PSI_VAR_NAME, [m4_bregexp(m4_bregexp([\$1], [\([^ ]+\)\$], [\1]), [\w+], [\&])])
158 dnl PSI_TYPE_INDIRECTION(decl arg, size, pointer_level_var, array_size_var)
159 dnl Calculates and assigns pointer_level and array_size of a decl arg to sh vars.
160 AC_DEFUN(PSI_TYPE_INDIRECTION, [
161 m4_define([psi_pointer_level], m4_len(m4_bpatsubst([PSI_VAR_TYPE(\$1)], [[^*]])))
162 m4_define([psi_array_size], [m4_bregexp([PSI_VAR_TYPE(\$1)], [@<:@\([0-9]+\)@:>@], [\1])])
164 ifelse(psi_array_size.\$2,0., [
165 AC_MSG_ERROR([cannot compute dynamic array size of a non-struct member])
166 ], [
167 ifelse(psi_pointer_level,0,[
168 m4_define([psi_type_size],[\$]AS_TR_SH([ac_cv_sizeof_]m4_bregexp(PSI_VAR_TYPE([\$1]), [^\( \|\w\)+], [\&])))
169 ],[
170 m4_define([psi_type_size],\$ac_cv_sizeof_void_p)
171 ])
172 ])
174 m4_case(psi_array_size,,[
175 \$3=psi_pointer_level
176 \$4=0]
177 ,0,[
178 \$3=m4_incr(psi_pointer_level)
179 \$4="`expr \$2 / psi_type_size`"
180 ], [
181 \$3=m4_incr(psi_pointer_level)
182 \$4=psi_array_size
183 ])
184 ])
186 dnl PSI_TYPE_PAIR(type)
187 dnl Expand to a PSI_T_<TYPE>, \\"<TYPENAME>\\" tuple.
188 dnl FIXME: There is also psi_type_pair()?
189 AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([\$1], [^\w+], [\&]),
190 [void], [PSI_T_VOID, \"void\"],
191 [struct], [PSI_T_STRUCT, \"m4_bregexp([\$1], [^struct \(\w+\)], [\1])\"],
192 [union], [PSI_T_UNION, \"m4_bregexp([\$1], [^union \(\w+\)], [\1])\"],
193 [PSI_T_NAME, \"m4_bregexp([\$1], [^\(\w+ \)*\w+], [\&])\"])])
195 dnl PSI_CHECK_STD_TYPES()
196 dnl Checks for standard ANSI-C, stdint and stdbool types.
197 AC_DEFUN(PSI_CHECK_STD_TYPES, [
201 AC_TYPE_INT8_T
202 PSI_CHECK_SIZEOF(int8_t)
203 AC_CHECK_ALIGNOF(int8_t)
204 AC_TYPE_UINT8_T
205 PSI_CHECK_SIZEOF(uint8_t)
206 AC_CHECK_ALIGNOF(uint8_t)
207 AC_TYPE_INT16_T
208 PSI_CHECK_SIZEOF(int16_t)
209 AC_CHECK_ALIGNOF(int16_t)
210 AC_TYPE_UINT16_T
211 PSI_CHECK_SIZEOF(uint16_t)
212 AC_CHECK_ALIGNOF(uint16_t)
213 AC_TYPE_INT32_T
214 PSI_CHECK_SIZEOF(int32_t)
215 AC_CHECK_ALIGNOF(int32_t)
216 AC_TYPE_UINT32_T
217 PSI_CHECK_SIZEOF(uint32_t)
218 AC_CHECK_ALIGNOF(uint32_t)
219 AC_TYPE_INT64_T
220 PSI_CHECK_SIZEOF(int64_t)
221 AC_CHECK_ALIGNOF(int64_t)
222 AC_TYPE_UINT64_T
223 PSI_CHECK_SIZEOF(uint64_t)
224 AC_CHECK_ALIGNOF(uint64_t)
226 PSI_CHECK_SIZEOF(void *)
227 AC_CHECK_ALIGNOF(void *)
229 PSI_STDTYPE(float)
230 AC_CHECK_ALIGNOF(float)
231 PSI_STDTYPE(double)
232 AC_CHECK_ALIGNOF(double)
233 PSI_STDTYPE(long double)
234 AC_CHECK_ALIGNOF(long double)
236 PSI_STDTYPE(bool)
237 AC_CHECK_ALIGNOF(bool, PSI_INCLUDES)
239 PSI_STDTYPE(char, int)
240 AC_CHECK_ALIGNOF(char)
241 PSI_STDTYPE(signed char, int)
242 PSI_STDTYPE(unsigned char, uint)
243 PSI_STDTYPE(short, int)
244 AC_CHECK_ALIGNOF(short)
245 PSI_STDTYPE(short int, int)
246 PSI_STDTYPE(signed short, int)
247 PSI_STDTYPE(signed short int, int)
248 PSI_STDTYPE(unsigned short, uint)
249 PSI_STDTYPE(unsigned short int, uint)
250 PSI_STDTYPE(int, int)
251 AC_CHECK_ALIGNOF(int)
252 PSI_STDTYPE(signed int, int)
253 PSI_STDTYPE(signed, int)
254 PSI_STDTYPE(unsigned int, uint)
255 PSI_STDTYPE(unsigned, uint)
256 PSI_STDTYPE(long, int)
257 AC_CHECK_ALIGNOF(long)
258 PSI_STDTYPE(long int, int)
259 PSI_STDTYPE(signed long int, int)
260 PSI_STDTYPE(unsigned long, uint)
261 PSI_STDTYPE(unsigned long int, uint)
262 PSI_STDTYPE(long long, int)
263 AC_CHECK_ALIGNOF(long long)
264 PSI_STDTYPE(signed long long, int)
265 PSI_STDTYPE(signed long long int, int)
266 PSI_STDTYPE(unsigned long long, uint)
267 PSI_STDTYPE(unsigned long long int, uint)
268 dnl this must come after the check for "unsigned long long int"; autoconf, wth?
269 PSI_STDTYPE(long long int, int)
270 ])