Browse Source

Fixed the generated code when specialising types represented the same way in C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/661/head
Dimitar Dobrev 9 years ago
parent
commit
00441bb300
  1. 11
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 2
      src/Generator/Passes/DelegatesPass.cs
  3. 3
      tests/Common/Common.h

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

@ -67,9 +67,10 @@ namespace CppSharp.Generators.CSharp
} }
} }
public static StringBuilder FormatTypesStringForIdentifier(StringBuilder types) public static string FormatTypesStringForIdentifier(StringBuilder types)
{ {
return types.Replace("global::System.", string.Empty).Replace("*", "Ptr").Replace('.', '_'); return types.Replace("global::System.", string.Empty).Replace("*", "Ptr")
.Replace('.', '_').Replace(' ', '_').Replace("::", "_").ToString();
} }
public static string GetSuffixForInternal(ClassTemplateSpecialization specialization, public static string GetSuffixForInternal(ClassTemplateSpecialization specialization,
@ -90,6 +91,7 @@ namespace CppSharp.Generators.CSharp
typePrinter.PushContext(CSharpTypePrinterContextKind.Managed); typePrinter.PushContext(CSharpTypePrinterContextKind.Managed);
typePrinter.PushMarshalKind(CSharpMarshalKind.Unknown); typePrinter.PushMarshalKind(CSharpMarshalKind.Unknown);
} }
var cppTypePrinter = new CppTypePrinter(false) { PrintScopeKind = CppTypePrintScopeKind.Qualified };
CSharpTypePrinter.AppendGlobal = false; CSharpTypePrinter.AppendGlobal = false;
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
@ -119,7 +121,7 @@ namespace CppSharp.Generators.CSharp
continue; continue;
} }
} }
suffix.Append(argType); suffix.Append(argType.Visit(cppTypePrinter));
} }
if (!nested) if (!nested)
{ {
@ -127,8 +129,7 @@ namespace CppSharp.Generators.CSharp
typePrinter.PopMarshalKind(); typePrinter.PopMarshalKind();
} }
CSharpTypePrinter.AppendGlobal = true; CSharpTypePrinter.AppendGlobal = true;
FormatTypesStringForIdentifier(suffix); return FormatTypesStringForIdentifier(suffix);
return suffix.ToString();
} }
} }

2
src/Generator/Passes/DelegatesPass.cs

@ -179,7 +179,7 @@ namespace CppSharp.Passes
} }
if (typesBuilder.Length > 0) if (typesBuilder.Length > 0)
typesBuilder.Remove(typesBuilder.Length - 1, 1); typesBuilder.Remove(typesBuilder.Length - 1, 1);
var delegateName = Helpers.FormatTypesStringForIdentifier(typesBuilder).ToString(); var delegateName = Helpers.FormatTypesStringForIdentifier(typesBuilder);
if (returnType.Type.IsPrimitiveType(PrimitiveType.Void)) if (returnType.Type.IsPrimitiveType(PrimitiveType.Void))
delegateName = "Action_" + delegateName; delegateName = "Action_" + delegateName;
else else

3
tests/Common/Common.h

@ -1131,6 +1131,9 @@ class UsesSpecialisationOfVoid
private: private:
SpecialisesVoid<void>* s; SpecialisesVoid<void>* s;
SpecialisesVoidInUnion<void>* h; SpecialisesVoidInUnion<void>* h;
SpecialisesVoid<int> i;
SpecialisesVoid<long> l;
SpecialisesVoid<unsigned int> u;
}; };
class DLL_API HasAbstractOperator class DLL_API HasAbstractOperator

Loading…
Cancel
Save