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

Function setVarIdStructMembers

lib/tokenize.cpp:4486–4553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4484
4485
4486static void setVarIdStructMembers(Token *&tok1,
4487 std::map<nonneg int, std::map<std::string, nonneg int>>& structMembers,
4488 nonneg int &varId)
4489{
4490 Token *tok = tok1;
4491
4492 if (Token::Match(tok, "%name% = { . %name% =|{")) {
4493 const nonneg int struct_varid = tok->varId();
4494 if (struct_varid == 0)
4495 return;
4496
4497 std::map<std::string, nonneg int>& members = structMembers[struct_varid];
4498
4499 tok = tok->tokAt(3);
4500 while (tok->str() != "}") {
4501 if (Token::Match(tok, "{|[|("))
4502 tok = tok->link();
4503 if (Token::Match(tok->previous(), "[,{] . %name% =|{")) {
4504 tok = tok->next();
4505 const auto it = utils::as_const(members).find(tok->str());
4506 if (it == members.cend()) {
4507 members[tok->str()] = ++varId;
4508 tok->varId(varId);
4509 } else {
4510 tok->varId(it->second);
4511 }
4512 }
4513 if (Token::Match(tok, "%name% = { . %name% =|{")) {
4514 setVarIdStructMembers(tok, structMembers, varId);
4515 tok = tok->linkAt(2);
4516 }
4517 tok = tok->next();
4518 }
4519
4520 return;
4521 }
4522
4523 while (Token::Match(tok->next(), ")| . %name% !!(")) {
4524 // Don't set varid for trailing return type
4525 if (tok->strAt(1) == ")" && Token::Match(tok->linkAt(1)->tokAt(-1), "%name%|]") && !tok->linkAt(1)->tokAt(-1)->isKeyword() &&
4526 TokenList::isFunctionHead(tok->linkAt(1), "{;")) {
4527 tok = tok->tokAt(3);
4528 continue;
4529 }
4530 const nonneg int struct_varid = tok->varId();
4531 tok = tok->tokAt(2);
4532 if (struct_varid == 0)
4533 continue;
4534
4535 if (tok->str() == ".")
4536 tok = tok->next();
4537
4538 // Don't set varid for template function
4539 if (TemplateSimplifier::templateParameters(tok->next()) > 0)
4540 break;
4541
4542 std::map<std::string, nonneg int>& members = structMembers[struct_varid];
4543 const auto it = utils::as_const(members).find(tok->str());

Callers 3

setVarIdClassDeclarationFunction · 0.85
setVarIdClassFunctionMethod · 0.85
setVarIdPass1Method · 0.85

Calls 6

nextMethod · 0.80
linkAtMethod · 0.80
tokAtMethod · 0.45
strMethod · 0.45
findMethod · 0.45
isKeywordMethod · 0.45

Tested by

no test coverage detected