refactoring CheckClass

This commit is contained in:
Daniel Marjamäki 2009-03-20 17:30:24 +01:00
parent e6e778e45f
commit 5914af4481
6 changed files with 42 additions and 51 deletions

View File

@ -20,6 +20,10 @@
//---------------------------------------------------------------------------
#include "checkclass.h"
#include "tokenize.h"
#include "token.h"
#include "errorlogger.h"
#include <locale>
#include <cstring>
@ -29,17 +33,6 @@
//---------------------------------------------------------------------------
CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger)
{
_tokenizer = tokenizer;
_settings = settings;
_errorLogger = errorLogger;
}
CheckClass::~CheckClass()
{
}
//---------------------------------------------------------------------------
@ -307,7 +300,7 @@ void CheckClass::constructors()
if (! constructor_token)
{
// If "--style" has been given, give a warning
if (ErrorLogger::noConstructor(_settings))
if (ErrorLogger::noConstructor(*_settings))
{
// If the class has member variables there should be an constructor
struct VAR *varlist = ClassChecking_GetVarList(tok1);

View File

@ -22,22 +22,49 @@
#define CheckClassH
//---------------------------------------------------------------------------
#include "tokenize.h"
#include "check.h"
#include "settings.h"
#include "errorlogger.h"
class CheckClass
class Token;
class CheckClass : public Check
{
public:
CheckClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger);
~CheckClass();
CheckClass() : Check()
{ }
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);
if (settings->_checkCodingStyle)
{
checkClass.constructors();
checkClass.operatorEq();
checkClass.privateFunctions();
}
checkClass.virtualDestructor();
}
// Check that all class constructors are ok.
void constructors();
// Check that all private functions are called.
void privateFunctions();
// Check that the memsets are valid.
// The 'memset' function can do dangerous things if used wrong.
// Important: The checking doesn't work on simplified tokens list.
void noMemset();
// 'operator=' should return something..
void operatorEq(); // Warning upon "void operator=(.."
// The destructor in a base class should be virtual
@ -64,10 +91,6 @@ private:
// Check constructors for a specified class
void CheckConstructors(const Token *tok1, struct VAR *varlist, const char funcname[]);
const Tokenizer *_tokenizer;
Settings _settings;
ErrorLogger *_errorLogger;
};
//---------------------------------------------------------------------------
#endif

View File

@ -24,7 +24,6 @@
#include "checkmemoryleak.h"
#include "checkbufferoverrun.h"
#include "checkdangerousfunctions.h"
#include "checkclass.h"
#include "checkheaders.h"
#include "checkother.h"
#include "checkfunctionusage.h"
@ -384,14 +383,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
_tokenizer.fillFunctionList();
// Check that the memsets are valid.
// The 'memset' function can do dangerous things if used wrong.
// Important: The checking doesn't work on simplified tokens list.
CheckClass checkClass(&_tokenizer, _settings, this);
if (ErrorLogger::memsetClass())
checkClass.noMemset();
// Coding style checks that must be run before the simplifyTokenList
CheckOther checkOther(&_tokenizer, _settings, this);
@ -422,14 +413,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc())
checkMemoryLeak.CheckMemoryLeak();
// Check that all class constructors are ok.
if (ErrorLogger::noConstructor(_settings) || ErrorLogger::uninitVar(_settings))
checkClass.constructors();
// Check that all base classes have virtual destructors
if (ErrorLogger::virtualDestructor())
checkClass.virtualDestructor();
// Array index out of bounds / Buffer overruns..
if (ErrorLogger::arrayIndexOutOfBounds(_settings) || ErrorLogger::bufferOverrun(_settings))
checkBufferOverrun.bufferOverrun();
@ -451,14 +434,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
ErrorLogger::sprintfOverlappingData())
checkOther.InvalidFunctionUsage();
// Check that all private functions are called.
if (ErrorLogger::unusedPrivateFunction(_settings))
checkClass.privateFunctions();
// 'operator=' should return something..
if (ErrorLogger::operatorEq(_settings))
checkClass.operatorEq();
// if (condition);
if (ErrorLogger::ifNoAction(_settings) || ErrorLogger::conditionAlwaysTrueFalse(_settings))
checkOther.WarningIf();

View File

@ -70,7 +70,7 @@ private:
// Check..
Settings settings;
CheckClass checkClass(&tokenizer, settings, this);
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.virtualDestructor();
}
@ -152,7 +152,7 @@ private:
// Check..
Settings settings;
CheckClass checkClass(&tokenizer, settings, this);
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors();
}
@ -316,7 +316,7 @@ private:
// Check..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, settings, this);
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors();
}

View File

@ -49,7 +49,7 @@ private:
// Check class constructors..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, settings, this);
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.constructors();
}

View File

@ -58,7 +58,7 @@ private:
// Check for unused private functions..
Settings settings;
settings._checkCodingStyle = true;
CheckClass checkClass(&tokenizer, settings, this);
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.privateFunctions();
}