MCPcopy Create free account
hub / github.com/andreasfertig/cppinsights / InsertTemplateParameters

Method InsertTemplateParameters

CodeGenerator.cpp:1782–1885  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1780//-----------------------------------------------------------------------------
1781
1782void CodeGenerator::InsertTemplateParameters(const TemplateParameterList& list,
1783 const TemplateParamsOnly templateParamsOnly)
1784{
1785 const bool full{TemplateParamsOnly::No == templateParamsOnly};
1786
1787 if(full) {
1788 for(const auto* param : list) {
1789 if(const auto* nonTmplParam = dyn_cast_or_null<NonTypeTemplateParmDecl>(param);
1790 nonTmplParam and nonTmplParam->hasDefaultArgument()) {
1791 if(auto val =
1792 EvaluateNTTPAsConstantExpr(nonTmplParam->getDefaultArgument().getArgument().getAsExpr())) {
1793 auto* init = GetGlobalAST().getTemplateParamObjectDecl(val->first, val->second);
1794
1795 InsertTemplateArgsObjectParam(*init);
1796 }
1797 }
1798 }
1799
1800 mOutputFormatHelper.Append(kwTemplate);
1801 }
1802
1803 mOutputFormatHelper.Append("<"sv);
1804
1805 for(OnceFalse needsComma{}; const auto* param : list) {
1806 mOutputFormatHelper.AppendComma(needsComma);
1807
1808 const auto& typeName = GetName(*param);
1809
1810 if(const auto* tt = dyn_cast_or_null<TemplateTypeParmDecl>(param)) {
1811 if(full) {
1812 if(tt->wasDeclaredWithTypename()) {
1813 mOutputFormatHelper.Append(kwTypeNameSpace);
1814 } else if(not tt->hasTypeConstraint()) {
1815 mOutputFormatHelper.Append(kwClassSpace);
1816 }
1817
1818 mOutputFormatHelper.Append(EllipsisSpace(tt->isParameterPack()));
1819 }
1820
1821 if(0 == typeName.size() or tt->isImplicit() /* fixes class container:auto*/) {
1822 AppendTemplateTypeParamName(mOutputFormatHelper, tt, not full);
1823
1824 } else {
1825 if(auto typeConstraint = GetTypeConstraintAsString(tt->getTypeConstraint());
1826 not typeConstraint.empty()) {
1827 mOutputFormatHelper.Append(std::move(typeConstraint), " "sv);
1828 }
1829
1830 mOutputFormatHelper.Append(typeName);
1831 }
1832
1833 mOutputFormatHelper.Append(EllipsisSpace(not full and tt->isParameterPack()));
1834
1835 if(tt->hasDefaultArgument() and not tt->defaultArgumentWasInherited()) {
1836 const auto& defaultArg = tt->getDefaultArgument();
1837
1838 if(const auto decltypeType = dyn_cast_or_null<DecltypeType>(defaultArg.getArgument().getAsType())) {
1839 mOutputFormatHelper.Append(hlpAssing);

Callers 1

GetDeclContextFunction · 0.80

Calls 13

GetNameFunction · 0.85
EllipsisSpaceFunction · 0.85
GetTypeNameAsParameterFunction · 0.85
EllipsisFunction · 0.85
ValueOrFunction · 0.85
AppendMethod · 0.80
AppendCommaMethod · 0.80
AppendNewLineMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected