Browse Source

Generate valid C# for types nested in external typedef-ed specializations

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1635/head
Dimitar Dobrev 4 years ago
parent
commit
9c52adae09
  1. 28
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  2. 9
      tests/NamespacesBase/NamespacesBase.h
  3. 2
      tests/NamespacesDerived/NamespacesDerived.Tests.cs
  4. 18
      tests/NamespacesDerived/NamespacesDerived.cpp
  5. 10
      tests/NamespacesDerived/NamespacesDerived.h

28
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -532,30 +532,22 @@ namespace CppSharp.Generators.CSharp
return ret; return ret;
} }
string GetName(Declaration decl) private string GetName(Declaration decl)
{ {
var names = new Stack<string>(); var names = new Stack<string>();
Declaration ctx; Declaration ctx = decl;
if (decl is ClassTemplateSpecialization specialization) if (decl is ClassTemplateSpecialization specialization &&
ContextKind == TypePrinterContextKind.Native &&
specialization.OriginalNamespace is Class &&
!(specialization.OriginalNamespace is ClassTemplateSpecialization))
{ {
ctx = specialization.TemplatedDecl.TemplatedClass.Namespace; names.Push(string.Format("{0}_{1}", decl.OriginalNamespace.Name, decl.Name));
if (ContextKind == TypePrinterContextKind.Native && ctx = ctx.Namespace ?? ctx;
specialization.OriginalNamespace is Class &&
!(specialization.OriginalNamespace is ClassTemplateSpecialization))
{
names.Push(string.Format("{0}_{1}", decl.OriginalNamespace.Name, decl.Name));
ctx = ctx.Namespace ?? ctx;
}
else
{
names.Push(decl.Name);
}
} }
else else
{ {
names.Push(decl.Name); names.Push(decl.Name);
ctx = decl.Namespace;
} }
if (decl is Variable && !(decl.Namespace is Class)) if (decl is Variable && !(decl.Namespace is Class))
@ -563,9 +555,11 @@ namespace CppSharp.Generators.CSharp
while (!(ctx is TranslationUnit)) while (!(ctx is TranslationUnit))
{ {
AddContextName(names, ctx); if (ctx is ClassTemplateSpecialization parentSpecialization)
ctx = parentSpecialization.TemplatedDecl.TemplatedDecl;
ctx = ctx.Namespace; ctx = ctx.Namespace;
AddContextName(names, ctx);
} }
if (PrintModuleOutputNamespace) if (PrintModuleOutputNamespace)

9
tests/NamespacesBase/NamespacesBase.h

@ -79,10 +79,14 @@ template <typename T>
class TemplateWithIndependentFields class TemplateWithIndependentFields
{ {
public: public:
void useDependentPointer(const T* t); class Nested
{
};
Nested useDependentPointer(const T* t);
const T& constField() const; const T& constField() const;
private: private:
T* t = new T; T* t = new T;
Nested nested;
}; };
template <typename T> template <typename T>
@ -92,8 +96,9 @@ const T& TemplateWithIndependentFields<T>::constField() const
} }
template <typename T> template <typename T>
void TemplateWithIndependentFields<T>::useDependentPointer(const T* t) typename TemplateWithIndependentFields<T>::Nested TemplateWithIndependentFields<T>::useDependentPointer(const T* t)
{ {
return Nested();
} }
class DLL_API HasVirtualInCore class DLL_API HasVirtualInCore

2
tests/NamespacesDerived/NamespacesDerived.Tests.cs

@ -14,7 +14,7 @@ public class NamespaceDerivedTests
{ {
using (new DerivedFromSecondaryBaseInDependency()) { } using (new DerivedFromSecondaryBaseInDependency()) { }
using (var der2 = new Derived2()) using (var der2 = new Derived2())
using (der2.ExplicitExternalSpecialization) { } using (der2.LocalTypedefSpecialization) { }
} }
[Test] [Test]

18
tests/NamespacesDerived/NamespacesDerived.cpp

@ -70,9 +70,9 @@ TemplateClass<int> Derived2::getTemplate()
return t; return t;
} }
TemplateWithIndependentFields<int> Derived2::getExplicitExternalSpecialization() Derived2::LocalTypedefSpecialization Derived2::getLocalTypedefSpecialization()
{ {
return TemplateWithIndependentFields<int>(); return LocalTypedefSpecialization();
} }
Abstract* Derived2::getAbstract() Abstract* Derived2::getAbstract()
@ -116,6 +116,20 @@ bool operator<<(const Base& b, const char* str)
return false; return false;
} }
const char* TestComments::GetIOHandlerControlSequence(char ch)
{
return 0;
}
int TestComments::SBAttachInfo(const char* path, bool wait_for)
{
return 0;
}
void TestComments::glfwDestroyWindow(int *window)
{
}
void forceUseSpecializations(ForwardedInIndependentHeader value) void forceUseSpecializations(ForwardedInIndependentHeader value)
{ {
} }

10
tests/NamespacesDerived/NamespacesDerived.h

@ -45,11 +45,6 @@ class Base3
template <typename T> class TemplateClass; template <typename T> class TemplateClass;
template<>
class DLL_API TemplateWithIndependentFields<int>
{
};
class DLL_API Derived2 : public Base3 class DLL_API Derived2 : public Base3
{ {
public: public:
@ -65,7 +60,8 @@ public:
void defaultEnumValueFromDependency(OverlappingNamespace::ColorsEnum c = OverlappingNamespace::ColorsEnum::black); void defaultEnumValueFromDependency(OverlappingNamespace::ColorsEnum c = OverlappingNamespace::ColorsEnum::black);
TemplateClass<int> getTemplate(); TemplateClass<int> getTemplate();
TemplateWithIndependentFields<int> getExplicitExternalSpecialization(); typedef TemplateWithIndependentFields<int> LocalTypedefSpecialization;
LocalTypedefSpecialization getLocalTypedefSpecialization();
Abstract* getAbstract(); Abstract* getAbstract();
private: private:
TemplateClass<int> t; TemplateClass<int> t;
@ -112,7 +108,7 @@ namespace NamespacesBase
/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor /** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
and therefore %HashBase pointers should never be used. and therefore %HashBase pointers should never be used.
*/ */
class TestComments class DLL_API TestComments
{ {
public: public:
//---------------------------------------------------------------------- //----------------------------------------------------------------------

Loading…
Cancel
Save