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"
CppCheckExecutor::CppCheckExecutor()
: time1(0), errorlist(false)
{
time1 = 0;
errorlist = false;
}
CppCheckExecutor::~CppCheckExecutor()
{
}
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. */
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() {
@ -85,7 +85,7 @@ public:
virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
/** 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 */
const std::string& name() const {
@ -109,7 +109,6 @@ public:
}
protected:
const std::string _name;
const Tokenizer * const _tokenizer;
const Settings * const _settings;
ErrorLogger * const _errorLogger;
@ -123,7 +122,7 @@ protected:
}
/** 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);
}
@ -136,17 +135,19 @@ protected:
}
/** 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);
}
private:
const std::string _name;
/** disabled assignment operator */
void operator=(const Check &);
/** 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;
for (std::list<const Token *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it) {
// --errorlist can provide null values here
@ -180,7 +181,7 @@ namespace std {
}
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().sort(std::less<Check *>());

View File

@ -64,7 +64,7 @@ private:
void assignmentAddressToIntegerError(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);
c.assignmentAddressToIntegerError(0);
c.assignmentIntegerToAddressError(0);

View File

@ -72,7 +72,7 @@ private:
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);
c.assignIfError(0, false);
c.comparisonError(0, 6, "==", 1, false);

View File

@ -87,7 +87,7 @@ private:
void errorInvalidDeallocation(const Token *tok);
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);
c.errorAutoVariableAssignment(0, false);
c.errorReturnAddressToAutoVariable(0);

View File

@ -55,7 +55,7 @@ public:
private:
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);
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 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);
std::vector<MathLib::bigint> indexes;
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 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);
c.noConstructorError(0, "classname", false);
c.uninitVarError(0, "classname", "varname");

View File

@ -96,7 +96,7 @@ private:
}
/** 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);
c.destructorsError(0);
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 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);
c.simplePatternError(0, "class {", "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);
/** 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);
c.memleakError(0, "varname");
@ -381,7 +381,7 @@ private:
void checkPublicFunctions(const Scope *scope, const Token *classtok);
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 {
@ -420,7 +420,7 @@ private:
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 {
@ -456,7 +456,7 @@ private:
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 {

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);
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);
/** 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);
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);
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 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);
// error

View File

@ -54,7 +54,7 @@ private:
/** Report Error */
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);
c.postfixOperatorError(0);
}

View File

@ -172,7 +172,7 @@ private:
void uselessCallsSwapError(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);
c.invalidIteratorError(0, "iterator");
c.iteratorsError(0, "container1", "container2");

View File

@ -82,7 +82,7 @@ public:
void uninitdataError(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);
// error

View File

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

View File

@ -77,7 +77,7 @@ public:
void unreadVariableError(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);
// style/warning

View File

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

View File

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

View File

@ -52,7 +52,7 @@ public:
TimerResults() {
}
void ShowResults();
void ShowResults() const;
virtual void AddResults(const std::string& str, std::clock_t clocks);
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);
t.syntaxError(0, ' ');

View File

@ -204,7 +204,7 @@ public:
/**
* 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);"
*/