Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
enable: break out 'performance' and 'portability' from the 'style' id…
…. Ticket: #3074
  • Loading branch information
Daniel Marjamäki committed Sep 3, 2011
1 parent 92c2df0 commit d23c58d
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions cli/cmdlineparser.cpp
Expand Up @@ -664,6 +664,10 @@ void CmdLineParser::PrintHelp()
" Enable all checks\n"
" * style\n"
" Check coding style\n"
" * performance\n"
" Check for performance problems\n"
" * portability\n"
" Check for portability problems\n"
" * information\n"
" Enable information messages\n"
" * unusedFunction\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/check64bit.cpp
Expand Up @@ -46,7 +46,7 @@ static bool isint(const Variable *var)

void Check64BitPortability::pointerassignment()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled("portability"))
return;

for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
Expand Down
4 changes: 2 additions & 2 deletions lib/checkbufferoverrun.cpp
Expand Up @@ -1057,7 +1057,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
if (varid && Token::Match(tok, "= %varid% + %num% ;", varid))
{
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");
if (index >= size && Token::Match(tok->tokAt(-2), "[;{}] %varid% =", varid))
pointerIsOutOfBounds = true;
Expand Down Expand Up @@ -1276,7 +1276,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
}

// 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));
if (index < 0 || index > arrayInfo.num(0))
Expand Down
2 changes: 1 addition & 1 deletion lib/checknonreentrantfunctions.cpp
Expand Up @@ -33,7 +33,7 @@ CheckNonReentrantFunctions instance;

void CheckNonReentrantFunctions::nonReentrantFunctions()
{
if (!_settings->posix || !_settings->isEnabled("style"))
if (!_settings->posix || !_settings->isEnabled("portability"))
return;

// Don't check C# and Java code
Expand Down
6 changes: 3 additions & 3 deletions lib/checkother.cpp
Expand Up @@ -1576,7 +1576,7 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname
//---------------------------------------------------------------------------
void CheckOther::checkConstantFunctionParameter()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled("performance"))
return;

const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase();
Expand Down Expand Up @@ -2368,7 +2368,7 @@ void CheckOther::duplicateExpressionError(const Token *tok1, const Token *tok2,
//---------------------------------------------------------------------------
void CheckOther::checkAlwaysTrueOrFalseStringCompare()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled("style") && !_settings->isEnabled("performance"))
return;

const char pattern1[] = "strcmp|stricmp|strcmpi|strcasecmp|wcscmp ( %str% , %str% )";
Expand Down Expand Up @@ -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 strings are supposed to be different, then there is a bug somewhere.");
}
else
else if (_settings->isEnabled("performance"))
{
reportError(tok, Severity::performance, "staticStringCompare",
"Unnecessary comparison of static strings.\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/checkpostfixoperator.cpp
Expand Up @@ -35,7 +35,7 @@ CheckPostfixOperator instance;

void CheckPostfixOperator::postfixOperator()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled("performance"))
return;

const Token *tok = _tokenizer->tokens();
Expand Down
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Expand Up @@ -848,7 +848,7 @@ bool CheckStl::isStlContainer(unsigned int varid)

void CheckStl::size()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled("performance"))
return;

for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
Expand Down
4 changes: 3 additions & 1 deletion lib/settings.cpp
Expand Up @@ -78,9 +78,11 @@ std::string Settings::addEnabled(const std::string &str)

std::set<std::string> id;
id.insert("style");
id.insert("performance");
id.insert("portability");
id.insert("information");
id.insert("missingInclude");
id.insert("unusedFunction");
id.insert("information");

if (str == "all")
{
Expand Down
3 changes: 2 additions & 1 deletion lib/tokenize.cpp
Expand Up @@ -10179,7 +10179,8 @@ void Tokenizer::removeUnnecessaryQualification()
continue;
}

unnecessaryQualificationError(tok, qualification);
if (_settings && _settings->isEnabled("portability"))
unnecessaryQualificationError(tok, qualification);

tok->deleteThis();
tok->deleteThis();
Expand Down
2 changes: 1 addition & 1 deletion test/test64bit.cpp
Expand Up @@ -47,7 +47,7 @@ class Test64BitPortability : public TestFixture
errout.str("");

Settings settings;
settings.addEnabled("style");
settings.addEnabled("portability");

// Tokenize..
Tokenizer tokenizer(&settings, this);
Expand Down
1 change: 1 addition & 0 deletions test/testbufferoverrun.cpp
Expand Up @@ -45,6 +45,7 @@ class TestBufferOverrun : public TestFixture
settings.inconclusive = true;
settings.experimental = experimental;
settings.addEnabled("style");
settings.addEnabled("portability");

// Tokenize..
Tokenizer tokenizer(&settings, this);
Expand Down
2 changes: 1 addition & 1 deletion test/testnonreentrantfunctions.cpp
Expand Up @@ -45,7 +45,7 @@ class TestNonReentrantFunctions : public TestFixture

Settings settings;
settings.posix = true;
settings.addEnabled("style");
settings.addEnabled("portability");

// Tokenize..
Tokenizer tokenizer(&settings, this);
Expand Down
3 changes: 2 additions & 1 deletion test/testother.cpp
Expand Up @@ -213,6 +213,7 @@ class TestOther : public TestFixture

Settings settings;
settings.addEnabled("style");
settings.addEnabled("performance");
settings.experimental = true;

// Preprocess file..
Expand Down Expand Up @@ -840,7 +841,7 @@ class TestOther : public TestFixture
errout.str("");

Settings settings;
settings.addEnabled("style");
settings.addEnabled("performance");

Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
Expand Down
4 changes: 2 additions & 2 deletions test/testpostfixoperator.cpp
Expand Up @@ -41,8 +41,8 @@ class TestPostfixOperator : public TestFixture
errout.str("");

Settings settings;
settings.addEnabled("style");
settings.inconclusive = true;
settings.addEnabled("performance");
//settings.inconclusive = true;

// Tokenize..
Tokenizer tokenizer(&settings, this);
Expand Down
1 change: 1 addition & 0 deletions test/testsimplifytokens.cpp
Expand Up @@ -383,6 +383,7 @@ class TestSimplifyTokens : public TestFixture
errout.str("");

Settings settings;
settings.addEnabled("portability");
Tokenizer tokenizer(&settings, this);

std::istringstream istr(code);
Expand Down
1 change: 1 addition & 0 deletions test/teststl.cpp
Expand Up @@ -120,6 +120,7 @@ class TestStl : public TestFixture

Settings settings;
settings.addEnabled("style");
settings.addEnabled("performance");

// Tokenize..
Tokenizer tokenizer(&settings, this);
Expand Down

0 comments on commit d23c58d

Please sign in to comment.