From 1a4ef60e7cf2958f050c48226bc65a16388a1743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 28 Jul 2016 13:40:52 +0200 Subject: [PATCH] Fixed #7639 (rule support partially broken since simplecpp was introduced) --- lib/cppcheck.cpp | 31 ++++++------------------------- lib/preprocessor.h | 5 +++++ 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index fce495434..4318113d3 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -137,35 +137,16 @@ unsigned int CppCheck::processFile(const std::string& filename, std::istream& fi if (it->tokenlist != "define") continue; - for (const simplecpp::Token *tok = tokens1.cbegin(); tok; tok = tok->next) { - if (tok->op != '#') + const std::list &directives = preprocessor.getDirectives(); + + for (std::list::const_iterator dir = directives.begin(); dir != directives.end(); ++dir) { + if (dir->str.compare(0,8,"#define ") != 0) continue; - if (tok->previous && tok->previous->location.sameline(tok->location)) - continue; - - std::string directive; - for (const simplecpp::Token *tok2 = tok; tok2 && tok->location.sameline(tok2->location); tok2 = tok2->next) { - if (tok2->comment) - continue; - while (directive.size() < tok2->location.col) - directive += ' '; - directive += tok2->str; - } - - if (directive.compare(0,8,"#define ") != 0) - continue; - - const std::string code = "#line " + - MathLib::toString(tok->location.line) + - '\"' + tok->location.file() + "\'\n" + - directive; - Tokenizer tokenizer2(&_settings, this); - std::istringstream istr2(code); - tokenizer2.list.createTokens(istr2, tok->location.file()); + std::istringstream istr2(std::string(std::min(1U,dir->linenr)-1U,'\n') + dir->str); + tokenizer2.list.createTokens(istr2, dir->file); executeRules("define", tokenizer2); } - break; } if (!_settings.force && configurations.size() > _settings.maxConfigs) { diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 1fd039898..7bcce66b3 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -90,6 +90,11 @@ public: void setDirectives(const simplecpp::TokenList &tokens); + /** list of all directives met while preprocessing file */ + const std::list &getDirectives() const { + return directives; + } + std::set getConfigs(const simplecpp::TokenList &tokens) const; void loadFiles(const simplecpp::TokenList &rawtokens, std::vector &files);