Browse Source

Merge pull request #49 from ddobrev/master

Extended the check for duplicate names to ignore repeated operators since they cannot be renamed
pull/50/head
João Matos 12 years ago
parent
commit
e0585a32cc
  1. 17
      src/Generator/Passes/CheckDuplicatedNamesPass.cs
  2. 9
      tests/Basic/Basic.Tests.cs
  3. 14
      tests/Basic/Basic.cpp
  4. 3
      tests/Basic/Basic.h

17
src/Generator/Passes/CheckDuplicatedNamesPass.cs

@ -8,12 +8,14 @@ namespace CppSharp.Passes @@ -8,12 +8,14 @@ namespace CppSharp.Passes
{
class DeclarationName
{
public Driver Driver { get; set; }
private readonly string Name;
private readonly Dictionary<string, int> methodSignatures;
private int Count;
public DeclarationName(string name)
public DeclarationName(string name, Driver driver)
{
Driver = driver;
Name = name;
methodSignatures = new Dictionary<string, int>();
}
@ -37,7 +39,7 @@ namespace CppSharp.Passes @@ -37,7 +39,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 +59,14 @@ namespace CppSharp.Passes @@ -57,7 +59,14 @@ 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
Driver.Diagnostics.EmitWarning("Duplicate operator {0} ignored", method.Name);
method.ExplicityIgnored = true;
}
else
method.Name += methodCount.ToString(CultureInfo.InvariantCulture);
return true;
}
}
@ -132,7 +141,7 @@ namespace CppSharp.Passes @@ -132,7 +141,7 @@ namespace CppSharp.Passes
// If the name is not yet on the map, then add it.
if (!names.ContainsKey(fullName))
names.Add(fullName, new DeclarationName(decl.Name));
names.Add(fullName, new DeclarationName(decl.Name, Driver));
if (names[fullName].UpdateName(decl))
Driver.Diagnostics.EmitWarning("Duplicate name {0}, renamed to {1}", fullName, decl.Name);

9
tests/Basic/Basic.Tests.cs

@ -61,5 +61,14 @@ public class BasicTests @@ -61,5 +61,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));
}
}

14
tests/Basic/Basic.cpp

@ -4,6 +4,20 @@ Foo::Foo() @@ -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()
{
}

3
tests/Basic/Basic.h

@ -22,6 +22,9 @@ class DLL_API Foo2 : public Foo @@ -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

Loading…
Cancel
Save