Some refactorizations

This commit is contained in:
PKEuS 2012-02-18 23:43:51 +01:00
parent 0e791929b5
commit b1ff900aaa
25 changed files with 37 additions and 38 deletions

View File

@ -33,14 +33,12 @@
#include "pathmatch.h" #include "pathmatch.h"
CppCheckExecutor::CppCheckExecutor() CppCheckExecutor::CppCheckExecutor()
: time1(0), errorlist(false)
{ {
time1 = 0;
errorlist = false;
} }
CppCheckExecutor::~CppCheckExecutor() CppCheckExecutor::~CppCheckExecutor()
{ {
} }
bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[]) bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[])

View File

@ -42,7 +42,7 @@ public:
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: _name(aname), _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger) : _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger), _name(aname)
{ } { }
virtual ~Check() { virtual ~Check() {
@ -85,7 +85,7 @@ public:
virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0; virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
/** get error messages */ /** get error messages */
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) = 0; virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0;
/** class name, used to generate documentation */ /** class name, used to generate documentation */
const std::string& name() const { const std::string& name() const {
@ -109,7 +109,6 @@ public:
} }
protected: protected:
const std::string _name;
const Tokenizer * const _tokenizer; const Tokenizer * const _tokenizer;
const Settings * const _settings; const Settings * const _settings;
ErrorLogger * const _errorLogger; ErrorLogger * const _errorLogger;
@ -123,7 +122,7 @@ protected:
} }
/** report an error */ /** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg) { void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg) {
reportError(callstack, severity, id, msg, false); reportError(callstack, severity, id, msg, false);
} }
@ -136,17 +135,19 @@ protected:
} }
/** report an inconclusive error */ /** report an inconclusive error */
void reportInconclusiveError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg) { void reportInconclusiveError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg) {
reportError(callstack, severity, id, msg, true); reportError(callstack, severity, id, msg, true);
} }
private: private:
const std::string _name;
/** disabled assignment operator */ /** disabled assignment operator */
void operator=(const Check &); void operator=(const Check &);
/** report an error */ /** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg, bool inconclusive) { void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg, bool inconclusive) {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList; std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) { for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) {
// --errorlist can provide null values here // --errorlist can provide null values here
@ -180,7 +181,7 @@ namespace std {
} }
inline Check::Check(const std::string &aname) inline Check::Check(const std::string &aname)
: _name(aname), _tokenizer(0), _settings(0), _errorLogger(0) : _tokenizer(0), _settings(0), _errorLogger(0), _name(aname)
{ {
instances().push_back(this); instances().push_back(this);
instances().sort(std::less<Check *>()); instances().sort(std::less<Check *>());

View File

@ -64,7 +64,7 @@ private:
void assignmentAddressToIntegerError(const Token *tok); void assignmentAddressToIntegerError(const Token *tok);
void assignmentIntegerToAddressError(const Token *tok); void assignmentIntegerToAddressError(const Token *tok);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
Check64BitPortability c(0, settings, errorLogger); Check64BitPortability c(0, settings, errorLogger);
c.assignmentAddressToIntegerError(0); c.assignmentAddressToIntegerError(0);
c.assignmentIntegerToAddressError(0); c.assignmentIntegerToAddressError(0);

View File

@ -72,7 +72,7 @@ private:
void multiConditionError(const Token *tok, unsigned int line1); void multiConditionError(const Token *tok, unsigned int line1);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckAssignIf c(0, settings, errorLogger); CheckAssignIf c(0, settings, errorLogger);
c.assignIfError(0, false); c.assignIfError(0, false);
c.comparisonError(0, 6, "==", 1, false); c.comparisonError(0, 6, "==", 1, false);

View File

@ -87,7 +87,7 @@ private:
void errorInvalidDeallocation(const Token *tok); void errorInvalidDeallocation(const Token *tok);
void errorReturnAddressOfFunctionParameter(const Token *tok, const std::string &varname); void errorReturnAddressOfFunctionParameter(const Token *tok, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckAutoVariables c(0,settings,errorLogger); CheckAutoVariables c(0,settings,errorLogger);
c.errorAutoVariableAssignment(0, false); c.errorAutoVariableAssignment(0, false);
c.errorReturnAddressToAutoVariable(0); c.errorReturnAddressToAutoVariable(0);

View File

@ -55,7 +55,7 @@ public:
private: private:
void boostForeachError(const Token *tok); void boostForeachError(const Token *tok);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckBoost c(0, settings, errorLogger); CheckBoost c(0, settings, errorLogger);
c.boostForeachError(0); c.boostForeachError(0);
} }

View File

@ -231,7 +231,7 @@ public:
void possibleBufferOverrunError(const Token *tok, const std::string &src, const std::string &dst, bool cat); void possibleBufferOverrunError(const Token *tok, const std::string &src, const std::string &dst, bool cat);
void possibleReadlinkBufferOverrunError(const Token *tok, const std::string &funcname, const std::string &varname); void possibleReadlinkBufferOverrunError(const Token *tok, const std::string &funcname, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckBufferOverrun c(0, settings, errorLogger); CheckBufferOverrun c(0, settings, errorLogger);
std::vector<MathLib::bigint> indexes; std::vector<MathLib::bigint> indexes;
indexes.push_back(2); indexes.push_back(2);

View File

@ -123,7 +123,7 @@ private:
void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname); void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname);
void initializerListError(const Token *tok1,const Token *tok2, const std::string & classname, const std::string &varname); void initializerListError(const Token *tok1,const Token *tok2, const std::string & classname, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckClass c(0, settings, errorLogger); CheckClass c(0, settings, errorLogger);
c.noConstructorError(0, "classname", false); c.noConstructorError(0, "classname", false);
c.uninitVarError(0, "classname", "varname"); c.uninitVarError(0, "classname", "varname");

View File

@ -96,7 +96,7 @@ private:
} }
/** Generate all possible errors (for --errorlist) */ /** Generate all possible errors (for --errorlist) */
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckExceptionSafety c(0, settings, errorLogger); CheckExceptionSafety c(0, settings, errorLogger);
c.destructorsError(0); c.destructorsError(0);
c.deallocThrowError(0, "p"); c.deallocThrowError(0, "p");

