Fixed #7639 (rule support partially broken since simplecpp was introduced)

This commit is contained in:
Daniel Marjamäki 2016-07-28 13:40:52 +02:00
parent 379b80ec27
commit 1a4ef60e7c
2 changed files with 11 additions and 25 deletions

View File

@ -137,35 +137,16 @@ unsigned int CppCheck::processFile(const std::string& filename, std::istream& fi
if (it->tokenlist != "define") if (it->tokenlist != "define")
continue; continue;
for (const simplecpp::Token *tok = tokens1.cbegin(); tok; tok = tok->next) { const std::list<Directive> &directives = preprocessor.getDirectives();
if (tok->op != '#')
for (std::list<Directive>::const_iterator dir = directives.begin(); dir != directives.end(); ++dir) {
if (dir->str.compare(0,8,"#define ") != 0)
continue; 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); Tokenizer tokenizer2(&_settings, this);
std::istringstream istr2(code); std::istringstream istr2(std::string(std::min(1U,dir->linenr)-1U,'\n') + dir->str);
tokenizer2.list.createTokens(istr2, tok->location.file()); tokenizer2.list.createTokens(istr2, dir->file);
executeRules("define", tokenizer2); executeRules("define", tokenizer2);
} }
break;
} }
if (!_settings.force && configurations.size() > _settings.maxConfigs) { if (!_settings.force && configurations.size() > _settings.maxConfigs) {

View File

@ -90,6 +90,11 @@ public:
void setDirectives(const simplecpp::TokenList &tokens); void setDirectives(const simplecpp::TokenList &tokens);
/** list of all directives met while preprocessing file */
const std::list<Directive> &getDirectives() const {
return directives;
}
std::set<std::string> getConfigs(const simplecpp::TokenList &tokens) const; std::set<std::string> getConfigs(const simplecpp::TokenList &tokens) const;
void loadFiles(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files); void loadFiles(const simplecpp::TokenList &rawtokens, std::vector<std::string> &files);