1 # psi_add_struct(struct members)
2 # Add a pre-defined struct to $PSI_STRUCTS.
4 cat >>$PSI_STRUCTS <<EOF
9 # psi_add_union(union/struct members)
10 # Add a pre-defined union to $PSI_UNIONS.
12 cat >>$PSI_UNIONS <<EOF
17 dnl PSI_STRUCT_MEMBER(struct name, decl member)
18 dnl INTERNAL: build $psi_struct_members
19 AC_DEFUN(PSI_STRUCT_MEMBER, [
20 m4_define([member_name], PSI_VAR_NAME($2))
21 m4_define([member_type], PSI_VAR_TYPE($2))
22 PSI_CHECK_SIZEOF(AS_TR_SH($1)[_]member_name,
23 [#define ]AS_TR_SH($1)[_]member_name (($1 *)0)->member_name
25 if PSI_SH_TEST_SIZEOF($1 member_name); then
26 PSI_CHECK_OFFSETOF($1, member_name)
27 PSI_TYPE_INDIRECTION($2, [PSI_SH_SIZEOF([$1 member_name])], pl, as)
29 psi_member_sizeof=PSI_SH_SIZEOF($1 member_name)
30 psi_member_offsetof=PSI_SH_OFFSETOF($1 member_name)
32 if test $pl -gt 0 && test $as -eq 0; then
33 check_size=PSI_SH_SIZEOF(void *)
34 elif test $pl -eq 1 && test $as -gt 0; then
35 check_size=`expr PSI_SH_SIZEOF(member_type) \* $as`
37 check_size=PSI_SH_SIZEOF(member_type)
39 if test $psi_member_sizeof != "$check_size"; then
40 psi_member_basic_type=PSI_SH_BASIC_TYPE(member_type)
41 psi_member_type_pair="`psi_type_pair $psi_member_basic_type $psi_member_sizeof`"
42 psi_struct_members="$psi_struct_members, {$psi_member_type_pair, \"[]member_name[]\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}"
43 AC_MSG_WARN(pre-defined size $check_size of $2 in $1 does not match computed size $psi_member_sizeof; adjusting to $psi_member_type_pair)
45 psi_struct_members="[$psi_struct_members, {]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}]"
50 dnl PSI_STRUCT(struct name, struct members)
51 dnl Check a struct and its members and add a pre-defined struct and possibly a
52 dnl pre-defined type for this struct.
53 dnl Calls PSI_CHECK_SIZEOF and PSI_CHECK_ALIGNOF for the struct.
54 dnl Calls PSI_CHECK_SIZEOF, PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member.
55 AC_DEFUN(PSI_STRUCT, [
57 if PSI_SH_TEST_SIZEOF($1); then
59 psi_struct_name=m4_bregexp([$1], [^\(struct \)?\(\w+\)], [\2])
60 psi_struct_members="{PSI_T_STRUCT, \"struct\", \"$psi_struct_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}"
61 ifelse([$2],,,[m4_map_args_sep([PSI_STRUCT_MEMBER($1, m4_normalize(], [))], [], $2)])
62 psi_add_struct "$psi_struct_members"
63 if test "$1" = "$psi_struct_name"; then
64 psi_add_type "{PSI_T_STRUCT, \"$1\", \"$1\"}"
69 dnl PSI_UNION(union name, union/struct members)
70 dnl Check a union and its members and add a pre-defined union and possibly a
71 dnl pre-defined type for this union.
72 dnl Calls PSI_CHECK_SIZEOF for the union and each member.
73 dnl Calls PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member.
76 if PSI_SH_TEST_SIZEOF($1); then
78 psi_struct_name=m4_bregexp([$1], [^\(union \)?\(\w+\)], [\2])
79 psi_struct_members="{PSI_T_UNION, \"union\", \"$psi_struct_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}"
80 ifelse([$2],,,[m4_map_args_sep([PSI_STRUCT_MEMBER($1, m4_normalize(], [))], [], $2)])
81 psi_add_union "$psi_struct_members"
82 if test "$1" = "$psi_struct_name"; then
83 psi_add_type "{PSI_T_UNION, \"$1\", \"$1\"}"