diff --git a/src/check.h b/src/check.h index 5f869a7a9..b9b497907 100644 --- a/src/check.h +++ b/src/check.h @@ -53,8 +53,13 @@ public: return _instances; } - /** run checks.. */ - virtual void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0; + /** run checks, the token list is not simplified */ + virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *) + { } + + /** run checks, the token list is simplified */ + virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0; + protected: const Tokenizer * const _tokenizer; diff --git a/src/checkautovariables.h b/src/checkautovariables.h index 5f187717b..98fcc4606 100644 --- a/src/checkautovariables.h +++ b/src/checkautovariables.h @@ -30,25 +30,30 @@ class CheckAutoVariables : public Check { public: - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + /** This constructor is used when registering the CheckClass */ + CheckAutoVariables() : Check() + { } + + /** This constructor is used when running checks.. */ + CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + : Check(tokenizer, settings, errorLogger) + { } + + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { - _tokenizer = tokenizer; - _settings = settings; - _errorLogger = errorLogger; - autoVariables(); + CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger); + checkAutoVariables.autoVariables(); } /** Check for buffer overruns */ void autoVariables(); + private: std::list fp_list; std::list vd_list; bool error_av(const Token* left, const Token* right); bool is_auto_var(const Token* t); void addVD(const Token* t); - const Tokenizer *_tokenizer; - const Settings *_settings; - ErrorLogger *_errorLogger; }; //--------------------------------------------------------------------------- diff --git a/src/checkbufferoverrun.h b/src/checkbufferoverrun.h index 09261ff8e..b8cfa648a 100644 --- a/src/checkbufferoverrun.h +++ b/src/checkbufferoverrun.h @@ -35,14 +35,16 @@ class CheckBufferOverrunClass : public Check { public: + /** This constructor is used when registering the CheckClass */ CheckBufferOverrunClass() : Check() { } + /** This constructor is used when running checks.. */ CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) : Check(tokenizer, settings, errorLogger) { } - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckBufferOverrunClass checkBufferOverrunClass(tokenizer, settings, errorLogger); if (settings->_showAll) diff --git a/src/checkclass.h b/src/checkclass.h index 755eedb57..92a2e5177 100644 --- a/src/checkclass.h +++ b/src/checkclass.h @@ -30,16 +30,22 @@ class Token; class CheckClass : public Check { public: + /** This constructor is used when registering the CheckClass */ CheckClass() : Check() { } + /** This constructor is used when running checks.. */ 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); + checkClass.noMemset(); + } + + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckClass checkClass(tokenizer, settings, errorLogger); diff --git a/src/checkdangerousfunctions.h b/src/checkdangerousfunctions.h index e2f3b5e63..f28ca7f33 100644 --- a/src/checkdangerousfunctions.h +++ b/src/checkdangerousfunctions.h @@ -28,14 +28,16 @@ class CheckDangerousFunctionsClass : public Check { public: + /** This constructor is used when registering the CheckClass */ CheckDangerousFunctionsClass() : Check() { } + /** This constructor is used when running checks.. */ CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) : Check(tokenizer, settings, errorLogger) { } - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckDangerousFunctionsClass checkDangerousFunctionsClass(tokenizer, settings, errorLogger); checkDangerousFunctionsClass.dangerousFunctions(); diff --git a/src/checkmemoryleak.h b/src/checkmemoryleak.h index b101890ae..ec37a63f6 100644 --- a/src/checkmemoryleak.h +++ b/src/checkmemoryleak.h @@ -44,7 +44,7 @@ public: : Check(tokenizer, settings, errorLogger) { } - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckMemoryLeakClass checkMemoryLeakClass(tokenizer, settings, errorLogger); checkMemoryLeakClass.CheckMemoryLeak(); diff --git a/src/checkother.h b/src/checkother.h index 07f0f32e9..16ef54b95 100644 --- a/src/checkother.h +++ b/src/checkother.h @@ -31,20 +31,24 @@ class Token; class CheckOther : public Check { public: + /** This constructor is used when registering the CheckClass */ CheckOther() : Check() { } + /** This constructor is used when running checks.. */ CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) : Check(tokenizer, settings, errorLogger) { } - // TODO: run these before simplification.. - // checkOther.CheckUnsignedDivision(); - // checkOther.CheckCharVariable(); - - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + { + CheckOther checkOther(tokenizer, settings, errorLogger); + checkOther.CheckUnsignedDivision(); + checkOther.CheckCharVariable(); + } + + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckOther checkOther(tokenizer, settings, errorLogger); diff --git a/src/checkstl.h b/src/checkstl.h index 940f06f43..2ffee895b 100644 --- a/src/checkstl.h +++ b/src/checkstl.h @@ -30,14 +30,16 @@ class Token; class CheckStl : public Check { public: + /** This constructor is used when registering the CheckClass */ CheckStl() : Check() { } + /** This constructor is used when running checks.. */ CheckStl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) : Check(tokenizer, settings, errorLogger) { } - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckStl checkStl(tokenizer, settings, errorLogger); diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index e0659dd24..13678fbbe 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -378,16 +378,21 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) _tokenizer.fillFunctionList(); + // call all "runChecks" in all registered Check classes + for (std::list::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) + { + (*it)->runChecks(&_tokenizer, &_settings, this); + } _tokenizer.simplifyTokenList(); if (_settings._unusedFunctions) _checkFunctionUsage.parseTokens(_tokenizer); - // Run all checks in all registered Check classes + // call all "runSimplifiedChecks" in all registered Check classes for (std::list::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { - (*it)->runChecks(&_tokenizer, &_settings, this); + (*it)->runSimplifiedChecks(&_tokenizer, &_settings, this); } }