Skip to content

Commit 9c52ada

Browse files
committed
Generate valid C# for types nested in external typedef-ed specializations
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent f5bed32 commit 9c52ada

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

src/Generator/Generators/CSharp/CSharpTypePrinter.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -532,40 +532,34 @@ public override TypePrinterResult VisitParameterDecl(Parameter parameter)
532532
return ret;
533533
}
534534

535-
string GetName(Declaration decl)
535+
private string GetName(Declaration decl)
536536
{
537537
var names = new Stack<string>();
538538

539-
Declaration ctx;
540-
if (decl is ClassTemplateSpecialization specialization)
539+
Declaration ctx = decl;
540+
if (decl is ClassTemplateSpecialization specialization &&
541+
ContextKind == TypePrinterContextKind.Native &&
542+
specialization.OriginalNamespace is Class &&
543+
!(specialization.OriginalNamespace is ClassTemplateSpecialization))
541544
{
542-
ctx = specialization.TemplatedDecl.TemplatedClass.Namespace;
543-
if (ContextKind == TypePrinterContextKind.Native &&
544-
specialization.OriginalNamespace is Class &&
545-
!(specialization.OriginalNamespace is ClassTemplateSpecialization))
546-
{
547-
names.Push(string.Format("{0}_{1}", decl.OriginalNamespace.Name, decl.Name));
548-
ctx = ctx.Namespace ?? ctx;
549-
}
550-
else
551-
{
552-
names.Push(decl.Name);
553-
}
545+
names.Push(string.Format("{0}_{1}", decl.OriginalNamespace.Name, decl.Name));
546+
ctx = ctx.Namespace ?? ctx;
554547
}
555548
else
556549
{
557550
names.Push(decl.Name);
558-
ctx = decl.Namespace;
559551
}
560552

561553
if (decl is Variable && !(decl.Namespace is Class))
562554
names.Push(decl.TranslationUnit.FileNameWithoutExtension);
563555

564556
while (!(ctx is TranslationUnit))
565557
{
566-
AddContextName(names, ctx);
558+
if (ctx is ClassTemplateSpecialization parentSpecialization)
559+
ctx = parentSpecialization.TemplatedDecl.TemplatedDecl;
567560

568561
ctx = ctx.Namespace;
562+
AddContextName(names, ctx);
569563
}
570564

571565
if (PrintModuleOutputNamespace)

tests/NamespacesBase/NamespacesBase.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ template <typename T>
7979
class TemplateWithIndependentFields
8080
{
8181
public:
82-
void useDependentPointer(const T* t);
82+
class Nested
83+
{
84+
};
85+
Nested useDependentPointer(const T* t);
8386
const T& constField() const;
8487
private:
8588
T* t = new T;
89+
Nested nested;
8690
};
8791

8892
template <typename T>
@@ -92,8 +96,9 @@ const T& TemplateWithIndependentFields<T>::constField() const
9296
}
9397

9498
template <typename T>
95-
void TemplateWithIndependentFields<T>::useDependentPointer(const T* t)
99+
typename TemplateWithIndependentFields<T>::Nested TemplateWithIndependentFields<T>::useDependentPointer(const T* t)
96100
{
101+
return Nested();
97102
}
98103

99104
class DLL_API HasVirtualInCore

tests/NamespacesDerived/NamespacesDerived.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void TestCodeGeneration()
1414
{
1515
using (new DerivedFromSecondaryBaseInDependency()) { }
1616
using (var der2 = new Derived2())
17-
using (der2.ExplicitExternalSpecialization) { }
17+
using (der2.LocalTypedefSpecialization) { }
1818
}
1919

2020
[Test]

tests/NamespacesDerived/NamespacesDerived.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ TemplateClass<int> Derived2::getTemplate()
7070
return t;
7171
}
7272

73-
TemplateWithIndependentFields<int> Derived2::getExplicitExternalSpecialization()
73+
Derived2::LocalTypedefSpecialization Derived2::getLocalTypedefSpecialization()
7474
{
75-
return TemplateWithIndependentFields<int>();
75+
return LocalTypedefSpecialization();
7676
}
7777

7878
Abstract* Derived2::getAbstract()
@@ -116,6 +116,20 @@ bool operator<<(const Base& b, const char* str)
116116
return false;
117117
}
118118

119+
const char* TestComments::GetIOHandlerControlSequence(char ch)
120+
{
121+
return 0;
122+
}
123+
124+
int TestComments::SBAttachInfo(const char* path, bool wait_for)
125+
{
126+
return 0;
127+
}
128+
129+
void TestComments::glfwDestroyWindow(int *window)
130+
{
131+
}
132+
119133
void forceUseSpecializations(ForwardedInIndependentHeader value)
120134
{
121135
}

tests/NamespacesDerived/NamespacesDerived.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class Base3
4545

4646
template <typename T> class TemplateClass;
4747

48-
template<>
49-
class DLL_API TemplateWithIndependentFields<int>
50-
{
51-
};
52-
5348
class DLL_API Derived2 : public Base3
5449
{
5550
public:
@@ -65,7 +60,8 @@ class DLL_API Derived2 : public Base3
6560
void defaultEnumValueFromDependency(OverlappingNamespace::ColorsEnum c = OverlappingNamespace::ColorsEnum::black);
6661

6762
TemplateClass<int> getTemplate();
68-
TemplateWithIndependentFields<int> getExplicitExternalSpecialization();
63+
typedef TemplateWithIndependentFields<int> LocalTypedefSpecialization;
64+
LocalTypedefSpecialization getLocalTypedefSpecialization();
6965
Abstract* getAbstract();
7066
private:
7167
TemplateClass<int> t;
@@ -112,7 +108,7 @@ namespace NamespacesBase
112108
/** Note that to prevent extra memory use due to vtable pointer, %HashBase intentionally does not declare a virtual destructor
113109
and therefore %HashBase pointers should never be used.
114110
*/
115-
class TestComments
111+
class DLL_API TestComments
116112
{
117113
public:
118114
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)