From 080241b7d1a940c3c7556ce1caee3ae01a1dd1ee Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Sun, 8 Jul 2012 08:43:03 -0700 Subject: [PATCH] Fix bugs with handling types of integer constants. We now follow the rule that the type of an integer constant is the first of int32, uint32, int64, uint64, that can hold the value. (Unless 'u' or 'l' suffixes have been provided.) Fixes issue #299. --- lex.ll | 25 +++++++++++++++++++------ parse.yy | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lex.ll b/lex.ll index 86879cdd..cc0b9b12 100644 --- a/lex.ll +++ b/lex.ll @@ -590,12 +590,25 @@ lParseInteger(bool dotdotdot) { return us ? TOKEN_UINT64_CONSTANT : TOKEN_INT64_CONSTANT; else if (ls == 1) return us ? TOKEN_UINT32_CONSTANT : TOKEN_INT32_CONSTANT; - - // See if we can fit this into a 32-bit integer... - if ((yylval.intVal & 0xffffffff) == yylval.intVal) - return us ? TOKEN_UINT32_CONSTANT : TOKEN_INT32_CONSTANT; - else - return us ? TOKEN_UINT64_CONSTANT : TOKEN_INT64_CONSTANT; + else if (us) { + // u suffix only + if (yylval.intVal <= 0xfffffffL) + return TOKEN_UINT32_CONSTANT; + else + return TOKEN_UINT64_CONSTANT; + } + else { + // No u or l suffix + // First, see if we can fit this into a 32-bit integer... + if (yylval.intVal <= 0x7fffffffLLU) + return TOKEN_INT32_CONSTANT; + else if (yylval.intVal <= 0xffffffffLLU) + return TOKEN_UINT32_CONSTANT; + else if (yylval.intVal <= 0x7fffffffffffffffLLU) + return TOKEN_INT64_CONSTANT; + else + return TOKEN_UINT64_CONSTANT; + } } } diff --git a/parse.yy b/parse.yy index 76d5b0ac..cb81a5a9 100644 --- a/parse.yy +++ b/parse.yy @@ -144,7 +144,7 @@ struct ForeachDimension { %} %union { - int64_t intVal; + uint64_t intVal; float floatVal; std::string *stringVal; const char *constCharPtr;