Merge branch 'sorted-instances'

This commit is contained in:
Daniel Marjamäki 2011-02-02 18:35:42 +01:00
commit 26b21a5ae0
15 changed files with 82 additions and 60 deletions

View File

@ -39,16 +39,11 @@ class Check
{
public:
/** This constructor is used when registering the CheckClass */
Check()
: _tokenizer(0), _settings(0), _errorLogger(0)
{
instances().push_back(this);
instances().sort();
}
Check(const std::string &aname);
/** This constructor is used when running checks. */
Check(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: _tokenizer(tokenizer), _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)
{ }
virtual ~Check()
@ -98,7 +93,10 @@ public:
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) = 0;
/** 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 */
virtual std::string classInfo() const = 0;
@ -114,6 +112,7 @@ public:
}
protected:
const std::string _name;
const Tokenizer * const _tokenizer;
const Settings * const _settings;
ErrorLogger * const _errorLogger;
@ -155,17 +154,28 @@ protected:
private:
/** compare the names of Check classes, used when sorting the Check descendants */
bool operator<(const Check *other) const
{
return (name() < other->name());
}
/** disabled assignment operator */
void operator=(const Check &);
};
namespace std {
/** compare the names of Check classes, used when sorting the Check descendants */
template <> struct less<Check *> {
bool operator()(const Check *p1, const Check *p2) const
{
return (p1->name() < p2->name());
}
};
}
inline Check::Check(const std::string &aname)
: _name(aname), _tokenizer(0), _settings(0), _errorLogger(0)
{
instances().push_back(this);
instances().sort(std::less<Check *>());
}
/// @}
#endif

View File

@ -34,12 +34,12 @@ class CheckAutoVariables : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckAutoVariables() : Check()
CheckAutoVariables() : Check(myName())
{ }
/** This constructor is used when running checks. */
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)
@ -98,7 +98,7 @@ private:
c.errorReturnTempPointer(0);
}
std::string name() const
std::string myName() const
{
return "Auto Variables";
}

View File

@ -50,12 +50,12 @@ class CheckBufferOverrun : public Check
public:
/** This constructor is used when registering the CheckClass */
CheckBufferOverrun() : Check()
CheckBufferOverrun() : Check(myName())
{ }
/** This constructor is used when running checks. */
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)
@ -209,7 +209,7 @@ public:
c.pointerOutOfBounds(0, "array");
}
std::string name() const
std::string myName() const
{
return "Bounds checking";
}

View File

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

View File

@ -36,7 +36,7 @@ class CheckClass : public Check
{
public:
/** @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. */
@ -144,7 +144,7 @@ private:
c.checkConstError(0, "class", "function");
}
std::string name() const
std::string myName() const
{
return "Class";
}

View File

@ -43,12 +43,12 @@ class CheckExceptionSafety : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckExceptionSafety() : Check()
CheckExceptionSafety() : Check(myName())
{ }
/** This constructor is used when running checks. */
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 */
@ -86,7 +86,7 @@ private:
}
/** Short description of class (for --doc) */
std::string name() const
std::string myName() const
{
return "Exception Safety";
}

View File

@ -172,12 +172,12 @@ class CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak
{
public:
/** @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 */
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
if (tokenizr)
@ -329,7 +329,7 @@ public:
* Get name of class (--doc)
* @return name of class
*/
std::string name() const
std::string myName() const
{
return "Memory leaks (function variables)";
}
@ -364,11 +364,11 @@ public:
class CheckMemoryLeakInClass : private Check, private CheckMemoryLeak
{
public:
CheckMemoryLeakInClass() : Check(), CheckMemoryLeak(0, 0)
CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(0, 0)
{ }
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)
@ -396,7 +396,7 @@ private:
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ }
std::string name() const
std::string myName() const
{
return "Memory leaks (class variables)";
}
@ -414,11 +414,11 @@ private:
class CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak
{
public:
CheckMemoryLeakStructMember() : Check(), CheckMemoryLeak(0, 0)
CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(0, 0)
{ }
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)
@ -434,7 +434,7 @@ private:
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ }
std::string name() const
std::string myName() const
{
return "Memory leaks (struct members)";
}
@ -452,11 +452,11 @@ private:
class CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak
{
public:
CheckMemoryLeakNoVar() : Check(), CheckMemoryLeak(0, 0)
CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(0, 0)
{ }
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)
@ -474,7 +474,7 @@ private:
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ }
std::string name() const
std::string myName() const
{
return "Memory leaks (address not taken)";
}

View File

@ -37,12 +37,12 @@ class CheckNullPointer : public Check
{
public:
/** @brief This constructor is used when registering the CheckNullPointer */
CheckNullPointer() : Check()
CheckNullPointer() : Check(myName())
{ }
/** @brief This constructor is used when running checks. */
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 */
@ -112,7 +112,7 @@ public:
}
/** Name of check */
std::string name() const
std::string myName() const
{
return "Null pointer";
}

View File

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

View File

@ -37,12 +37,12 @@ class CheckOther : public Check
{
public:
/** @brief This constructor is used when registering the CheckClass */
CheckOther() : Check()
CheckOther() : Check(myName())
{ }
/** @brief This constructor is used when running checks. */
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 */
@ -245,7 +245,7 @@ public:
c.clarifyCalculationError(0);
}
std::string name() const
std::string myName() const
{
return "Other";
}

View File

@ -35,12 +35,12 @@ class CheckPostfixOperator : public Check
{
public:
/** This constructor is used when registering the CheckPostfixOperator */
CheckPostfixOperator() : Check()
CheckPostfixOperator() : Check(myName())
{ }
/** This constructor is used when running checks. */
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)
@ -62,7 +62,7 @@ private:
c.postfixOperatorError(0);
}
std::string name() const
std::string myName() const
{
return "Using postfix operators";
}

View File

@ -35,12 +35,12 @@ class CheckStl : public Check
{
public:
/** This constructor is used when registering the CheckClass */
CheckStl() : Check()
CheckStl() : Check(myName())
{ }
/** This constructor is used when running checks. */
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. */
@ -173,7 +173,7 @@ private:
c.redundantIfRemoveError(0);
}
std::string name() const
std::string myName() const
{
return "STL usage";
}

View File

@ -37,12 +37,12 @@ class CheckUninitVar : public Check
{
public:
/** @brief This constructor is used when registering the CheckUninitVar */
CheckUninitVar() : Check()
CheckUninitVar() : Check(myName())
{ }
/** @brief This constructor is used when running checks. */
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 */
@ -87,7 +87,7 @@ public:
c.uninitvarError(0, "varname");
}
std::string name() const
std::string myName() const
{
return "Uninitialized variables";
}

View File

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

View File

@ -66,9 +66,21 @@ private:
void run()
{
TEST_CASE(instancesSorted);
TEST_CASE(getErrorMessages);
}
void instancesSorted()
{
for (std::list<Check *>::iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) {
std::list<Check *>::iterator j = i;
++j;
if (j != Check::instances().end()) {
ASSERT_EQUALS(true, (*i)->name() < (*j)->name());
}
}
}
void getErrorMessages()
{
ErrorLogger2 errorLogger;