CheckAutoVariables: change type of vd_list member to std::set.
Change type of vda_list from std::list to std::set. It allows to us use find() method instead of self-written loop which may be slow. No functional change.
This commit is contained in:
parent
ec81080d0b
commit
053e6f8b9a
|
@ -62,30 +62,12 @@ bool CheckAutoVariables::errorAv(const Token* left, const Token* right)
|
||||||
if (it_fp == fp_list.end())
|
if (it_fp == fp_list.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::list<unsigned int>::const_iterator id_vd;
|
return isAutoVar(right->varId());
|
||||||
for (id_vd = vd_list.begin(); id_vd != vd_list.end(); ++id_vd)
|
|
||||||
{
|
|
||||||
//The left argument is a variable declaration
|
|
||||||
if (*id_vd == right->varId())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//The left argument is NOT a variable declaration
|
|
||||||
if (id_vd == vd_list.end())
|
|
||||||
return false;
|
|
||||||
//If I reach this point there is a wrong assignement of an auto-variable to an effective parameter of a function
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckAutoVariables::isAutoVar(unsigned int varId)
|
bool CheckAutoVariables::isAutoVar(unsigned int varId)
|
||||||
{
|
{
|
||||||
std::list<unsigned int>::iterator id_vd;
|
return (vd_list.find(varId) != vd_list.end());
|
||||||
for (id_vd = vd_list.begin(); id_vd != vd_list.end(); ++id_vd)
|
|
||||||
{
|
|
||||||
if (*id_vd == varId)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckAutoVariables::isAutoVarArray(unsigned int varId)
|
bool CheckAutoVariables::isAutoVarArray(unsigned int varId)
|
||||||
|
@ -131,10 +113,9 @@ bool isExternOrStatic(const Token *tok)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckAutoVariables::addVD(const Token* tok)
|
void CheckAutoVariables::addVD(unsigned int varId)
|
||||||
{
|
{
|
||||||
//std::cout << "VD " << tok->linenr() << " " << tok->str() << std::endl;
|
vd_list.insert(varId);
|
||||||
vd_list.push_back(tok->varId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckAutoVariables::addVDA(unsigned int varId)
|
void CheckAutoVariables::addVDA(unsigned int varId)
|
||||||
|
@ -182,7 +163,7 @@ void CheckAutoVariables::autoVariables()
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "%type% :: %any%") && !isExternOrStatic(tok)) //Inside a function
|
else if (bindent > 0 && Token::Match(tok, "%type% :: %any%") && !isExternOrStatic(tok)) //Inside a function
|
||||||
{
|
{
|
||||||
addVD(tok->tokAt(2));
|
addVD(tok->tokAt(2)->varId());
|
||||||
}
|
}
|
||||||
// Inside a function body
|
// Inside a function body
|
||||||
else if (bindent > 0 && Token::Match(tok, "%type% %var% ["))
|
else if (bindent > 0 && Token::Match(tok, "%type% %var% ["))
|
||||||
|
@ -193,13 +174,13 @@ void CheckAutoVariables::autoVariables()
|
||||||
{
|
{
|
||||||
if (!isTypeName(tok))
|
if (!isTypeName(tok))
|
||||||
continue;
|
continue;
|
||||||
addVD(tok->tokAt(1));
|
addVD(tok->next()->varId());
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "const %var% %var% ;") && !isExternOrStatic(tok)) //Inside a function
|
else if (bindent > 0 && Token::Match(tok, "const %var% %var% ;") && !isExternOrStatic(tok)) //Inside a function
|
||||||
{
|
{
|
||||||
if (!isTypeName(tok->tokAt(1)))
|
if (!isTypeName(tok->tokAt(1)))
|
||||||
continue;
|
continue;
|
||||||
addVD(tok->tokAt(2));
|
addVD(tok->tokAt(2)->varId());
|
||||||
}
|
}
|
||||||
else if (bindent > 0 && Token::Match(tok, "[;{}] %var% = & %var%")) //Critical assignement
|
else if (bindent > 0 && Token::Match(tok, "[;{}] %var% = & %var%")) //Critical assignement
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,12 +58,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<std::string> fp_list;
|
std::list<std::string> fp_list;
|
||||||
std::list<unsigned int> vd_list;
|
std::set<unsigned int> vd_list;
|
||||||
std::set<unsigned int> vda_list;
|
std::set<unsigned int> vda_list;
|
||||||
bool errorAv(const Token* left, const Token* right);
|
bool errorAv(const Token* left, const Token* right);
|
||||||
bool isAutoVar(unsigned int varId);
|
bool isAutoVar(unsigned int varId);
|
||||||
bool isAutoVarArray(unsigned int varId);
|
bool isAutoVarArray(unsigned int varId);
|
||||||
void addVD(const Token* t);
|
void addVD(unsigned int varId);
|
||||||
void addVDA(unsigned int varId);
|
void addVDA(unsigned int varId);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue