| 652 | } |
| 653 | |
| 654 | bool TemplateSimplifier::getTemplateDeclarations() |
| 655 | { |
| 656 | bool codeWithTemplates = false; |
| 657 | for (Token *tok = mTokenList.front(); tok; tok = tok->next()) { |
| 658 | if (!Token::simpleMatch(tok, "template <")) |
| 659 | continue; |
| 660 | // ignore template template parameter |
| 661 | if (tok->strAt(-1) == "<" || tok->strAt(-1) == ",") |
| 662 | continue; |
| 663 | // ignore nested template |
| 664 | if (tok->strAt(-1) == ">") |
| 665 | continue; |
| 666 | // skip to last nested template parameter |
| 667 | const Token *tok1 = tok; |
| 668 | while (tok1 && tok1->next()) { |
| 669 | const Token *closing = tok1->next()->findClosingBracket(); |
| 670 | if (!Token::simpleMatch(closing, "> template <")) |
| 671 | break; |
| 672 | tok1 = closing->next(); |
| 673 | } |
| 674 | if (!Token::Match(tok, "%any% %any%")) |
| 675 | syntaxError(tok); |
| 676 | if (tok->strAt(2)=="typename" && |
| 677 | !Token::Match(tok->tokAt(3), "%name%|...|,|=|>")) |
| 678 | syntaxError(tok->next()); |
| 679 | codeWithTemplates = true; |
| 680 | const Token * const parmEnd = tok1->next()->findClosingBracket(); |
| 681 | for (const Token *tok2 = parmEnd; tok2; tok2 = tok2->next()) { |
| 682 | if (tok2->str() == "(" && tok2->link()) |
| 683 | tok2 = tok2->link(); |
| 684 | else if (tok2->str() == ")") |
| 685 | break; |
| 686 | // skip decltype(...) |
| 687 | else if (Token::simpleMatch(tok2, "decltype (")) |
| 688 | tok2 = tok2->linkAt(1); |
| 689 | else if (Token::Match(tok2, "{|=|;")) { |
| 690 | const int namepos = getTemplateNamePosition(parmEnd); |
| 691 | if (namepos > 0) { |
| 692 | if (!tok->scopeInfo()) |
| 693 | syntaxError(tok); |
| 694 | TokenAndName decl(tok, tok->scopeInfo()->name, parmEnd->tokAt(namepos), parmEnd); |
| 695 | if (decl.isForwardDeclaration()) { |
| 696 | // Declaration => add to mTemplateForwardDeclarations |
| 697 | mTemplateForwardDeclarations.emplace_back(std::move(decl)); |
| 698 | } else { |
| 699 | // Implementation => add to mTemplateDeclarations |
| 700 | mTemplateDeclarations.emplace_back(std::move(decl)); |
| 701 | } |
| 702 | Token *end = findTemplateDeclarationEnd(tok); |
| 703 | if (end) |
| 704 | tok = end; |
| 705 | break; |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | return codeWithTemplates; |
| 711 | } |
nothing calls this directly
no test coverage detected