Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rules: Make it possible to write rules that check #define macros

  • Loading branch information...
commit 828551099698061a7e8e43cd7ee81ecf8e34b126 1 parent cfd697d
@danmar authored
Showing with 33 additions and 0 deletions.
  1. +22 −0 lib/cppcheck.cpp
  2. +11 −0 rules/show-all-defines.rule
View
22 lib/cppcheck.cpp
@@ -162,6 +162,28 @@ unsigned int CppCheck::processFile(const std::string& filename)
preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths);
}
+ // Run rules on this code
+ for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
+ if (it->tokenlist == "define") {
+ Tokenizer tokenizer2(&_settings, this);
+ std::istringstream istr2(filedata);
+ tokenizer2.list.createTokens(istr2, filename);
+
+ for (const Token *tok = tokenizer2.list.front(); tok; tok = tok->next()) {
+ if (tok->str() == "#define") {
+ std::string code = std::string(tok->linenr()-1U, '\n');
+ for (const Token *tok2 = tok; tok2 && tok2->linenr() == tok->linenr(); tok2 = tok2->next())
+ code += " " + tok2->str();
+ Tokenizer tokenizer3(&_settings, this);
+ std::istringstream istr3(code);
+ tokenizer3.list.createTokens(istr3, tokenizer2.list.file(tok));
+ executeRules("define", tokenizer3);
+ }
+ }
+ break;
+ }
+ }
+
if (_settings.checkConfiguration) {
return 0;
}
View
11 rules/show-all-defines.rule
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<rule version="1.0">
+ <tokenlist>define</tokenlist>
+ <pattern>.*</pattern>
+ <message>
+ <id>showalldefines</id>
+ <severity>information</severity>
+ <summary/>
+ </message>
+</rule>
+
Please sign in to comment.
Something went wrong with that request. Please try again.