From c0e7bebc766fcdd5ed3e42ca34ef9bdb3c573f7a Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Fri, 12 Sep 2008 14:18:20 +0000 Subject: [PATCH] Print constant suffixes and properly print floats. [r21898] --- ast.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ast.c b/ast.c index f20956e..067720f 100644 --- a/ast.c +++ b/ast.c @@ -26,6 +26,7 @@ #include "lang_features.h" #include +#include #include #include #include @@ -199,10 +200,28 @@ static void print_const(const const_expression_t *cnst) if (is_type_integer(type)) { fprintf(out, "%lld", cnst->v.int_value); } else if (is_type_float(type)) { - fprintf(out, "%Lf", cnst->v.float_value); + long double const val = cnst->v.float_value; + fprintf(out, "%.20Lg", val); + if (isfinite(val) && truncl(val) == val) + fputs(".0", out); } else { panic("unknown constant"); } + + char const* suffix; + switch (type->atomic.akind) { + case ATOMIC_TYPE_UINT: suffix = "U"; break; + case ATOMIC_TYPE_LONG: suffix = "L"; break; + case ATOMIC_TYPE_ULONG: suffix = "UL"; break; + case ATOMIC_TYPE_LONGLONG: suffix = "LL"; break; + case ATOMIC_TYPE_ULONGLONG: suffix = "ULL"; break; + case ATOMIC_TYPE_FLOAT: suffix = "F"; break; + case ATOMIC_TYPE_LONG_DOUBLE: suffix = "L"; break; + + default: suffix = NULL; break; + } + if (suffix != NULL) + fputs(suffix, out); } /** -- 2.20.1