From 4bfece6ab944806418b98edd929820a130fe7acb Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 28 Nov 2017 17:26:17 +0200 Subject: [PATCH] Fixed the generated C# for specialisations with an ignored specialisation as an arg. Signed-off-by: Dimitar Dobrev --- src/Generator/Library.cs | 2 +- src/Generator/Passes/CheckIgnoredDecls.cs | 22 +++++++++++++++++++++- tests/CSharp/CSharp.cs | 1 + tests/CSharp/CSharpTemplates.cpp | 4 ++++ tests/CSharp/CSharpTemplates.h | 6 ++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Generator/Library.cs b/src/Generator/Library.cs index 92ec7615..c3408616 100644 --- a/src/Generator/Library.cs +++ b/src/Generator/Library.cs @@ -185,7 +185,7 @@ namespace CppSharp public static void IgnoreClassWithName(this ASTContext context, string name) { foreach (var @class in context.FindClass(name)) - @class.GenerationKind = GenerationKind.Internal; + @class.ExplicitlyIgnore(); } public static void SetClassAsOpaque(this ASTContext context, string name) diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs index dab85807..7de12e78 100644 --- a/src/Generator/Passes/CheckIgnoredDecls.cs +++ b/src/Generator/Passes/CheckIgnoredDecls.cs @@ -37,7 +37,7 @@ namespace CppSharp.Passes injectedClasses.Add(@class); if (!@class.IsDependent) - return false; + return true; if (Options.GenerateClassTemplates) IgnoreUnsupportedTemplates(@class); @@ -49,6 +49,26 @@ namespace CppSharp.Passes return true; } + public override bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecialization specialization) + { + if (!base.VisitClassTemplateSpecializationDecl(specialization)) + return false; + + Declaration decl = null; + if (specialization.Arguments.Any(a => + a.Type.Type?.TryGetDeclaration(out decl) == true)) + { + decl.Visit(this); + if (decl.Ignore) + { + specialization.ExplicitlyIgnore(); + return false; + } + } + + return true; + } + public override bool VisitDeclaration(Declaration decl) { if (AlreadyVisited(decl)) diff --git a/tests/CSharp/CSharp.cs b/tests/CSharp/CSharp.cs index 72a7490b..fdcb4e47 100644 --- a/tests/CSharp/CSharp.cs +++ b/tests/CSharp/CSharp.cs @@ -39,6 +39,7 @@ namespace CppSharp.Tests ctx.SetClassAsValueType("QRect"); ctx.SetClassAsValueType("StructTestArrayTypeFromTypedef"); ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); + ctx.IgnoreClassWithName("Ignored"); var macroRegex = new Regex("(MY_MACRO_TEST_.*)"); var list = (from unit in ctx.TranslationUnits diff --git a/tests/CSharp/CSharpTemplates.cpp b/tests/CSharp/CSharpTemplates.cpp index fc7bfcce..e80abfe6 100644 --- a/tests/CSharp/CSharpTemplates.cpp +++ b/tests/CSharp/CSharpTemplates.cpp @@ -131,6 +131,10 @@ void forceUseSpecializations(IndependentFields _1, IndependentFields { } +void hasIgnoredParam(DependentValueFields> ii) +{ +} + DependentValueFields specialiseReturnOnly() { return DependentValueFields(); diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index 1f9a7f99..6a7eae2c 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -18,6 +18,10 @@ class DLL_API T2 { }; +class DLL_API Ignored +{ +}; + template class DLL_API IndependentFields : public T1 { @@ -507,6 +511,8 @@ void forceUseSpecializations(IndependentFields _1, IndependentFields TemplateWithIndexer _12, TemplateDerivedFromRegularDynamic _13, IndependentFields> _14, std::string s); +void hasIgnoredParam(DependentValueFields> ii); + DLL_API DependentValueFields specialiseReturnOnly(); // force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source