| 400 | } |
| 401 | |
| 402 | static const Token* doAssignment(Variables &variables, const Token *tok, bool dereference, const Scope *scope) |
| 403 | { |
| 404 | // a = a + b; |
| 405 | if (Token::Match(tok, "%var% = %var% !!;")) { |
| 406 | const Token* rhsVarTok = tok->tokAt(2); |
| 407 | if (tok->varId() == rhsVarTok->varId()) { |
| 408 | return rhsVarTok; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | if (Token::Match(tok, "%var% %assign%") && tok->strAt(1) != "=") |
| 413 | return tok->next(); |
| 414 | |
| 415 | const Token* const tokOld = tok; |
| 416 | |
| 417 | // check for aliased variable |
| 418 | const nonneg int varid1 = tok->varId(); |
| 419 | Variables::VariableUsage *var1 = variables.find(varid1); |
| 420 | |
| 421 | if (var1) { |
| 422 | if (var1->mType == Variables::pointerArray) |
| 423 | variables.use(varid1, tok); |
| 424 | |
| 425 | // jump behind '=' |
| 426 | tok = tok->next(); |
| 427 | while (!tok->isAssignmentOp()) { |
| 428 | if (tok->varId()) |
| 429 | variables.read(tok->varId(), tok); |
| 430 | tok = tok->next(); |
| 431 | } |
| 432 | tok = tok->next(); |
| 433 | |
| 434 | if (Token::Match(tok, "( const| struct|union| %type% * ) ( (")) |
| 435 | tok = tok->link()->next(); |
| 436 | |
| 437 | if (Token::Match(tok, "( [(<] const| struct|union| %type% *| [>)]")) |
| 438 | tok = tok->next(); |
| 439 | |
| 440 | if (Token::Match(tok, "(| &| %name%") || |
| 441 | (Token::Match(tok->next(), "< const| struct|union| %type% *| > ( &| %name%"))) { |
| 442 | bool addressOf = false; |
| 443 | |
| 444 | if (Token::Match(tok, "%var% .")) |
| 445 | variables.use(tok->varId(), tok); // use = read + write |
| 446 | |
| 447 | // check for C style cast |
| 448 | if (tok->str() == "(") { |
| 449 | tok = tok->next(); |
| 450 | if (tok->str() == "const") |
| 451 | tok = tok->next(); |
| 452 | |
| 453 | if (Token::Match(tok, "struct|union")) |
| 454 | tok = tok->next(); |
| 455 | |
| 456 | while ((tok->isName() && tok->varId() == 0) || (tok->str() == "*") || (tok->str() == ")")) |
| 457 | tok = tok->next(); |
| 458 | |
| 459 | if (tok->str() == "&") { |
no test coverage detected