| 2320 | } |
| 2321 | |
| 2322 | bool CheckClassImpl::isMemberVar(const Scope *scope, const Token *tok) const |
| 2323 | { |
| 2324 | bool again = false; |
| 2325 | |
| 2326 | // try to find the member variable |
| 2327 | do { |
| 2328 | again = false; |
| 2329 | |
| 2330 | if (tok->str() == "this") |
| 2331 | return !getFuncTokFromThis(tok); // function calls are handled elsewhere |
| 2332 | if (Token::simpleMatch(tok->tokAt(-3), "( * this )")) |
| 2333 | return true; |
| 2334 | if (Token::Match(tok->tokAt(-3), "%name% ) . %name%")) { |
| 2335 | tok = tok->tokAt(-3); |
| 2336 | again = true; |
| 2337 | } else if (Token::Match(tok->tokAt(-2), "%name% . %name%")) { |
| 2338 | tok = tok->tokAt(-2); |
| 2339 | again = true; |
| 2340 | } else if (Token::Match(tok->tokAt(-2), "] . %name%")) { |
| 2341 | tok = tok->linkAt(-2)->previous(); |
| 2342 | again = true; |
| 2343 | } else if (tok->str() == "]") { |
| 2344 | tok = tok->link()->previous(); |
| 2345 | again = true; |
| 2346 | } else if (Token::Match(tok, "%name% ::")) { |
| 2347 | tok = tok->tokAt(2); |
| 2348 | again = true; |
| 2349 | } |
| 2350 | } while (again); |
| 2351 | |
| 2352 | if (tok->isKeyword() || tok->isStandardType()) |
| 2353 | return false; |
| 2354 | if (tok->variable() && (tok->variable()->isArgument() || tok->variable()->isLocal())) |
| 2355 | return false; |
| 2356 | if (tok->function() || tok->type() || tok->enumerator()) |
| 2357 | return false; |
| 2358 | |
| 2359 | for (const Variable& var : scope->varlist) { |
| 2360 | if (var.name() == tok->str()) { |
| 2361 | if (Token::Match(tok, "%name% ::")) |
| 2362 | continue; |
| 2363 | const Token* fqTok = tok; |
| 2364 | while (Token::Match(fqTok->tokAt(-2), "%name% ::")) |
| 2365 | fqTok = fqTok->tokAt(-2); |
| 2366 | if (fqTok->strAt(-1) == "::") |
| 2367 | fqTok = fqTok->previous(); |
| 2368 | bool isMember = tok == fqTok; |
| 2369 | std::string scopeStr; |
| 2370 | const Scope* curScope = scope; |
| 2371 | while (!isMember && curScope && curScope->type != ScopeType::eGlobal) { |
| 2372 | scopeStr.insert(0, curScope->className + " :: "); |
| 2373 | isMember = Token::Match(fqTok, scopeStr.c_str()); |
| 2374 | |
| 2375 | curScope = curScope->nestedIn; |
| 2376 | } |
| 2377 | if (isMember) { |
| 2378 | if (tok->varId() == 0) |
| 2379 | mSymbolDatabase->debugMessage(tok, "varid0", "CheckClass::isMemberVar found used member variable \'" + tok->str() + "\' with varid 0"); |
nothing calls this directly
no test coverage detected