Browse Source

Fixed the parsing of subclasses of dynamic template instantiations.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/621/head
Dimitar Dobrev 10 years ago
parent
commit
9ab71aeac7
  1. 4
      src/Generator/AST/VTables.cs
  2. 30
      src/Generator/Passes/DelegatesPass.cs
  3. 3
      tests/Common/Common.Tests.cs
  4. 4
      tests/Common/Common.cpp
  5. 24
      tests/Common/Common.h

4
src/Generator/AST/VTables.cs

@ -73,7 +73,9 @@ namespace CppSharp.AST @@ -73,7 +73,9 @@ namespace CppSharp.AST
return entry.Method != null &&
(entry.Method.IsOperator ||
(!entry.Method.IsDeclared &&
((Class) entry.Method.Namespace).GetPropertyByConstituentMethod(entry.Method) == null));
((Class) entry.Method.Namespace).GetPropertyByConstituentMethod(entry.Method) == null) ||
// virtuals defined in templates are not yet supported
entry.Method.Namespace is ClassTemplateSpecialization);
}
}
}

30
src/Generator/Passes/DelegatesPass.cs

@ -52,6 +52,36 @@ namespace CppSharp.Passes @@ -52,6 +52,36 @@ namespace CppSharp.Passes
return result;
}
public override bool VisitClassDecl(Class @class)
{
if (!base.VisitClassDecl(@class))
return false;
// dependent types with virtuals have no own virtual layouts
// so virtuals are considered different objects in template instantiations
// therefore the method itself won't be visited, so let's visit it through the v-table
if (Driver.Options.IsMicrosoftAbi)
{
foreach (var method in from vfTable in @class.Layout.VFTables
from component in vfTable.Layout.Components
where component.Method != null
select component.Method)
VisitMethodDecl(method);
}
else
{
if (@class.Layout.Layout == null)
return false;
foreach (var method in from component in @class.Layout.Layout.Components
where component.Method != null
select component.Method)
VisitMethodDecl(method);
}
return true;
}
public override bool VisitMethodDecl(Method method)
{
if (!base.VisitMethodDecl(method) || !method.IsVirtual || method.Ignore)

3
tests/Common/Common.Tests.cs

@ -22,6 +22,9 @@ public class CommonTests : GeneratorTestFixture @@ -22,6 +22,9 @@ public class CommonTests : GeneratorTestFixture
{
Assert.That(overridesNonDirectVirtual.retInt(), Is.EqualTo(3));
}
using (var derivedFromTemplateInstantiationWithVirtual = new DerivedFromTemplateInstantiationWithVirtual())
{
}
}
[Test]

4
tests/Common/Common.cpp

@ -602,3 +602,7 @@ NonTrivialDtor::~NonTrivialDtor() @@ -602,3 +602,7 @@ NonTrivialDtor::~NonTrivialDtor()
{
dtorCalled = true;
}
DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual()
{
}

24
tests/Common/Common.h

@ -1019,3 +1019,27 @@ ForwardedTemplate<T> ForwardedTemplate<T>::functionInForwardedTemplate() const @@ -1019,3 +1019,27 @@ ForwardedTemplate<T> ForwardedTemplate<T>::functionInForwardedTemplate() const
{
return ForwardedTemplate<T>();
}
template <typename T>
class TemplateWithVirtual
{
public:
TemplateWithVirtual();
virtual void v();
};
template <class T>
TemplateWithVirtual<T>::TemplateWithVirtual()
{
}
template <class T>
void TemplateWithVirtual<T>::v()
{
}
class DLL_API DerivedFromTemplateInstantiationWithVirtual : public TemplateWithVirtual<int>
{
public:
DerivedFromTemplateInstantiationWithVirtual();
};

Loading…
Cancel
Save