From a41f6077e154bd370fc2272ddb1ca2dd3e9f2237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 Jun 2014 13:28:15 +0200 Subject: [PATCH] Tokenizer: Use 'podtype' info from library. Partial fix for #5623 --- lib/tokenize.cpp | 29 +++++++++++++++++++++++++++-- lib/tokenize.h | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 06077fb23..83a5e8a29 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2457,8 +2457,12 @@ static bool isInitList(const Token *tok) void Tokenizer::setVarId() { // Clear all variable ids - for (Token *tok = list.front(); tok; tok = tok->next()) - tok->varId(0); + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (tok->isName()) + tok->varId(0); + } + + setPodTypes(); // Variable declarations can't start with "return" etc. std::set notstart; @@ -10519,3 +10523,24 @@ void Tokenizer::reportError(const std::list& callstack, Severity:: else Check::reportError(errmsg); } + +void Tokenizer::setPodTypes() +{ + if (_settings) { + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (!tok->isName()) + continue; + + // pod type + const struct Library::PodType *podType = _settings->library.podtype(tok->str()); + if (podType) { + const Token *prev = tok->previous(); + while (prev && prev->isName()) + prev = prev->previous(); + if (prev && !Token::Match(prev, ";|{|}|,|(")) + continue; + tok->isStandardType(true); + } + } + } +} diff --git a/lib/tokenize.h b/lib/tokenize.h index 83f78ff01..8edc0e451 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -798,6 +798,9 @@ private: return const_cast(startOfExecutableScope(const_cast(tok))); } + /** Set pod types */ + void setPodTypes(); + /** settings */ const Settings * _settings;