Made some functions static or const according to cppcheck results
This commit is contained in:
parent
ea601ef2b0
commit
4bb2a1b27b
|
@ -160,7 +160,7 @@ private:
|
|||
|
||||
// operatorEqToSelf helper functions
|
||||
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
|
||||
bool isMemberVar(const Scope *scope, const Token *tok);
|
||||
|
@ -180,7 +180,7 @@ private:
|
|||
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
|
||||
|
@ -188,7 +188,7 @@ private:
|
|||
* @param scope pointer to variable Scope
|
||||
* @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
|
||||
|
@ -196,7 +196,7 @@ private:
|
|||
* @param scope pointer to variable Scope
|
||||
* @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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
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");
|
||||
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"
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
* @param tok token where resource is leaked
|
||||
* @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
|
||||
|
@ -287,7 +287,7 @@ public:
|
|||
* Simplify code e.g. by replacing empty "{ }" with ";"
|
||||
* @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);
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
// only create base list for classes and structures
|
||||
if (new_scope->isClassOrStruct()) {
|
||||
// goto initial '{'
|
||||
tok2 = initBaseInfo(new_scope, tok);
|
||||
tok2 = new_scope->initBaseInfo(tok);
|
||||
|
||||
// make sure we have valid code
|
||||
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 '{'
|
||||
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
|
||||
scope->derivedFrom.push_back(base);
|
||||
derivedFrom.push_back(base);
|
||||
}
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
|
|
|
@ -493,6 +493,8 @@ public:
|
|||
type_, scope_));
|
||||
}
|
||||
|
||||
const Token *initBaseInfo(const Token *tok);
|
||||
|
||||
/** @brief initialize varlist */
|
||||
void getVariableList();
|
||||
|
||||
|
@ -588,7 +590,6 @@ private:
|
|||
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);
|
||||
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;
|
||||
|
||||
/** class/struct types */
|
||||
|
|
|
@ -5885,7 +5885,7 @@ bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2,
|
|||
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% ["));
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
void Tokenizer::syntaxError(const Token *tok, char c)
|
||||
void Tokenizer::syntaxError(const Token *tok, char c) const
|
||||
{
|
||||
reportError(tok, Severity::error, "syntaxError",
|
||||
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",
|
||||
"The extra qualification \'" + qualification + "\' is unnecessary and is considered an error by many compilers.");
|
||||
|
|
|
@ -329,13 +329,13 @@ public:
|
|||
* Utility function for simplifyKnownVariables. Get data about an
|
||||
* 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
|
||||
* 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 */
|
||||
void simplifyGoto();
|
||||
|
@ -465,7 +465,7 @@ public:
|
|||
* @param source The string to be modified, e.g. "\x61"
|
||||
* @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 ">"
|
||||
|
@ -536,10 +536,10 @@ public:
|
|||
void createLinks2();
|
||||
|
||||
/** Syntax error */
|
||||
void syntaxError(const Token *tok);
|
||||
void syntaxError(const Token *tok) const;
|
||||
|
||||
/** 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
|
||||
|
@ -591,7 +591,7 @@ public:
|
|||
/**
|
||||
* 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()'
|
||||
|
|
|
@ -373,7 +373,7 @@ private:
|
|||
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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue