Browse Source

Handled nested template specialisations with fields of the place-holder type.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/658/head
Dimitar Dobrev 9 years ago
parent
commit
eb748db73b
  1. 43
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 5
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  3. 2
      tests/CSharp/CSharp.Tests.cs
  4. 2
      tests/CSharp/CSharpTemplates.h

43
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -73,10 +73,11 @@ namespace CppSharp.Generators.CSharp
} }
public static string GetSuffixForInternal(ClassTemplateSpecialization specialization, public static string GetSuffixForInternal(ClassTemplateSpecialization specialization,
CSharpTypePrinter typePrinter) CSharpTypePrinter typePrinter, bool nested = false)
{ {
if (specialization.TemplatedDecl.TemplatedClass.Fields.All( if (!nested &&
f => !f.IsDependent || f.Type.IsAddress())) specialization.TemplatedDecl.TemplatedClass.Fields.All(
f => !f.IsDependent || f.Type.IsAddress()))
return string.Empty; return string.Empty;
if (specialization.Arguments.All( if (specialization.Arguments.All(
@ -84,18 +85,44 @@ namespace CppSharp.Generators.CSharp
return "_Ptr"; return "_Ptr";
// we don't want internals in the names of internals :) // we don't want internals in the names of internals :)
typePrinter.PushContext(CSharpTypePrinterContextKind.Managed); if (!nested)
typePrinter.PushMarshalKind(CSharpMarshalKind.Unknown); {
typePrinter.PushContext(CSharpTypePrinterContextKind.Managed);
typePrinter.PushMarshalKind(CSharpMarshalKind.Unknown);
}
var suffix = new StringBuilder(); var suffix = new StringBuilder();
foreach (var argType in from argType in specialization.Arguments foreach (var argType in from argType in specialization.Arguments
where argType.Type.Type != null where argType.Type.Type != null
select argType.Type.ToString()) select argType.Type.Type)
{ {
suffix.Append('_'); suffix.Append('_');
ClassTemplateSpecialization nestedSpecialization;
if (argType.TryGetDeclaration(out nestedSpecialization))
{
suffix.Append(typePrinter.GetNestedQualifiedName(nestedSpecialization));
suffix.Append(GetSuffixForInternal(nestedSpecialization, typePrinter, true));
continue;
}
Class @class;
if (argType.TryGetClass(out @class))
{
nestedSpecialization = @class.Namespace as ClassTemplateSpecialization;
if (nestedSpecialization != null)
{
suffix.Append(typePrinter.GetNestedQualifiedName(nestedSpecialization));
suffix.Append(GetSuffixForInternal(nestedSpecialization, typePrinter, true));
suffix.Append('_');
suffix.Append(@class.Name);
continue;
}
}
suffix.Append(argType); suffix.Append(argType);
} }
typePrinter.PopContext(); if (!nested)
typePrinter.PopMarshalKind(); {
typePrinter.PopContext();
typePrinter.PopMarshalKind();
}
FormatTypesStringForIdentifier(suffix); FormatTypesStringForIdentifier(suffix);
return suffix.ToString(); return suffix.ToString();
} }

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

@ -611,6 +611,11 @@ namespace CppSharp.Generators.CSharp
return GetNestedQualifiedName(@enum); return GetNestedQualifiedName(@enum);
} }
public string GetNestedQualifiedName(ClassTemplateSpecialization decl)
{
return GetNestedQualifiedName(decl.Namespace, decl);
}
private string GetNestedQualifiedName(Declaration decl) private string GetNestedQualifiedName(Declaration decl)
{ {
return GetNestedQualifiedName(decl.Namespace, decl); return GetNestedQualifiedName(decl.Namespace, decl);

2
tests/CSharp/CSharp.Tests.cs

@ -514,7 +514,7 @@ public class CSharpTests : GeneratorTestFixture
typeof(CSharp.DependentValueFields.Internal_float), typeof(CSharp.DependentValueFields.Internal_float),
typeof(CSharp.DependentPointerFields.Internal), typeof(CSharp.DependentPointerFields.Internal),
typeof(CSharp.DependentValueFields.Internal_Ptr), typeof(CSharp.DependentValueFields.Internal_Ptr),
typeof(CSharp.HasDefaultTemplateArgument.Internal_int_IndependentFields) typeof(CSharp.HasDefaultTemplateArgument.Internal_int_IndependentFields_int)
}) })
{ {
var independentFields = internalType.GetFields(); var independentFields = internalType.GetFields();

2
tests/CSharp/CSharpTemplates.h

@ -57,6 +57,8 @@ private:
HasDefaultTemplateArgument<int> hasDefaultTemplateArgument; HasDefaultTemplateArgument<int> hasDefaultTemplateArgument;
DependentValueFields<T1> dependentPointerFieldsT1; DependentValueFields<T1> dependentPointerFieldsT1;
DependentValueFields<T2> dependentPointerFieldsT2; DependentValueFields<T2> dependentPointerFieldsT2;
DependentValueFields<IndependentFields<int>> specializeWithSpecialization;
DependentValueFields<IndependentFields<bool>> specializeWithSameSpecialization;
void completeSpecializationInParameter(DependentValueFields<float> p1, void completeSpecializationInParameter(DependentValueFields<float> p1,
DependentValueFields<int*> p2, DependentValueFields<int*> p2,
DependentValueFields<float*> p3); DependentValueFields<float*> p3);

Loading…
Cancel
Save