From 50ee4147999e02c05fe09a85dcf91dfc11235cce Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 2 Sep 2016 01:19:32 +0300 Subject: [PATCH] Fixed the C++ type printer to handle const value types. Signed-off-by: Dimitar Dobrev --- src/AST/CppTypePrinter.cs | 3 ++- src/Generator.Tests/AST/TestAST.cs | 9 +++++++++ tests/Native/AST.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/AST/CppTypePrinter.cs b/src/AST/CppTypePrinter.cs index 513c83b1..572d902b 100644 --- a/src/AST/CppTypePrinter.cs +++ b/src/AST/CppTypePrinter.cs @@ -39,7 +39,8 @@ namespace CppSharp.AST public string VisitTagType(TagType tag, TypeQualifiers quals) { - return tag.Declaration.Visit(this); + var qual = PrintTypeQualifiers && quals.IsConst ? "const " : string.Empty; + return string.Format("{0}{1}", qual, tag.Declaration.Visit(this)); } public string VisitArrayType(ArrayType array, TypeQualifiers quals) diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs index 993e7b66..b810fe00 100644 --- a/src/Generator.Tests/AST/TestAST.cs +++ b/src/Generator.Tests/AST/TestAST.cs @@ -408,5 +408,14 @@ namespace CppSharp.Generator.Tests.AST Assert.That(template.Specializations[0].Constructors.First().QualifiedName, Is.Not.EqualTo(template.Specializations[1].Constructors.First().QualifiedName)); } + + [Test] + public void TestPrintingSpecializationWithConstValue() + { + var template = AstContext.FindDecl("TestSpecializationArguments").First(); + var cppTypePrinter = new CppTypePrinter { PrintScopeKind = CppTypePrintScopeKind.Qualified }; + Assert.That(template.Specializations.Last().Visit(cppTypePrinter), + Is.EqualTo("TestSpecializationArguments")); + } } } diff --git a/tests/Native/AST.h b/tests/Native/AST.h index c46d1b48..3ee30d5d 100644 --- a/tests/Native/AST.h +++ b/tests/Native/AST.h @@ -154,3 +154,5 @@ class ForwardedTemplate; typedef ForwardedTemplate i; typedef ForwardedTemplate l; + +template class TestSpecializationArguments;