expand let marshal's parameters
[m6w6/ext-psi] / m4 / psi_type.m4
index 050f80542bf504338b750afbb28aff6990972b46..ad2d0001cbc6275d722f0c836d13f318bc65f0a0 100644 (file)
@@ -1,28 +1,35 @@
 # psi_add_type(type triplet)
 # Add a pre-defined type to $PSI_TYPES.
 psi_add_type() {
-       cat >>$PSI_TYPES <<<"   $1, "
+       cat >>$PSI_TYPES <<EOF
+       $1, 
+EOF
 }
 
 psi_add_stdtype() {
-       cat >>$PSI_STDTYPES <<<"        $1, "
+       cat >>$PSI_STDTYPES <<EOF
+       $1, 
+EOF
 }
 
 # psi_type_pair(type, size)
 # Output a PSI_T_<TYPE>, \"<TYPENAME>\" tuple.
 # Uses stdint types when possible.
 psi_type_pair() {
-       local psi_type_name=`tr -cd A-Za-z0-9_ <<<$1`
-       local psi_type_lower=`tr A-Z a-z <<<$psi_type_name`
+       local psi_type_name=`printf "%s" "$1" | tr -cd A-Za-z0-9_`
+       local psi_type_lower=`printf "%s" "$1" | tr A-Z a-z`
        case $psi_type_lower in
        int*|uint*)
-               local psi_type_upper=`tr a-z A-Z <<<$psi_type_name`
+               local psi_type_upper=`printf "%s" "$psi_type_name" | tr a-z A-Z`
                local psi_type_bits=`expr $2 \* 8`
                echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\""
                ;;
        struct*)
                echo "PSI_T_STRUCT, \"$2\""
                ;;
+       union*)
+               echo "PSI_T_UNION, \"$2\""
+               ;;
        void)
                echo "PSI_T_VOID, \"void\""
                ;;
@@ -86,7 +93,7 @@ AC_DEFUN(PSI_OPAQUE_TYPE, [
        PSI_CHECK_SIZEOF($1)
        if PSI_SH_TEST_SIZEOF($1); then
                psi_type_class=
-               AC_CACHE_CHECK(type class of $1, AS_TR_SH([psi_cv_type_class_]$1), [
+               AC_CACHE_CHECK(kind of $1, AS_TR_SH([psi_cv_type_class_]$1), [
                        AC_TRY_COMPILE(PSI_INCLUDES, [char test@<:@($1)1@:>@;], [
                                psi_type_class=scalar
                        ], [
@@ -114,12 +121,20 @@ AC_DEFUN(PSI_OPAQUE_TYPE, [
                        psi_add_type "{PSI_T_POINTER, \"void\", \"$1\"}"
                        ;;
                *)
-                       AC_MSG_WARN(could not detect type class of $1)
+                       AC_MSG_WARN(could not detect kind of $1)
                        ;;
                esac
        fi
 ])
 
+dnl PSI_FUNCTOR_TYPE(type functor_name, args)
+dnl Forwards to PSI_DECL_TYPE.
+AC_DEFUN(PSI_FUNCTOR_TYPE, [
+       dnl psi_add_type "{PSI_T_POINTER, \"void\", \"PSI_VAR_NAME($1)\"}"
+       AS_TR_SH([ac_cv_sizeof_]PSI_VAR_NAME($1))=PSI_SH_SIZEOF(void *)
+       PSI_DECL_TYPE([$1], [$2])
+])
+
 dnl PSI_VAR_TYPE(decl arg)
 dnl Extracts the type of a decl arg, e.g. dnl unsigned char* buf[16] -> unsigned char*.
 AC_DEFUN(PSI_VAR_TYPE, [m4_bregexp([$1], [^\(const \)?\(.*\) \([*]*\)[^ ]+$], [\2\3])])
@@ -162,6 +177,7 @@ dnl FIXME: There is also psi_type_pair()?
 AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([$1], [^\w+], [\&]),
        [void], [PSI_T_VOID, \"void\"],
        [struct], [PSI_T_STRUCT, \"m4_bregexp([$1], [^struct \(\w+\)], [\1])\"],
+       [union], [PSI_T_UNION, \"m4_bregexp([$1], [^union \(\w+\)], [\1])\"],
        [PSI_T_NAME, \"m4_bregexp([$1], [^\(\w+ \)*\w+], [\&])\"])])
 
 dnl PSI_CHECK_STD_TYPES()