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

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

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

2
tests/CSharp/CSharp.Tests.cs

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

2
tests/CSharp/CSharpTemplates.h

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

Loading…
Cancel
Save