X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=m4%2Fpsi_type.m4;h=85750d9183892591b7521b350e5412dc8cd4ec6b;hp=3b0a22efc0bff960e3645332983e5d68c42649a0;hb=5abcb8724ac7046d62203ea643e9ce69f63a6a8a;hpb=2421d323be79e4a811a4197914330a8c0124b130 diff --git a/m4/psi_type.m4 b/m4/psi_type.m4 index 3b0a22e..85750d9 100644 --- a/m4/psi_type.m4 +++ b/m4/psi_type.m4 @@ -7,7 +7,7 @@ psi_type_pair() { local psi_type_upper=`tr a-z A-Z <<<$psi_type_name` local psi_type_bits=`expr $2 \* 8` echo "PSI_T_${psi_type_upper}${psi_type_bits}, \"${psi_type_lower}${psi_type_bits}_t\"" - eval AS_TR_SH([psi_standard_type_]$1)="${psi_type_lower}${psi_type_bits}_t" + #eval AS_TR_SH([psi_standard_type_]$1)="${psi_type_lower}${psi_type_bits}_t" ;; struct*) echo "PSI_T_STRUCT, \"$2\"" @@ -21,16 +21,16 @@ psi_type_pair() { esac } -dnl PSI_TYPE(type name, basic type, includes) +dnl PSI_TYPE(type name, basic type) AC_DEFUN(PSI_TYPE, [ ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1)) PSI_CHECK_SIZEOF($1, PSI_INCLUDES) - psi_basic_type=$2 + psi_basic_type=AS_TR_SH($2) case $psi_basic_type in int) AX_CHECK_SIGN($1, :, [ psi_basic_type=uint - ], $psi_header) + ], PSI_INCLUDES) ;; sint) psi_basic_type=int @@ -38,7 +38,45 @@ AC_DEFUN(PSI_TYPE, [ esac if test "$2" && test "$AS_TR_SH([ac_cv_sizeof_]$1)" -gt 0; then AS_TR_SH(psi_basic_type_$1)=$psi_basic_type - PSI_TYPES="{`psi_type_pair $psi_basic_type $AS_TR_SH([ac_cv_sizeof_]$1)`, \"$1\"}, $PSI_TYPES" + cat >>$PSI_TYPES <<<" {`psi_type_pair $psi_basic_type $AS_TR_SH([ac_cv_sizeof_]$1)`, \"$1\"}, " + fi +]) + +AC_DEFUN(PSI_OPAQUE_TYPE, [ + ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1)) + PSI_CHECK_SIZEOF($1, PSI_INCLUDES) + if test "$AS_TR_SH([ac_cv_sizeof_]$1)" -gt 0; then + psi_type_class= + AC_CACHE_CHECK(type class of $1, AS_TR_SH([psi_cv_type_class_]$1), [ + AC_TRY_COMPILE(PSI_INCLUDES, [char test@<:@($1)1@:>@;], [ + psi_type_class=scalar + ], [ + AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = 0;], [ + AC_TRY_COMPILE(PSI_INCLUDES, [$1 test = (($1)0)+1;], [ + psi_type_class="pointer of known type" + ], [ + psi_type_class="pointer of opaque type" + ]) + ], [ + psi_type_class=struct + ]) + ]) + AS_TR_SH([psi_cv_type_class_]$1)="$psi_type_class" + ]) + case "$AS_TR_SH([psi_cv_type_class_]$1)" in + scalar) + PSI_TYPE($1, int) + ;; + struct) + PSI_STRUCT($1) + ;; + pointer*) + cat >>$PSI_TYPES <<<" {PSI_T_POINTER, \"void\", \"$1\"}, " + ;; + *) + AC_MSG_WARN(could not detect type class of $1) + ;; + esac fi ]) @@ -58,32 +96,32 @@ AC_DEFUN(PSI_TYPE_BITS, [`expr 8 \* $AS_TR_SH([ac_cv_sizeof_]$1)`]) dnl PSI_TYPE_INDIRECTION(type, size, pointer_level_var, array_size_var) AC_DEFUN(PSI_TYPE_INDIRECTION, [ - AC_MSG_CHECKING(indirection of $1) - m4_define([pointer_level], m4_len(m4_bpatsubst([PSI_VAR_TYPE($1)], [[^*]]))) - m4_define([array_size], [m4_bregexp([PSI_VAR_TYPE($1)], [@<:@\([0-9]+\)@:>@], [\1])]) - - ifelse(array_size.$2,0., [ + dnl AC_MSG_CHECKING(indirection of $1) + m4_define([psi_pointer_level], m4_len(m4_bpatsubst([PSI_VAR_TYPE($1)], [[^*]]))) + m4_define([psi_array_size], [m4_bregexp([PSI_VAR_TYPE($1)], [@<:@\([0-9]+\)@:>@], [\1])]) + + ifelse(psi_array_size.$2,0., [ AC_MSG_ERROR([cannot compute dynamic array size of a non-struct member]) ], [ - ifelse(pointer_level,0,[ - m4_define([type_size],[$]AS_TR_SH([ac_cv_sizeof_]m4_bregexp(PSI_VAR_TYPE([$1]), [^\( \|\w\)+], [\&]))) + ifelse(psi_pointer_level,0,[ + m4_define([psi_type_size],[$]AS_TR_SH([ac_cv_sizeof_]m4_bregexp(PSI_VAR_TYPE([$1]), [^\( \|\w\)+], [\&]))) ],[ - m4_define([type_size],$ac_cv_sizeof_void_p) + m4_define([psi_type_size],$ac_cv_sizeof_void_p) ]) ]) - - m4_case(array_size,,[ - $3=pointer_level + + m4_case(psi_array_size,,[ + $3=psi_pointer_level $4=0] ,0,[ - $3=m4_incr(pointer_level) - $4="`expr $2 / type_size`" + $3=m4_incr(psi_pointer_level) + $4="`expr $2 / psi_type_size`" ], [ - $3=m4_incr(pointer_level) - $4=array_size + $3=m4_incr(psi_pointer_level) + $4=psi_array_size ]) - - AC_MSG_RESULT([[$]$3, [$]$4]) + + dnl AC_MSG_RESULT([[$]$3, [$]$4]) ]) AC_DEFUN(PSI_TYPE_PAIR, [m4_case(m4_bregexp([$1], [^\w+], [\&]), @@ -123,16 +161,34 @@ AC_DEFUN(PSI_CHECK_STD_TYPES, [ AC_CHECK_ALIGNOF(float) PSI_TYPE(double) AC_CHECK_ALIGNOF(double) + PSI_TYPE(long double) + AC_CHECK_ALIGNOF(long double) PSI_TYPE(void *) AC_CHECK_ALIGNOF(void *) PSI_TYPE(char, int) + PSI_TYPE(signed char, int) PSI_TYPE(unsigned char, uint) PSI_TYPE(short, int) + PSI_TYPE(short int, int) + PSI_TYPE(signed short, int) + PSI_TYPE(signed short int, int) PSI_TYPE(unsigned short, uint) + PSI_TYPE(unsigned short int, uint) PSI_TYPE(int, int) + PSI_TYPE(signed int, int) + PSI_TYPE(signed, int) PSI_TYPE(unsigned int, uint) PSI_TYPE(unsigned, uint) PSI_TYPE(long, int) + PSI_TYPE(long int, int) + PSI_TYPE(signed long int, int) PSI_TYPE(unsigned long, uint) + PSI_TYPE(unsigned long int, uint) + PSI_TYPE(long long, int) + PSI_TYPE(long long int, int) + PSI_TYPE(signed long long, int) + PSI_TYPE(signed long long int, int) + PSI_TYPE(unsigned long long, uint) + PSI_TYPE(unsigned long long int, uint) ])