Use temp variables, better variable names
This commit is contained in:
parent
d3c629cce9
commit
074639548b
|
@ -2811,17 +2811,19 @@ void Tokenizer::setVarId()
|
||||||
}
|
}
|
||||||
|
|
||||||
// class members..
|
// class members..
|
||||||
std::map<std::string, std::map<std::string, unsigned int> > varlist;
|
std::map<std::string, std::map<std::string, unsigned int> > varsByClass;
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "namespace|class|struct %name% {|:")) {
|
if (Token::Match(tok, "namespace|class|struct %name% {|:")) {
|
||||||
const std::string &classname(tok->next()->str());
|
const std::string &classname(tok->next()->str());
|
||||||
const bool namesp = tok->str() == "namespace";
|
std::map<std::string, unsigned int>& thisClassVars = varsByClass[classname];
|
||||||
const Token* tokStart = tok->tokAt(2);
|
const Token* tokStart = tok->tokAt(2);
|
||||||
while (tokStart && tokStart->str() != "{") {
|
while (tokStart && tokStart->str() != "{") {
|
||||||
if (Token::Match(tokStart, "public|private|protected %name%"))
|
if (Token::Match(tokStart, "public|private|protected %name%"))
|
||||||
tokStart = tokStart->next();
|
tokStart = tokStart->next();
|
||||||
if (tokStart->strAt(1) == "," || tokStart->strAt(1) == "{")
|
if (tokStart->strAt(1) == "," || tokStart->strAt(1) == "{") {
|
||||||
varlist[classname].insert(varlist[tokStart->str()].begin(), varlist[tokStart->str()].end());
|
const std::map<std::string, unsigned int>& baseClassVars = varsByClass[tokStart->str()];
|
||||||
|
thisClassVars.insert(baseClassVars.begin(), baseClassVars.end());
|
||||||
|
}
|
||||||
tokStart = tokStart->next();
|
tokStart = tokStart->next();
|
||||||
}
|
}
|
||||||
// What member variables are there in this class?
|
// What member variables are there in this class?
|
||||||
|
@ -2831,7 +2833,7 @@ void Tokenizer::setVarId()
|
||||||
if (tok2->link()) {
|
if (tok2->link()) {
|
||||||
if (tok2->str() == "{") {
|
if (tok2->str() == "{") {
|
||||||
if (tok2->strAt(-1) == ")" || tok2->strAt(-2) == ")")
|
if (tok2->strAt(-1) == ")" || tok2->strAt(-2) == ")")
|
||||||
setVarIdClassFunction(classname, tok2, tok2->link(), varlist[classname], &structMembers, &_varId);
|
setVarIdClassFunction(classname, tok2, tok2->link(), thisClassVars, &structMembers, &_varId);
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
} else if (tok2->str() == "(" && tok2->link()->strAt(1) != "(")
|
} else if (tok2->str() == "(" && tok2->link()->strAt(1) != "(")
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
|
@ -2839,12 +2841,12 @@ void Tokenizer::setVarId()
|
||||||
|
|
||||||
// Found a member variable..
|
// Found a member variable..
|
||||||
else if (tok2->varId() > 0)
|
else if (tok2->varId() > 0)
|
||||||
varlist[classname][tok2->str()] = tok2->varId();
|
thisClassVars[tok2->str()] = tok2->varId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are there any member variables in this class?
|
// Are there any member variables in this class?
|
||||||
if (varlist[classname].empty())
|
if (thisClassVars.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Member variables
|
// Member variables
|
||||||
|
@ -2854,10 +2856,10 @@ void Tokenizer::setVarId()
|
||||||
|
|
||||||
Token *tok2 = *func;
|
Token *tok2 = *func;
|
||||||
tok2 = tok2->tokAt(2);
|
tok2 = tok2->tokAt(2);
|
||||||
tok2->varId(varlist[classname][tok2->str()]);
|
tok2->varId(thisClassVars[tok2->str()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (namesp || isC())
|
if (isC() || tok->str() == "namespace")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Set variable ids in member functions for this class..
|
// Set variable ids in member functions for this class..
|
||||||
|
@ -2875,7 +2877,7 @@ void Tokenizer::setVarId()
|
||||||
// If this is a function implementation.. add it to funclist
|
// If this is a function implementation.. add it to funclist
|
||||||
Token * start = startOfFunction(tok2);
|
Token * start = startOfFunction(tok2);
|
||||||
if (start) {
|
if (start) {
|
||||||
setVarIdClassFunction(classname, start, start->link(), varlist[classname], &structMembers, &_varId);
|
setVarIdClassFunction(classname, start, start->link(), thisClassVars, &structMembers, &_varId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor with initializer list
|
// constructor with initializer list
|
||||||
|
@ -2883,12 +2885,13 @@ void Tokenizer::setVarId()
|
||||||
Token *tok3 = tok2;
|
Token *tok3 = tok2;
|
||||||
do {
|
do {
|
||||||
Token *vartok = tok3->tokAt(2);
|
Token *vartok = tok3->tokAt(2);
|
||||||
if (varlist[classname].find(vartok->str()) != varlist[classname].end())
|
std::map<std::string, unsigned int>::const_iterator varpos = thisClassVars.find(vartok->str());
|
||||||
vartok->varId(varlist[classname][vartok->str()]);
|
if (varpos != thisClassVars.end())
|
||||||
tok3 = tok3->linkAt(3);
|
vartok->varId(varpos->second);
|
||||||
|
tok3 = vartok->linkAt(1);
|
||||||
} while (Token::Match(tok3, ")|} [:,] %name% (|{"));
|
} while (Token::Match(tok3, ")|} [:,] %name% (|{"));
|
||||||
if (Token::Match(tok3, ")|} {")) {
|
if (Token::Match(tok3, ")|} {")) {
|
||||||
setVarIdClassFunction(classname, tok2, tok3->next()->link(), varlist[classname], &structMembers, &_varId);
|
setVarIdClassFunction(classname, tok2, tok3->next()->link(), thisClassVars, &structMembers, &_varId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue