diff --git a/src/checkclass.cpp b/src/checkclass.cpp index e42e1e389..ca7bbde8d 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -20,6 +20,10 @@ //--------------------------------------------------------------------------- #include "checkclass.h" +#include "tokenize.h" +#include "token.h" +#include "errorlogger.h" + #include #include @@ -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); diff --git a/src/checkclass.h b/src/checkclass.h index e3f8ff634..755eedb57 100644 --- a/src/checkclass.h +++ b/src/checkclass.h @@ -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 diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index fbf560d1c..8efb07ad9 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -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(); diff --git a/test/testclass.cpp b/test/testclass.cpp index 722cab723..2b1e8c212 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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(); } diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 02d1c7320..a3137ee24 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -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(); } diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index f64e72a0d..549999da5 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -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(); }