Browse Source

Merge pull request #253 from azeno/const-method-overload-fix

Const method overload fix
pull/254/merge
João Matos 11 years ago
parent
commit
128d70a849
  1. 31
      src/Generator.Tests/Passes/TestPasses.cs
  2. 4
      src/Generator/Passes/CheckAmbiguousFunctions.cs
  3. 9
      tests/Native/Passes.h

31
src/Generator.Tests/Passes/TestPasses.cs

@ -1,6 +1,7 @@
using System.Linq; using System.Linq;
using CppSharp; using CppSharp;
using CppSharp.Passes; using CppSharp.Passes;
using CppSharp.AST;
using NUnit.Framework; using NUnit.Framework;
namespace CppSharp.Generator.Tests.Passes namespace CppSharp.Generator.Tests.Passes
@ -158,5 +159,35 @@ namespace CppSharp.Generator.Tests.Passes
Assert.IsFalse(AstContext.FindClass(className).First().Properties.Find( Assert.IsFalse(AstContext.FindClass(className).First().Properties.Find(
m => m.Name == "ReadOnlyPropertyMethod").HasSetter); m => m.Name == "ReadOnlyPropertyMethod").HasSetter);
} }
[Test]
public void TestCheckAmbiguousFunctionsPass()
{
passBuilder.AddPass(new CheckAmbiguousFunctions());
passBuilder.RunPasses(pass => pass.VisitLibrary(AstContext));
var @class = AstContext.FindClass("TestCheckAmbiguousFunctionsPass").FirstOrDefault();
Assert.IsNotNull(@class);
var overloads = @class.Methods.Where(m => m.Name == "Method");
var constMethod = overloads
.Where(m => m.IsConst && m.Parameters.Count == 0)
.FirstOrDefault();
var nonConstMethod = overloads
.Where(m => !m.IsConst && m.Parameters.Count == 0)
.FirstOrDefault();
Assert.IsNotNull(constMethod);
Assert.IsNotNull(nonConstMethod);
Assert.IsTrue(constMethod.GenerationKind == GenerationKind.None);
Assert.IsTrue(nonConstMethod.GenerationKind == GenerationKind.Generate);
var constMethodWithParam = overloads
.Where(m => m.IsConst && m.Parameters.Count == 1)
.FirstOrDefault();
var nonConstMethodWithParam = overloads
.Where(m => !m.IsConst && m.Parameters.Count == 1)
.FirstOrDefault();
Assert.IsNotNull(constMethodWithParam);
Assert.IsNotNull(nonConstMethodWithParam);
Assert.IsTrue(constMethodWithParam.GenerationKind == GenerationKind.None);
Assert.IsTrue(nonConstMethodWithParam.GenerationKind == GenerationKind.Generate);
}
} }
} }

4
src/Generator/Passes/CheckAmbiguousFunctions.cs

@ -44,10 +44,10 @@ namespace CppSharp.Passes
if (!overload.IsGenerated) continue; if (!overload.IsGenerated) continue;
if (!CheckDefaultParameters(function, overload)) if (!CheckConstness(function, overload))
continue; continue;
if (!CheckConstness(function, overload)) if (!CheckDefaultParameters(function, overload))
continue; continue;
function.IsAmbiguous = true; function.IsAmbiguous = true;

9
tests/Native/Passes.h

@ -52,3 +52,12 @@ enum
UnnamedEnumB1, UnnamedEnumB1,
EnumUnnamedB2 EnumUnnamedB2
}; };
struct TestCheckAmbiguousFunctionsPass
{
// Tests removal of const method overloads
int Method();
int Method() const;
int Method(int x);
int Method(int x) const;
};

Loading…
Cancel
Save