Revert "Add a dynamic rule enable/disable system"
This reverts commit 231b486e49
.
There was regressions reported in tools/generate_and_run_more_tests.sh.
This commit is contained in:
parent
231b486e49
commit
6545172d8c
|
@ -641,68 +641,43 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
|
else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
|
||||||
Settings::Rule rule;
|
Settings::Rule rule;
|
||||||
rule.pattern = 7 + argv[i];
|
rule.pattern = 7 + argv[i];
|
||||||
_settings->rules[rule.id] = rule;
|
_settings->rules.push_back(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rule file
|
// Rule file
|
||||||
else if (std::strncmp(argv[i], "--rule-file=", 12) == 0) {
|
else if (std::strncmp(argv[i], "--rule-file=", 12) == 0) {
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_NO_ERROR) {
|
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_NO_ERROR) {
|
||||||
const tinyxml2::XMLElement *node = doc.FirstChildElement();
|
tinyxml2::XMLElement *node = doc.FirstChildElement();
|
||||||
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
|
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
|
||||||
Settings::Rule rule;
|
Settings::Rule rule;
|
||||||
|
|
||||||
const tinyxml2::XMLElement *tokenlist = node->FirstChildElement("tokenlist");
|
tinyxml2::XMLElement *tokenlist = node->FirstChildElement("tokenlist");
|
||||||
if (tokenlist)
|
if (tokenlist)
|
||||||
rule.tokenlist = tokenlist->GetText();
|
rule.tokenlist = tokenlist->GetText();
|
||||||
|
|
||||||
const tinyxml2::XMLElement *pattern = node->FirstChildElement("pattern");
|
tinyxml2::XMLElement *pattern = node->FirstChildElement("pattern");
|
||||||
if (pattern) {
|
if (pattern) {
|
||||||
rule.pattern = pattern->GetText();
|
rule.pattern = pattern->GetText();
|
||||||
}
|
}
|
||||||
|
|
||||||
const tinyxml2::XMLElement *message = node->FirstChildElement("message");
|
tinyxml2::XMLElement *message = node->FirstChildElement("message");
|
||||||
if (message) {
|
if (message) {
|
||||||
const tinyxml2::XMLElement *severity = message->FirstChildElement("severity");
|
tinyxml2::XMLElement *severity = message->FirstChildElement("severity");
|
||||||
if (severity)
|
if (severity)
|
||||||
rule.severity = severity->GetText();
|
rule.severity = severity->GetText();
|
||||||
|
|
||||||
const tinyxml2::XMLElement *id = message->FirstChildElement("id");
|
tinyxml2::XMLElement *id = message->FirstChildElement("id");
|
||||||
if (id)
|
if (id)
|
||||||
rule.id = id->GetText();
|
rule.id = id->GetText();
|
||||||
|
|
||||||
const tinyxml2::XMLElement *summary = message->FirstChildElement("summary");
|
tinyxml2::XMLElement *summary = message->FirstChildElement("summary");
|
||||||
if (summary)
|
if (summary)
|
||||||
rule.summary = summary->GetText() ? summary->GetText() : "";
|
rule.summary = summary->GetText() ? summary->GetText() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
tinyxml2::XMLElement *state = node->FirstChildElement("state");
|
|
||||||
if (state) {
|
|
||||||
std::string rule_state = state->GetText();
|
|
||||||
if (rule_state == "enabled")
|
|
||||||
rule.enabled = true;
|
|
||||||
else if (rule_state == "disabled")
|
|
||||||
rule.enabled = false;
|
|
||||||
else {
|
|
||||||
std::string msg("cppcheck: error: unrecognized rule state: \"");
|
|
||||||
msg += rule_state;
|
|
||||||
msg += "\". Supported states: disable, enable.";
|
|
||||||
PrintMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tinyxml2::XMLElement *disabled = node->FirstChildElement("disable");
|
|
||||||
if (disabled) {
|
|
||||||
rule.disable_rules = disabled->GetText();
|
|
||||||
}
|
|
||||||
|
|
||||||
tinyxml2::XMLElement *enabled = node->FirstChildElement("enable");
|
|
||||||
if (enabled) {
|
|
||||||
rule.enable_rules = enabled->GetText();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rule.pattern.empty())
|
if (!rule.pattern.empty())
|
||||||
_settings->rules[rule.id] = rule;
|
_settings->rules.push_back(rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,8 +168,8 @@ unsigned int CppCheck::processFile(const std::string& filename, std::istream& fi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run rules on this code
|
// Run rules on this code
|
||||||
for (std::map<std::string, Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
||||||
if (it->second.enabled && it->second.tokenlist == "define") {
|
if (it->tokenlist == "define") {
|
||||||
Tokenizer tokenizer2(&_settings, this);
|
Tokenizer tokenizer2(&_settings, this);
|
||||||
std::istringstream istr2(filedata);
|
std::istringstream istr2(filedata);
|
||||||
tokenizer2.list.createTokens(istr2, filename);
|
tokenizer2.list.createTokens(istr2, filename);
|
||||||
|
@ -320,8 +320,8 @@ bool CppCheck::checkFile(const std::string &code, const char FileName[], std::se
|
||||||
_tokenizer.setTimerResults(&S_timerResults);
|
_tokenizer.setTimerResults(&S_timerResults);
|
||||||
try {
|
try {
|
||||||
// Execute rules for "raw" code
|
// Execute rules for "raw" code
|
||||||
for (std::map<std::string, Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
||||||
if (it->second.enabled && it->second.tokenlist == "raw") {
|
if (it->tokenlist == "raw") {
|
||||||
Tokenizer tokenizer2(&_settings, this);
|
Tokenizer tokenizer2(&_settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer2.list.createTokens(istr, FileName);
|
tokenizer2.list.createTokens(istr, FileName);
|
||||||
|
@ -439,8 +439,8 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
|
||||||
#ifdef HAVE_RULES
|
#ifdef HAVE_RULES
|
||||||
// Are there rules to execute?
|
// Are there rules to execute?
|
||||||
bool isrule = false;
|
bool isrule = false;
|
||||||
for (std::map<std::string, Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
||||||
if (it->second.enabled && it->second.tokenlist == tokenlist)
|
if (it->tokenlist == tokenlist)
|
||||||
isrule = true;
|
isrule = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,9 +454,9 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
|
||||||
ostr << " " << tok->str();
|
ostr << " " << tok->str();
|
||||||
const std::string str(ostr.str());
|
const std::string str(ostr.str());
|
||||||
|
|
||||||
for (std::map<std::string, Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
for (std::list<Settings::Rule>::const_iterator it = _settings.rules.begin(); it != _settings.rules.end(); ++it) {
|
||||||
const Settings::Rule &rule = it->second;
|
const Settings::Rule &rule = *it;
|
||||||
if (rule.pattern.empty() || rule.id.empty() || rule.severity.empty() || rule.tokenlist != tokenlist || !rule.enabled)
|
if (rule.pattern.empty() || rule.id.empty() || rule.severity.empty() || rule.tokenlist != tokenlist)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const char *error = nullptr;
|
const char *error = nullptr;
|
||||||
|
@ -511,26 +511,6 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
|
||||||
|
|
||||||
// Report error
|
// Report error
|
||||||
reportErr(errmsg);
|
reportErr(errmsg);
|
||||||
|
|
||||||
// Disable rules that must be disabled
|
|
||||||
std::istringstream disable(rule.disable_rules);
|
|
||||||
do {
|
|
||||||
std::string rule_to_disable;
|
|
||||||
disable >> rule_to_disable;
|
|
||||||
if (rule_to_disable != "") {
|
|
||||||
_settings.rules[rule_to_disable].enabled = false;
|
|
||||||
}
|
|
||||||
} while (disable);
|
|
||||||
|
|
||||||
// Enable rules that must be enabled
|
|
||||||
std::istringstream enable(rule.enable_rules);
|
|
||||||
do {
|
|
||||||
std::string rule_to_enable;
|
|
||||||
enable >> rule_to_enable;
|
|
||||||
if (rule_to_enable != "") {
|
|
||||||
_settings.rules[rule_to_enable].enabled = true;
|
|
||||||
}
|
|
||||||
} while (enable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pcre_free(re);
|
pcre_free(re);
|
||||||
|
|
|
@ -218,10 +218,7 @@ public:
|
||||||
Rule()
|
Rule()
|
||||||
: tokenlist("simple") // use simple tokenlist
|
: tokenlist("simple") // use simple tokenlist
|
||||||
, id("rule") // default id
|
, id("rule") // default id
|
||||||
, severity("style") // default severity
|
, severity("style") { // default severity
|
||||||
, disable_rules("") // default disabled rules
|
|
||||||
, enable_rules("") // default enabled rules
|
|
||||||
, enabled(true) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tokenlist;
|
std::string tokenlist;
|
||||||
|
@ -229,15 +226,12 @@ public:
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string severity;
|
std::string severity;
|
||||||
std::string summary;
|
std::string summary;
|
||||||
std::string disable_rules;
|
|
||||||
std::string enable_rules;
|
|
||||||
bool enabled;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Extra rules
|
* @brief Extra rules
|
||||||
*/
|
*/
|
||||||
std::map<std::string, Rule> rules;
|
std::list<Rule> rules;
|
||||||
|
|
||||||
/** Is the 'configuration checking' wanted? */
|
/** Is the 'configuration checking' wanted? */
|
||||||
bool checkConfiguration;
|
bool checkConfiguration;
|
||||||
|
|
Loading…
Reference in New Issue