Skip to content

Commit a119bdb

Browse files
committed
Fixed the generated C# for subclasses of specialisations used as secondary bases.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent cb6d2ae commit a119bdb

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ private void GenerateDisposeMethods(Class @class)
19791979
{
19801980
var @base = @class.GetNonIgnoredRootBase();
19811981

1982-
// Use interfaces if any - derived types with a this class as a seconary base, must be compatible with the map
1982+
// Use interfaces if any - derived types with a this class as a secondary base, must be compatible with the map
19831983
var @interface = @base.Namespace.Classes.FirstOrDefault(
19841984
c => c.IsInterface && c.OriginalClass == @base);
19851985

src/Generator/Passes/MultipleInheritancePass.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MultipleInheritancePass()
3030
public override bool VisitTranslationUnit(TranslationUnit unit)
3131
{
3232
bool result = base.VisitTranslationUnit(unit);
33-
foreach (var @interface in interfaces)
33+
foreach (var @interface in interfaces.Where(i => !(i.Key is ClassTemplateSpecialization)))
3434
@interface.Key.Namespace.Classes.Add(@interface.Value);
3535
interfaces.Clear();
3636
return result;
@@ -79,11 +79,9 @@ private Class GetNewInterface(string name, Class @base)
7979
else
8080
{
8181
Class template = specialization.TemplatedDecl.TemplatedClass;
82-
Class templatedInterface;
83-
if (templatedInterfaces.ContainsKey(template))
84-
templatedInterface = templatedInterfaces[template];
85-
else
86-
templatedInterfaces[template] = templatedInterface = GetInterface(template);
82+
Class templatedInterface = GetInterface(template);
83+
if (interfaces.ContainsKey(specialization))
84+
return interfaces[specialization];
8785
var specializedInterface = new ClassTemplateSpecialization();
8886
specializedInterface.Arguments.AddRange(specialization.Arguments);
8987
specializedInterface.TemplatedDecl = new ClassTemplate { TemplatedDecl = templatedInterface };
@@ -94,11 +92,6 @@ private Class GetNewInterface(string name, Class @base)
9492
@interface.Access = @base.Access;
9593
@interface.Type = ClassType.Interface;
9694
@interface.OriginalClass = @base;
97-
if (@base.IsTemplate)
98-
{
99-
@interface.IsDependent = true;
100-
@interface.TemplateParameters.AddRange(@base.TemplateParameters);
101-
}
10295

10396
@interface.Bases.AddRange(
10497
from b in @base.Bases
@@ -157,8 +150,15 @@ where property.IsDeclared
157150

158151
@base.Bases.Add(new BaseClassSpecifier { Type = new TagType(@interface) });
159152

160-
if (specialization == null)
161-
interfaces.Add(@base, @interface);
153+
interfaces.Add(@base, @interface);
154+
if (@base.IsTemplate)
155+
{
156+
@interface.IsDependent = true;
157+
@interface.TemplateParameters.AddRange(@base.TemplateParameters);
158+
templatedInterfaces[@base] = @interface;
159+
foreach (var spec in @base.Specializations)
160+
GetNewInterface(name, spec);
161+
}
162162
return @interface;
163163
}
164164

tests/CSharp/CSharpTemplates.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ int HasVirtualTemplate::function()
8787
return v->function();
8888
}
8989

90+
SpecializedInterfaceForMap::SpecializedInterfaceForMap()
91+
{
92+
}
93+
94+
SpecializedInterfaceForMap::~SpecializedInterfaceForMap()
95+
{
96+
}
97+
9098
HasSpecializationForSecondaryBase::HasSpecializationForSecondaryBase()
9199
{
92100
}

tests/CSharp/CSharpTemplates.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,14 @@ class DLL_API HasVirtualTemplate
432432
HasDefaultTemplateArgument<bool, bool> explicitSpecialization;
433433
};
434434

435-
class DLL_API HasSpecializationForSecondaryBase : T1, DependentValueFields<int>, IndependentFields<int>
435+
class DLL_API SpecializedInterfaceForMap : InternalWithExtension<char>
436+
{
437+
public:
438+
SpecializedInterfaceForMap();
439+
~SpecializedInterfaceForMap();
440+
};
441+
442+
class DLL_API HasSpecializationForSecondaryBase : T1, DependentValueFields<int>, IndependentFields<int>, InternalWithExtension<float>
436443
{
437444
public:
438445
HasSpecializationForSecondaryBase();
@@ -593,6 +600,7 @@ template class DLL_API TemplateWithIndexer<int>;
593600
template class DLL_API TemplateWithIndexer<UsedInTemplatedIndexer>;
594601
template class DLL_API TemplateWithIndexer<T1>;
595602
template class DLL_API TemplateWithIndexer<T2*>;
603+
template class DLL_API TemplateWithIndexer<float>;
596604
template class DLL_API TemplateDerivedFromRegularDynamic<RegularDynamic>;
597605

598606
class TestForwardedClassInAnotherUnit;

0 commit comments

Comments
 (0)