refactoring: loop through all Check instances and execute the runChecks function

This commit is contained in:
Daniel Marjamäki 2009-03-19 19:24:13 +01:00
parent 47d7ff983f
commit 16b6a7a605
5 changed files with 37 additions and 17 deletions

View File

@ -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" />

View File

@ -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

View File

@ -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())

View File

@ -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;
};
//---------------------------------------------------------------------------

View File

@ -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