Tokenize:simplifyFloatCast(): added corresponding suffix, incase of type 'float'.

This commit is contained in:
orbitcowboy 2013-11-20 23:58:43 -08:00
parent 7d45e9be73
commit b74db1b791
2 changed files with 6 additions and 4 deletions

View File

@ -4796,9 +4796,11 @@ void Tokenizer::simplifyFloatCasts()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok->next(), "( float|double ) %num%") && MathLib::isInt(tok->strAt(4))) {
const bool isFloatType(tok->strAt(2) == "float");
tok->deleteNext(3);
tok = tok->next();
tok->str(tok->str() + ".0");
// in case of type 'float', add the corresponding suffix 'f'
tok->str(tok->str() + (isFloatType ? ".0f":".0"));
}
}
}

View File

@ -1127,9 +1127,9 @@ private:
void simplifyFloatCasts() { // float casting integers
// C-style casts
ASSERT_EQUALS("a = 1.0 ;", tokenizeAndStringify("a = (float)1;"));
ASSERT_EQUALS("a = 1.0 ;", tokenizeAndStringify("a = ((float)1);"));
ASSERT_EQUALS("a = 291.0 ;", tokenizeAndStringify("a = ((float)0x123);"));
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;"));
ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = ((float)1);"));
ASSERT_EQUALS("a = 291.0f ;", tokenizeAndStringify("a = ((float)0x123);"));
ASSERT_EQUALS("a = 1.0 ;", tokenizeAndStringify("a = (double)1;"));
ASSERT_EQUALS("a = 1.0 ;", tokenizeAndStringify("a = ((double)1);"));