Browse Source

Fixed the generated C# for templates derived from regular dynamic classes.

Fixes https://github.com/mono/CppSharp/issues/967.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/980/head
Dimitar Dobrev 8 years ago
parent
commit
764806e759
  1. 2
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 9
      tests/CSharp/CSharp.Tests.cs
  3. 19
      tests/CSharp/CSharpTemplates.cpp
  4. 29
      tests/CSharp/CSharpTemplates.h

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

@ -1379,7 +1379,7 @@ namespace CppSharp.Generators.CSharp @@ -1379,7 +1379,7 @@ namespace CppSharp.Generators.CSharp
// Generate a delegate type for each method.
foreach (var method in wrappedEntries.Select(e => e.Method))
GenerateVTableMethodDelegates(containingClass, containingClass.IsDependent ?
GenerateVTableMethodDelegates(containingClass, method.Namespace.IsDependent ?
(Method) method.InstantiatedFrom : method);
WriteLine("private static void*[] __ManagedVTables;");

9
tests/CSharp/CSharp.Tests.cs

@ -841,6 +841,15 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -841,6 +841,15 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
}
[Test]
public void TestTemplateDerivedFromRegularDynamic()
{
using (var templateDerivedFromRegularDynamic = new TemplateDerivedFromRegularDynamic<RegularDynamic>())
{
templateDerivedFromRegularDynamic.VirtualFunction();
}
}
[Test]
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
{

19
tests/CSharp/CSharpTemplates.cpp

@ -108,9 +108,24 @@ void TemplateSpecializer::completeSpecializationInParameter(TwoTemplateArgs<int @@ -108,9 +108,24 @@ void TemplateSpecializer::completeSpecializationInParameter(TwoTemplateArgs<int
{
}
RegularDynamic::RegularDynamic()
{
}
RegularDynamic::~RegularDynamic()
{
}
void RegularDynamic::virtualFunction()
{
}
void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> _2,
IndependentFields<T1> _3, IndependentFields<std::string> _4,
VirtualTemplate<int> _5, VirtualTemplate<bool> _6,
HasDefaultTemplateArgument<int, int> _7, std::string s)
DependentValueFields<int> _5,
VirtualTemplate<int> _6, VirtualTemplate<bool> _7,
HasDefaultTemplateArgument<int, int> _8, DerivedChangesTypeName<T1> _9,
TemplateWithIndexer<int> _10, TemplateWithIndexer<T1> _11,
TemplateWithIndexer<T2*> _12, TemplateDerivedFromRegularDynamic<RegularDynamic> _13, std::string s)
{
}

29
tests/CSharp/CSharpTemplates.h

@ -449,6 +449,32 @@ struct MapResultType<InputSequence<T>, MapFunctor> @@ -449,6 +449,32 @@ struct MapResultType<InputSequence<T>, MapFunctor>
typedef InputSequence<typename LazyResultType<MapFunctor>::Type> ResultType;
};
class RegularDynamic
{
public:
RegularDynamic();
~RegularDynamic();
virtual void virtualFunction();
};
template<typename T>
class TemplateDerivedFromRegularDynamic : public RegularDynamic
{
public:
TemplateDerivedFromRegularDynamic();
~TemplateDerivedFromRegularDynamic();
};
template<typename T>
TemplateDerivedFromRegularDynamic<T>::TemplateDerivedFromRegularDynamic()
{
}
template<typename T>
TemplateDerivedFromRegularDynamic<T>::~TemplateDerivedFromRegularDynamic()
{
}
// we optimise specialisations so that only actually used ones are wrapped
void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> _2,
IndependentFields<T1> _3, IndependentFields<std::string> _4,
@ -456,7 +482,7 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool> @@ -456,7 +482,7 @@ void forceUseSpecializations(IndependentFields<int> _1, IndependentFields<bool>
VirtualTemplate<int> _6, VirtualTemplate<bool> _7,
HasDefaultTemplateArgument<int, int> _8, DerivedChangesTypeName<T1> _9,
TemplateWithIndexer<int> _10, TemplateWithIndexer<T1> _11,
TemplateWithIndexer<T2*> _12, std::string s);
TemplateWithIndexer<T2*> _12, TemplateDerivedFromRegularDynamic<RegularDynamic> _13, std::string s);
// force the symbols for the template instantiations because we do not have the auto-compilation for the generated C++ source
template class DLL_API IndependentFields<int>;
@ -472,6 +498,7 @@ template class DLL_API DerivedChangesTypeName<T1>; @@ -472,6 +498,7 @@ template class DLL_API DerivedChangesTypeName<T1>;
template class DLL_API TemplateWithIndexer<int>;
template class DLL_API TemplateWithIndexer<T1>;
template class DLL_API TemplateWithIndexer<T2*>;
template class DLL_API TemplateDerivedFromRegularDynamic<RegularDynamic>;
class TestForwardedClassInAnotherUnit;

Loading…
Cancel
Save