Browse Source

Ensured implementations of interface members are properly renamed.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/483/head
Dimitar Dobrev 11 years ago
parent
commit
d7e74c68e6
  1. 2
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 2
      src/Generator/Passes/MultipleInheritancePass.cs
  3. 48
      src/Generator/Passes/RenamePass.cs
  4. 4
      tests/CSharpTemp/CSharpTemp.cpp
  5. 12
      tests/CSharpTemp/CSharpTemp.h

2
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -446,8 +446,6 @@ namespace CppSharp.Generators.CSharp
NewLine(); NewLine();
WriteStartBraceIndent(); WriteStartBraceIndent();
GenerateDeclContext(@class);
foreach (var method in @class.Methods.Where(m => foreach (var method in @class.Methods.Where(m =>
!ASTUtils.CheckIgnoreMethod(m, Options) && m.Access == AccessSpecifier.Public)) !ASTUtils.CheckIgnoreMethod(m, Options) && m.Access == AccessSpecifier.Public))
{ {

2
src/Generator/Passes/MultipleInheritancePass.cs

@ -147,6 +147,8 @@ namespace CppSharp.Passes
select new Property(property) { Namespace = @interface }); select new Property(property) { Namespace = @interface });
@interface.Fields.AddRange(@base.Fields); @interface.Fields.AddRange(@base.Fields);
// avoid conflicts when potentially renaming later
@interface.Declarations.AddRange(@base.Declarations);
if (@interface.Bases.Count == 0) if (@interface.Bases.Count == 0)
{ {

48
src/Generator/Passes/RenamePass.cs

@ -37,7 +37,33 @@ namespace CppSharp.Passes
Targets = targets; Targets = targets;
} }
public abstract bool Rename(string name, out string newName); public virtual bool Rename(Declaration decl, out string newName)
{
var method = decl as Method;
if (method != null)
{
var rootBaseMethod = ((Class) method.Namespace).GetRootBaseMethod(method);
if (rootBaseMethod != null && rootBaseMethod != method)
{
newName = rootBaseMethod.Name;
return true;
}
}
var property = decl as Property;
if (property != null)
{
var rootBaseProperty = ((Class) property.Namespace).GetRootBaseProperty(property);
if (rootBaseProperty != null && rootBaseProperty != property)
{
newName = rootBaseProperty.Name;
return true;
}
}
newName = decl.Name;
return false;
}
public bool IsRenameableDecl(Declaration decl) public bool IsRenameableDecl(Declaration decl)
{ {
@ -93,7 +119,7 @@ namespace CppSharp.Passes
private bool Rename(Declaration decl) private bool Rename(Declaration decl)
{ {
string newName; string newName;
if (Rename(decl.Name, out newName) && !AreThereConflicts(decl, newName)) if (Rename(decl, out newName) && !AreThereConflicts(decl, newName))
decl.Name = newName; decl.Name = newName;
return true; return true;
} }
@ -147,7 +173,7 @@ namespace CppSharp.Passes
return false; return false;
string newName; string newName;
if (Rename(item.Name, out newName)) if (Rename(item, out newName))
{ {
item.Name = newName; item.Name = newName;
return true; return true;
@ -262,11 +288,13 @@ namespace CppSharp.Passes
Targets = targets; Targets = targets;
} }
public override bool Rename(string name, out string newName) public override bool Rename(Declaration decl, out string newName)
{ {
var replace = Regex.Replace(name, Pattern, Replacement); if (base.Rename(decl, out newName)) return true;
if (!name.Equals(replace)) var replace = Regex.Replace(decl.Name, Pattern, Replacement);
if (!decl.Name.Equals(replace))
{ {
newName = replace; newName = replace;
return true; return true;
@ -296,17 +324,17 @@ namespace CppSharp.Passes
Pattern = pattern; Pattern = pattern;
} }
public override bool Rename(string name, out string newName) public override bool Rename(Declaration decl, out string newName)
{ {
newName = null; if (base.Rename(decl, out newName)) return true;
switch (Pattern) switch (Pattern)
{ {
case RenameCasePattern.LowerCamelCase: case RenameCasePattern.LowerCamelCase:
newName = ConvertCaseString(name, RenameCasePattern.LowerCamelCase); newName = ConvertCaseString(decl.Name, RenameCasePattern.LowerCamelCase);
return true; return true;
case RenameCasePattern.UpperCamelCase: case RenameCasePattern.UpperCamelCase:
newName = ConvertCaseString(name, RenameCasePattern.UpperCamelCase); newName = ConvertCaseString(decl.Name, RenameCasePattern.UpperCamelCase);
return true; return true;
} }

4
tests/CSharpTemp/CSharpTemp.cpp

@ -483,6 +483,10 @@ void SecondaryBase::setProperty(int value)
{ {
} }
void SecondaryBase::function()
{
}
void TestOverrideFromSecondaryBase::VirtualMember() void TestOverrideFromSecondaryBase::VirtualMember()
{ {
} }

12
tests/CSharpTemp/CSharpTemp.h

@ -482,9 +482,21 @@ protected:
class DLL_API SecondaryBase class DLL_API SecondaryBase
{ {
public: public:
enum Property
{
P1,
P2
};
enum Function
{
M1,
M2
};
virtual void VirtualMember(); virtual void VirtualMember();
int property(); int property();
void setProperty(int value); void setProperty(int value);
void function();
}; };
class DLL_API TestOverrideFromSecondaryBase : public Foo, public SecondaryBase class DLL_API TestOverrideFromSecondaryBase : public Foo, public SecondaryBase

Loading…
Cancel
Save