Tokenizer::setVarIdNew: fixed TestTokenizer::varid_in_class2 test case
This commit is contained in:
parent
79af6f65d7
commit
71050bc586
|
@ -2901,6 +2901,41 @@ static void setVarIdClassDeclaration(Token * const startToken, const std::map<st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void setVarIdStructMembers(Token **tok1,
|
||||||
|
std::map<unsigned int, std::map<std::string,unsigned int> > *structMembers,
|
||||||
|
unsigned int *_varId)
|
||||||
|
{
|
||||||
|
Token *tok = *tok1;
|
||||||
|
while (Token::Match(tok->next(), ". %var% !!(")) {
|
||||||
|
const unsigned int struct_varid = tok->varId();
|
||||||
|
tok = tok->tokAt(2);
|
||||||
|
if (struct_varid == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::map<unsigned int, std::map<std::string,unsigned int> >::iterator structIterator;
|
||||||
|
structIterator = structMembers->find(struct_varid);
|
||||||
|
if (structIterator == structMembers->end()) {
|
||||||
|
std::map<std::string,unsigned int> members;
|
||||||
|
members[tok->str()] = ++ (*_varId);
|
||||||
|
(*structMembers)[struct_varid] = members;
|
||||||
|
tok->varId(*_varId);
|
||||||
|
} else {
|
||||||
|
std::map<std::string,unsigned int> &members = structIterator->second;
|
||||||
|
std::map<std::string,unsigned int>::const_iterator memberIterator;
|
||||||
|
memberIterator = members.find(tok->str());
|
||||||
|
if (memberIterator == members.end()) {
|
||||||
|
members[tok->str()] = ++(*_varId);
|
||||||
|
tok->varId(*_varId);
|
||||||
|
} else {
|
||||||
|
tok->varId(memberIterator->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tok)
|
||||||
|
*tok1 = tok;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Tokenizer::setVarIdNew()
|
void Tokenizer::setVarIdNew()
|
||||||
{
|
{
|
||||||
// Clear all variable ids
|
// Clear all variable ids
|
||||||
|
@ -3005,31 +3040,7 @@ void Tokenizer::setVarIdNew()
|
||||||
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
|
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
|
||||||
if (it != variableId.end()) {
|
if (it != variableId.end()) {
|
||||||
tok->varId(it->second);
|
tok->varId(it->second);
|
||||||
while (Token::Match(tok->next(), ". %var% !!(")) {
|
setVarIdStructMembers(&tok, &structMembers, &_varId);
|
||||||
const unsigned int struct_varid = it->second;
|
|
||||||
tok = tok->tokAt(2);
|
|
||||||
if (struct_varid == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
std::map<unsigned int, std::map<std::string,unsigned int> >::iterator structIterator;
|
|
||||||
structIterator = structMembers.find(struct_varid);
|
|
||||||
if (structIterator == structMembers.end()) {
|
|
||||||
std::map<std::string,unsigned int> members;
|
|
||||||
members[tok->str()] = ++_varId;
|
|
||||||
structMembers[struct_varid] = members;
|
|
||||||
tok->varId(_varId);
|
|
||||||
} else {
|
|
||||||
std::map<std::string,unsigned int> &members = structIterator->second;
|
|
||||||
std::map<std::string,unsigned int>::const_iterator memberIterator;
|
|
||||||
memberIterator = members.find(tok->str());
|
|
||||||
if (memberIterator == members.end()) {
|
|
||||||
members[tok->str()] = ++_varId;
|
|
||||||
tok->varId(_varId);
|
|
||||||
} else {
|
|
||||||
tok->varId(memberIterator->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, "::|. %var%")) {
|
} else if (Token::Match(tok, "::|. %var%")) {
|
||||||
// Don't set varid after a :: or . token
|
// Don't set varid after a :: or . token
|
||||||
|
@ -3037,6 +3048,10 @@ void Tokenizer::setVarIdNew()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the structMembers because it will be used when member functions
|
||||||
|
// are parsed. The old info is not bad, it is just redundant.
|
||||||
|
structMembers.clear();
|
||||||
|
|
||||||
// Member functions and variables in this source
|
// Member functions and variables in this source
|
||||||
std::list<Token *> allMemberFunctions;
|
std::list<Token *> allMemberFunctions;
|
||||||
std::list<Token *> allMemberVars;
|
std::list<Token *> allMemberVars;
|
||||||
|
@ -3119,6 +3134,7 @@ void Tokenizer::setVarIdNew()
|
||||||
tok2->strAt(-1) != "." &&
|
tok2->strAt(-1) != "." &&
|
||||||
varlist.find(tok2->str()) != varlist.end()) {
|
varlist.find(tok2->str()) != varlist.end()) {
|
||||||
tok2->varId(varlist[tok2->str()]);
|
tok2->varId(varlist[tok2->str()]);
|
||||||
|
setVarIdStructMembers(&tok2, &structMembers, &_varId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3418,8 +3418,8 @@ private:
|
||||||
"8: void foo :: bar ( )\n"
|
"8: void foo :: bar ( )\n"
|
||||||
"9: {\n"
|
"9: {\n"
|
||||||
"10: POINT pOutput@3 ; pOutput@3 = { 0 , 0 } ;\n"
|
"10: POINT pOutput@3 ; pOutput@3 = { 0 , 0 } ;\n"
|
||||||
"11: int x@4 ; x@4 = pOutput@3 . x@6 ;\n"
|
"11: int x@4 ; x@4 = pOutput@3 . x@5 ;\n"
|
||||||
"12: int y@5 ; y@5 = pOutput@3 . y@7 ;\n"
|
"12: int y@6 ; y@6 = pOutput@3 . y@7 ;\n"
|
||||||
"13: }\n");
|
"13: }\n");
|
||||||
|
|
||||||
ASSERT_EQUALS(expected, actual);
|
ASSERT_EQUALS(expected, actual);
|
||||||
|
|
Loading…
Reference in New Issue