Skip to content

Commit 365b8db

Browse files
committed
Print C++ for some kinds of non-type template parameters
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
1 parent da251d4 commit 365b8db

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/Generator/Generators/C/CppTypePrinter.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using CppSharp.AST;
56
using CppSharp.AST.Extensions;
@@ -559,8 +560,31 @@ public override TypePrinterResult VisitClassDecl(Class @class)
559560
public override TypePrinterResult VisitClassTemplateSpecializationDecl(
560561
ClassTemplateSpecialization specialization)
561562
{
562-
var args = specialization.Arguments.Where(a => a.Type.Type != null &&
563-
!(a.Type.Type is DependentNameType)).Select(a => a.Type.Visit(this));
563+
var args = new List<string>();
564+
for (int i = 0; i < specialization.Arguments.Count; i++)
565+
{
566+
TemplateArgument arg = specialization.Arguments[i];
567+
switch (arg.Kind)
568+
{
569+
case TemplateArgument.ArgumentKind.Type:
570+
args.Add(arg.Type.Visit(this));
571+
break;
572+
case TemplateArgument.ArgumentKind.Declaration:
573+
args.Add(arg.Declaration.Visit(this));
574+
break;
575+
case TemplateArgument.ArgumentKind.Integral:
576+
Class template = specialization.TemplatedDecl.TemplatedClass;
577+
var nonTypeTemplateParameter = template.TemplateParameters[i]
578+
as NonTypeTemplateParameter;
579+
if (!(nonTypeTemplateParameter?.DefaultArgument is
580+
BuiltinTypeExpressionObsolete builtinExpression) ||
581+
builtinExpression.Value != arg.Integral)
582+
{
583+
args.Add(arg.Integral.ToString(CultureInfo.InvariantCulture));
584+
}
585+
break;
586+
}
587+
}
564588
return $"{specialization.TemplatedDecl.Visit(this)}<{string.Join(", ", args)}>";
565589
}
566590

0 commit comments

Comments
 (0)