From 71050bc586045fbf35f627a95da1cabb6966f082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 22 Apr 2012 08:51:19 +0200 Subject: [PATCH] Tokenizer::setVarIdNew: fixed TestTokenizer::varid_in_class2 test case --- lib/tokenize.cpp | 66 +++++++++++++++++++++++++++---------------- test/testtokenize.cpp | 4 +-- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d98ed81e4..fad2a4f12 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2901,6 +2901,41 @@ static void setVarIdClassDeclaration(Token * const startToken, const std::map > *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 >::iterator structIterator; + structIterator = structMembers->find(struct_varid); + if (structIterator == structMembers->end()) { + std::map members; + members[tok->str()] = ++ (*_varId); + (*structMembers)[struct_varid] = members; + tok->varId(*_varId); + } else { + std::map &members = structIterator->second; + std::map::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() { // Clear all variable ids @@ -3005,31 +3040,7 @@ void Tokenizer::setVarIdNew() const std::map::const_iterator it = variableId.find(tok->str()); if (it != variableId.end()) { tok->varId(it->second); - while (Token::Match(tok->next(), ". %var% !!(")) { - const unsigned int struct_varid = it->second; - tok = tok->tokAt(2); - if (struct_varid == 0) - continue; - - std::map >::iterator structIterator; - structIterator = structMembers.find(struct_varid); - if (structIterator == structMembers.end()) { - std::map members; - members[tok->str()] = ++_varId; - structMembers[struct_varid] = members; - tok->varId(_varId); - } else { - std::map &members = structIterator->second; - std::map::const_iterator memberIterator; - memberIterator = members.find(tok->str()); - if (memberIterator == members.end()) { - members[tok->str()] = ++_varId; - tok->varId(_varId); - } else { - tok->varId(memberIterator->second); - } - } - } + setVarIdStructMembers(&tok, &structMembers, &_varId); } } else if (Token::Match(tok, "::|. %var%")) { // 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 std::list allMemberFunctions; std::list allMemberVars; @@ -3119,6 +3134,7 @@ void Tokenizer::setVarIdNew() tok2->strAt(-1) != "." && varlist.find(tok2->str()) != varlist.end()) { tok2->varId(varlist[tok2->str()]); + setVarIdStructMembers(&tok2, &structMembers, &_varId); } } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 4c9a7ab01..86dfb9209 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3418,8 +3418,8 @@ private: "8: void foo :: bar ( )\n" "9: {\n" "10: POINT pOutput@3 ; pOutput@3 = { 0 , 0 } ;\n" - "11: int x@4 ; x@4 = pOutput@3 . x@6 ;\n" - "12: int y@5 ; y@5 = pOutput@3 . y@7 ;\n" + "11: int x@4 ; x@4 = pOutput@3 . x@5 ;\n" + "12: int y@6 ; y@6 = pOutput@3 . y@7 ;\n" "13: }\n"); ASSERT_EQUALS(expected, actual);