Browse Source

Merge pull request #483 from ddobrev/master

Ensured implementations of interface members are properly renamed
pull/484/head
João Matos 10 years ago
parent
commit
7c1342c6cd
  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 @@ -446,8 +446,6 @@ namespace CppSharp.Generators.CSharp
NewLine();
WriteStartBraceIndent();
GenerateDeclContext(@class);
foreach (var method in @class.Methods.Where(m =>
!ASTUtils.CheckIgnoreMethod(m, Options) && m.Access == AccessSpecifier.Public))
{

2
src/Generator/Passes/MultipleInheritancePass.cs

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

48
src/Generator/Passes/RenamePass.cs

@ -37,7 +37,33 @@ namespace CppSharp.Passes @@ -37,7 +37,33 @@ namespace CppSharp.Passes
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)
{
@ -93,7 +119,7 @@ namespace CppSharp.Passes @@ -93,7 +119,7 @@ namespace CppSharp.Passes
private bool Rename(Declaration decl)
{
string newName;
if (Rename(decl.Name, out newName) && !AreThereConflicts(decl, newName))
if (Rename(decl, out newName) && !AreThereConflicts(decl, newName))
decl.Name = newName;
return true;
}
@ -147,7 +173,7 @@ namespace CppSharp.Passes @@ -147,7 +173,7 @@ namespace CppSharp.Passes
return false;
string newName;
if (Rename(item.Name, out newName))
if (Rename(item, out newName))
{
item.Name = newName;
return true;
@ -262,11 +288,13 @@ namespace CppSharp.Passes @@ -262,11 +288,13 @@ namespace CppSharp.Passes
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;
return true;
@ -296,17 +324,17 @@ namespace CppSharp.Passes @@ -296,17 +324,17 @@ namespace CppSharp.Passes
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)
{
case RenameCasePattern.LowerCamelCase:
newName = ConvertCaseString(name, RenameCasePattern.LowerCamelCase);
newName = ConvertCaseString(decl.Name, RenameCasePattern.LowerCamelCase);
return true;
case RenameCasePattern.UpperCamelCase:
newName = ConvertCaseString(name, RenameCasePattern.UpperCamelCase);
newName = ConvertCaseString(decl.Name, RenameCasePattern.UpperCamelCase);
return true;
}

4
tests/CSharpTemp/CSharpTemp.cpp

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

12
tests/CSharpTemp/CSharpTemp.h

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

Loading…
Cancel
Save