View File

@ -68,7 +68,7 @@ private:
void complexPatternError(const Token *tok, const std::string &pattern, const std::string &funcname); void complexPatternError(const Token *tok, const std::string &pattern, const std::string &funcname);
void missingPercentCharacterError(const Token *tok, const std::string &pattern, const std::string &funcname); void missingPercentCharacterError(const Token *tok, const std::string &pattern, const std::string &funcname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckInternal c(0, settings, errorLogger); CheckInternal c(0, settings, errorLogger);
c.simplePatternError(0, "class {", "Match"); c.simplePatternError(0, "class {", "Match");
c.complexPatternError(0, "%type% ( )", "Match"); c.complexPatternError(0, "%type% ( )", "Match");

View File

@ -306,7 +306,7 @@ public:
void checkScope(const Token *Tok1, const std::string &varname, unsigned int varid, bool classmember, unsigned int sz); void checkScope(const Token *Tok1, const std::string &varname, unsigned int varid, bool classmember, unsigned int sz);
/** Report all possible errors (for the --errorlist) */ /** Report all possible errors (for the --errorlist) */
void getErrorMessages(ErrorLogger *e, const Settings *settings) { void getErrorMessages(ErrorLogger *e, const Settings *settings) const {
CheckMemoryLeakInFunction c(0, settings, e); CheckMemoryLeakInFunction c(0, settings, e);
c.memleakError(0, "varname"); c.memleakError(0, "varname");
@ -381,7 +381,7 @@ private:
void checkPublicFunctions(const Scope *scope, const Token *classtok); void checkPublicFunctions(const Scope *scope, const Token *classtok);
void publicAllocationError(const Token *tok, const std::string &varname); void publicAllocationError(const Token *tok, const std::string &varname);
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const
{ } { }
std::string myName() const { std::string myName() const {
@ -420,7 +420,7 @@ private:
void checkStructVariable(const Token * const vartok); void checkStructVariable(const Token * const vartok);
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const
{ } { }
std::string myName() const { std::string myName() const {
@ -456,7 +456,7 @@ private:
void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall); void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall);
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const
{ } { }
std::string myName() const { std::string myName() const {

View File

@ -82,7 +82,7 @@ private:
} }
} }
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckNonReentrantFunctions c(0, settings, errorLogger); CheckNonReentrantFunctions c(0, settings, errorLogger);
std::map<std::string,std::string>::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end()); std::map<std::string,std::string>::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end());

View File

@ -103,7 +103,7 @@ public:
void nullPointerError(const Token *tok, const std::string &varname, const unsigned int line, bool inconclusive = false); void nullPointerError(const Token *tok, const std::string &varname, const unsigned int line, bool inconclusive = false);
/** Get error messages. Used by --errorlist */ /** Get error messages. Used by --errorlist */
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckNullPointer c(0, settings, errorLogger); CheckNullPointer c(0, settings, errorLogger);
c.nullPointerError(0, "pointer"); c.nullPointerError(0, "pointer");
} }

View File

