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
{ {
this.log = log; this.log = log;
foreach (var method in @class.Methods.Where( 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); DistributeMethod(method);
} }
@ -36,7 +37,7 @@ namespace CppSharp.Passes
foreach (Method getter in foreach (Method getter in
from getter in getters 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) ((Class) getter.Namespace).Methods.All(m => m == getter || m.Ignore || m.Name != getter.Name)
select getter) select getter)
{ {

16
tests/NamespacesBase/NamespacesBase.cpp

@ -9,5 +9,21 @@ Base::Base(int i)
Base::Base() 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 @@
using System; using System;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Passes;
using CppSharp.Utils; using CppSharp.Utils;
namespace CppSharp.Tests namespace CppSharp.Tests
@ -15,6 +16,7 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver) public override void SetupPasses(Driver driver)
{ {
driver.Options.GeneratePropertiesAdvanced = true;
} }
public override void Preprocess(Driver driver, ASTContext ctx) public override void Preprocess(Driver driver, ASTContext ctx)
@ -23,6 +25,9 @@ namespace CppSharp.Tests
public override void Postprocess(Driver driver, ASTContext ctx) 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
public: public:
Base(int i); Base(int i);
Base(); Base();
int parent();
private: private:
int b; int b;
}; };
class DLL_API Base2 : public Base
{
public:
Base2(int i);
Base2();
virtual void parent(int i);
};
class DLL_API Abstract class DLL_API Abstract
{ {
public: public:

14
tests/NamespacesDerived/NamespacesDerived.Tests.cs

@ -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(
{ {
} }
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)
baseComponent = b; baseComponent = b;
} }
void Derived::parent(int i)
{
}
OverlappingNamespace::InBaseLib Derived::getNestedNSComponent() OverlappingNamespace::InBaseLib Derived::getNestedNSComponent()
{ {
return nestedNSComponent; return nestedNSComponent;
@ -29,22 +33,12 @@ void Derived::setNestedNSComponent(OverlappingNamespace::InBaseLib c)
nestedNSComponent = c; nestedNSComponent = c;
} }
Base3 Derived2::getBase()
Base2::Base2()
{
}
Derived2::Derived2() : Base2()
{
}
Base2 Derived2::getBase()
{ {
return baseComponent; return baseComponent;
} }
void Derived2::setBase(Base2 b) void Derived2::setBase(Base3 b)
{ {
baseComponent = b; baseComponent = b;
} }

6
tests/NamespacesDerived/NamespacesDerived.cs

@ -1,5 +1,6 @@
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Passes;
using CppSharp.Utils; using CppSharp.Utils;
namespace CppSharp.Tests namespace CppSharp.Tests
@ -15,6 +16,7 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver) public override void SetupPasses(Driver driver)
{ {
driver.Options.GenerateDefaultValuesForArguments = true; driver.Options.GenerateDefaultValuesForArguments = true;
driver.Options.GeneratePropertiesAdvanced = true;
} }
public override void Preprocess(Driver driver, ASTContext ctx) public override void Preprocess(Driver driver, ASTContext ctx)
@ -30,8 +32,10 @@ namespace CppSharp.Tests
public override void Postprocess(Driver driver, ASTContext ctx) 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 { public class NamespacesDerived {

19
tests/NamespacesDerived/NamespacesDerived.h

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

Loading…
Cancel
Save