Commit e6ff97b1 by Rodney Brown Committed by Benjamin Kosnik

gen-num-limits.cc (traps): Add fflush prior to trapping signal (UnixWare 7 workaround).


2001-03-12  Rodney Brown  <RodneyBrown@mynd.com>

        * src/gen-num-limits.cc (traps) [SPECIALIZE_TRAPPING]: Add fflush
        prior to trapping signal (UnixWare 7 workaround).

From-SVN: r40422
parent 23712c11
2001-03-12 Rodney Brown <RodneyBrown@mynd.com>
* src/gen-num-limits.cc (traps) [SPECIALIZE_TRAPPING]: Add fflush
prior to trapping signal (UnixWare 7 workaround).
2001-03-12 Craig Rodrigues <rodrigc@mediaone.net> 2001-03-12 Craig Rodrigues <rodrigc@mediaone.net>
* include/backward/hashtable.h: Same. * include/backward/hashtable.h: Same.
......
...@@ -139,49 +139,55 @@ bool trapping(const Operation& op) ...@@ -139,49 +139,55 @@ bool trapping(const Operation& op)
return false; return false;
} }
template<typename T> struct division_by_zero { template<typename T>
struct division_by_zero
{
void operator() () const void operator() () const
{ {
volatile T zero = T(); volatile T zero = T();
volatile T one = T(1); volatile T one = T(1);
volatile T infinity = one / zero; volatile T infinity = one / zero;
} }
}; };
template<typename T> struct overflow { template<typename T>
struct overflow
{
void operator() () const void operator() () const
{ {
T i = T(1); T i = T(1);
T j = T(); T j = T();
while (i>j) { while (i>j) {
j = i; j = i;
i = i * 2 + 1; i = i * 2 + 1;
} }
} }
}; };
template<typename T> struct underflow {}; template<typename T> struct underflow { };
// traps // traps
template<typename T> void traps() template<typename T> void traps()
{ {
signal_adapter (signal, SIGFPE, signal_handler); fflush(NULL);
signal_adapter (signal, SIGTRAP, signal_handler); signal_adapter (signal, SIGFPE, signal_handler);
bool trap_flag = trapping(division_by_zero<T>()); signal_adapter (signal, SIGTRAP, signal_handler);
signal_adapter (signal, SIGFPE, signal_handler); bool trap_flag = trapping(division_by_zero<T>());
signal_adapter (signal, SIGTRAP, signal_handler); signal_adapter (signal, SIGFPE, signal_handler);
trap_flag = trap_flag || trapping(overflow<T>()); signal_adapter (signal, SIGTRAP, signal_handler);
const char* p = bool_alpha[trap_flag]; trap_flag = trap_flag || trapping(overflow<T>());
printf("%s%s = %s;\n", tab2, "static const bool traps", p); const char* p = bool_alpha[trap_flag];
printf("%s%s = %s;\n", tab2, "static const bool traps", p);
} }
#define SPECIALIZE_TRAPPING(T) \ #define SPECIALIZE_TRAPPING(T) \
template<> void traps< T >() \ template<> void traps< T >() \
{ \ { \
signal_adapter (signal, SIGFPE, signal_handler); \ fflush(NULL); \
signal_adapter (signal, SIGTRAP, signal_handler); \ signal_adapter (signal, SIGFPE, signal_handler); \
const char* p = bool_alpha[trapping(division_by_zero<T>())]; \ signal_adapter (signal, SIGTRAP, signal_handler); \
printf("%s%s = %s;\n", tab2, "static const bool traps", p); \ const char* p = bool_alpha[trapping(division_by_zero<T>())]; \
printf("%s%s = %s;\n", tab2, "static const bool traps", p); \
} }
SPECIALIZE_TRAPPING(unsigned char); SPECIALIZE_TRAPPING(unsigned char);
...@@ -194,10 +200,12 @@ SPECIALIZE_TRAPPING(unsigned long long); ...@@ -194,10 +200,12 @@ SPECIALIZE_TRAPPING(unsigned long long);
#undef SPECIALIZE_TRAPPING #undef SPECIALIZE_TRAPPING
template<typename T> struct type_name_trait { template<typename T>
struct type_name_trait
{
static const char type_name[]; static const char type_name[];
static const char trait_name[]; static const char trait_name[];
}; };
#define DEFINED_TYPE_NAME(T) \ #define DEFINED_TYPE_NAME(T) \
const char type_name_trait< T >::type_name[] = #T; \ const char type_name_trait< T >::type_name[] = #T; \
...@@ -225,40 +233,41 @@ DEFINED_TYPE_NAME(long double); ...@@ -225,40 +233,41 @@ DEFINED_TYPE_NAME(long double);
#undef DEFINED_TYPE_NAME #undef DEFINED_TYPE_NAME
// declarator // declarator
template<typename T> struct declarator : type_name_trait<T> { template<typename T>
struct declarator : type_name_trait<T>
{
typedef type_name_trait<T> base; typedef type_name_trait<T> base;
static void start() static void start()
{ {
printf("%s%s %s %s\n", tab, "template<> struct", printf("%s%s %s %s\n", tab, "template<> struct", base::trait_name, "{");
base::trait_name, "{");
} }
static void end() static void end()
{ { printf("%s};\n\n", tab); }
printf("%s};\n\n", tab); };
}
};
// //
// Predicates // Predicates
// //
template<typename T> struct predicate { template<typename T>
struct predicate
{
static const bool is_signed; static const bool is_signed;
static const bool is_integer; static const bool is_integer;
static const bool is_exact; static const bool is_exact;
static const bool has_infinity; static const bool has_infinity;
static const bool has_quiet_nan; static const bool has_quiet_nan;
static const bool has_signaling_nan; static const bool has_signaling_nan;
static const bool has_denorm; static const bool has_denorm;
static const bool has_denorm_loss; static const bool has_denorm_loss;
static const bool is_iec559; static const bool is_iec559;
static const bool is_bounded; static const bool is_bounded;
static const bool traps; static const bool traps;
}; };
template<typename T> template<typename T>
const bool predicate<T>::is_signed = T(-1) < 0; const bool predicate<T>::is_signed = T(-1) < 0;
...@@ -321,23 +330,24 @@ SPECIALIZE_IEC559(unsigned long long); ...@@ -321,23 +330,24 @@ SPECIALIZE_IEC559(unsigned long long);
// //
// Values // Values
// //
template<typename T>
template<typename T> struct value { struct value
{
static const char min[]; static const char min[];
static const char max[]; static const char max[];
static const int digits; static const int digits;
static const int digits10; static const int digits10;
static const int radix; static const int radix;
static const char epsilon[]; static const char epsilon[];
static const char round_error[]; static const char round_error[];
static const int min_exponent; static const int min_exponent;
static const int min_exponent10; static const int min_exponent10;
static const int max_exponent; static const int max_exponent;
static const int max_exponent10; static const int max_exponent10;
}; };
#define DEFINE_EXTREMA(T, m, M) DO_DEFINE_EXTREMA(T, m, M) #define DEFINE_EXTREMA(T, m, M) DO_DEFINE_EXTREMA(T, m, M)
#define DO_DEFINE_EXTREMA(T, m, M) \ #define DO_DEFINE_EXTREMA(T, m, M) \
...@@ -507,283 +517,285 @@ SPECIALIZE_EXPONENTS(long double, LDBL_MIN_EXP, LDBL_MIN_10_EXP, ...@@ -507,283 +517,285 @@ SPECIALIZE_EXPONENTS(long double, LDBL_MIN_EXP, LDBL_MIN_10_EXP,
template<typename T> void is_signed() template<typename T> void is_signed()
{ {
printf("%s%s = %s;\n", tab2, "static const bool is_signed", printf("%s%s = %s;\n", tab2, "static const bool is_signed",
bool_alpha[predicate<T>::is_signed]); bool_alpha[predicate<T>::is_signed]);
} }
// a fundamental type is modulo iff it isn't signed // a fundamental type is modulo iff it isn't signed
template<typename T> void is_modulo() template<typename T> void is_modulo()
{ {
printf("%s%s = %s;\n", tab2, "static const bool is_modulo", printf("%s%s = %s;\n", tab2, "static const bool is_modulo",
bool_alpha[! predicate<T>::is_signed]); bool_alpha[! predicate<T>::is_signed]);
} }
template<typename T> template<typename T>
void min() void min()
{ {
printf("%s%s%s%s\n%s%s%s%s\n", tab2, "static ", declarator<T>::type_name, printf("%s%s%s%s\n%s%s%s%s\n", tab2, "static ", declarator<T>::type_name,
" min() throw()", tab2, "{ return ", value<T>::min, "; }"); " min() throw()", tab2, "{ return ", value<T>::min, "; }");
} }
template<typename T> template<typename T>
void max() void max()
{ {
printf("%s%s%s%s\n%s%s%s%s\n", tab2, "static ", declarator<T>::type_name, printf("%s%s%s%s\n%s%s%s%s\n", tab2, "static ", declarator<T>::type_name,
" max() throw()", tab2, "{ return ", value<T>::max, "; }"); " max() throw()", tab2, "{ return ", value<T>::max, "; }");
} }
template<typename T> template<typename T>
void is_integer() void is_integer()
{ {
printf("%s%s = %s;\n", tab2, "static const bool is_integer", printf("%s%s = %s;\n", tab2, "static const bool is_integer",
bool_alpha[predicate<T>::is_integer]); bool_alpha[predicate<T>::is_integer]);
} }
template<typename T> template<typename T>
void is_exact() void is_exact()
{ {
printf("%s%s = %s;\n", tab2, "static const bool is_exact", printf("%s%s = %s;\n", tab2, "static const bool is_exact",
bool_alpha[predicate<T>::is_exact]); bool_alpha[predicate<T>::is_exact]);
} }
template<typename T> template<typename T>
void digits() void digits()
{ {
printf("%s%s = %d;\n", tab2, "static const int digits", printf("%s%s = %d;\n", tab2, "static const int digits",
value<T>::digits); value<T>::digits);
} }
template<typename T> template<typename T>
void digits10() void digits10()
{ {
printf("%s%s = %d;\n", tab2, "static const int digits10", printf("%s%s = %d;\n", tab2, "static const int digits10",
int(log10_of_two * value<T>::digits)); int(log10_of_two * value<T>::digits));
} }
template<typename T> template<typename T>
void radix() void radix()
{ {
printf("%s%s = %d;\n", tab2, "static const int radix", printf("%s%s = %d;\n", tab2, "static const int radix",
value<T>::radix); value<T>::radix);
} }
template<typename T> template<typename T>
void epsilon() void epsilon()
{ {
printf("%s%s %s %s\n%s%s %s%s\n", tab2, "static", printf("%s%s %s %s\n%s%s %s%s\n", tab2, "static",
declarator<T>::type_name, "epsilon() throw()", declarator<T>::type_name, "epsilon() throw()",
tab2, "{ return", value<T>::epsilon, "; }"); tab2, "{ return", value<T>::epsilon, "; }");
} }
template<typename T> template<typename T>
void round_error() void round_error()
{ {
printf("%s%s %s %s\n%s%s %s%s\n", tab2, "static", printf("%s%s %s %s\n%s%s %s%s\n", tab2, "static",
declarator<T>::type_name, "round_error() throw()", declarator<T>::type_name, "round_error() throw()",
tab2, "{ return", value<T>::round_error, "; }"); tab2, "{ return", value<T>::round_error, "; }");
} }
template<typename T> template<typename T>
void min_exponent() void min_exponent()
{ {
printf("%s%s = %d;\n", tab2, "static const int min_exponent", printf("%s%s = %d;\n", tab2, "static const int min_exponent",
value<T>::min_exponent); value<T>::min_exponent);
} }
template<typename T> template<typename T>
void min_exponent10() void min_exponent10()
{ {
printf("%s%s = %d;\n", tab2, "static const int min_exponent10", printf("%s%s = %d;\n", tab2, "static const int min_exponent10",
value<T>::min_exponent10); value<T>::min_exponent10);
} }
template<typename T> template<typename T>
void max_exponent() void max_exponent()
{ {
printf("%s%s = %d;\n", tab2, "static const int max_exponent", printf("%s%s = %d;\n", tab2, "static const int max_exponent",
value<T>::max_exponent); value<T>::max_exponent);
} }
template<typename T> template<typename T>
void max_exponent10() void max_exponent10()
{ {
printf("%s%s = %d;\n", tab2, "static const int max_exponent10", printf("%s%s = %d;\n", tab2, "static const int max_exponent10",
value<T>::max_exponent10); value<T>::max_exponent10);
} }
template<typename T> template<typename T>
void has_infinity() void has_infinity()
{ {
printf("%s%s = %s;\n", tab2, "static const bool has_infinity", printf("%s%s = %s;\n", tab2, "static const bool has_infinity",
bool_alpha[predicate<T>::has_infinity]); bool_alpha[predicate<T>::has_infinity]);
} }
template<typename T> template<typename T>
void has_quiet_nan() void has_quiet_nan()
{ {
printf("%s%s = %s;\n", tab2, "static const bool has_quiet_NaN", printf("%s%s = %s;\n", tab2, "static const bool has_quiet_NaN",
bool_alpha[predicate<T>::has_quiet_nan]); bool_alpha[predicate<T>::has_quiet_nan]);
} }
template<typename T> template<typename T>
void has_signaling_nan() void has_signaling_nan()
{ {
printf("%s%s = %s;\n", tab2, "static const bool has_signaling_NaN", printf("%s%s = %s;\n", tab2, "static const bool has_signaling_NaN",
bool_alpha[predicate<T>::has_signaling_nan]); bool_alpha[predicate<T>::has_signaling_nan]);
} }
template<typename T> template<typename T>
void has_denorm_loss() void has_denorm_loss()
{ {
printf("%s%s = %s;\n", tab2, "static const bool has_denorm_loss", printf("%s%s = %s;\n", tab2, "static const bool has_denorm_loss",
bool_alpha[predicate<T>::has_denorm_loss]); bool_alpha[predicate<T>::has_denorm_loss]);
} }
template<typename T> struct infinity_trait { template<typename T>
struct infinity_trait
{
static void has_denorm() static void has_denorm()
{ {
printf("%s%s;\n", tab2, "static const float_denorm_style " printf("%s%s;\n", tab2, "static const float_denorm_style "
"has_denorm = denorm_absent"); "has_denorm = denorm_absent");
} }
static void infinity() static void infinity()
{ {
printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static", printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static",
declarator<T>::type_name, "infinity() throw()", declarator<T>::type_name, "infinity() throw()", tab2,
tab2, "{ return static_cast<", declarator<T>::type_name, "{ return static_cast<", declarator<T>::type_name, ">(0); }");
">(0); }");
} }
static void quiet_NaN() static void quiet_NaN()
{ {
printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static", printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static",
declarator<T>::type_name, "quiet_NaN() throw()", declarator<T>::type_name, "quiet_NaN() throw()",
tab2, "{ return static_cast<", declarator<T>::type_name, tab2, "{ return static_cast<", declarator<T>::type_name,
">(0); }"); ">(0); }");
} }
static void signaling_NaN() static void signaling_NaN()
{ {
printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static", printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static",
declarator<T>::type_name, "signaling_NaN() throw()", declarator<T>::type_name, "signaling_NaN() throw()",
tab2, "{ return static_cast<", declarator<T>::type_name, tab2, "{ return static_cast<", declarator<T>::type_name,
">(0); }"); ">(0); }");
} }
static void denorm_min() static void denorm_min()
{ {
printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static", printf("%s%s %s %s\n%s%s%s%s\n", tab2, "static",
declarator<T>::type_name, "denorm_min() throw()", declarator<T>::type_name, "denorm_min() throw()",
tab2, "{ return static_cast<", declarator<T>::type_name, tab2, "{ return static_cast<", declarator<T>::type_name,
">(0); }"); ">(0); }");
} }
}; };
template<typename T> template<typename T>
void is_iec559() void is_iec559()
{ {
printf("%s%s = %s;\n", tab2, "static const bool is_iec559", printf("%s%s = %s;\n", tab2, "static const bool is_iec559",
bool_alpha[predicate<T>::is_iec559]); bool_alpha[predicate<T>::is_iec559]);
} }
// tinyness_before // tinyness_before
template<typename T> template<typename T>
void tinyness_before() void tinyness_before()
{ {
printf("%s%s;\n", tab2, "static const bool tinyness_before = false"); printf("%s%s;\n", tab2, "static const bool tinyness_before = false");
} }
// round style // round style
template<typename T> template<typename T>
void round_style() void round_style()
{ {
printf("%s%s;\n", tab2, "static const float_round_style " printf("%s%s;\n", tab2, "static const float_round_style "
"round_style = round_toward_zero"); "round_style = round_toward_zero");
} }
// type traits // type traits
template<typename T> struct type_trait { template<typename T>
struct type_trait
{
type_trait() type_trait()
{ {
declarator<T>::start(); declarator<T>::start();
printf("%s%s;\n\n", tab2, "static const bool is_specialized = true"); printf("%s%s;\n\n", tab2, "static const bool is_specialized = true");
min<T>(); min<T>();
max<T>(); max<T>();
printf("\n"); printf("\n");
digits<T>(); digits<T>();
digits10<T>(); digits10<T>();
is_signed<T>(); is_signed<T>();
is_integer<T>(); is_integer<T>();
is_exact<T>(); is_exact<T>();
radix<T>(); radix<T>();
epsilon<T>(); epsilon<T>();
round_error<T>(); round_error<T>();
printf("\n"); printf("\n");
min_exponent<T>(); min_exponent<T>();
min_exponent10<T>(); min_exponent10<T>();
max_exponent<T>(); max_exponent<T>();
max_exponent10<T>(); max_exponent10<T>();
printf("\n"); printf("\n");
has_infinity<T>(); has_infinity<T>();
has_quiet_nan<T>(); has_quiet_nan<T>();
has_signaling_nan<T>(); has_signaling_nan<T>();
infinity_trait<T>::has_denorm(); infinity_trait<T>::has_denorm();
has_denorm_loss<T>(); has_denorm_loss<T>();
printf("\n"); printf("\n");
infinity_trait<T>::infinity(); infinity_trait<T>::infinity();
infinity_trait<T>::quiet_NaN(); infinity_trait<T>::quiet_NaN();
infinity_trait<T>::signaling_NaN(); infinity_trait<T>::signaling_NaN();
infinity_trait<T>::denorm_min(); infinity_trait<T>::denorm_min();
printf("\n"); printf("\n");
is_iec559<T>(); is_iec559<T>();
printf("%s%s;\n", tab2, "static const bool is_bounded = true"); printf("%s%s;\n", tab2, "static const bool is_bounded = true");
is_modulo<T>(); is_modulo<T>();
printf("\n"); printf("\n");
traps<T>(); traps<T>();
tinyness_before<T>(); tinyness_before<T>();
round_style<T>(); round_style<T>();
declarator<T>::end(); declarator<T>::end();
} }
}; };
int main() int main()
{ {
type_trait<bool>(); type_trait<bool>();
type_trait<char>(); type_trait<char>();
type_trait<signed char>(); type_trait<signed char>();
type_trait<unsigned char>(); type_trait<unsigned char>();
#if defined( _GLIBCPP_USE_WCHAR_T) #if defined( _GLIBCPP_USE_WCHAR_T)
type_trait<wchar_t>(); type_trait<wchar_t>();
#endif #endif
type_trait<short>(); type_trait<short>();
type_trait<unsigned short>(); type_trait<unsigned short>();
type_trait<int>(); type_trait<int>();
type_trait<unsigned int>(); type_trait<unsigned int>();
type_trait<long>(); type_trait<long>();
type_trait<unsigned long>(); type_trait<unsigned long>();
#ifdef _GLIBCPP_USE_LONG_LONG #ifdef _GLIBCPP_USE_LONG_LONG
type_trait<long long>(); type_trait<long long>();
type_trait<unsigned long long>(); type_trait<unsigned long long>();
#endif #endif
type_trait<float>(); type_trait<float>();
type_trait<double>(); type_trait<double>();
type_trait<long double>(); type_trait<long double>();
// x86/linux gets this weirdness for the min/max functions: // x86/linux gets this weirdness for the min/max functions:
// static long double min() throw() // static long double min() throw()
// { return (__extension__ ((union __convert_long_double) // { return (__extension__ ((union __convert_long_double)
// {__convert_long_double_i: {0x0, 0x80000000, 0x1, 0x0}}) // {__convert_long_double_i: {0x0, 0x80000000, 0x1, 0x0}})
// .__convert_long_double_d); } // .__convert_long_double_d); }
} }
// G++ doesn't have support for automatic instantiation of static data // G++ doesn't have support for automatic instantiation of static data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment