refactoring CheckClass
This commit is contained in:
parent
e6e778e45f
commit
5914af4481
|
@ -20,6 +20,10 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#include "checkclass.h"
|
#include "checkclass.h"
|
||||||
|
|
||||||
|
#include "tokenize.h"
|
||||||
|
#include "token.h"
|
||||||
|
#include "errorlogger.h"
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
|
||||||
#include <cstring>
|
#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 (! constructor_token)
|
||||||
{
|
{
|
||||||
// If "--style" has been given, give a warning
|
// 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
|
// If the class has member variables there should be an constructor
|
||||||
struct VAR *varlist = ClassChecking_GetVarList(tok1);
|
struct VAR *varlist = ClassChecking_GetVarList(tok1);
|
||||||
|
|
|
@ -22,22 +22,49 @@
|
||||||
#define CheckClassH
|
#define CheckClassH
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "tokenize.h"
|
#include "check.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "errorlogger.h"
|
|
||||||
|
|
||||||
class CheckClass
|
class Token;
|
||||||
|
|
||||||
|
class CheckClass : public Check
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CheckClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger);
|
CheckClass() : Check()
|
||||||
~CheckClass();
|
{ }
|
||||||
|
|
||||||
|
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();
|
void constructors();
|
||||||
|
|
||||||
|
// Check that all private functions are called.
|
||||||
void privateFunctions();
|
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();
|
void noMemset();
|
||||||
|
|
||||||
|
// 'operator=' should return something..
|
||||||
void operatorEq(); // Warning upon "void operator=(.."
|
void operatorEq(); // Warning upon "void operator=(.."
|
||||||
|
|
||||||
// The destructor in a base class should be virtual
|
// The destructor in a base class should be virtual
|
||||||
|
@ -64,10 +91,6 @@ private:
|
||||||
|
|
||||||
// Check constructors for a specified class
|
// Check constructors for a specified class
|
||||||
void CheckConstructors(const Token *tok1, struct VAR *varlist, const char funcname[]);
|
void CheckConstructors(const Token *tok1, struct VAR *varlist, const char funcname[]);
|
||||||
|
|
||||||
const Tokenizer *_tokenizer;
|
|
||||||
Settings _settings;
|
|
||||||
ErrorLogger *_errorLogger;
|
|
||||||
};
|
};
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "checkmemoryleak.h"
|
#include "checkmemoryleak.h"
|
||||||
#include "checkbufferoverrun.h"
|
#include "checkbufferoverrun.h"
|
||||||
#include "checkdangerousfunctions.h"
|
#include "checkdangerousfunctions.h"
|
||||||
#include "checkclass.h"
|
|
||||||
#include "checkheaders.h"
|
#include "checkheaders.h"
|
||||||
#include "checkother.h"
|
#include "checkother.h"
|
||||||
#include "checkfunctionusage.h"
|
#include "checkfunctionusage.h"
|
||||||
|
@ -384,14 +383,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
|
|
||||||
_tokenizer.fillFunctionList();
|
_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
|
// Coding style checks that must be run before the simplifyTokenList
|
||||||
CheckOther checkOther(&_tokenizer, _settings, this);
|
CheckOther checkOther(&_tokenizer, _settings, this);
|
||||||
|
|
||||||
|
@ -422,14 +413,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc())
|
if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc())
|
||||||
checkMemoryLeak.CheckMemoryLeak();
|
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..
|
// Array index out of bounds / Buffer overruns..
|
||||||
if (ErrorLogger::arrayIndexOutOfBounds(_settings) || ErrorLogger::bufferOverrun(_settings))
|
if (ErrorLogger::arrayIndexOutOfBounds(_settings) || ErrorLogger::bufferOverrun(_settings))
|
||||||
checkBufferOverrun.bufferOverrun();
|
checkBufferOverrun.bufferOverrun();
|
||||||
|
@ -451,14 +434,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
ErrorLogger::sprintfOverlappingData())
|
ErrorLogger::sprintfOverlappingData())
|
||||||
checkOther.InvalidFunctionUsage();
|
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 (condition);
|
||||||
if (ErrorLogger::ifNoAction(_settings) || ErrorLogger::conditionAlwaysTrueFalse(_settings))
|
if (ErrorLogger::ifNoAction(_settings) || ErrorLogger::conditionAlwaysTrueFalse(_settings))
|
||||||
checkOther.WarningIf();
|
checkOther.WarningIf();
|
||||||
|
|
|
@ -70,7 +70,7 @@ private:
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
CheckClass checkClass(&tokenizer, settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.virtualDestructor();
|
checkClass.virtualDestructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ private:
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
CheckClass checkClass(&tokenizer, settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.constructors();
|
checkClass.constructors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ private:
|
||||||
// Check..
|
// Check..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
CheckClass checkClass(&tokenizer, settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.constructors();
|
checkClass.constructors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ private:
|
||||||
// Check class constructors..
|
// Check class constructors..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
CheckClass checkClass(&tokenizer, settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.constructors();
|
checkClass.constructors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
// Check for unused private functions..
|
// Check for unused private functions..
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._checkCodingStyle = true;
|
settings._checkCodingStyle = true;
|
||||||
CheckClass checkClass(&tokenizer, settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.privateFunctions();
|
checkClass.privateFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue