| 1633 | //----------------------------------------------------------------------------- |
| 1634 | |
| 1635 | void CodeGenerator::InsertMethodBody(const FunctionDecl* stmt, const size_t posBeforeFunc) |
| 1636 | { |
| 1637 | auto IsPrimaryTemplate = [&] { |
| 1638 | // For now, don't transform the primary template of a coroutine |
| 1639 | if(const auto* cxxMethod = dyn_cast_or_null<CXXMethodDecl>(stmt)) { |
| 1640 | if(const auto* tmpl = cxxMethod->getParent()->getDescribedClassTemplate(); |
| 1641 | tmpl and not isa<ClassTemplateSpecializationDecl>(cxxMethod->getParent())) { |
| 1642 | return true; |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | return (FunctionDecl::TK_FunctionTemplate == stmt->getTemplatedKind()) or |
| 1647 | (ProcessingPrimaryTemplate::Yes == mProcessingPrimaryTemplate); |
| 1648 | }; |
| 1649 | |
| 1650 | if(stmt->doesThisDeclarationHaveABody()) { |
| 1651 | mOutputFormatHelper.AppendNewLine(); |
| 1652 | |
| 1653 | // If this function has a CoroutineBodyStmt as direct descend and coroutine transformation is enabled use |
| 1654 | // the \c CoroutinesCodeGenerator, otherwise insert the body as usual. |
| 1655 | if(const auto* corBody = dyn_cast_or_null<CoroutineBodyStmt>(stmt->getBody()); |
| 1656 | (nullptr != corBody) and not IsPrimaryTemplate() and GetInsightsOptions().ShowCoroutineTransformation) { |
| 1657 | |
| 1658 | CoroutinesCodeGenerator codeGenerator{mOutputFormatHelper, posBeforeFunc}; |
| 1659 | codeGenerator.InsertCoroutine(*stmt, corBody); |
| 1660 | } else { |
| 1661 | const auto exSpec = stmt->getExceptionSpecType(); |
| 1662 | const bool showNoexcept = |
| 1663 | GetInsightsOptions().UseShowNoexcept and is{exSpec}.any_of(EST_BasicNoexcept, EST_NoexceptTrue); |
| 1664 | |
| 1665 | // handle C++ [basic.start.main] §5: main can have no return statement |
| 1666 | if(stmt->hasImplicitReturnZero()) { |
| 1667 | mRequiresImplicitReturnZero = ranges::none_of(dyn_cast<CompoundStmt>(stmt->getBody())->body(), |
| 1668 | [](const Stmt* e) { return isa<ReturnStmt>(e); }); |
| 1669 | } |
| 1670 | |
| 1671 | const auto* body = stmt->getBody(); |
| 1672 | |
| 1673 | if(showNoexcept) { |
| 1674 | EnableGlobalInsert(GlobalInserts::HeaderException); |
| 1675 | |
| 1676 | body = mkCompoundStmt(Try(body, Catch(Call("std::terminate"sv, {})))); |
| 1677 | } |
| 1678 | |
| 1679 | if(GetInsightsOptions().ShowLifetime) { |
| 1680 | for(const auto* param : stmt->parameters()) { |
| 1681 | auto paramType = param->getType(); |
| 1682 | const bool isPassByValue{not paramType->isPointerType() and not paramType->isReferenceType()}; |
| 1683 | if(const auto* rd = paramType->getAsRecordDecl(); rd and isPassByValue) { |
| 1684 | mLifeTimeTracker.Add(param); |
| 1685 | } |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | InsertArg(body); |
| 1690 | } |
| 1691 | |
| 1692 | mOutputFormatHelper.AppendNewLine(); |
nothing calls this directly
no test coverage detected