Skip to content

Commit a41f607

Browse files
committed
Tokenizer: Use 'podtype' info from library. Partial fix for cppcheck-opensource#5623
1 parent 9e81fa0 commit a41f607

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/tokenize.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,8 +2457,12 @@ static bool isInitList(const Token *tok)
24572457
void Tokenizer::setVarId()
24582458
{
24592459
// Clear all variable ids
2460-
for (Token *tok = list.front(); tok; tok = tok->next())
2461-
tok->varId(0);
2460+
for (Token *tok = list.front(); tok; tok = tok->next()) {
2461+
if (tok->isName())
2462+
tok->varId(0);
2463+
}
2464+
2465+
setPodTypes();
24622466

24632467
// Variable declarations can't start with "return" etc.
24642468
std::set<std::string> notstart;
@@ -10519,3 +10523,24 @@ void Tokenizer::reportError(const std::list<const Token*>& callstack, Severity::
1051910523
else
1052010524
Check::reportError(errmsg);
1052110525
}
10526+
10527+
void Tokenizer::setPodTypes()
10528+
{
10529+
if (_settings) {
10530+
for (Token *tok = list.front(); tok; tok = tok->next()) {
10531+
if (!tok->isName())
10532+
continue;
10533+
10534+
// pod type
10535+
const struct Library::PodType *podType = _settings->library.podtype(tok->str());
10536+
if (podType) {
10537+
const Token *prev = tok->previous();
10538+
while (prev && prev->isName())
10539+
prev = prev->previous();
10540+
if (prev && !Token::Match(prev, ";|{|}|,|("))
10541+
continue;
10542+
tok->isStandardType(true);
10543+
}
10544+
}
10545+
}
10546+
}

lib/tokenize.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ class CPPCHECKLIB Tokenizer {
798798
return const_cast<Token*>(startOfExecutableScope(const_cast<const Token *>(tok)));
799799
}
800800

801+
/** Set pod types */
802+
void setPodTypes();
803+
801804
/** settings */
802805
const Settings * _settings;
803806

0 commit comments

Comments
 (0)