@ -127,7 +127,7 @@ private:
} }
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckObsoleteFunctions c(0, settings, errorLogger); CheckObsoleteFunctions c(0, settings, errorLogger);
std::map<std::string,std::string>::const_iterator it(_obsoletePosixFunctions.begin()), itend(_obsoletePosixFunctions.end()); std::map<std::string,std::string>::const_iterator it(_obsoletePosixFunctions.begin()), itend(_obsoletePosixFunctions.end());

View File

@ -309,7 +309,7 @@ public:
void doubleFreeError(const Token *tok, const std::string &varname); void doubleFreeError(const Token *tok, const std::string &varname);
void doubleCloseDirError(const Token *tok, const std::string &varname); void doubleCloseDirError(const Token *tok, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckOther c(0, settings, errorLogger); CheckOther c(0, settings, errorLogger);
// error // error

View File

@ -54,7 +54,7 @@ private:
/** Report Error */ /** Report Error */
void postfixOperatorError(const Token *tok); void postfixOperatorError(const Token *tok);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckPostfixOperator c(0, settings, errorLogger); CheckPostfixOperator c(0, settings, errorLogger);
c.postfixOperatorError(0); c.postfixOperatorError(0);
} }

View File

@ -172,7 +172,7 @@ private:
void uselessCallsSwapError(const Token *tok, const std::string &varname); void uselessCallsSwapError(const Token *tok, const std::string &varname);
void uselessCallsSubstrError(const Token *tok, const std::string &varname); void uselessCallsSubstrError(const Token *tok, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckStl c(0, settings, errorLogger); CheckStl c(0, settings, errorLogger);
c.invalidIteratorError(0, "iterator"); c.invalidIteratorError(0, "iterator");
c.iteratorsError(0, "container1", "container2"); c.iteratorsError(0, "container1", "container2");

View File

@ -82,7 +82,7 @@ public:
void uninitdataError(const Token *tok, const std::string &varname); void uninitdataError(const Token *tok, const std::string &varname);
void uninitvarError(const Token *tok, const std::string &varname); void uninitvarError(const Token *tok, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckUninitVar c(0, settings, errorLogger); CheckUninitVar c(0, settings, errorLogger);
// error // error

View File

@ -49,7 +49,7 @@ public:
private: private:
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckUnusedFunctions c(0, settings, errorLogger); CheckUnusedFunctions c(0, settings, errorLogger);
c.unusedFunctionError(errorLogger, "", 0, "funcName"); c.unusedFunctionError(errorLogger, "", 0, "funcName");
} }

View File

@ -77,7 +77,7 @@ public:
void unreadVariableError(const Token *tok, const std::string &varname); void unreadVariableError(const Token *tok, const std::string &varname);
void unassignedVariableError(const Token *tok, const std::string &varname); void unassignedVariableError(const Token *tok, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckUnusedVar c(0, settings, errorLogger); CheckUnusedVar c(0, settings, errorLogger);
// style/warning // style/warning

View File

@ -36,7 +36,7 @@
* errors or places that could be improved. * errors or places that could be improved.
* Usage: See check() for more info. * Usage: See check() for more info.
*/ */
class CppCheck : public ErrorLogger { class CppCheck : ErrorLogger {
public: public:
/** /**
* @brief Constructor. * @brief Constructor.
@ -134,7 +134,7 @@ public:
/** /**
* @brief Get dependencies. Use this after calling 'check'. * @brief Get dependencies. Use this after calling 'check'.
*/ */
std::set<std::string> dependencies() const { const std::set<std::string>& dependencies() const {
return _dependencies; return _dependencies;
} }

View File

@ -31,7 +31,7 @@
*/ */
void TimerResults::ShowResults() void TimerResults::ShowResults() const
{ {
std::clock_t overallClocks = 0; std::clock_t overallClocks = 0;

View File

@ -52,7 +52,7 @@ public:
TimerResults() { TimerResults() {
} }
void ShowResults(); void ShowResults() const;
virtual void AddResults(const std::string& str, std::clock_t clocks); virtual void AddResults(const std::string& str, std::clock_t clocks);
private: private:

View File

@ -8280,7 +8280,7 @@ void Tokenizer::simplifyConst()
} }
} }
void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
{ {
Tokenizer t(settings, errorLogger); Tokenizer t(settings, errorLogger);
t.syntaxError(0, ' '); t.syntaxError(0, ' ');

View File

@ -204,7 +204,7 @@ public:
/** /**
* get error messages that the tokenizer generate * get error messages that the tokenizer generate
*/ */
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings); virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const;
/** Simplify assignment in function call "f(x=g());" => "x=g();f(x);" /** Simplify assignment in function call "f(x=g());" => "x=g();f(x);"
*/ */