From d9bc5bec86aceb005191a898d2f905fc98e9d9fa Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 23 Aug 2013 04:19:00 +0300 Subject: [PATCH] Extended the check for duplicate names to ignore repeated operators since they cannot be renamed. Added an ignored test for an unrelated run-time issue. Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/CheckDuplicatedNamesPass.cs | 8 ++++++-- tests/Basic/Basic.Tests.cs | 9 +++++++++ tests/Basic/Basic.cpp | 14 ++++++++++++++ tests/Basic/Basic.h | 3 +++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Generator/Passes/CheckDuplicatedNamesPass.cs b/src/Generator/Passes/CheckDuplicatedNamesPass.cs index 82fc9b09..474415a0 100644 --- a/src/Generator/Passes/CheckDuplicatedNamesPass.cs +++ b/src/Generator/Passes/CheckDuplicatedNamesPass.cs @@ -37,7 +37,7 @@ namespace CppSharp.Passes return true; } - private bool UpdateName(Method method) + private bool UpdateName(Function method) { var @params = method.Parameters.Where(p => p.Kind != ParameterKind.IndirectReturnType) .Select(p => p.QualifiedType.ToString()); @@ -57,7 +57,11 @@ namespace CppSharp.Passes if (Count < methodCount+1) Count = methodCount+1; - method.Name += methodCount.ToString(CultureInfo.InvariantCulture); + if (method.IsOperator) + // TODO: turn into a method; append the original type (say, "signed long") of the last parameter to the type so that the user knows which overload is called + method.ExplicityIgnored = true; + else + method.Name += methodCount.ToString(CultureInfo.InvariantCulture); return true; } } diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs index e4aaf48e..aa5f1010 100644 --- a/tests/Basic/Basic.Tests.cs +++ b/tests/Basic/Basic.Tests.cs @@ -52,5 +52,14 @@ public class BasicTests Assert.That(barSum.A, Is.EqualTo(bar.A + bar1.A)); Assert.That(barSum.B, Is.EqualTo(bar.B + bar1.B)); } + + [Test, Ignore] + public void TestLeftShiftOperator() + { + Foo2 foo2 = new Foo2(); + foo2.C = 2; + Foo2 result = foo2 << 3; + Assert.That(result.C, Is.EqualTo(16)); + } } \ No newline at end of file diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index 1744ff77..438130ef 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -4,6 +4,20 @@ Foo::Foo() { } +Foo2& Foo2::operator <<(signed int i) +{ + Foo2 foo; + foo.C = C << i; + return foo; +} + +Foo2& Foo2::operator <<(signed long l) +{ + Foo2 foo; + foo.C = C << l; + return foo; +} + Bar::Bar() { } diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 7c4ae134..e40768e6 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -22,6 +22,9 @@ class DLL_API Foo2 : public Foo public: int C; + + Foo2& operator<<(signed int i); + Foo2& operator<<(signed long l); }; struct DLL_API Bar