initialise Check::_name in constructor rather than relying on virtual Check::name()

This commit is contained in:
Greg Hewgill 2011-02-02 22:29:10 +13:00
parent c3ad3f78e9
commit be195a72c9
14 changed files with 54 additions and 50 deletions

View File

@ -39,16 +39,16 @@ class Check
{ {
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
Check() Check(const std::string &aname)
: _tokenizer(0), _settings(0), _errorLogger(0) : _name(aname), _tokenizer(0), _settings(0), _errorLogger(0)
{ {
instances().push_back(this); instances().push_back(this);
instances().sort(); instances().sort();
} }
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
Check(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger) : _name(aname), _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger)
{ } { }
virtual ~Check() virtual ~Check()
@ -98,7 +98,10 @@ public:
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) = 0; virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) = 0;
/** class name, used to generate documentation */ /** class name, used to generate documentation */
virtual std::string name() const = 0; std::string name() const
{
return _name;
}
/** get information about this class, used to generate documentation */ /** get information about this class, used to generate documentation */
virtual std::string classInfo() const = 0; virtual std::string classInfo() const = 0;
@ -114,6 +117,7 @@ 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;

View File

@ -34,12 +34,12 @@ class CheckAutoVariables : public Check
{ {
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckAutoVariables() : Check() CheckAutoVariables() : Check(myName())
{ } { }
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
@ -98,7 +98,7 @@ private:
c.errorReturnTempPointer(0); c.errorReturnTempPointer(0);
} }
std::string name() const std::string myName() const
{ {
return "Auto Variables"; return "Auto Variables";
} }

View File

@ -50,12 +50,12 @@ class CheckBufferOverrun : public Check
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckBufferOverrun() : Check() CheckBufferOverrun() : Check(myName())
{ } { }
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
@ -209,7 +209,7 @@ public:
c.pointerOutOfBounds(0, "array"); c.pointerOutOfBounds(0, "array");
} }
std::string name() const std::string myName() const
{ {
return "Bounds checking"; return "Bounds checking";
} }

View File

