Removed unnecessary variable Function::start - The value is already stored in Function::functionScope->classStart.
This commit is contained in:
parent
26f5f08614
commit
dc64ac2918
|
@ -1401,9 +1401,9 @@ void CheckBufferOverrun::checkStructVariable()
|
|||
// check for member variables
|
||||
if (func_scope->functionOf == &*scope) {
|
||||
// only check non-empty function
|
||||
if (func_scope->function->start->next() != func_scope->function->start->link()) {
|
||||
if (func_scope->classStart->next() != func_scope->classEnd) {
|
||||
// start checking after the {
|
||||
const Token *tok = func_scope->function->start->next();
|
||||
const Token *tok = func_scope->classStart->next();
|
||||
checkScope(tok, arrayInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ void CheckClass::constructors()
|
|||
|
||||
// It's non-static and it's not initialized => error
|
||||
if (func->type == Function::eOperatorEqual) {
|
||||
const Token *operStart = func->token->next();
|
||||
const Token *operStart = func->arg;
|
||||
|
||||
bool classNameUsed = false;
|
||||
for (const Token *operTok = operStart; operTok != operStart->link(); operTok = operTok->next()) {
|
||||
|
@ -236,9 +236,9 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope)
|
|||
void CheckClass::initializeVarList(const Function &func, std::list<std::string> &callstack, const Scope *scope, std::vector<Usage> &usage)
|
||||
{
|
||||
bool initList = true;
|
||||
const Token *ftok = func.token->linkAt(1);
|
||||
const Token *ftok = func.arg->link();
|
||||
|
||||
for (; ftok != func.start->link(); ftok = ftok->next()) {
|
||||
for (; ftok != func.functionScope->classEnd; ftok = ftok->next()) {
|
||||
if (!ftok->next())
|
||||
break;
|
||||
|
||||
|
@ -555,8 +555,8 @@ static bool checkFunctionUsage(const std::string& name, const Scope* scope)
|
|||
return true; // Assume its used, if scope is not seen
|
||||
|
||||
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
||||
if (func->start) {
|
||||
for (const Token *ftok = func->start; ftok != func->start->link(); ftok = ftok->next()) {
|
||||
if (func->functionScope) {
|
||||
for (const Token *ftok = func->functionScope->classStart; ftok != func->functionScope->classEnd; ftok = ftok->next()) {
|
||||
if (ftok->str() == name && ftok->next()->str() == "(") // Function called. TODO: Handle overloads
|
||||
return true;
|
||||
}
|
||||
|
@ -815,7 +815,7 @@ void CheckClass::operatorEqRetRefThis()
|
|||
if (Token::Match(func->tokenDef->tokAt(-3), ";|}|{|public:|protected:|private:|virtual %type% &") &&
|
||||
func->tokenDef->strAt(-2) == scope->className) {
|
||||
|
||||
checkReturnPtrThis(&(*scope), &(*func), func->start->next(), func->start->link());
|
||||
checkReturnPtrThis(&(*scope), &(*func), func->functionScope->classStart, func->functionScope->classEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -948,8 +948,8 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope)
|
|||
// - alloc member
|
||||
// That is not ideal because it can cause false negatives but its currently
|
||||
// necessary to prevent false positives.
|
||||
const Token *last = func->start->link();
|
||||
for (const Token *tok = func->start; tok && (tok != last); tok = tok->next()) {
|
||||
const Token *last = func->functionScope->classEnd;
|
||||
for (const Token *tok = func->functionScope->classStart; tok && (tok != last); tok = tok->next()) {
|
||||
if (Token::Match(tok, "%var% = malloc|realloc|calloc|new") && isMemberVar(scope, tok))
|
||||
return true;
|
||||
|
||||
|
@ -977,8 +977,8 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope)
|
|||
|
||||
bool CheckClass::hasAssignSelf(const Function *func, const Token *rhs)
|
||||
{
|
||||
const Token *last = func->start->link();
|
||||
for (const Token *tok = func->start; tok && tok != last; tok = tok->next()) {
|
||||
const Token *last = func->functionScope->classEnd;
|
||||
for (const Token *tok = func->functionScope->classStart; tok && tok != last; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, "if (")) {
|
||||
const Token *tok1 = tok->tokAt(2);
|
||||
const Token *tok2 = tok->next()->link();
|
||||
|
@ -1427,7 +1427,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func)
|
|||
{
|
||||
// if the function doesn't have any assignment nor function call,
|
||||
// it can be a const function..
|
||||
for (const Token *tok1 = func->start; tok1 && tok1 != func->start->link(); tok1 = tok1->next()) {
|
||||
for (const Token *tok1 = func->functionScope->classStart; tok1 && tok1 != func->functionScope->classEnd; tok1 = tok1->next()) {
|
||||
// assignment.. = += |= ..
|
||||
if (tok1->isAssignmentOp()) {
|
||||
if (tok1->next()->str() == "this") {
|
||||
|
|
|
@ -39,9 +39,9 @@ void CheckExceptionSafety::destructors()
|
|||
for (std::list<Scope>::const_iterator i = symbolDatabase->scopeList.begin(); i != symbolDatabase->scopeList.end(); ++i) {
|
||||
for (std::list<Function>::const_iterator j = i->functionList.begin(); j != i->functionList.end(); ++j) {
|
||||
// only looking for destructors
|
||||
if (j->type == Function::eDestructor && j->start) {
|
||||
if (j->type == Function::eDestructor && j->functionScope) {
|
||||
// Inspect this destructor..
|
||||
for (const Token *tok = j->start->next(); tok != j->start->link(); tok = tok->next()) {
|
||||
for (const Token *tok = j->functionScope->classStart->next(); tok != j->functionScope->classEnd; tok = tok->next()) {
|
||||
// throw found within a destructor
|
||||
if (tok->str() == "throw") {
|
||||
destructorsError(tok);
|
||||
|
|
|
@ -484,7 +484,7 @@ const char *CheckMemoryLeak::functionArgAlloc(const Function *func, unsigned int
|
|||
{
|
||||
allocType = No;
|
||||
|
||||
if (!func || !func->start)
|
||||
if (!func || !func->functionScope)
|
||||
return "";
|
||||
|
||||
std::list<Variable>::const_iterator arg = func->argumentList.begin();
|
||||
|
@ -507,7 +507,7 @@ const char *CheckMemoryLeak::functionArgAlloc(const Function *func, unsigned int
|
|||
|
||||
// Check if pointer is allocated.
|
||||
int realloc = 0;
|
||||
for (tok = func->start; tok && tok != func->start->link(); tok = tok->next()) {
|
||||
for (tok = func->functionScope->classStart; tok && tok != func->functionScope->classEnd; tok = tok->next()) {
|
||||
if (tok->varId() == arg->varId()) {
|
||||
if (Token::Match(tok->tokAt(-3), "free ( * %var% )")) {
|
||||
realloc = 1;
|
||||
|
@ -705,9 +705,9 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
|||
const Variable* param = function->getArgumentVar(par-1);
|
||||
if (!param || !param->nameToken())
|
||||
return "use";
|
||||
if (!function->start)
|
||||
if (!function->functionScope)
|
||||
return "use";
|
||||
Token *func = getcode(function->start->next(), callstack, param->varId(), alloctype, dealloctype, false, sz);
|
||||
Token *func = getcode(function->functionScope->classStart->next(), callstack, param->varId(), alloctype, dealloctype, false, sz);
|
||||
//simplifycode(func);
|
||||
const Token *func_ = func;
|
||||
while (func_ && func_->str() == ";")
|
||||
|
@ -2338,9 +2338,9 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
|
|||
const bool constructor = func->type == Function::eConstructor;
|
||||
const bool destructor = func->type == Function::eDestructor;
|
||||
bool body = false;
|
||||
const Token *end = func->start->link();
|
||||
for (const Token *tok = func->token->linkAt(1); tok != end; tok = tok->next()) {
|
||||
if (tok == func->start)
|
||||
const Token *end = func->functionScope->classEnd;
|
||||
for (const Token *tok = func->arg->link(); tok != end; tok = tok->next()) {
|
||||
if (tok == func->functionScope->classStart)
|
||||
body = true;
|
||||
else {
|
||||
if (!body) {
|
||||
|
|
|
@ -1101,7 +1101,7 @@ void CheckStl::string_c_str()
|
|||
else if (Token::Match(scope->function->tokenDef->tokAt(-3), "std :: string !!&"))
|
||||
returnType = stdString;
|
||||
|
||||
for (const Token *tok = scope->function->start; tok && tok != scope->function->start->link(); tok = tok->next()) {
|
||||
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
// Invalid usage..
|
||||
if (Token::Match(tok, "throw %var% . c_str ( ) ;") && isLocal(symbolDatabase, tok->next()->varId())) {
|
||||
string_c_strThrowError(tok);
|
||||
|
|
|
@ -326,9 +326,6 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
|||
if (!end)
|
||||
continue;
|
||||
|
||||
// save start of function
|
||||
function.start = end;
|
||||
|
||||
scope->functionList.push_back(function);
|
||||
|
||||
const Token *tok2 = funcStart;
|
||||
|
@ -940,13 +937,6 @@ Function* SymbolDatabase::addGlobalFunction(Scope*& scope, const Token*& tok, co
|
|||
function->token = funcStart;
|
||||
function->hasBody = true;
|
||||
|
||||
// find start of function '{'
|
||||
const Token *start = tok;
|
||||
while (start && start->str() != "{")
|
||||
start = start->next();
|
||||
// save start of function
|
||||
function->start = start;
|
||||
|
||||
addNewFunction(&scope, &tok);
|
||||
|
||||
if (scope) {
|
||||
|
@ -1059,29 +1049,15 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
|
|||
|
||||
for (func = scope1->functionList.begin(); func != scope1->functionList.end(); ++func) {
|
||||
if (!func->hasBody && func->tokenDef->str() == (*tok)->str()) {
|
||||
if (func->type == Function::eDestructor && destructor) {
|
||||
if (Function::argsMatch(scope1, func->tokenDef->next(), (*tok)->next(), path, path_length)) {
|
||||
if (Function::argsMatch(scope1, func->argDef, (*tok)->next(), path, path_length)) {
|
||||
if (func->type == Function::eDestructor && destructor) {
|
||||
func->hasBody = true;
|
||||
func->token = *tok;
|
||||
func->arg = argStart;
|
||||
const Token *start = argStart->link()->next();
|
||||
while (start && start->str() != "{")
|
||||
start = start->next();
|
||||
func->start = start;
|
||||
}
|
||||
} else if (func->type != Function::eDestructor && !destructor) {
|
||||
if (Function::argsMatch(scope1, func->tokenDef->next(), (*tok)->next(), path, path_length)) {
|
||||
} else if (func->type != Function::eDestructor && !destructor) {
|
||||
// normal function?
|
||||
if (!func->retFuncPtr && (*tok)->next()->link()) {
|
||||
if ((func->isConst && (*tok)->next()->link()->next()->str() == "const") ||
|
||||
(!func->isConst && (*tok)->next()->link()->next()->str() != "const")) {
|
||||
func->hasBody = true;
|
||||
func->token = *tok;
|
||||
func->arg = argStart;
|
||||
const Token *start = argStart->link()->next();
|
||||
while (start && start->str() != "{")
|
||||
start = start->next();
|
||||
func->start = start;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1089,24 +1065,20 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
|
|||
else if (func->retFuncPtr) {
|
||||
// todo check for const
|
||||
func->hasBody = true;
|
||||
func->token = *tok;
|
||||
func->arg = argStart;
|
||||
const Token *start = argStart->link()->linkAt(2)->next();
|
||||
while (start && start->str() != "{")
|
||||
start = start->next();
|
||||
func->start = start;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (func->hasBody) {
|
||||
addNewFunction(scope, tok);
|
||||
if (*scope) {
|
||||
(*scope)->functionOf = scope1;
|
||||
(*scope)->function = &*func;
|
||||
(*scope)->function->functionScope = *scope;
|
||||
if (func->hasBody) {
|
||||
func->token = *tok;
|
||||
func->arg = argStart;
|
||||
addNewFunction(scope, tok);
|
||||
if (*scope) {
|
||||
(*scope)->functionOf = scope1;
|
||||
(*scope)->function = &*func;
|
||||
(*scope)->function->functionScope = *scope;
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -366,7 +366,6 @@ public:
|
|||
argDef(NULL),
|
||||
token(NULL),
|
||||
arg(NULL),
|
||||
start(NULL),
|
||||
functionScope(NULL),
|
||||
type(eFunction),
|
||||
access(Public),
|
||||
|
@ -395,7 +394,6 @@ public:
|
|||
const Token *argDef; // function argument start '(' in class definition
|
||||
const Token *token; // function name token in implementation
|
||||
const Token *arg; // function argument start '('
|
||||
const Token *start; // function start '{'
|
||||
Scope *functionScope; // scope of function body
|
||||
std::list<Variable> argumentList; // argument list
|
||||
Type type; // constructor, destructor, ...
|
||||
|
|
|
@ -697,7 +697,7 @@ private:
|
|||
GET_SYMBOL_DB("void func();\n"
|
||||
"int bar() {}\n"
|
||||
"void func() {}")
|
||||
ASSERT_EQUALS(3, db->findScopeByName("func")->function->start->linenr());
|
||||
ASSERT_EQUALS(3, db->findScopeByName("func")->classStart->linenr());
|
||||
}
|
||||
|
||||
void hasGlobalVariables1() {
|
||||
|
|
Loading…
Reference in New Issue