Made some functions static or const according to cppcheck results

This commit is contained in:
PKEuS 2012-05-17 01:33:24 -07:00
parent ea601ef2b0
commit 4bb2a1b27b
8 changed files with 24 additions and 23 deletions

View File

@ -160,7 +160,7 @@ private:
// operatorEqToSelf helper functions // operatorEqToSelf helper functions
bool hasAllocation(const Function *func, const Scope* scope); bool hasAllocation(const Function *func, const Scope* scope);
bool hasAssignSelf(const Function *func, const Token *rhs); static bool hasAssignSelf(const Function *func, const Token *rhs);
// checkConst helper functions // checkConst helper functions
bool isMemberVar(const Scope *scope, const Token *tok); bool isMemberVar(const Scope *scope, const Token *tok);
@ -180,7 +180,7 @@ private:
bool init; bool init;
}; };
bool isBaseClassFunc(const Token *tok, const Scope *scope); static bool isBaseClassFunc(const Token *tok, const Scope *scope);
/** /**
* @brief assign a variable in the varlist * @brief assign a variable in the varlist
@ -188,7 +188,7 @@ private:
* @param scope pointer to variable Scope * @param scope pointer to variable Scope
* @param usage reference to usage vector * @param usage reference to usage vector
*/ */
void assignVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage); static void assignVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage);
/** /**
* @brief initialize a variable in the varlist * @brief initialize a variable in the varlist
@ -196,7 +196,7 @@ private:
* @param scope pointer to variable Scope * @param scope pointer to variable Scope
* @param usage reference to usage vector * @param usage reference to usage vector
*/ */
void initVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage); static void initVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage);
/** /**
* @brief set all variables in list assigned * @brief set all variables in list assigned

View File

@ -377,7 +377,7 @@ void CheckMemoryLeak::memleakUponReallocFailureError(const Token *tok, const std
reportErr(tok, Severity::error, "memleakOnRealloc", "Common realloc mistake: \'" + varname + "\' nulled but not freed upon failure"); reportErr(tok, Severity::error, "memleakOnRealloc", "Common realloc mistake: \'" + varname + "\' nulled but not freed upon failure");
} }
void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &varname) void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &varname) const
{ {
std::string errmsg("Resource leak"); std::string errmsg("Resource leak");
if (!varname.empty()) if (!varname.empty())
@ -1387,7 +1387,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
void CheckMemoryLeakInFunction::simplifycode(Token *tok) void CheckMemoryLeakInFunction::simplifycode(Token *tok) const
{ {
{ {
// Replace "throw" that is not in a try block with "return" // Replace "throw" that is not in a try block with "return"

View File

@ -143,7 +143,7 @@ public:
* @param tok token where resource is leaked * @param tok token where resource is leaked
* @param varname name of variable * @param varname name of variable
*/ */
void resourceLeakError(const Token *tok, const std::string &varname); void resourceLeakError(const Token *tok, const std::string &varname) const;
/** /**
* @brief Report error: deallocating a deallocated pointer * @brief Report error: deallocating a deallocated pointer
@ -287,7 +287,7 @@ public:
* Simplify code e.g. by replacing empty "{ }" with ";" * Simplify code e.g. by replacing empty "{ }" with ";"
* @param tok first token. The tokens list can be modified. * @param tok first token. The tokens list can be modified.
*/ */
void simplifycode(Token *tok); void simplifycode(Token *tok) const;
static const Token *findleak(const Token *tokens); static const Token *findleak(const Token *tokens);

View File

@ -66,7 +66,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// only create base list for classes and structures // only create base list for classes and structures
if (new_scope->isClassOrStruct()) { if (new_scope->isClassOrStruct()) {
// goto initial '{' // goto initial '{'
tok2 = initBaseInfo(new_scope, tok); tok2 = new_scope->initBaseInfo(tok);
// make sure we have valid code // make sure we have valid code
if (!tok2) { if (!tok2) {
@ -1152,7 +1152,7 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
} }
} }
const Token *SymbolDatabase::initBaseInfo(Scope *scope, const Token *tok) const Token *Scope::initBaseInfo(const Token *tok)
{ {
// goto initial '{' // goto initial '{'
const Token *tok2 = tok->tokAt(2); const Token *tok2 = tok->tokAt(2);
@ -1236,7 +1236,7 @@ const Token *SymbolDatabase::initBaseInfo(Scope *scope, const Token *tok)
} }
// save pattern for base class name // save pattern for base class name
scope->derivedFrom.push_back(base); derivedFrom.push_back(base);
} }
tok2 = tok2->next(); tok2 = tok2->next();
} }

View File