@ -42,7 +42,7 @@ CheckClass instance;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger), : Check(myName(), tokenizer, settings, errorLogger),
symbolDatabase(NULL) symbolDatabase(NULL)
{ {

View File

@ -36,7 +36,7 @@ class CheckClass : public Check
{ {
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckClass() : Check(), symbolDatabase(NULL) CheckClass() : Check(myName()), symbolDatabase(NULL)
{ } { }
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
@ -144,7 +144,7 @@ private:
c.checkConstError(0, "class", "function"); c.checkConstError(0, "class", "function");
} }
std::string name() const std::string myName() const
{ {
return "Class"; return "Class";
} }

View File

@ -43,12 +43,12 @@ class CheckExceptionSafety : public Check
{ {
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckExceptionSafety() : Check() CheckExceptionSafety() : Check(myName())
{ } { }
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
/** Checks that uses the simplified token list */ /** Checks that uses the simplified token list */
@ -86,7 +86,7 @@ private:
} }
/** Short description of class (for --doc) */ /** Short description of class (for --doc) */
std::string name() const std::string myName() const
{ {
return "Exception Safety"; return "Exception Safety";
} }

View File

@ -172,12 +172,12 @@ class CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak
{ {
public: public:
/** @brief This constructor is used when registering this class */ /** @brief This constructor is used when registering this class */
CheckMemoryLeakInFunction() : Check(), CheckMemoryLeak(0, 0), symbolDatabase(NULL) CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(0, 0), symbolDatabase(NULL)
{ } { }
/** @brief This constructor is used when running checks */ /** @brief This constructor is used when running checks */
CheckMemoryLeakInFunction(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) CheckMemoryLeakInFunction(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
: Check(tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog) : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog)
{ {
// get the symbol database // get the symbol database
if (tokenizr) if (tokenizr)
@ -329,7 +329,7 @@ public:
* Get name of class (--doc) * Get name of class (--doc)
* @return name of class * @return name of class
*/ */
std::string name() const std::string myName() const
{ {
return "Memory leaks (function variables)"; return "Memory leaks (function variables)";
} }
@ -364,11 +364,11 @@ public:
class CheckMemoryLeakInClass : private Check, private CheckMemoryLeak class CheckMemoryLeakInClass : private Check, private CheckMemoryLeak
{ {
public: public:
CheckMemoryLeakInClass() : Check(), CheckMemoryLeak(0, 0) CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(0, 0)
{ } { }
CheckMemoryLeakInClass(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) CheckMemoryLeakInClass(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
: Check(tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog) : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
@ -396,7 +396,7 @@ private:
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ } { }
std::string name() const std::string myName() const
{ {
return "Memory leaks (class variables)"; return "Memory leaks (class variables)";
} }
@ -414,11 +414,11 @@ private:
class CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak class CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak
{ {
public: public:
CheckMemoryLeakStructMember() : Check(), CheckMemoryLeak(0, 0) CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(0, 0)
{ } { }
CheckMemoryLeakStructMember(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) CheckMemoryLeakStructMember(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
: Check(tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog) : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
@ -434,7 +434,7 @@ private:
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ } { }
std::string name() const std::string myName() const
{ {
return "Memory leaks (struct members)"; return "Memory leaks (struct members)";
} }
@ -452,11 +452,11 @@ private:
class CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak class CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak
{ {
public: public:
CheckMemoryLeakNoVar() : Check(), CheckMemoryLeak(0, 0) CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(0, 0)
{ } { }
CheckMemoryLeakNoVar(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) CheckMemoryLeakNoVar(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
: Check(tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog) : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
@ -474,7 +474,7 @@ private:
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ } { }
std::string name() const std::string myName() const
{ {
return "Memory leaks (address not taken)"; return "Memory leaks (address not taken)";
} }

View File

@ -37,12 +37,12 @@ class CheckNullPointer : public Check
{ {
public: public:
/** @brief This constructor is used when registering the CheckNullPointer */ /** @brief This constructor is used when registering the CheckNullPointer */
CheckNullPointer() : Check() CheckNullPointer() : Check(myName())
{ } { }
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckNullPointer(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckNullPointer(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
/** @brief Run checks against the normal token list */ /** @brief Run checks against the normal token list */
@ -112,7 +112,7 @@ public:
} }
/** Name of check */ /** Name of check */
std::string name() const std::string myName() const
{ {
return "Null pointer"; return "Null pointer";
} }

View File

@ -38,14 +38,14 @@ class CheckObsoleteFunctions : public Check
{ {
public: public:
/** This constructor is used when registering the CheckObsoleteFunctions */ /** This constructor is used when registering the CheckObsoleteFunctions */
CheckObsoleteFunctions() : Check() CheckObsoleteFunctions() : Check(myName())
{ {
initObsoleteFunctions(); initObsoleteFunctions();
} }
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckObsoleteFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckObsoleteFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ {
initObsoleteFunctions(); initObsoleteFunctions();
} }
@ -125,7 +125,7 @@ private:
} }
} }
std::string name() const std::string myName() const
{ {
return "Obsolete functions"; return "Obsolete functions";
} }

View File

@ -37,12 +37,12 @@ class CheckOther : public Check
{ {
public: public:
/** @brief This constructor is used when registering the CheckClass */ /** @brief This constructor is used when registering the CheckClass */
CheckOther() : Check() CheckOther() : Check(myName())
{ } { }
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
/** @brief Run checks against the normal token list */ /** @brief Run checks against the normal token list */
@ -245,7 +245,7 @@ public:
c.clarifyCalculationError(0); c.clarifyCalculationError(0);
} }
std::string name() const std::string myName() const
{ {
return "Other"; return "Other";
} }

View File

@ -35,12 +35,12 @@ class CheckPostfixOperator : public Check
{ {
public: public:
/** This constructor is used when registering the CheckPostfixOperator */ /** This constructor is used when registering the CheckPostfixOperator */
CheckPostfixOperator() : Check() CheckPostfixOperator() : Check(myName())
{ } { }
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckPostfixOperator(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckPostfixOperator(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
@ -62,7 +62,7 @@ private:
c.postfixOperatorError(0); c.postfixOperatorError(0);
} }
std::string name() const std::string myName() const
{ {
return "Using postfix operators"; return "Using postfix operators";
} }

View File

@ -35,12 +35,12 @@ class CheckStl : public Check
{ {
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckStl() : Check() CheckStl() : Check(myName())
{ } { }
/** This constructor is used when running checks. */ /** This constructor is used when running checks. */
CheckStl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckStl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
/** Simplified checks. The token list is simplified. */ /** Simplified checks. The token list is simplified. */
@ -173,7 +173,7 @@ private:
c.redundantIfRemoveError(0); c.redundantIfRemoveError(0);
} }
std::string name() const std::string myName() const
{ {
return "STL usage"; return "STL usage";
} }

View File

@ -37,12 +37,12 @@ class CheckUninitVar : public Check
{ {
public: public:
/** @brief This constructor is used when registering the CheckUninitVar */ /** @brief This constructor is used when registering the CheckUninitVar */
CheckUninitVar() : Check() CheckUninitVar() : Check(myName())
{ } { }
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
/** @brief Run checks against the normal token list */ /** @brief Run checks against the normal token list */
@ -87,7 +87,7 @@ public:
c.uninitvarError(0, "varname"); c.uninitvarError(0, "varname");
} }
std::string name() const std::string myName() const
{ {
return "Uninitialized variables"; return "Uninitialized variables";
} }

View File

@ -33,12 +33,12 @@ class CheckUnusedFunctions: public Check
{ {
public: public:
/** @brief This constructor is used when registering the CheckUnusedFunctions */ /** @brief This constructor is used when registering the CheckUnusedFunctions */
CheckUnusedFunctions() : Check() CheckUnusedFunctions() : Check(myName())
{ } { }
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckUnusedFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckUnusedFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(myName(), tokenizer, settings, errorLogger)
{ } { }
// Parse current tokens and determine.. // Parse current tokens and determine..
@ -69,7 +69,7 @@ private:
} }
std::string name() const std::string myName() const
{ {
return "Unused functions"; return "Unused functions";
} }