From 00bf3714cac92927ea48ba4ed3d50c271957a0b8 Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Tue, 29 Oct 2013 14:49:42 +0000 Subject: [PATCH 1/4] Hack to silently ignore non-class base class (e.g. templates etc) --- src/AST/Class.cs | 2 +- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AST/Class.cs b/src/AST/Class.cs index 30c4adaf..a9601dd7 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -213,7 +213,7 @@ namespace CppSharp.AST public Method GetRootBaseMethod(Method @override, bool onlyFirstBase = false) { return (from @base in Bases - where !onlyFirstBase || !@base.Class.IsInterface + where @base.IsClass && (!onlyFirstBase || !@base.Class.IsInterface) let baseMethod = ( from method in @base.Class.Methods where diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 6760952e..2c2770c0 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -716,6 +716,7 @@ namespace CppSharp.Generators.CSharp { bases.AddRange( from @base in @class.Bases + where @base.IsClass select QualifiedIdentifier(@base.Class)); } From 4b782d7af3946d2c501f9db01c246a3089370b36 Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Tue, 29 Oct 2013 13:16:09 +0000 Subject: [PATCH 2/4] Add a test case for the Curiously Recurring Template Pattern --- tests/Basic/Basic.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 78ecdcde..95a7f34a 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -153,3 +153,13 @@ struct DLL_API DefaultParameters void Bar() const; void Bar(); }; + +// The Curiously Recurring Template Pattern (CRTP) +template +class Base +{ + // methods within Base can use template to access members of Derived +}; +class Derived : public Base +{ +}; From 0c7a72c400517e344cbb5c237558985d111e3621 Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Wed, 30 Oct 2013 12:13:18 +0000 Subject: [PATCH 3/4] Hack for CLI version --- src/Generator/Generators/CLI/CLISourcesTemplate.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index 9bb47ef0..1dbe96ee 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -545,7 +545,7 @@ namespace CppSharp.Generators.CLI private bool GenerateClassConstructorBase(Class @class, bool isIntPtr, Method method = null) { - var hasBase = @class.HasBase && !@class.Bases[0].Class.Ignore; + var hasBase = @class.HasBase && @class.Bases[0].IsClass && !@class.Bases[0].Class.Ignore; if (!hasBase) return false; From 6cff480f2b7977c403ce9db25eb2391b907ee73f Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Wed, 30 Oct 2013 12:13:46 +0000 Subject: [PATCH 4/4] Update test with method which should appear in "Derived" --- tests/Basic/Basic.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 95a7f34a..7cbfba3f 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -159,6 +159,7 @@ template class Base { // methods within Base can use template to access members of Derived + Derived* create() { return new Derived(); } }; class Derived : public Base {