From 8dccbfefcfcb156a82aca9b0e28fb9c71b87e4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 3 Jan 2016 13:34:47 +0100 Subject: [PATCH] ValueType: handle lowercase number suffix, for instance '0ll' --- lib/symboldatabase.cpp | 16 ++++++++-------- test/testsymboldatabase.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 70bba7691..5e52df956 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3802,7 +3802,8 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, char defaultSignedne if (tok->isNumber()) { if (MathLib::isFloat(tok->str())) { 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; ::setValueType(tok, ValueType(ValueType::Sign::UNKNOWN_SIGN, type, 0U), defsign); } else if (MathLib::isInt(tok->str())) { @@ -3810,13 +3811,12 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, char defaultSignedne ValueType::Type type = ValueType::Type::INT; if (MathLib::isIntHex(tok->str())) sign = ValueType::Sign::UNSIGNED; - else if (tok->str().find_first_of("uU") != std::string::npos) - sign = ValueType::Sign::UNSIGNED; - if (tok->str()[tok->str().size() - 1U] == 'L') { - if (tok->str()[tok->str().size() - 2U] == 'L') - type = ValueType::Type::LONGLONG; - else - type = ValueType::Type::LONG; + 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; + if (suffix == 'l' || suffix == 'L') + type = (type == ValueType::Type::INT) ? ValueType::Type::LONG : ValueType::Type::LONGLONG; } ::setValueType(tok, ValueType(sign, type, 0U), defsign); } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 3f47816ed..6e6e02797 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -3098,6 +3098,12 @@ private: 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("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("double", typeOf("1.0", "1.0"));