ExecutionPath: Refactoring. Removed the bailOut variable

This commit is contained in:
Daniel Marjamäki 2009-12-29 09:30:02 +01:00
parent cfdf2b8cfe
commit 4cbae159b2
3 changed files with 45 additions and 77 deletions

View File

@ -1330,12 +1330,9 @@ private:
std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it)
{
if (!(*it)->bailOut())
{
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
c->alloc = true;
}
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
c->alloc = true;
}
}
@ -1349,21 +1346,18 @@ private:
std::list<ExecutionPath *>::iterator it = checks.begin();
while (it != checks.end())
{
if (!(*it)->bailOut())
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
{
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
if (c->alloc)
{
if (c->alloc)
{
delete c;
checks.erase(it++);
continue;
}
else
{
use_pointer(foundError, checks, tok);
}
delete c;
checks.erase(it++);
continue;
}
else
{
use_pointer(foundError, checks, tok);
}
}
@ -1381,23 +1375,20 @@ private:
std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it)
{
if (!(*it)->bailOut())
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
{
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
if (!c->alloc)
{
if (!c->alloc)
CheckOther *checkOther = dynamic_cast<CheckOther *>(c->owner);
if (checkOther)
{
CheckOther *checkOther = dynamic_cast<CheckOther *>(c->owner);
if (checkOther)
{
foundError = true;
checkOther->uninitvarError(tok, c->varname);
break;
}
foundError = true;
checkOther->uninitvarError(tok, c->varname);
break;
}
c->alloc = false;
}
c->alloc = false;
}
}
}
@ -1418,33 +1409,30 @@ private:
std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++it)
{
if (!(*it)->bailOut())
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
{
CheckUninitVar *c = dynamic_cast<CheckUninitVar *>(*it);
if (c && c->varId == varid)
// mode 0 : the variable is used "directly"
// example: .. = var;
// it is ok to read the address of an uninitialized array.
// it is ok to read the address of an allocated pointer
if (mode == 0 && (c->array || (c->pointer && c->alloc)))
continue;
// mode 2 : bad usage of pointer. if it's not a pointer then the usage is ok.
// example: ptr->foo();
if (mode == 2 && !c->pointer)
continue;
CheckOther *checkOther = dynamic_cast<CheckOther *>(c->owner);
if (checkOther)
{
// mode 0 : the variable is used "directly"
// example: .. = var;
// it is ok to read the address of an uninitialized array.
// it is ok to read the address of an allocated pointer
if (mode == 0 && (c->array || (c->pointer && c->alloc)))
continue;
// mode 2 : bad usage of pointer. if it's not a pointer then the usage is ok.
// example: ptr->foo();
if (mode == 2 && !c->pointer)
continue;
CheckOther *checkOther = dynamic_cast<CheckOther *>(c->owner);
if (checkOther)
{
if (c->pointer && c->alloc)
checkOther->uninitdataError(tok, c->varname);
else
checkOther->uninitvarError(tok, c->varname);
foundError = true;
break;
}
if (c->pointer && c->alloc)
checkOther->uninitdataError(tok, c->varname);
else
checkOther->uninitvarError(tok, c->varname);
foundError = true;
break;
}
}
}

View File

@ -175,19 +175,6 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
{
bool foundError = false;
tok = check->parse(*tok, foundError, checks);
std::list<ExecutionPath *>::iterator it;
for (it = checks.begin(); it != checks.end();)
{
if ((*it)->bailOut())
{
delete *it;
it = checks.erase(it);
}
else
{
++it;
}
}
if (checks.empty())
return 0;
else if (foundError)

View File

@ -31,8 +31,6 @@ class Check;
class ExecutionPath
{
private:
bool bailout_;
/** No implementation */
void operator=(const ExecutionPath &);
@ -41,7 +39,7 @@ protected:
Check * const owner;
public:
ExecutionPath(Check *c, unsigned int id) : bailout_(false), varId(id), owner(c), ifinfo(0)
ExecutionPath(Check *c, unsigned int id) : varId(id), owner(c), ifinfo(0)
{ }
virtual ~ExecutionPath()
@ -53,11 +51,6 @@ public:
/** Some kind of if-information */
unsigned int ifinfo;
bool bailOut() const
{
return bailout_;
}
/**
* bail out all execution paths
* @param checks the execution paths to bail out on