Revert "Partially reverted 5cd36d6f8a for upcoming release."

This reverts commit 5f8a8aba6d.
This commit is contained in:
PKEuS 2015-11-15 10:04:27 +01:00
parent 958f2ac091
commit 41fbc5355d
2 changed files with 19 additions and 19 deletions

View File

@ -413,26 +413,26 @@ bool CheckClass::canNotMove(const Scope *scope)
return constructor && !(publicAssign || publicCopy || publicMove);
}
void CheckClass::assignVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage)
void CheckClass::assignVar(unsigned int varid, const Scope *scope, std::vector<Usage> &usage)
{
std::list<Variable>::const_iterator var;
unsigned int count = 0;
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var, ++count) {
if (var->name() == varname) {
if (var->declarationId() == varid) {
usage[count].assign = true;
return;
}
}
}
void CheckClass::initVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage)
void CheckClass::initVar(unsigned int varid, const Scope *scope, std::vector<Usage> &usage)
{
std::list<Variable>::const_iterator var;
unsigned int count = 0;
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var, ++count) {
if (var->name() == varname) {
if (var->declarationId() == varid) {
usage[count].init = true;
return;
}
@ -491,7 +491,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
if (initList) {
if (level == 0 && Token::Match(ftok, "%name% {|(") && Token::Match(ftok->linkAt(1), "}|) ,|{")) {
if (ftok->str() != func.name()) {
initVar(ftok->str(), scope, usage);
initVar(ftok->varId(), scope, usage);
} else { // c++11 delegate constructor
const Function *member = ftok->function();
// member function found
@ -519,7 +519,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
}
}
} else if (level != 0 && Token::Match(ftok, "%name% =")) // assignment in the initializer: var(value = x)
assignVar(ftok->str(), scope, usage);
assignVar(ftok->varId(), scope, usage);
// Level handling
if (ftok->link() && Token::Match(ftok, "(|<"))
@ -539,7 +539,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
// Variable getting value from stream?
if (Token::Match(ftok, ">> %name%")) {
assignVar(ftok->strAt(1), scope, usage);
assignVar(ftok->next()->varId(), scope, usage);
}
// Before a new statement there is "[{};()=[]"
@ -567,7 +567,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
if (var->declarationId() == ftok->next()->varId()) {
/** @todo false negative: we assume function changes variable state */
assignVar(ftok->next()->str(), scope, usage);
assignVar(ftok->next()->varId(), scope, usage);
break;
}
}
@ -613,7 +613,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
else if (Token::Match(ftok, "::| memset ( %name% ,")) {
if (ftok->str() == "::")
ftok = ftok->next();
assignVar(ftok->strAt(2), scope, usage);
assignVar(ftok->tokAt(2)->varId(), scope, usage);
ftok = ftok->linkAt(1);
continue;
}
@ -688,7 +688,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
tok2 = tok2->next();
if (tok2->str() == "&")
tok2 = tok2->next();
assignVar(tok2->str(), scope, usage);
assignVar(tok2->varId(), scope, usage);
}
}
}
@ -718,7 +718,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
else {
for (const Token *tok = ftok->tokAt(2); tok && tok != ftok->next()->link(); tok = tok->next()) {
if (tok->isName()) {
assignVar(tok->str(), scope, usage);
assignVar(tok->varId(), scope, usage);
}
}
}
@ -727,7 +727,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
// Assignment of member variable?
else if (Token::Match(ftok, "%name% =")) {
assignVar(ftok->str(), scope, usage);
assignVar(ftok->varId(), scope, usage);
bool bailout = ftok->variable() && ftok->variable()->isReference();
const Token* tok2 = ftok->tokAt(2);
if (tok2->str() == "&") {
@ -735,7 +735,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
bailout = true;
}
if (tok2->variable() && (bailout || tok2->variable()->isArray()) && tok2->strAt(1) != "[")
assignVar(tok2->str(), scope, usage);
assignVar(tok2->varId(), scope, usage);
}
// Assignment of array item of member variable?
@ -750,19 +750,19 @@ void CheckClass::initializeVarList(const Function &func, std::list<const Functio
break;
}
if (tok2 && tok2->strAt(1) == "=")
assignVar(ftok->str(), scope, usage);
assignVar(ftok->varId(), scope, usage);
}
// Assignment of array item of member variable?
else if (Token::Match(ftok, "* %name% =")) {
assignVar(ftok->next()->str(), scope, usage);
assignVar(ftok->next()->varId(), scope, usage);
} else if (Token::Match(ftok, "* this . %name% =")) {
assignVar(ftok->strAt(3), scope, usage);
assignVar(ftok->tokAt(3)->varId(), scope, usage);
}
// The functions 'clear' and 'Clear' are supposed to initialize variable.
if (Token::Match(ftok, "%name% . clear|Clear (")) {
assignVar(ftok->str(), scope, usage);
assignVar(ftok->varId(), scope, usage);
}
}
}

View File

@ -258,7 +258,7 @@ private:
* @param scope pointer to variable Scope
* @param usage reference to usage vector
*/
static void assignVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage);
static void assignVar(unsigned int varid, const Scope *scope, std::vector<Usage> &usage);
/**
* @brief initialize a variable in the varlist
@ -266,7 +266,7 @@ private:
* @param scope pointer to variable Scope
* @param usage reference to usage vector
*/
static void initVar(const std::string &varname, const Scope *scope, std::vector<Usage> &usage);
static void initVar(unsigned int varid, const Scope *scope, std::vector<Usage> &usage);
/**
* @brief set all variables in list assigned