ValueType: handle lowercase number suffix, for instance '0ll'

This commit is contained in:
Daniel Marjamäki 2016-01-03 13:34:47 +01:00
parent cd89e68f60
commit 8dccbfefcf
2 changed files with 14 additions and 8 deletions

View File

@ -3802,7 +3802,8 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, char defaultSignedne
if (tok->isNumber()) { if (tok->isNumber()) {
if (MathLib::isFloat(tok->str())) { if (MathLib::isFloat(tok->str())) {
ValueType::Type type = ValueType::Type::DOUBLE; ValueType::Type type = ValueType::Type::DOUBLE;
if (tok->str()[tok->str().size() - 1U] == 'f') const char suffix = tok->str()[tok->str().size() - 1U];
if (suffix == 'f' || suffix == 'F')
type = ValueType::Type::FLOAT; type = ValueType::Type::FLOAT;
::setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, type, 0U), defsign); ::setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, type, 0U), defsign);
} else if (MathLib::isInt(tok->str())) { } else if (MathLib::isInt(tok->str())) {
@ -3810,13 +3811,12 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, char defaultSignedne
ValueType::Type type = ValueType::Type::INT; ValueType::Type type = ValueType::Type::INT;
if (MathLib::isIntHex(tok->str())) if (MathLib::isIntHex(tok->str()))
sign = ValueType::Sign::UNSIGNED; sign = ValueType::Sign::UNSIGNED;
else if (tok->str().find_first_of("uU") != std::string::npos) for (unsigned int pos = tok->str().size() - 1U; pos > 0U && std::isalpha(tok->str()[pos]); --pos) {
const char suffix = tok->str()[pos];
if (suffix == 'u' || suffix == 'U')
sign = ValueType::Sign::UNSIGNED; sign = ValueType::Sign::UNSIGNED;
if (tok->str()[tok->str().size() - 1U] == 'L') { if (suffix == 'l' || suffix == 'L')
if (tok->str()[tok->str().size() - 2U] == 'L') type = (type == ValueType::Type::INT) ? ValueType::Type::LONG : ValueType::Type::LONGLONG;
type = ValueType::Type::LONGLONG;
else
type = ValueType::Type::LONG;
} }
::setValueType(tok, ValueType(sign, type, 0U), defsign); ::setValueType(tok, ValueType(sign, type, 0U), defsign);
} }

View File

@ -3098,6 +3098,12 @@ private:
ASSERT_EQUALS("unsigned long", typeOf("1UL", "1UL")); ASSERT_EQUALS("unsigned long", typeOf("1UL", "1UL"));
ASSERT_EQUALS("signed long long", typeOf("1LL", "1LL")); ASSERT_EQUALS("signed long long", typeOf("1LL", "1LL"));
ASSERT_EQUALS("unsigned long long", typeOf("1ULL", "1ULL")); ASSERT_EQUALS("unsigned long long", typeOf("1ULL", "1ULL"));
ASSERT_EQUALS("unsigned int", typeOf("1u", "1u"));
ASSERT_EQUALS("signed long", typeOf("1l", "1l"));
ASSERT_EQUALS("unsigned long", typeOf("1ul", "1ul"));
ASSERT_EQUALS("signed long long", typeOf("1ll", "1ll"));
ASSERT_EQUALS("unsigned long long", typeOf("1ull", "1ull"));
ASSERT_EQUALS("float", typeOf("1.0F", "1.0F"));
ASSERT_EQUALS("float", typeOf("1.0f", "1.0f")); ASSERT_EQUALS("float", typeOf("1.0f", "1.0f"));
ASSERT_EQUALS("double", typeOf("1.0", "1.0")); ASSERT_EQUALS("double", typeOf("1.0", "1.0"));