ExecutionPath: Refactoring the interface

This commit is contained in:
Daniel Marjamäki 2009-12-25 20:12:06 +01:00
parent b5291825ce
commit 7bf0622ae0
4 changed files with 54 additions and 69 deletions

View File

@ -2653,9 +2653,8 @@ private:
return &tok;
}
public:
/** going out of scope - all execution paths end */
static void end(const std::list<ExecutionPath *> &checks, const Token *tok)
void end(const std::list<ExecutionPath *> &checks, const Token *tok) const
{
bool foundError = false;
ret(checks, tok, foundError);
@ -2665,34 +2664,8 @@ public:
void CheckMemoryLeakInFunction::localleaks()
{
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (tok->str() != ")")
continue;
// Start of implementation..
if (Token::Match(tok, ") const| {"))
{
// goto the "{"
tok = tok->next();
if (tok->str() == "const")
tok = tok->next();
// Check this scope..
std::list<ExecutionPath *> checks;
checks.push_back(new CheckLocalLeaks(this));
checkExecutionPaths(tok->next(), checks);
CheckLocalLeaks::end(checks, tok->link());
while (!checks.empty())
{
delete checks.back();
checks.pop_back();
}
// skip this scope - it has been checked
tok = tok->link();
}
}
// Check this scope..
CheckLocalLeaks c(this);
checkExecutionPaths(_tokenizer->tokens(), &c);
}

View File

@ -1630,42 +1630,16 @@ private:
void CheckOther::executionPaths()
{
// start of function: ") const| {"
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
// Check for null pointer errors..
{
if (tok->str() != ")")
continue;
if (!Token::Match(tok, ") const| {"))
continue;
while (tok->str() != "{")
tok = tok->next();
CheckNullpointer c(this);
checkExecutionPaths(_tokenizer->tokens(), &c);
}
// check for null pointer errors..
{
std::list<ExecutionPath *> checks;
checks.push_back(new CheckNullpointer(this));
checkExecutionPaths(tok->next(), checks);
while (!checks.empty())
{
delete checks.back();
checks.pop_back();
}
}
// check if variable is accessed uninitialized..
{
std::list<ExecutionPath *> checks;
checks.push_back(new CheckUninitVar(this));
checkExecutionPaths(tok->next(), checks);
while (!checks.empty())
{
delete checks.back();
checks.pop_back();
}
}
// skip function body..
tok = tok->link();
// check if variable is accessed uninitialized..
{
CheckUninitVar c(this);
checkExecutionPaths(_tokenizer->tokens(), &c);
}
}

View File

@ -48,7 +48,7 @@ bool ExecutionPath::parseCondition(const Token &tok, std::list<ExecutionPath *>
}
const Token *checkExecutionPaths(const Token *tok, std::list<ExecutionPath *> &checks)
static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &checks)
{
const std::auto_ptr<ExecutionPath> check(checks.front()->copy());
@ -118,7 +118,7 @@ const Token *checkExecutionPaths(const Token *tok, std::list<ExecutionPath *> &c
std::list<ExecutionPath *>::iterator it;
for (it = checks.begin(); it != checks.end(); ++it)
c.push_back((*it)->copy());
const Token *tokerr = checkExecutionPaths(tok->next(), c);
const Token *tokerr = checkExecutionPaths_(tok->next(), c);
if (tokerr)
return tokerr;
while (!c.empty())
@ -141,7 +141,7 @@ const Token *checkExecutionPaths(const Token *tok, std::list<ExecutionPath *> &c
continue;
// there is no "if"..
const Token *tokerr = checkExecutionPaths(tok->next(), checks);
const Token *tokerr = checkExecutionPaths_(tok->next(), checks);
if (tokerr)
return tokerr;
@ -187,3 +187,37 @@ const Token *checkExecutionPaths(const Token *tok, std::list<ExecutionPath *> &c
return 0;
}
void checkExecutionPaths(const Token *tok, ExecutionPath *c)
{
for (; tok; tok = tok->next())
{
if (tok->str() != ")")
continue;
// Start of implementation..
if (Token::Match(tok, ") const| {"))
{
// goto the "{"
tok = tok->next();
if (tok->str() == "const")
tok = tok->next();
std::list<ExecutionPath *> checks;
checks.push_back(c->copy());
checkExecutionPaths_(tok, checks);
c->end(checks, tok->link());
while (!checks.empty())
{
delete checks.back();
checks.pop_back();
}
// skip this scope - it has been checked
tok = tok->link();
}
}
}

View File

@ -93,10 +93,14 @@ public:
* @return true => bail out all checking
**/
virtual bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks) const;
/** going out of scope - all execution paths end */
virtual void end(const std::list<ExecutionPath *> & /*checks*/, const Token * /*tok*/) const
{ }
};
const Token *checkExecutionPaths(const Token *tok, std::list<ExecutionPath *> &checks);
void checkExecutionPaths(const Token *tok, ExecutionPath *c);
#endif