From 0b8f252d1b627ff347e1d705e510aab0ce6980e3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Thu, 11 Nov 2021 23:20:56 +0200 Subject: [PATCH] Generate valid C# for fields with types system template specializations Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/MarkUsedClassInternalsPass.cs | 5 +++++ src/Generator/Passes/StripUnusedSystemTypesPass.cs | 4 ++-- tests/CSharp/CSharp.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Generator/Passes/MarkUsedClassInternalsPass.cs b/src/Generator/Passes/MarkUsedClassInternalsPass.cs index 0e3e7426..0c90d1df 100644 --- a/src/Generator/Passes/MarkUsedClassInternalsPass.cs +++ b/src/Generator/Passes/MarkUsedClassInternalsPass.cs @@ -57,6 +57,11 @@ namespace CppSharp.Passes MarkUsedFieldTypes(decl, visitedDeclarationContexts); } + foreach (var @base in @class.Bases.Where( + b => b.IsClass && b.Class.Ignore && b.Class.Fields.Count > 0)) + { + @base.Class.GenerationKind = GenerationKind.Internal; + } } } } diff --git a/src/Generator/Passes/StripUnusedSystemTypesPass.cs b/src/Generator/Passes/StripUnusedSystemTypesPass.cs index 4d111cb7..58b6a930 100644 --- a/src/Generator/Passes/StripUnusedSystemTypesPass.cs +++ b/src/Generator/Passes/StripUnusedSystemTypesPass.cs @@ -40,7 +40,8 @@ namespace CppSharp.Passes private bool TryMarkType(Type desugared) { - var tagType = desugared as TagType; + var templateType = desugared as TemplateSpecializationType; + var tagType = desugared as TagType ?? templateType?.Desugared.Type as TagType; if (tagType != null) { var specialization = tagType.Declaration as ClassTemplateSpecialization; @@ -56,7 +57,6 @@ namespace CppSharp.Passes return true; } - var templateType = desugared as TemplateSpecializationType; if (templateType != null) { var template = templateType.Template; diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 5f55bca0..31552a77 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "AnotherUnit.h" #include "ExcludedUnit.hpp" #include "CSharpTemplates.h" @@ -201,6 +202,7 @@ protected: AbstractProprietor(int i); int m_value; long m_property; + std::mutex m_mutex; }; class DLL_API Proprietor : public AbstractProprietor