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; std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++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); c->alloc = true;
if (c && c->varId == varid)
c->alloc = true;
}
} }
} }
@ -1349,21 +1346,18 @@ private:
std::list<ExecutionPath *>::iterator it = checks.begin(); std::list<ExecutionPath *>::iterator it = checks.begin();
while (it != checks.end()) 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->alloc)
if (c && c->varId == varid)
{ {
if (c->alloc) delete c;
{ checks.erase(it++);
delete c; continue;
checks.erase(it++); }
continue; else
} {
else use_pointer(foundError, checks, tok);
{
use_pointer(foundError, checks, tok);
}
} }
} }
@ -1381,23 +1375,20 @@ private:
std::list<ExecutionPath *>::const_iterator it; std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++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->alloc)
if (c && c->varId == varid)
{ {
if (!c->alloc) CheckOther *checkOther = dynamic_cast<CheckOther *>(c->owner);
if (checkOther)
{ {
CheckOther *checkOther = dynamic_cast<CheckOther *>(c->owner); foundError = true;
if (checkOther) 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; std::list<ExecutionPath *>::const_iterator it;
for (it = checks.begin(); it != checks.end(); ++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); // mode 0 : the variable is used "directly"
if (c && c->varId == varid) // 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" if (c->pointer && c->alloc)
// example: .. = var; checkOther->uninitdataError(tok, c->varname);
// it is ok to read the address of an uninitialized array. else
// it is ok to read the address of an allocated pointer checkOther->uninitvarError(tok, c->varname);
if (mode == 0 && (c->array || (c->pointer && c->alloc))) foundError = true;
continue; break;
// 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;
}
} }
} }
} }

View File

@ -175,19 +175,6 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
{ {
bool foundError = false; bool foundError = false;
tok = check->parse(*tok, foundError, checks); 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()) if (checks.empty())
return 0; return 0;
else if (foundError) else if (foundError)

View File

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