refactoring: there are now 2 functions for running checks. 'runChecks' and 'runSimplifiedChecks'
This commit is contained in:
parent
0ed425d105
commit
170f817a19
|
@ -53,8 +53,13 @@ public:
|
||||||
return _instances;
|
return _instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** run checks.. */
|
/** run checks, the token list is not simplified */
|
||||||
virtual void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
|
virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/** run checks, the token list is simplified */
|
||||||
|
virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Tokenizer * const _tokenizer;
|
const Tokenizer * const _tokenizer;
|
||||||
|
|
|
@ -30,25 +30,30 @@
|
||||||
class CheckAutoVariables : public Check
|
class CheckAutoVariables : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
/** This constructor is used when registering the CheckClass */
|
||||||
|
CheckAutoVariables() : Check()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/** This constructor is used when running checks.. */
|
||||||
|
CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
: Check(tokenizer, settings, errorLogger)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
_tokenizer = tokenizer;
|
CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger);
|
||||||
_settings = settings;
|
checkAutoVariables.autoVariables();
|
||||||
_errorLogger = errorLogger;
|
|
||||||
autoVariables();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check for buffer overruns */
|
/** Check for buffer overruns */
|
||||||
void autoVariables();
|
void autoVariables();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<std::string> fp_list;
|
std::list<std::string> fp_list;
|
||||||
std::list<std::string> vd_list;
|
std::list<std::string> vd_list;
|
||||||
bool error_av(const Token* left, const Token* right);
|
bool error_av(const Token* left, const Token* right);
|
||||||
bool is_auto_var(const Token* t);
|
bool is_auto_var(const Token* t);
|
||||||
void addVD(const Token* t);
|
void addVD(const Token* t);
|
||||||
const Tokenizer *_tokenizer;
|
|
||||||
const Settings *_settings;
|
|
||||||
ErrorLogger *_errorLogger;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -35,14 +35,16 @@ class CheckBufferOverrunClass : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/** This constructor is used when registering the CheckClass */
|
||||||
CheckBufferOverrunClass() : Check()
|
CheckBufferOverrunClass() : Check()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/** This constructor is used when running checks.. */
|
||||||
CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(tokenizer, settings, errorLogger)
|
: Check(tokenizer, settings, errorLogger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckBufferOverrunClass checkBufferOverrunClass(tokenizer, settings, errorLogger);
|
CheckBufferOverrunClass checkBufferOverrunClass(tokenizer, settings, errorLogger);
|
||||||
if (settings->_showAll)
|
if (settings->_showAll)
|
||||||
|
|
|
@ -30,16 +30,22 @@ class Token;
|
||||||
class CheckClass : public Check
|
class CheckClass : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** This constructor is used when registering the CheckClass */
|
||||||
CheckClass() : Check()
|
CheckClass() : Check()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/** This constructor is used when running checks.. */
|
||||||
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(tokenizer, settings, errorLogger)
|
: Check(tokenizer, settings, errorLogger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// TODO: run noMemset
|
|
||||||
|
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
{
|
||||||
|
CheckClass checkClass(tokenizer, settings, errorLogger);
|
||||||
|
checkClass.noMemset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckClass checkClass(tokenizer, settings, errorLogger);
|
CheckClass checkClass(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,16 @@
|
||||||
class CheckDangerousFunctionsClass : public Check
|
class CheckDangerousFunctionsClass : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** This constructor is used when registering the CheckClass */
|
||||||
CheckDangerousFunctionsClass() : Check()
|
CheckDangerousFunctionsClass() : Check()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/** This constructor is used when running checks.. */
|
||||||
CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(tokenizer, settings, errorLogger)
|
: Check(tokenizer, settings, errorLogger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckDangerousFunctionsClass checkDangerousFunctionsClass(tokenizer, settings, errorLogger);
|
CheckDangerousFunctionsClass checkDangerousFunctionsClass(tokenizer, settings, errorLogger);
|
||||||
checkDangerousFunctionsClass.dangerousFunctions();
|
checkDangerousFunctionsClass.dangerousFunctions();
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
: Check(tokenizer, settings, errorLogger)
|
: Check(tokenizer, settings, errorLogger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckMemoryLeakClass checkMemoryLeakClass(tokenizer, settings, errorLogger);
|
CheckMemoryLeakClass checkMemoryLeakClass(tokenizer, settings, errorLogger);
|
||||||
checkMemoryLeakClass.CheckMemoryLeak();
|
checkMemoryLeakClass.CheckMemoryLeak();
|
||||||
|
|
|
@ -31,20 +31,24 @@ class Token;
|
||||||
class CheckOther : public Check
|
class CheckOther : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** This constructor is used when registering the CheckClass */
|
||||||
CheckOther() : Check()
|
CheckOther() : Check()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/** This constructor is used when running checks.. */
|
||||||
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(tokenizer, settings, errorLogger)
|
: Check(tokenizer, settings, errorLogger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
// TODO: run these before simplification..
|
|
||||||
// checkOther.CheckUnsignedDivision();
|
|
||||||
// checkOther.CheckCharVariable();
|
|
||||||
|
|
||||||
|
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
|
{
|
||||||
|
CheckOther checkOther(tokenizer, settings, errorLogger);
|
||||||
|
checkOther.CheckUnsignedDivision();
|
||||||
|
checkOther.CheckCharVariable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckOther checkOther(tokenizer, settings, errorLogger);
|
CheckOther checkOther(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,16 @@ class Token;
|
||||||
class CheckStl : public Check
|
class CheckStl : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** This constructor is used when registering the CheckClass */
|
||||||
CheckStl() : Check()
|
CheckStl() : Check()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/** This constructor is used when running checks.. */
|
||||||
CheckStl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
CheckStl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(tokenizer, settings, errorLogger)
|
: Check(tokenizer, settings, errorLogger)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
CheckStl checkStl(tokenizer, settings, errorLogger);
|
CheckStl checkStl(tokenizer, settings, errorLogger);
|
||||||
|
|
||||||
|
|
|
@ -378,16 +378,21 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
|
|
||||||
_tokenizer.fillFunctionList();
|
_tokenizer.fillFunctionList();
|
||||||
|
|
||||||
|
// call all "runChecks" in all registered Check classes
|
||||||
|
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
||||||
|
{
|
||||||
|
(*it)->runChecks(&_tokenizer, &_settings, this);
|
||||||
|
}
|
||||||
|
|
||||||
_tokenizer.simplifyTokenList();
|
_tokenizer.simplifyTokenList();
|
||||||
|
|
||||||
if (_settings._unusedFunctions)
|
if (_settings._unusedFunctions)
|
||||||
_checkFunctionUsage.parseTokens(_tokenizer);
|
_checkFunctionUsage.parseTokens(_tokenizer);
|
||||||
|
|
||||||
// Run all checks in all registered Check classes
|
// call all "runSimplifiedChecks" in all registered Check classes
|
||||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
||||||
{
|
{
|
||||||
(*it)->runChecks(&_tokenizer, &_settings, this);
|
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue