Browse Source

Fixed incorrect renaming of methods when there's a property with the same name in a dependency.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/512/head
Dimitar Dobrev 10 years ago
parent
commit
1c823fbf40
  1. 5
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  2. 16
      tests/NamespacesBase/NamespacesBase.cpp
  3. 5
      tests/NamespacesBase/NamespacesBase.cs
  4. 9
      tests/NamespacesBase/NamespacesBase.h
  5. 14
      tests/NamespacesDerived/NamespacesDerived.Tests.cs
  6. 20
      tests/NamespacesDerived/NamespacesDerived.cpp
  7. 6
      tests/NamespacesDerived/NamespacesDerived.cs
  8. 19
      tests/NamespacesDerived/NamespacesDerived.h

5
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -25,7 +25,8 @@ namespace CppSharp.Passes @@ -25,7 +25,8 @@ namespace CppSharp.Passes
{
this.log = log;
foreach (var method in @class.Methods.Where(
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator && m.IsGenerated))
m => !m.IsConstructor && !m.IsDestructor && !m.IsOperator &&
(m.IsGenerated || m.GenerationKind == GenerationKind.Link)))
DistributeMethod(method);
}
@ -36,7 +37,7 @@ namespace CppSharp.Passes @@ -36,7 +37,7 @@ namespace CppSharp.Passes
foreach (Method getter in
from getter in getters
where getter.IsGenerated &&
where (getter.IsGenerated || getter.GenerationKind == GenerationKind.Link) &&
((Class) getter.Namespace).Methods.All(m => m == getter || m.Ignore || m.Name != getter.Name)
select getter)
{

16
tests/NamespacesBase/NamespacesBase.cpp

@ -9,5 +9,21 @@ Base::Base(int i) @@ -9,5 +9,21 @@ Base::Base(int i)
Base::Base()
{
}
int Base::parent()
{
return 0;
}
Base2::Base2() : Base()
{
}
Base2::Base2(int i) : Base(i)
{
}
void Base2::parent(int i)
{
}

5
tests/NamespacesBase/NamespacesBase.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
using CppSharp.Utils;
namespace CppSharp.Tests
@ -15,6 +16,7 @@ namespace CppSharp.Tests @@ -15,6 +16,7 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GeneratePropertiesAdvanced = true;
}
public override void Preprocess(Driver driver, ASTContext ctx)
@ -23,6 +25,9 @@ namespace CppSharp.Tests @@ -23,6 +25,9 @@ namespace CppSharp.Tests
public override void Postprocess(Driver driver, ASTContext ctx)
{
new CaseRenamePass(
RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate | RenameTargets.Variable,
RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext);
}
}

9
tests/NamespacesBase/NamespacesBase.h

@ -28,11 +28,20 @@ class DLL_API Base @@ -28,11 +28,20 @@ class DLL_API Base
public:
Base(int i);
Base();
int parent();
private:
int b;
};
class DLL_API Base2 : public Base
{
public:
Base2(int i);
Base2();
virtual void parent(int i);
};
class DLL_API Abstract
{
public:

14
tests/NamespacesDerived/NamespacesDerived.Tests.cs

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
using NamespacesDerived;
using NUnit.Framework;
[TestFixture]
public class NamespaceDerivedTests
{
[Test]
public void TestNonRenamedMethod()
{
var derived = new Derived();
var parent = derived.Parent;
derived.parent(0);
}
}

20
tests/NamespacesDerived/NamespacesDerived.cpp

@ -5,7 +5,7 @@ OverlappingNamespace::InDerivedLib::InDerivedLib() : parentNSComponent(), color( @@ -5,7 +5,7 @@ OverlappingNamespace::InDerivedLib::InDerivedLib() : parentNSComponent(), color(
{
}
Derived::Derived() : Base(10), baseComponent(5), nestedNSComponent(), color(OverlappingNamespace::blue)
Derived::Derived() : Base2(10), baseComponent(5), nestedNSComponent(), color(OverlappingNamespace::blue)
{
}
@ -19,6 +19,10 @@ void Derived::setBase(Base b) @@ -19,6 +19,10 @@ void Derived::setBase(Base b)
baseComponent = b;
}
void Derived::parent(int i)
{
}
OverlappingNamespace::InBaseLib Derived::getNestedNSComponent()
{
return nestedNSComponent;
@ -29,22 +33,12 @@ void Derived::setNestedNSComponent(OverlappingNamespace::InBaseLib c) @@ -29,22 +33,12 @@ void Derived::setNestedNSComponent(OverlappingNamespace::InBaseLib c)
nestedNSComponent = c;
}
Base2::Base2()
{
}
Derived2::Derived2() : Base2()
{
}
Base2 Derived2::getBase()
Base3 Derived2::getBase()
{
return baseComponent;
}
void Derived2::setBase(Base2 b)
void Derived2::setBase(Base3 b)
{
baseComponent = b;
}

6
tests/NamespacesDerived/NamespacesDerived.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
using CppSharp.Utils;
namespace CppSharp.Tests
@ -15,6 +16,7 @@ namespace CppSharp.Tests @@ -15,6 +16,7 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.GenerateDefaultValuesForArguments = true;
driver.Options.GeneratePropertiesAdvanced = true;
}
public override void Preprocess(Driver driver, ASTContext ctx)
@ -30,8 +32,10 @@ namespace CppSharp.Tests @@ -30,8 +32,10 @@ namespace CppSharp.Tests
public override void Postprocess(Driver driver, ASTContext ctx)
{
new CaseRenamePass(
RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate | RenameTargets.Variable,
RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext);
}
}
public class NamespacesDerived {

19
tests/NamespacesDerived/NamespacesDerived.h

@ -17,7 +17,7 @@ namespace OverlappingNamespace @@ -17,7 +17,7 @@ namespace OverlappingNamespace
// Using a type imported from a different library.
class DLL_API Derived : public Base
class DLL_API Derived : public Base2
{
public:
Derived();
@ -26,6 +26,8 @@ public: @@ -26,6 +26,8 @@ public:
Base getBase();
void setBase(Base);
void parent(int i);
OverlappingNamespace::InBaseLib nestedNSComponent;
OverlappingNamespace::InBaseLib getNestedNSComponent();
void setNestedNSComponent(OverlappingNamespace::InBaseLib);
@ -36,22 +38,17 @@ private: @@ -36,22 +38,17 @@ private:
int d;
};
// For reference: using a type derived in the same library
class Base2
class Base3
{
public:
Base2();
};
class Derived2 : public Base2
class Derived2 : public Base3
{
public:
Derived2();
Base2 baseComponent;
Base2 getBase();
void setBase(Base2);
Base3 baseComponent;
Base3 getBase();
void setBase(Base3);
OverlappingNamespace::InDerivedLib nestedNSComponent;
OverlappingNamespace::InDerivedLib getNestedNSComponent();

Loading…
Cancel
Save