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