refactoring: there are now 2 functions for running checks. 'runChecks' and 'runSimplifiedChecks'

This commit is contained in:
Daniel Marjamäki 2009-03-21 07:53:23 +01:00
parent 0ed425d105
commit 170f817a19
9 changed files with 54 additions and 23 deletions

View File

@ -53,8 +53,13 @@ public:
return _instances;
}
/** run checks.. */
virtual void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
/** run checks, the token list is not simplified */
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:
const Tokenizer * const _tokenizer;

View File

@ -30,25 +30,30 @@
class CheckAutoVariables : public Check
{
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;
_settings = settings;
_errorLogger = errorLogger;
autoVariables();
CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger);
checkAutoVariables.autoVariables();
}
/** Check for buffer overruns */
void autoVariables();
private:
std::list<std::string> fp_list;
std::list<std::string> vd_list;
bool error_av(const Token* left, const Token* right);
bool is_auto_var(const Token* t);
void addVD(const Token* t);
const Tokenizer *_tokenizer;
const Settings *_settings;
ErrorLogger *_errorLogger;
};
//---------------------------------------------------------------------------

View File

@ -35,14 +35,16 @@ class CheckBufferOverrunClass : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckBufferOverrunClass() : Check()
{ }
/** This constructor is used when running checks.. */
CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *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);
if (settings->_showAll)

View File

@ -30,16 +30,22 @@ class Token;
class CheckClass : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckClass() : Check()
{ }
/** This constructor is used when running checks.. */
CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger)
{ }
// TODO: run noMemset
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);

View File

@ -28,14 +28,16 @@
class CheckDangerousFunctionsClass : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckDangerousFunctionsClass() : Check()
{ }
/** This constructor is used when running checks.. */
CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *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.dangerousFunctions();

View File

@ -44,7 +44,7 @@ public:
: 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.CheckMemoryLeak();

View File

@ -31,20 +31,24 @@ class Token;
class CheckOther : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckOther() : Check()
{ }
/** This constructor is used when running checks.. */
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger)
{ }
// TODO: run these before simplification..
// checkOther.CheckUnsignedDivision();
// checkOther.CheckCharVariable();
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);

View File

@ -30,14 +30,16 @@ class Token;
class CheckStl : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckStl() : Check()
{ }
/** This constructor is used when running checks.. */
CheckStl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *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);

View File

@ -378,16 +378,21 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
_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();
if (_settings._unusedFunctions)
_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)
{
(*it)->runChecks(&_tokenizer, &_settings, this);
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
}
}