Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions lib/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -98,7 +93,10 @@ class Check
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;
Expand All @@ -114,6 +112,7 @@ class Check
}

protected:
const std::string _name;
const Tokenizer * const _tokenizer;
const Settings * const _settings;
ErrorLogger * const _errorLogger;
Expand Down Expand Up @@ -155,17 +154,28 @@ class Check


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
Expand Down
6 changes: 3 additions & 3 deletions lib/checkautovariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -98,7 +98,7 @@ class CheckAutoVariables : public Check
c.errorReturnTempPointer(0);
}

std::string name() const
std::string myName() const
{
return "Auto Variables";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkbufferoverrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -209,7 +209,7 @@ class CheckBufferOverrun : public Check
c.pointerOutOfBounds(0, "array");
}

std::string name() const
std::string myName() const
{
return "Bounds checking";
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down
4 changes: 2 additions & 2 deletions lib/checkclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -144,7 +144,7 @@ class CheckClass : public Check
c.checkConstError(0, "class", "function");
}

std::string name() const
std::string myName() const
{
return "Class";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkexceptionsafety.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -86,7 +86,7 @@ class CheckExceptionSafety : public Check
}

/** Short description of class (for --doc) */
std::string name() const
std::string myName() const
{
return "Exception Safety";
}
Expand Down
24 changes: 12 additions & 12 deletions lib/checkmemoryleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -329,7 +329,7 @@ class CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak
* Get name of class (--doc)
* @return name of class
*/
std::string name() const
std::string myName() const
{
return "Memory leaks (function variables)";
}
Expand Down Expand Up @@ -364,11 +364,11 @@ class CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak
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)
Expand Down Expand Up @@ -396,7 +396,7 @@ class CheckMemoryLeakInClass : private Check, private CheckMemoryLeak
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ }

std::string name() const
std::string myName() const
{
return "Memory leaks (class variables)";
}
Expand All @@ -414,11 +414,11 @@ class CheckMemoryLeakInClass : private Check, private CheckMemoryLeak
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)
Expand All @@ -434,7 +434,7 @@ class CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ }

std::string name() const
std::string myName() const
{
return "Memory leaks (struct members)";
}
Expand All @@ -452,11 +452,11 @@ class CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak
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)
Expand All @@ -474,7 +474,7 @@ class CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
{ }

std::string name() const
std::string myName() const
{
return "Memory leaks (address not taken)";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checknullpointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -112,7 +112,7 @@ class CheckNullPointer : public Check
}

/** Name of check */
std::string name() const
std::string myName() const
{
return "Null pointer";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkobsoletefunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -125,7 +125,7 @@ class CheckObsoleteFunctions : public Check
}
}

std::string name() const
std::string myName() const
{
return "Obsolete functions";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkother.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -245,7 +245,7 @@ class CheckOther : public Check
c.clarifyCalculationError(0);
}

std::string name() const
std::string myName() const
{
return "Other";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkpostfixoperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -62,7 +62,7 @@ class CheckPostfixOperator : public Check
c.postfixOperatorError(0);
}

std::string name() const
std::string myName() const
{
return "Using postfix operators";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/checkstl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -173,7 +173,7 @@ class CheckStl : public Check
c.redundantIfRemoveError(0);
}

std::string name() const
std::string myName() const
{
return "STL usage";
}
Expand Down
Loading