refactoring: loop through all Check instances and execute the runChecks function
This commit is contained in:
parent
47d7ff983f
commit
16b6a7a605
|
@ -43,6 +43,7 @@
|
|||
<Unit filename="gui/resultsview.h" />
|
||||
<Unit filename="gui/settingsdialog.cpp" />
|
||||
<Unit filename="gui/settingsdialog.h" />
|
||||
<Unit filename="src/check.h" />
|
||||
<Unit filename="src/checkbufferoverrun.cpp" />
|
||||
<Unit filename="src/checkbufferoverrun.h" />
|
||||
<Unit filename="src/checkclass.cpp" />
|
||||
|
|
28
src/check.h
28
src/check.h
|
@ -21,6 +21,7 @@
|
|||
#define checkH
|
||||
|
||||
#include "settings.h"
|
||||
#include <list>
|
||||
|
||||
class Tokenizer;
|
||||
class ErrorLogger;
|
||||
|
@ -28,21 +29,26 @@ class ErrorLogger;
|
|||
class Check
|
||||
{
|
||||
public:
|
||||
|
||||
Check(const Tokenizer * const tokenizer, const Settings &settings, ErrorLogger *errorLogger)
|
||||
: _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger)
|
||||
{ }
|
||||
// This constructor is used when registering the CheckClass
|
||||
Check()
|
||||
{
|
||||
instances().push_back(this);
|
||||
}
|
||||
|
||||
virtual ~Check()
|
||||
{ }
|
||||
{
|
||||
instances().remove(this);
|
||||
}
|
||||
|
||||
/** get instances of this */
|
||||
static std::list<Check *> &instances()
|
||||
{
|
||||
static std::list<Check *> _instances;
|
||||
return _instances;
|
||||
}
|
||||
|
||||
/** run checks.. */
|
||||
virtual void runChecks() = 0;
|
||||
|
||||
protected:
|
||||
const Tokenizer * const _tokenizer;
|
||||
const Settings &_settings;
|
||||
ErrorLogger *_errorLogger;
|
||||
virtual void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
#include "token.h"
|
||||
|
||||
|
||||
// Create a static instance of this
|
||||
static CheckStl instance;
|
||||
|
||||
|
||||
void CheckStl::iterators()
|
||||
{
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||
|
|
|
@ -31,14 +31,12 @@ class CheckStl : public Check
|
|||
{
|
||||
public:
|
||||
|
||||
CheckStl(const Tokenizer * const tokenizer, const Settings &settings, ErrorLogger *errorLogger)
|
||||
: Check(tokenizer, settings, errorLogger)
|
||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
_settings = settings;
|
||||
_errorLogger = errorLogger;
|
||||
|
||||
}
|
||||
|
||||
void runChecks()
|
||||
{
|
||||
stlOutOfBounds();
|
||||
iterators();
|
||||
erase();
|
||||
|
@ -76,6 +74,10 @@ private:
|
|||
* @param it iterator token
|
||||
*/
|
||||
void eraseCheckLoop(const Token *it);
|
||||
|
||||
const Tokenizer *_tokenizer;
|
||||
const Settings *_settings;
|
||||
ErrorLogger *_errorLogger;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "checkfunctionusage.h"
|
||||
#include "filelister.h"
|
||||
|
||||
#include "check.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
@ -481,6 +483,11 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
// Unusual pointer arithmetic
|
||||
if (ErrorLogger::strPlusChar())
|
||||
checkOther.strPlusChar();
|
||||
|
||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
||||
{
|
||||
(*it)->runChecks(&_tokenizer, &_settings, this);
|
||||
}
|
||||
}
|
||||
|
||||
Settings CppCheck::settings() const
|
||||
|
|
Loading…
Reference in New Issue