From ae9eede6f14df5428b894b2b20960f2c104176ce Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 24 Dec 2017 19:05:33 +0200 Subject: [PATCH] Fixed a crash when a constructor takes a template or specialisation. Signed-off-by: Dimitar Dobrev --- src/AST/ClassExtensions.cs | 22 +++++++++++++++++++ .../Generators/CSharp/CSharpSources.cs | 2 +- .../Passes/ParamTypeToInterfacePass.cs | 17 +------------- tests/CSharp/CSharpTemplates.h | 12 ++++++++++ 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/AST/ClassExtensions.cs b/src/AST/ClassExtensions.cs index 3554a647db..76ad2c81a1 100644 --- a/src/AST/ClassExtensions.cs +++ b/src/AST/ClassExtensions.cs @@ -178,6 +178,28 @@ private static IEnumerable GetSpecializedClassesOf(this Class dependentCl c => c.Name == dependentClass.Name)).ToList(); } + public static Class GetInterface(this Class @class) + { + var specialization = @class as ClassTemplateSpecialization; + Class @interface = null; + if (specialization == null) + { + @interface = @class.Namespace.Classes.Find( + c => c.OriginalClass == @class && c.IsInterface); + } + else + { + Class template = specialization.TemplatedDecl.TemplatedClass; + Class templatedInterface = @class.Namespace.Classes.Find( + c => c.OriginalClass == template && c.IsInterface); + if (templatedInterface != null) + @interface = templatedInterface.Specializations.FirstOrDefault( + s => s.OriginalClass == specialization && s.IsInterface); + } + + return @interface; + } + public static bool HasDependentValueFieldInLayout(this Class @class) { if (@class.Fields.Any(f => IsValueDependent(f.Type))) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 5aae09c1df..664d2090d4 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -2595,7 +2595,7 @@ private void GenerateOperator(Method method, QualifiedType returnType) Class paramClass; Class @interface = null; if (paramType.TryGetClass(out paramClass)) - @interface = paramClass.Namespace.Classes.Find(c => c.OriginalClass == paramClass); + @interface = paramClass.GetInterface(); var paramName = string.Format("{0}{1}", method.Parameters[0].Type.IsPrimitiveTypeConvertibleToRef() ? diff --git a/src/Generator/Passes/ParamTypeToInterfacePass.cs b/src/Generator/Passes/ParamTypeToInterfacePass.cs index 96203bd217..47e4cbc9ac 100644 --- a/src/Generator/Passes/ParamTypeToInterfacePass.cs +++ b/src/Generator/Passes/ParamTypeToInterfacePass.cs @@ -59,22 +59,7 @@ private static void ChangeToInterfaceType(ref QualifiedType type) if (!finalType.TryGetClass(out @class)) return; - var specialization = @class as ClassTemplateSpecialization; - Class @interface = null; - if (specialization == null) - { - @interface = @class.Namespace.Classes.Find( - c => c.OriginalClass == @class && c.IsInterface); - } - else - { - Class template = specialization.TemplatedDecl.TemplatedClass; - Class templatedInterface = @class.Namespace.Classes.Find( - c => c.OriginalClass == template && c.IsInterface); - if (templatedInterface != null) - @interface = templatedInterface.Specializations.FirstOrDefault( - s => s.OriginalClass == specialization); - } + Class @interface = @class.GetInterface(); if (@interface == null) return; diff --git a/tests/CSharp/CSharpTemplates.h b/tests/CSharp/CSharpTemplates.h index c9f70bf75c..a35aad33f9 100644 --- a/tests/CSharp/CSharpTemplates.h +++ b/tests/CSharp/CSharpTemplates.h @@ -137,6 +137,7 @@ class DLL_API DependentValueFields : public Base T field; }; DependentValueFields(); + DependentValueFields(IndependentFields i); ~DependentValueFields(); DependentValueFields& returnInjectedClass(); DependentValueFields returnValue(); @@ -163,6 +164,11 @@ DependentValueFields::~DependentValueFields() { } +template +DependentValueFields::DependentValueFields(IndependentFields i) +{ +} + template T DependentValueFields::getDependentValue() { @@ -404,6 +410,7 @@ class VirtualTemplate { public: VirtualTemplate(); + VirtualTemplate(IndependentFields i); VirtualTemplate(OptionalTemplateArgs optionalTemplateArgs); virtual ~VirtualTemplate(); virtual int function(); @@ -415,6 +422,11 @@ VirtualTemplate::VirtualTemplate() { } +template +VirtualTemplate::VirtualTemplate(IndependentFields i) +{ +} + template VirtualTemplate::VirtualTemplate(OptionalTemplateArgs optionalTemplateArgs) {