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

9
tests/NamespacesBase/NamespacesBase.h

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

2
tests/NamespacesDerived/NamespacesDerived.Tests.cs

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

18
tests/NamespacesDerived/NamespacesDerived.cpp

@ -70,9 +70,9 @@ TemplateClass<int> Derived2::getTemplate() @@ -70,9 +70,9 @@ TemplateClass<int> Derived2::getTemplate()
return t;
}
TemplateWithIndependentFields<int> Derived2::getExplicitExternalSpecialization()
Derived2::LocalTypedefSpecialization Derived2::getLocalTypedefSpecialization()
{
return TemplateWithIndependentFields<int>();
return LocalTypedefSpecialization();
}
Abstract* Derived2::getAbstract()
@ -116,6 +116,20 @@ bool operator<<(const Base& b, const char* str) @@ -116,6 +116,20 @@ bool operator<<(const Base& b, const char* str)
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)
{
}

10
tests/NamespacesDerived/NamespacesDerived.h

@ -45,11 +45,6 @@ class Base3 @@ -45,11 +45,6 @@ class Base3
template <typename T> class TemplateClass;
template<>
class DLL_API TemplateWithIndependentFields<int>
{
};
class DLL_API Derived2 : public Base3
{
public:
@ -65,7 +60,8 @@ public: @@ -65,7 +60,8 @@ public:
void defaultEnumValueFromDependency(OverlappingNamespace::ColorsEnum c = OverlappingNamespace::ColorsEnum::black);
TemplateClass<int> getTemplate();
TemplateWithIndependentFields<int> getExplicitExternalSpecialization();
typedef TemplateWithIndependentFields<int> LocalTypedefSpecialization;
LocalTypedefSpecialization getLocalTypedefSpecialization();
Abstract* getAbstract();
private:
TemplateClass<int> t;
@ -112,7 +108,7 @@ namespace NamespacesBase @@ -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
and therefore %HashBase pointers should never be used.
*/
class TestComments
class DLL_API TestComments
{
public:
//----------------------------------------------------------------------

Loading…
Cancel
Save