@ -493,6 +493,8 @@ public:
type_, scope_)); type_, scope_));
} }
const Token *initBaseInfo(const Token *tok);
/** @brief initialize varlist */ /** @brief initialize varlist */
void getVariableList(); void getVariableList();
@ -588,7 +590,6 @@ private:
Function* addGlobalFunctionDecl(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart); Function* addGlobalFunctionDecl(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
Function* addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart); Function* addGlobalFunction(Scope*& scope, const Token*& tok, const Token *argStart, const Token* funcStart);
void addNewFunction(Scope **info, const Token **tok); void addNewFunction(Scope **info, const Token **tok);
const Token *initBaseInfo(Scope *info, const Token *tok);
bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart) const; bool isFunction(const Token *tok, const Scope* outerScope, const Token **funcStart, const Token **argStart) const;
/** class/struct types */ /** class/struct types */

View File

@ -5885,7 +5885,7 @@ bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2,
return true; return true;
} }
bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) const
{ {
const bool pointeralias(valueToken->isName() || Token::Match(valueToken, "& %var% [")); const bool pointeralias(valueToken->isName() || Token::Match(valueToken, "& %var% ["));
@ -7440,12 +7440,12 @@ const char *Tokenizer::getParameterName(const Token *ftok, unsigned int par)
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void Tokenizer::syntaxError(const Token *tok) void Tokenizer::syntaxError(const Token *tok) const
{ {
reportError(tok, Severity::error, "syntaxError", "syntax error"); reportError(tok, Severity::error, "syntaxError", "syntax error");
} }
void Tokenizer::syntaxError(const Token *tok, char c) void Tokenizer::syntaxError(const Token *tok, char c) const
{ {
reportError(tok, Severity::error, "syntaxError", reportError(tok, Severity::error, "syntaxError",
std::string("Invalid number of character (") + c + ") " + std::string("Invalid number of character (") + c + ") " +
@ -8722,7 +8722,7 @@ void Tokenizer::removeUnnecessaryQualification()
} }
} }
void Tokenizer::unnecessaryQualificationError(const Token *tok, const std::string &qualification) void Tokenizer::unnecessaryQualificationError(const Token *tok, const std::string &qualification) const
{ {
reportError(tok, Severity::portability, "unnecessaryQualification", reportError(tok, Severity::portability, "unnecessaryQualification",
"The extra qualification \'" + qualification + "\' is unnecessary and is considered an error by many compilers."); "The extra qualification \'" + qualification + "\' is unnecessary and is considered an error by many compilers.");

View File

@ -329,13 +329,13 @@ public:
* Utility function for simplifyKnownVariables. Get data about an * Utility function for simplifyKnownVariables. Get data about an
* assigned variable. * assigned variable.
*/ */
bool simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar); static bool simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, Token **_tok3, std::string &value, unsigned int &valueVarId, bool &valueIsPointer, bool floatvar);
/** /**
* utility function for simplifyKnownVariables. Perform simplification * utility function for simplifyKnownVariables. Perform simplification
* of a given variable * of a given variable
*/ */
bool simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel); bool simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsigned int varid, const std::string &structname, std::string &value, unsigned int valueVarId, bool valueIsPointer, const Token * const valueToken, int indentlevel) const;
/** Replace a "goto" with the statements */ /** Replace a "goto" with the statements */
void simplifyGoto(); void simplifyGoto();
@ -465,7 +465,7 @@ public:
* @param source The string to be modified, e.g. "\x61" * @param source The string to be modified, e.g. "\x61"
* @return Modified string, e.g. "a" * @return Modified string, e.g. "a"
*/ */
std::string simplifyString(const std::string &source); static std::string simplifyString(const std::string &source);
/** /**
* Use "<" comparison instead of ">" * Use "<" comparison instead of ">"
@ -536,10 +536,10 @@ public:
void createLinks2(); void createLinks2();
/** Syntax error */ /** Syntax error */
void syntaxError(const Token *tok); void syntaxError(const Token *tok) const;
/** Syntax error. Example: invalid number of ')' */ /** Syntax error. Example: invalid number of ')' */
void syntaxError(const Token *tok, char c); void syntaxError(const Token *tok, char c) const;
/** /**
* assert that tokens are ok - used during debugging for example * assert that tokens are ok - used during debugging for example
@ -591,7 +591,7 @@ public:
/** /**
* unnecessary member qualification error * unnecessary member qualification error
*/ */
void unnecessaryQualificationError(const Token *tok, const std::string &qualification); void unnecessaryQualificationError(const Token *tok, const std::string &qualification) const;
/** /**
* Remove Microsoft MFC 'DECLARE_MESSAGE_MAP()' * Remove Microsoft MFC 'DECLARE_MESSAGE_MAP()'

View File

@ -373,7 +373,7 @@ private:
ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "%oror%|&&")); ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "%oror%|&&"));
} }
void append_vector(std::vector<std::string> &dest, const std::vector<std::string> &src) { void append_vector(std::vector<std::string> &dest, const std::vector<std::string> &src) const {
dest.insert(dest.end(), src.begin(), src.end()); dest.insert(dest.end(), src.begin(), src.end());
} }