Fixed #855 (Refactoring: move conditions into checks)
This commit is contained in:
parent
96d66af478
commit
c26e619b23
|
@ -434,6 +434,9 @@ void CheckClass::initializeVarList(const Token *tok1, const Token *ftok, Var *va
|
||||||
|
|
||||||
void CheckClass::constructors()
|
void CheckClass::constructors()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
const char pattern_class[] = "class|struct %var% [{:]";
|
const char pattern_class[] = "class|struct %var% [{:]";
|
||||||
|
|
||||||
// Locate class
|
// Locate class
|
||||||
|
@ -608,6 +611,9 @@ void CheckClass::checkConstructors(const Token *tok1, const std::string &funcnam
|
||||||
|
|
||||||
void CheckClass::privateFunctions()
|
void CheckClass::privateFunctions()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
// Locate some class
|
// Locate some class
|
||||||
for (const Token *tok1 = Token::findmatch(_tokenizer->tokens(), "class|struct %var% {"); tok1; tok1 = Token::findmatch(tok1->next(), "class|struct %var% {"))
|
for (const Token *tok1 = Token::findmatch(_tokenizer->tokens(), "class|struct %var% {"); tok1; tok1 = Token::findmatch(tok1->next(), "class|struct %var% {"))
|
||||||
{
|
{
|
||||||
|
@ -866,6 +872,9 @@ void CheckClass::noMemset()
|
||||||
|
|
||||||
void CheckClass::operatorEq()
|
void CheckClass::operatorEq()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
const Token *tok2 = _tokenizer->tokens();
|
const Token *tok2 = _tokenizer->tokens();
|
||||||
const Token *tok;
|
const Token *tok;
|
||||||
|
|
||||||
|
@ -960,6 +969,9 @@ void CheckClass::operatorEqRetRefThis_finderr(const Token *tok, const std::strin
|
||||||
|
|
||||||
void CheckClass::operatorEqRetRefThis()
|
void CheckClass::operatorEqRetRefThis()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
const Token *tok2 = _tokenizer->tokens();
|
const Token *tok2 = _tokenizer->tokens();
|
||||||
const Token *tok;
|
const Token *tok;
|
||||||
|
|
||||||
|
@ -1204,6 +1216,9 @@ static bool hasMultipleInheritanceGlobal(const Token * start, const std::string
|
||||||
|
|
||||||
void CheckClass::operatorEqToSelf()
|
void CheckClass::operatorEqToSelf()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle || !_settings->inconclusive)
|
||||||
|
return;
|
||||||
|
|
||||||
const Token *tok2 = _tokenizer->tokens();
|
const Token *tok2 = _tokenizer->tokens();
|
||||||
const Token *tok;
|
const Token *tok;
|
||||||
|
|
||||||
|
@ -1464,6 +1479,9 @@ void CheckClass::thisSubtractionError(const Token *tok)
|
||||||
|
|
||||||
void CheckClass::thisSubtraction()
|
void CheckClass::thisSubtraction()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle || !_settings->inconclusive)
|
||||||
|
return;
|
||||||
|
|
||||||
const Token *tok = _tokenizer->tokens();
|
const Token *tok = _tokenizer->tokens();
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,18 +57,14 @@ public:
|
||||||
{
|
{
|
||||||
CheckClass checkClass(tokenizer, settings, errorLogger);
|
CheckClass checkClass(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
if (settings->_checkCodingStyle)
|
// Coding style checks
|
||||||
{
|
|
||||||
checkClass.constructors();
|
checkClass.constructors();
|
||||||
checkClass.operatorEq();
|
checkClass.operatorEq();
|
||||||
checkClass.privateFunctions();
|
checkClass.privateFunctions();
|
||||||
checkClass.operatorEqRetRefThis();
|
checkClass.operatorEqRetRefThis();
|
||||||
if (settings->inconclusive)
|
|
||||||
{
|
|
||||||
checkClass.thisSubtraction();
|
checkClass.thisSubtraction();
|
||||||
checkClass.operatorEqToSelf();
|
checkClass.operatorEqToSelf();
|
||||||
}
|
|
||||||
}
|
|
||||||
checkClass.virtualDestructor();
|
checkClass.virtualDestructor();
|
||||||
checkClass.checkConst();
|
checkClass.checkConst();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@ CheckDangerousFunctions instance;
|
||||||
|
|
||||||
void CheckDangerousFunctions::dangerousFunctions()
|
void CheckDangerousFunctions::dangerousFunctions()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::simpleMatch(tok, "mktemp ("))
|
if (Token::simpleMatch(tok, "mktemp ("))
|
||||||
|
|
|
@ -46,11 +46,8 @@ public:
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckDangerousFunctions checkDangerousFunctions(tokenizer, settings, errorLogger);
|
CheckDangerousFunctions checkDangerousFunctions(tokenizer, settings, errorLogger);
|
||||||
if (settings->_checkCodingStyle)
|
|
||||||
{
|
|
||||||
checkDangerousFunctions.dangerousFunctions();
|
checkDangerousFunctions.dangerousFunctions();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Check for dangerous functions */
|
/** Check for dangerous functions */
|
||||||
void dangerousFunctions();
|
void dangerousFunctions();
|
||||||
|
|
|
@ -45,6 +45,9 @@ CheckOther instance;
|
||||||
|
|
||||||
void CheckOther::warningOldStylePointerCast()
|
void CheckOther::warningOldStylePointerCast()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// Old style pointer casting..
|
// Old style pointer casting..
|
||||||
|
@ -77,6 +80,8 @@ void CheckOther::warningOldStylePointerCast()
|
||||||
|
|
||||||
void CheckOther::warningRedundantCode()
|
void CheckOther::warningRedundantCode()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
// if (p) delete p
|
// if (p) delete p
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
|
@ -219,6 +224,9 @@ void CheckOther::redundantCondition2()
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
void CheckOther::checkEmptyStringTest()
|
void CheckOther::checkEmptyStringTest()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// Non-empty string tests
|
// Non-empty string tests
|
||||||
|
@ -403,6 +411,9 @@ void CheckOther::checkUnsignedDivision()
|
||||||
|
|
||||||
void CheckOther::unreachableCode()
|
void CheckOther::unreachableCode()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
const Token *tok = _tokenizer->tokens();
|
const Token *tok = _tokenizer->tokens();
|
||||||
while ((tok = Token::findmatch(tok, "[;{}] return")) != NULL)
|
while ((tok = Token::findmatch(tok, "[;{}] return")) != NULL)
|
||||||
{
|
{
|
||||||
|
@ -495,6 +506,9 @@ public:
|
||||||
|
|
||||||
void CheckOther::functionVariableUsage()
|
void CheckOther::functionVariableUsage()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
// Parse all executing scopes..
|
// Parse all executing scopes..
|
||||||
for (const Token *token = Token::findmatch(_tokenizer->tokens(), ") const| {"); token;)
|
for (const Token *token = Token::findmatch(_tokenizer->tokens(), ") const| {"); token;)
|
||||||
{
|
{
|
||||||
|
@ -745,6 +759,9 @@ void CheckOther::unassignedVariableError(const Token *tok, const std::string &va
|
||||||
|
|
||||||
void CheckOther::checkVariableScope()
|
void CheckOther::checkVariableScope()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
// Walk through all tokens..
|
// Walk through all tokens..
|
||||||
bool func = false;
|
bool func = false;
|
||||||
int indentlevel = 0;
|
int indentlevel = 0;
|
||||||
|
@ -919,6 +936,9 @@ void CheckOther::lookupVar(const Token *tok1, const std::string &varname)
|
||||||
|
|
||||||
void CheckOther::checkConstantFunctionParameter()
|
void CheckOther::checkConstantFunctionParameter()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::Match(tok, "[,(] const std :: %type% %var% [,)]"))
|
if (Token::Match(tok, "[,(] const std :: %type% %var% [,)]"))
|
||||||
|
@ -976,6 +996,9 @@ void CheckOther::checkConstantFunctionParameter()
|
||||||
|
|
||||||
void CheckOther::checkStructMemberUsage()
|
void CheckOther::checkStructMemberUsage()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
std::string structname;
|
std::string structname;
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
@ -1065,6 +1088,9 @@ void CheckOther::checkStructMemberUsage()
|
||||||
|
|
||||||
void CheckOther::checkCharVariable()
|
void CheckOther::checkCharVariable()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// Declaring the variable..
|
// Declaring the variable..
|
||||||
|
@ -1143,6 +1169,9 @@ void CheckOther::checkCharVariable()
|
||||||
|
|
||||||
void CheckOther::checkIncompleteStatement()
|
void CheckOther::checkIncompleteStatement()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
int parlevel = 0;
|
int parlevel = 0;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
|
@ -2754,6 +2783,9 @@ void CheckOther::checkMathFunctions()
|
||||||
|
|
||||||
void CheckOther::postIncrement()
|
void CheckOther::postIncrement()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle || !_settings->inconclusive)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::simpleMatch(tok, "for ("))
|
if (Token::simpleMatch(tok, "for ("))
|
||||||
|
|
|
@ -51,8 +51,8 @@ public:
|
||||||
CheckOther checkOther(tokenizer, settings, errorLogger);
|
CheckOther checkOther(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
checkOther.nullPointer();
|
checkOther.nullPointer();
|
||||||
if (settings->_checkCodingStyle)
|
|
||||||
{
|
// Coding style checks
|
||||||
checkOther.warningOldStylePointerCast();
|
checkOther.warningOldStylePointerCast();
|
||||||
checkOther.checkUnsignedDivision();
|
checkOther.checkUnsignedDivision();
|
||||||
checkOther.checkCharVariable();
|
checkOther.checkCharVariable();
|
||||||
|
@ -60,25 +60,19 @@ public:
|
||||||
checkOther.checkVariableScope();
|
checkOther.checkVariableScope();
|
||||||
checkOther.checkStructMemberUsage();
|
checkOther.checkStructMemberUsage();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** @brief Run checks against the simplified token list */
|
/** @brief Run checks against the simplified token list */
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckOther checkOther(tokenizer, settings, errorLogger);
|
CheckOther checkOther(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
if (settings->_checkCodingStyle)
|
// Coding style checks
|
||||||
{
|
|
||||||
checkOther.warningRedundantCode();
|
checkOther.warningRedundantCode();
|
||||||
checkOther.checkConstantFunctionParameter();
|
checkOther.checkConstantFunctionParameter();
|
||||||
checkOther.checkIncompleteStatement();
|
checkOther.checkIncompleteStatement();
|
||||||
checkOther.unreachableCode();
|
checkOther.unreachableCode();
|
||||||
checkOther.checkEmptyStringTest();
|
checkOther.checkEmptyStringTest();
|
||||||
if (settings->inconclusive)
|
|
||||||
{
|
|
||||||
checkOther.postIncrement();
|
checkOther.postIncrement();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkOther.strPlusChar();
|
checkOther.strPlusChar();
|
||||||
checkOther.invalidFunctionUsage();
|
checkOther.invalidFunctionUsage();
|
||||||
|
|
|
@ -619,6 +619,9 @@ bool CheckStl::isStlContainer(const Token *tok)
|
||||||
|
|
||||||
void CheckStl::size()
|
void CheckStl::size()
|
||||||
{
|
{
|
||||||
|
if (!_settings->_checkCodingStyle || !_settings->inconclusive)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::Match(tok, "%var% . size ( )"))
|
if (Token::Match(tok, "%var% . size ( )"))
|
||||||
|
|
|
@ -55,11 +55,9 @@ public:
|
||||||
checkStl.stlBoundries();
|
checkStl.stlBoundries();
|
||||||
checkStl.if_find();
|
checkStl.if_find();
|
||||||
|
|
||||||
if (settings->_checkCodingStyle && settings->inconclusive)
|
// Style check
|
||||||
{
|
|
||||||
checkStl.size();
|
checkStl.size();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,6 +56,7 @@ private:
|
||||||
|
|
||||||
// Check char variable usage..
|
// Check char variable usage..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.checkCharVariable();
|
checkOther.checkCharVariable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,7 @@ private:
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.operatorEq();
|
checkClass.operatorEq();
|
||||||
}
|
}
|
||||||
|
@ -1397,6 +1398,7 @@ private:
|
||||||
// Check..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.inconclusive = true;
|
settings.inconclusive = true;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.constructors();
|
checkClass.constructors();
|
||||||
}
|
}
|
||||||
|
@ -2113,6 +2115,7 @@ private:
|
||||||
// Check..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
|
settings.inconclusive = true;
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.thisSubtraction();
|
checkClass.thisSubtraction();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ private:
|
||||||
|
|
||||||
// Check for dangerous functions..
|
// Check for dangerous functions..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
settings.inconclusive = true;
|
settings.inconclusive = true;
|
||||||
CheckDangerousFunctions checkDangerousFunctions(&tokenizer, &settings, this);
|
CheckDangerousFunctions checkDangerousFunctions(&tokenizer, &settings, this);
|
||||||
checkDangerousFunctions.dangerousFunctions();
|
checkDangerousFunctions.dangerousFunctions();
|
||||||
|
|
|
@ -49,6 +49,7 @@ private:
|
||||||
|
|
||||||
// Check for incomplete statements..
|
// Check for incomplete statements..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.checkIncompleteStatement();
|
checkOther.checkIncompleteStatement();
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,9 @@ private:
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
// Check for redundant code..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.warningRedundantCode();
|
checkOther.warningRedundantCode();
|
||||||
checkOther.checkZeroDivision();
|
checkOther.checkZeroDivision();
|
||||||
|
@ -2051,6 +2052,7 @@ private:
|
||||||
// Check for redundant code..
|
// Check for redundant code..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
|
settings.inconclusive = true;
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.postIncrement();
|
checkOther.postIncrement();
|
||||||
}
|
}
|
||||||
|
@ -2164,6 +2166,7 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.checkConstantFunctionParameter();
|
checkOther.checkConstantFunctionParameter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ private:
|
||||||
|
|
||||||
// Check for unused variables..
|
// Check for unused variables..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.checkStructMemberUsage();
|
checkOther.checkStructMemberUsage();
|
||||||
}
|
}
|
||||||
|
@ -310,6 +311,7 @@ private:
|
||||||
|
|
||||||
// Check for unused variables..
|
// Check for unused variables..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
settings._checkCodingStyle = true;
|
||||||
CheckOther checkOther(&tokenizer, &settings, this);
|
CheckOther checkOther(&tokenizer, &settings, this);
|
||||||
checkOther.functionVariableUsage();
|
checkOther.functionVariableUsage();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue