| 1634 | }; |
| 1635 | |
| 1636 | void TemplateSimplifier::expandTemplate( |
| 1637 | const TokenAndName &templateDeclaration, |
| 1638 | const TokenAndName &templateInstantiation, |
| 1639 | const std::vector<const Token *> &typeParametersInDeclaration, |
| 1640 | const std::string &newName, |
| 1641 | bool copy) |
| 1642 | { |
| 1643 | bool inTemplateDefinition = false; |
| 1644 | const Token *startOfTemplateDeclaration = nullptr; |
| 1645 | const Token *endOfTemplateDefinition = nullptr; |
| 1646 | const Token * const templateDeclarationNameToken = templateDeclaration.nameToken(); |
| 1647 | const Token * const templateDeclarationToken = templateDeclaration.paramEnd(); |
| 1648 | const bool isClass = templateDeclaration.isClass(); |
| 1649 | const bool isFunction = templateDeclaration.isFunction(); |
| 1650 | const bool isSpecialization = templateDeclaration.isSpecialization(); |
| 1651 | const bool isVariable = templateDeclaration.isVariable(); |
| 1652 | |
| 1653 | std::vector<newInstantiation> newInstantiations; |
| 1654 | |
| 1655 | for (const Token* tok = templateInstantiation.token()->next()->findClosingBracket(); |
| 1656 | tok && tok != templateInstantiation.token(); tok = tok->previous()) { |
| 1657 | if (tok->isName()) |
| 1658 | mUsedVariables[newName].insert(tok->str()); |
| 1659 | } |
| 1660 | |
| 1661 | // add forward declarations |
| 1662 | if (copy && isClass) { |
| 1663 | templateDeclaration.token()->insertTokenBefore(templateDeclarationToken->strAt(1)); |
| 1664 | templateDeclaration.token()->insertTokenBefore(newName); |
| 1665 | templateDeclaration.token()->insertTokenBefore(";"); |
| 1666 | } else if ((isFunction && (copy || isSpecialization)) || |
| 1667 | (isVariable && !isSpecialization) || |
| 1668 | (isClass && isSpecialization && mTemplateSpecializationMap.find(templateDeclaration.token()) != mTemplateSpecializationMap.end())) { |
| 1669 | Token * dst = templateDeclaration.token(); |
| 1670 | Token * dstStart = dst->previous(); |
| 1671 | bool isStatic = false; |
| 1672 | std::string scope; |
| 1673 | const Token * start; |
| 1674 | const Token * end; |
| 1675 | auto it = mTemplateForwardDeclarationsMap.find(dst); |
| 1676 | if (!isSpecialization && it != mTemplateForwardDeclarationsMap.end()) { |
| 1677 | dst = it->second; |
| 1678 | dstStart = dst->previous(); |
| 1679 | const Token * temp1 = dst->tokAt(1)->findClosingBracket(); |
| 1680 | const Token * temp2 = temp1->tokAt(getTemplateNamePosition(temp1)); |
| 1681 | start = temp1->next(); |
| 1682 | end = temp2->linkAt(1)->next(); |
| 1683 | } else { |
| 1684 | if (it != mTemplateForwardDeclarationsMap.end()) { |
| 1685 | const auto it1 = std::find_if(mTemplateForwardDeclarations.cbegin(), |
| 1686 | mTemplateForwardDeclarations.cend(), |
| 1687 | FindToken(it->second)); |
| 1688 | if (it1 != mTemplateForwardDeclarations.cend()) |
| 1689 | mMemberFunctionsToDelete.push_back(*it1); |
| 1690 | } |
| 1691 | |
| 1692 | auto it2 = mTemplateSpecializationMap.find(dst); |
| 1693 | if (it2 != mTemplateSpecializationMap.end()) { |
nothing calls this directly
no test coverage detected