Skip to content

Commit 8cce83e

Browse files
authored
Token: small update_property_info() cleanup (danmar#6601)
1 parent 76f1aac commit 8cce83e

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

lib/token.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,19 @@ static const std::unordered_set<std::string> controlFlowKeywords = {
103103
void Token::update_property_info()
104104
{
105105
setFlag(fIsControlFlowKeyword, controlFlowKeywords.find(mStr) != controlFlowKeywords.end());
106+
isStandardType(false);
106107

107108
if (!mStr.empty()) {
108109
if (mStr == "true" || mStr == "false")
109110
tokType(eBoolean);
110-
else if (isStringLiteral(mStr))
111+
else if (isStringLiteral(mStr)) {
111112
tokType(eString);
112-
else if (isCharLiteral(mStr))
113+
isLong(isPrefixStringCharLiteral(mStr, '"', "L"));
114+
}
115+
else if (isCharLiteral(mStr)) {
113116
tokType(eChar);
117+
isLong(isPrefixStringCharLiteral(mStr, '\'', "L"));
118+
}
114119
else if (std::isalpha((unsigned char)mStr[0]) || mStr[0] == '_' || mStr[0] == '$') { // Name
115120
if (mImpl->mVarId)
116121
tokType(eVariable);
@@ -157,12 +162,11 @@ void Token::update_property_info()
157162
tokType(eEllipsis);
158163
else
159164
tokType(eOther);
165+
166+
update_property_isStandardType();
160167
} else {
161168
tokType(eNone);
162169
}
163-
164-
update_property_char_string_literal();
165-
update_property_isStandardType();
166170
}
167171

168172
static const std::unordered_set<std::string> stdTypes = { "bool"
@@ -180,9 +184,7 @@ static const std::unordered_set<std::string> stdTypes = { "bool"
180184

181185
void Token::update_property_isStandardType()
182186
{
183-
isStandardType(false);
184-
185-
if (mStr.size() < 3)
187+
if (mStr.size() < 3 || mStr.size() > 7)
186188
return;
187189

188190
if (stdTypes.find(mStr)!=stdTypes.end()) {
@@ -191,15 +193,6 @@ void Token::update_property_isStandardType()
191193
}
192194
}
193195

194-
void Token::update_property_char_string_literal()
195-
{
196-
if (mTokType != Token::eString && mTokType != Token::eChar)
197-
return;
198-
199-
isLong(((mTokType == Token::eString) && isPrefixStringCharLiteral(mStr, '"', "L")) ||
200-
((mTokType == Token::eChar) && isPrefixStringCharLiteral(mStr, '\'', "L")));
201-
}
202-
203196
bool Token::isUpperCaseName() const
204197
{
205198
if (!isName())

lib/token.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,9 +1418,6 @@ class CPPCHECKLIB Token {
14181418
/** Update internal property cache about isStandardType() */
14191419
void update_property_isStandardType();
14201420

1421-
/** Update internal property cache about string and char literals */
1422-
void update_property_char_string_literal();
1423-
14241421
/** Internal helper function to avoid excessive string allocations */
14251422
void astStringVerboseRecursive(std::string& ret, const nonneg int indent1 = 0, const nonneg int indent2 = 0) const;
14261423

0 commit comments

Comments
 (0)