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