| 504 | } |
| 505 | |
| 506 | void Tokenizer::simplifyTypedefLHS() |
| 507 | { |
| 508 | if (!list.front()) |
| 509 | return; |
| 510 | |
| 511 | for (Token* tok = list.front()->next(); tok; tok = tok->next()) { |
| 512 | if (tok->str() == "typedef") { |
| 513 | bool doSimplify = !Token::Match(tok->previous(), ";|{|}|:|public:|private:|protected:"); |
| 514 | if (doSimplify && Token::simpleMatch(tok->previous(), ")") && Token::Match(tok->linkAt(-1)->previous(), "if|for|while")) |
| 515 | doSimplify = false; |
| 516 | bool haveStart = false; |
| 517 | Token* start{}; |
| 518 | if (!doSimplify && Token::simpleMatch(tok->previous(), "}")) { |
| 519 | start = tok->linkAt(-1)->previous(); |
| 520 | while (Token::Match(start, "%name%")) { |
| 521 | if (Token::Match(start, "class|struct|union|enum")) { |
| 522 | start = start->previous(); |
| 523 | doSimplify = true; |
| 524 | haveStart = true; |
| 525 | break; |
| 526 | } |
| 527 | start = start->previous(); |
| 528 | } |
| 529 | } |
| 530 | if (doSimplify) { |
| 531 | if (!haveStart) { |
| 532 | start = tok; |
| 533 | while (start && !Token::Match(start, "[;{}]")) |
| 534 | start = start->previous(); |
| 535 | } |
| 536 | if (start) |
| 537 | start = start->next(); |
| 538 | else |
| 539 | start = list.front(); |
| 540 | start->insertTokenBefore(tok->str()); |
| 541 | tok->deleteThis(); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | namespace { |
| 548 | class TypedefSimplifier { |
nothing calls this directly
no test coverage detected