Browse Source

Generate valid C# for destructors of templates with dependent fields

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1641/head
Dimitar Dobrev 4 years ago
parent
commit
50cba5552c
  1. 14
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 9
      tests/CSharp/CSharp.Tests.cs
  3. 4
      tests/CSharp/CSharpTemplates.cpp
  4. 25
      tests/CSharp/CSharpTemplates.h

14
src/Generator/Generators/CSharp/CSharpSources.cs

@ -2257,13 +2257,15 @@ namespace CppSharp.Generators.CSharp @@ -2257,13 +2257,15 @@ namespace CppSharp.Generators.CSharp
// The local var must be of the exact type in the object map because of TryRemove
WriteLine("NativeToManagedMap.TryRemove({0}, out _);", Helpers.InstanceIdentifier);
var classInternal = TypePrinter.PrintNative(@class);
if (@class.IsDynamic && GetUniqueVTableMethodEntries(@class).Count != 0)
var realClass = @class.IsTemplate ? @class.Specializations[0] : @class;
var classInternal = TypePrinter.PrintNative(realClass);
if (@class.IsDynamic && GetUniqueVTableMethodEntries(realClass).Count != 0)
{
ClassLayout layout = (@class.IsDependent ? @class.Specializations[0] : @class).Layout;
for (var i = 0; i < layout.VTablePointers.Count; i++)
WriteLine($@"(({classInternal}*) {Helpers.InstanceIdentifier})->{
layout.VTablePointers[i].Name} = __VTables.Tables[{i}];");
for (int i = 0; i < realClass.Layout.VTablePointers.Count; i++)
{
var offset = realClass.Layout.VTablePointers[i].Offset;
WriteLine($"*(IntPtr*)({Helpers.InstanceIdentifier} + {offset}) = __VTables.Tables[{i}];");
}
}
}

9
tests/CSharp/CSharp.Tests.cs

@ -1128,6 +1128,15 @@ public unsafe class CSharpTests @@ -1128,6 +1128,15 @@ public unsafe class CSharpTests
bool b = true;
Assert.That(*virtualTemplate.Function(ref b), Is.EqualTo(true));
}
using (var virtualTemplate = new VirtualDependentValueFields<int>())
{
}
using (var virtualTemplate = new VirtualDependentValueFields<float>())
{
}
using (var virtualTemplate = new VirtualDependentValueFields<string>())
{
}
}
[Test]

4
tests/CSharp/CSharpTemplates.cpp

@ -114,7 +114,9 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> @@ -114,7 +114,9 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool>
IndependentFields<OnlySpecialisedInTypeArg<double>> _15,
DependentPointerFields<float> _16, IndependentFields<const T1&> _17,
TemplateWithIndexer<T2*> _18, IndependentFields<int(*)(int)> _19,
TemplateWithIndexer<const char*> _20, std::string s)
TemplateWithIndexer<const char*> _20, VirtualDependentValueFields<int> _21,
VirtualDependentValueFields<float> _22, VirtualDependentValueFields<const char*> _23,
std::string s)
{
}

25
tests/CSharp/CSharpTemplates.h

@ -543,6 +543,27 @@ T* VirtualTemplate<T>::function(T* t) @@ -543,6 +543,27 @@ T* VirtualTemplate<T>::function(T* t)
return t;
}
template <typename T>
class VirtualDependentValueFields
{
public:
VirtualDependentValueFields();
virtual ~VirtualDependentValueFields();
private:
T t;
};
template <typename T>
VirtualDependentValueFields<T>::VirtualDependentValueFields()
{
}
template <typename T>
VirtualDependentValueFields<T>::~VirtualDependentValueFields()
{
}
class DLL_API HasVirtualTemplate
{
public:
@ -768,7 +789,9 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> @@ -768,7 +789,9 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool>
IndependentFields<OnlySpecialisedInTypeArg<double>> _15,
DependentPointerFields<float> _16, IndependentFields<const T1&> _17,
TemplateWithIndexer<T2*> _18, IndependentFields<int(*)(int)> _19,
TemplateWithIndexer<const char*> _20, std::string s);
TemplateWithIndexer<const char*> _20, VirtualDependentValueFields<int> _21,
VirtualDependentValueFields<float> _22, VirtualDependentValueFields<const char*> _23,
std::string s);
void hasIgnoredParam(DependentValueFields<IndependentFields<Ignored>> ii);

Loading…
Cancel
Save