enable: break out 'performance' and 'portability' from the 'style' id. Ticket: #3074

This commit is contained in:
Daniel Marjamäki 2011-09-03 15:30:30 +02:00
parent 92c2df0a28
commit d23c58d387
16 changed files with 27 additions and 16 deletions

View File

@ -664,6 +664,10 @@ void CmdLineParser::PrintHelp()
" Enable all checks\n" " Enable all checks\n"
" * style\n" " * style\n"
" Check coding style\n" " Check coding style\n"
" * performance\n"
" Check for performance problems\n"
" * portability\n"
" Check for portability problems\n"
" * information\n" " * information\n"
" Enable information messages\n" " Enable information messages\n"
" * unusedFunction\n" " * unusedFunction\n"

View File

@ -46,7 +46,7 @@ static bool isint(const Variable *var)
void Check64BitPortability::pointerassignment() void Check64BitPortability::pointerassignment()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("portability"))
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())

View File

@ -1057,7 +1057,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
if (varid && Token::Match(tok, "= %varid% + %num% ;", varid)) if (varid && Token::Match(tok, "= %varid% + %num% ;", varid))
{ {
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3)); const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
if (index > size && _settings->isEnabled("style")) if (index > size && _settings->isEnabled("portability"))
pointerOutOfBoundsError(tok->next(), "buffer"); pointerOutOfBoundsError(tok->next(), "buffer");
if (index >= size && Token::Match(tok->tokAt(-2), "[;{}] %varid% =", varid)) if (index >= size && Token::Match(tok->tokAt(-2), "[;{}] %varid% =", varid))
pointerIsOutOfBounds = true; pointerIsOutOfBounds = true;
@ -1276,7 +1276,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
} }
// undefined behaviour: result of pointer arithmetic is out of bounds // undefined behaviour: result of pointer arithmetic is out of bounds
if (_settings->isEnabled("style") && Token::Match(tok, "= %varid% + %num% ;", arrayInfo.varid())) if (_settings->isEnabled("portability") && Token::Match(tok, "= %varid% + %num% ;", arrayInfo.varid()))
{ {
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3)); const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
if (index < 0 || index > arrayInfo.num(0)) if (index < 0 || index > arrayInfo.num(0))

View File

@ -33,7 +33,7 @@ CheckNonReentrantFunctions instance;
void CheckNonReentrantFunctions::nonReentrantFunctions() void CheckNonReentrantFunctions::nonReentrantFunctions()
{ {
if (!_settings->posix || !_settings->isEnabled("style")) if (!_settings->posix || !_settings->isEnabled("portability"))
return; return;
// Don't check C# and Java code // Don't check C# and Java code

View File

@ -1576,7 +1576,7 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkConstantFunctionParameter() void CheckOther::checkConstantFunctionParameter()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("performance"))
return; return;
const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
@ -2368,7 +2368,7 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2,
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckOther::checkAlwaysTrueOrFalseStringCompare() void CheckOther::checkAlwaysTrueOrFalseStringCompare()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("style") && !_settings->isEnabled("performance"))
return; return;
const char pattern1[] = "strcmp|stricmp|strcmpi|strcasecmp|wcscmp ( %str% , %str% )"; const char pattern1[] = "strcmp|stricmp|strcmpi|strcasecmp|wcscmp ( %str% , %str% )";
@ -2403,7 +2403,7 @@ void CheckOther::alwaysTrueFalseStringCompareError(const Token *tok, const std::
"If the purpose is to compare these two strings, the comparison is unnecessary. " "If the purpose is to compare these two strings, the comparison is unnecessary. "
"If the strings are supposed to be different, then there is a bug somewhere."); "If the strings are supposed to be different, then there is a bug somewhere.");
} }
else else if (_settings->isEnabled("performance"))
{ {
reportError(tok, Severity::performance, "staticStringCompare", reportError(tok, Severity::performance, "staticStringCompare",
"Unnecessary comparison of static strings.\n" "Unnecessary comparison of static strings.\n"

View File

@ -35,7 +35,7 @@ CheckPostfixOperator instance;
void CheckPostfixOperator::postfixOperator() void CheckPostfixOperator::postfixOperator()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("performance"))
return; return;
const Token *tok = _tokenizer->tokens(); const Token *tok = _tokenizer->tokens();

View File

@ -848,7 +848,7 @@ bool CheckStl::isStlContainer(unsigned int varid)
void CheckStl::size() void CheckStl::size()
{ {
if (!_settings->isEnabled("style")) if (!_settings->isEnabled("performance"))
return; return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())

View File

@ -78,9 +78,11 @@ std::string Settings::addEnabled(const std::string &str)
std::set<std::string> id; std::set<std::string> id;
id.insert("style"); id.insert("style");
id.insert("performance");
id.insert("portability");
id.insert("information");
id.insert("missingInclude"); id.insert("missingInclude");
id.insert("unusedFunction"); id.insert("unusedFunction");
id.insert("information");
if (str == "all") if (str == "all")
{ {

View File

@ -10179,6 +10179,7 @@ void Tokenizer::removeUnnecessaryQualification()
continue; continue;
} }
if (_settings && _settings->isEnabled("portability"))
unnecessaryQualificationError(tok, qualification); unnecessaryQualificationError(tok, qualification);
tok->deleteThis(); tok->deleteThis();

View File

@ -47,7 +47,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("portability");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -45,6 +45,7 @@ private:
settings.inconclusive = true; settings.inconclusive = true;
settings.experimental = experimental; settings.experimental = experimental;
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("portability");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -45,7 +45,7 @@ private:
Settings settings; Settings settings;
settings.posix = true; settings.posix = true;
settings.addEnabled("style"); settings.addEnabled("portability");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -213,6 +213,7 @@ private:
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("performance");
settings.experimental = true; settings.experimental = true;
// Preprocess file.. // Preprocess file..
@ -840,7 +841,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("performance");
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);

View File

@ -41,8 +41,8 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("performance");
settings.inconclusive = true; //settings.inconclusive = true;
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);

View File

@ -383,6 +383,7 @@ private:
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("portability");
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);

View File

@ -120,6 +120,7 @@ private:
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("style");
settings.addEnabled("performance");
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);