Browse Source

Resolved ambiguity between char-like types in the generated C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1125/head
Dimitar Dobrev 7 years ago
parent
commit
3346be0084
  1. 38
      src/Generator/Passes/CheckDuplicatedNamesPass.cs
  2. 8
      tests/CSharp/CSharp.cpp
  3. 2
      tests/CSharp/CSharp.h

38
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -3,6 +3,9 @@ using System.Globalization;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.AST.Extensions; using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.CLI;
using CppSharp.Generators.CSharp;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {
@ -100,14 +103,10 @@ namespace CppSharp.Passes
return signature; return signature;
} }
private class ParameterTypeComparer : IEqualityComparer<Parameter> public class ParameterTypeComparer : IEqualityComparer<Parameter>
{ {
public static readonly ParameterTypeComparer Instance = new ParameterTypeComparer(); public static readonly ParameterTypeComparer Instance = new ParameterTypeComparer();
private ParameterTypeComparer()
{
}
public bool Equals(Parameter x, Parameter y) public bool Equals(Parameter x, Parameter y)
{ {
Type left = x.Type.Desugar(resolveTemplateSubstitution: false); Type left = x.Type.Desugar(resolveTemplateSubstitution: false);
@ -115,17 +114,24 @@ namespace CppSharp.Passes
if (left.Equals(right)) if (left.Equals(right))
return true; 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 leftPointee = left.GetPointee();
Type rightPointee = right.GetPointee(); Type rightPointee = right.GetPointee();
return (leftPointee != null && leftPointee.Desugar(false).Equals(right)) || if ((leftPointee != null && leftPointee.Desugar(false).Equals(right)) ||
(rightPointee != null && rightPointee.Desugar(false).Equals(left)); (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) public int GetHashCode(Parameter obj)
{ {
return obj.Type.GetHashCode(); return obj.Type.GetHashCode();
} }
public static TypePrinter TypePrinter { get; set; }
} }
} }
@ -139,6 +145,22 @@ namespace CppSharp.Passes
names = new Dictionary<string, DeclarationName>(); names = new Dictionary<string, DeclarationName>();
} }
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) public override bool VisitProperty(Property decl)
{ {
if (!VisitDeclaration(decl)) if (!VisitDeclaration(decl))

8
tests/CSharp/CSharp.cpp

@ -14,6 +14,14 @@ Foo::Foo(int a, int p) : publicFieldMappedToEnum(TestFlag::Flag2)
P = p; P = p;
} }
Foo::Foo(char16_t ch)
{
}
Foo::Foo(wchar_t ch)
{
}
int Foo::method() int Foo::method()
{ {
return 1; return 1;

2
tests/CSharp/CSharp.h

@ -13,6 +13,8 @@ class DLL_API Foo
public: public:
Foo(const char* name = 0); Foo(const char* name = 0);
Foo(int a, int p = 0); Foo(int a, int p = 0);
Foo(char16_t ch);
Foo(wchar_t ch);
int method(); int method();
int operator[](int i) const; int operator[](int i) const;
int operator[](unsigned int i); int operator[](unsigned int i);

Loading…
Cancel
Save