Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,19 @@ static const std::unordered_set<std::string> 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);
Expand Down Expand Up @@ -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<std::string> stdTypes = { "bool"
Expand All @@ -180,9 +184,7 @@ static const std::unordered_set<std::string> 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()) {
Expand All @@ -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())
Expand Down
3 changes: 0 additions & 3 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down