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.
This commit is contained in:
Matt Pharr
2012-07-08 08:43:03 -07:00
parent 0d534720bb
commit 080241b7d1
2 changed files with 20 additions and 7 deletions

25
lex.ll
View File

@@ -590,12 +590,25 @@ lParseInteger(bool dotdotdot) {
return us ? TOKEN_UINT64_CONSTANT : TOKEN_INT64_CONSTANT; return us ? TOKEN_UINT64_CONSTANT : TOKEN_INT64_CONSTANT;
else if (ls == 1) else if (ls == 1)
return us ? TOKEN_UINT32_CONSTANT : TOKEN_INT32_CONSTANT; return us ? TOKEN_UINT32_CONSTANT : TOKEN_INT32_CONSTANT;
else if (us) {
// See if we can fit this into a 32-bit integer... // u suffix only
if ((yylval.intVal & 0xffffffff) == yylval.intVal) if (yylval.intVal <= 0xfffffffL)
return us ? TOKEN_UINT32_CONSTANT : TOKEN_INT32_CONSTANT; return TOKEN_UINT32_CONSTANT;
else else
return us ? TOKEN_UINT64_CONSTANT : TOKEN_INT64_CONSTANT; 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;
}
} }
} }

View File

@@ -144,7 +144,7 @@ struct ForeachDimension {
%} %}
%union { %union {
int64_t intVal; uint64_t intVal;
float floatVal; float floatVal;
std::string *stringVal; std::string *stringVal;
const char *constCharPtr; const char *constCharPtr;