MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / setVarIdPass2

Method setVarIdPass2

lib/tokenize.cpp:5230–5476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5228}
5229
5230void Tokenizer::setVarIdPass2()
5231{
5232 std::map<nonneg int, std::map<std::string, nonneg int>> structMembers;
5233
5234 // Member functions and variables in this source
5235 std::list<Member> allMemberFunctions;
5236 std::list<Member> allMemberVars;
5237 if (!isC()) {
5238 std::map<const Token *, std::string> endOfScope;
5239 std::list<std::string> scope;
5240 std::list<const Token *> usingnamespaces;
5241 for (Token *tok = list.front(); tok; tok = tok->next()) {
5242 if (!tok->previous() || Token::Match(tok->previous(), "[;{}]")) {
5243 if (Token::Match(tok, "using namespace %name% ::|;")) {
5244 Token *endtok = tok->tokAt(2);
5245 while (Token::Match(endtok, "%name% ::"))
5246 endtok = endtok->tokAt(2);
5247 if (Token::Match(endtok, "%name% ;"))
5248 usingnamespaces.push_back(tok->tokAt(2));
5249 tok = endtok;
5250 continue;
5251 }
5252 if (Token::Match(tok, "namespace %name% {")) {
5253 scope.push_back(tok->strAt(1));
5254 endOfScope[tok->linkAt(2)] = tok->strAt(1);
5255 }
5256 }
5257
5258 if (tok->str() == "}") {
5259 const auto it = utils::as_const(endOfScope).find(tok);
5260 if (it != endOfScope.cend())
5261 scope.remove(it->second);
5262 }
5263
5264 Token* const tok1 = tok;
5265 if (Token::Match(tok, "%name% :: ~| %name%"))
5266 tok = tok->next();
5267 else if (Token::Match(tok, "%name% <") && Token::Match(tok->next()->findClosingBracket(),"> :: ~| %name%"))
5268 tok = tok->next()->findClosingBracket()->next();
5269 else if (usingnamespaces.empty() || tok->varId() || !tok->isName() || tok->isStandardType() || tok->tokType() == Token::eKeyword || tok->tokType() == Token::eBoolean ||
5270 Token::Match(tok->previous(), ".|namespace|class|struct|&|&&|*|> %name%") || Token::Match(tok->previous(), "%type%| %name% ( %type%|)") || Token::Match(tok, "public:|private:|protected:") ||
5271 (!tok->next() && Token::Match(tok->previous(), "}|; %name%")))
5272 continue;
5273
5274 if (tok->strAt(-1) == "::" && tok->tokAt(-2) && tok->tokAt(-2)->isName())
5275 continue;
5276
5277 while (Token::Match(tok, ":: ~| %name%")) {
5278 tok = tok->next();
5279 if (tok->str() == "~")
5280 tok = tok->next();
5281 else if (Token::Match(tok, "%name% <") && Token::Match(tok->next()->findClosingBracket(),"> :: ~| %name%"))
5282 tok = tok->next()->findClosingBracket()->next();
5283 else if (Token::Match(tok, "%name% ::"))
5284 tok = tok->next();
5285 else
5286 break;
5287 }

Callers

nothing calls this directly

Calls 15

ScopeInfo2Class · 0.85
skipInitializerListFunction · 0.85
matchMemberVarNameFunction · 0.85
matchMemberFunctionNameFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
isCFunction · 0.70
simpleMatchFunction · 0.70
tokAtMethod · 0.45
push_backMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected