diff --git a/src/Generator/Passes/CheckDuplicatedNamesPass.cs b/src/Generator/Passes/CheckDuplicatedNamesPass.cs index 7b2f43d5..0d303e35 100644 --- a/src/Generator/Passes/CheckDuplicatedNamesPass.cs +++ b/src/Generator/Passes/CheckDuplicatedNamesPass.cs @@ -3,6 +3,9 @@ using System.Globalization; using System.Linq; using CppSharp.AST; using CppSharp.AST.Extensions; +using CppSharp.Generators; +using CppSharp.Generators.CLI; +using CppSharp.Generators.CSharp; namespace CppSharp.Passes { @@ -100,14 +103,10 @@ namespace CppSharp.Passes return signature; } - private class ParameterTypeComparer : IEqualityComparer + public class ParameterTypeComparer : IEqualityComparer { public static readonly ParameterTypeComparer Instance = new ParameterTypeComparer(); - private ParameterTypeComparer() - { - } - public bool Equals(Parameter x, Parameter y) { Type left = x.Type.Desugar(resolveTemplateSubstitution: false); @@ -115,17 +114,24 @@ namespace CppSharp.Passes if (left.Equals(right)) return true; - // TODO: some target languages might maek a difference between values and pointers + // TODO: some target languages might make a difference between values and pointers Type leftPointee = left.GetPointee(); Type rightPointee = right.GetPointee(); - return (leftPointee != null && leftPointee.Desugar(false).Equals(right)) || - (rightPointee != null && rightPointee.Desugar(false).Equals(left)); + if ((leftPointee != null && leftPointee.Desugar(false).Equals(right)) || + (rightPointee != null && rightPointee.Desugar(false).Equals(left))) + return true; + + return TypePrinter != null && + left.IsPrimitiveType() && right.IsPrimitiveType() && + left.Visit(TypePrinter).Type == right.Visit(TypePrinter).Type; } public int GetHashCode(Parameter obj) { return obj.Type.GetHashCode(); } + + public static TypePrinter TypePrinter { get; set; } } } @@ -139,6 +145,22 @@ namespace CppSharp.Passes names = new Dictionary(); } + public override bool VisitASTContext(ASTContext context) + { + TypePrinter typePrinter = null; + switch (Options.GeneratorKind) + { + case GeneratorKind.CLI: + typePrinter = new CLITypePrinter(Context); + break; + case GeneratorKind.CSharp: + typePrinter = new CSharpTypePrinter(Context); + break; + } + DeclarationName.ParameterTypeComparer.TypePrinter = typePrinter; + return base.VisitASTContext(context); + } + public override bool VisitProperty(Property decl) { if (!VisitDeclaration(decl)) diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 12d5995e..77bbb2f7 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -14,6 +14,14 @@ Foo::Foo(int a, int p) : publicFieldMappedToEnum(TestFlag::Flag2) P = p; } +Foo::Foo(char16_t ch) +{ +} + +Foo::Foo(wchar_t ch) +{ +} + int Foo::method() { return 1; diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index aa4f3b92..fddda755 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -13,6 +13,8 @@ class DLL_API Foo public: Foo(const char* name = 0); Foo(int a, int p = 0); + Foo(char16_t ch); + Foo(wchar_t ch); int method(); int operator[](int i) const; int operator[](unsigned int i);