diff --git a/lib/token.cpp b/lib/token.cpp index 1188a75c6f6..9da5c45665c 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -103,14 +103,19 @@ static const std::unordered_set controlFlowKeywords = { void Token::update_property_info() { setFlag(fIsControlFlowKeyword, controlFlowKeywords.find(mStr) != controlFlowKeywords.end()); + isStandardType(false); if (!mStr.empty()) { if (mStr == "true" || mStr == "false") tokType(eBoolean); - else if (isStringLiteral(mStr)) + else if (isStringLiteral(mStr)) { tokType(eString); - else if (isCharLiteral(mStr)) + isLong(isPrefixStringCharLiteral(mStr, '"', "L")); + } + else if (isCharLiteral(mStr)) { tokType(eChar); + isLong(isPrefixStringCharLiteral(mStr, '\'', "L")); + } else if (std::isalpha((unsigned char)mStr[0]) || mStr[0] == '_' || mStr[0] == '$') { // Name if (mImpl->mVarId) tokType(eVariable); @@ -157,12 +162,11 @@ void Token::update_property_info() tokType(eEllipsis); else tokType(eOther); + + update_property_isStandardType(); } else { tokType(eNone); } - - update_property_char_string_literal(); - update_property_isStandardType(); } static const std::unordered_set stdTypes = { "bool" @@ -180,9 +184,7 @@ static const std::unordered_set stdTypes = { "bool" void Token::update_property_isStandardType() { - isStandardType(false); - - if (mStr.size() < 3) + if (mStr.size() < 3 || mStr.size() > 7) return; if (stdTypes.find(mStr)!=stdTypes.end()) { @@ -191,15 +193,6 @@ void Token::update_property_isStandardType() } } -void Token::update_property_char_string_literal() -{ - if (mTokType != Token::eString && mTokType != Token::eChar) - return; - - isLong(((mTokType == Token::eString) && isPrefixStringCharLiteral(mStr, '"', "L")) || - ((mTokType == Token::eChar) && isPrefixStringCharLiteral(mStr, '\'', "L"))); -} - bool Token::isUpperCaseName() const { if (!isName()) diff --git a/lib/token.h b/lib/token.h index 1d538bf2284..87ccea46350 100644 --- a/lib/token.h +++ b/lib/token.h @@ -1418,9 +1418,6 @@ class CPPCHECKLIB Token { /** Update internal property cache about isStandardType() */ void update_property_isStandardType(); - /** Update internal property cache about string and char literals */ - void update_property_char_string_literal(); - /** Internal helper function to avoid excessive string allocations */ void astStringVerboseRecursive(std::string& ret, const nonneg int indent1 = 0, const nonneg int indent2 = 0) const;