Permalink
Browse files

Changed the getting of a root base method to use the list of overrides.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jul 27, 2017
1 parent 845bf5b commit 0ecb7fc156948b6dc8447641f332ae84b8ed0475
@@ -118,6 +118,7 @@ public Method(Function function)
public bool IsConst { get; set; }
public bool IsExplicit { get; set; }
public bool IsOverride => OverriddenMethods.Any();
public Method BaseMethod => IsOverride ? OverriddenMethods[0] : null;
// True if the method is final / sealed.
public bool IsFinal { get; set; }
@@ -165,6 +166,12 @@ public bool IsDestructor
public List<Method> OverriddenMethods { get; } = new List<Method>();
public Method GetRootBaseMethod()
{
return BaseMethod == null || BaseMethod.BaseMethod == null ?
BaseMethod : BaseMethod.GetRootBaseMethod();
}
public override T Visit<T>(IDeclVisitor<T> visitor)
{
return visitor.VisitMethodDecl(this);
@@ -25,7 +25,7 @@ public override bool VisitMethodDecl(Method method)
if (!base.VisitMethodDecl(method) || !method.IsOverride)
return false;
var baseMethod = ((Class) method.Namespace).GetBaseMethod(method);
var baseMethod = method.GetRootBaseMethod();
if (!baseMethod.IsGenerated)
return false;
@@ -9,7 +9,7 @@ public override bool VisitMethodDecl(Method method)
if (!method.IsOverride || method.IsSynthetized)
return true;
Method rootBaseMethod = ((Class)method.Namespace).GetBaseMethod(method);
Method rootBaseMethod = method.GetRootBaseMethod();
for (int i = 0; i < method.Parameters.Count; i++)
{
var rootBaseParameter = rootBaseMethod.Parameters[i];
@@ -2,7 +2,6 @@
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
namespace CppSharp.Passes
{
@@ -64,7 +64,7 @@ private void VisitMethod(Method method, Block block)
GenerateEquals(@class, block, method);
if (method.Name == "ToString" && method.Parameters.Count == 0)
GenerateToString(@class, block, method);
GenerateToString(block);
}
void GenerateGetHashCode(Block block)
@@ -86,7 +86,7 @@ void GenerateEquals(Class @class, Block block, Method method)
block.Write("return __Instance == obj->__Instance;");
}
void GenerateToString(Class @class, Block block, Method method)
void GenerateToString(Block block)
{
needsStreamInclude = true;
block.WriteLine("std::ostringstream os;");
@@ -129,7 +129,7 @@ public override bool VisitClassDecl(Class @class)
SynthKind = FunctionSynthKind.ComplementOperator,
IsProxy = true
};
toStringMethod.OverriddenMethods.Add(new Method { Name = "Equals" });
toStringMethod.OverriddenMethods.Add(new Method { Name = "ToString" });
@class.Methods.Add(toStringMethod);
Diagnostics.Debug("Function converted to ToString: {0}::{1}",
@@ -49,7 +49,12 @@ public virtual bool Rename(Declaration decl, out string newName)
var method = decl as Method;
if (method != null && !method.IsStatic)
{
var rootBaseMethod = ((Class) method.Namespace).GetBaseMethod(method);
Method rootBaseMethod;
var @class = method.OriginalNamespace as Class;
if (@class != null && @class.IsInterface)
rootBaseMethod = (Method) method.OriginalFunction;
else
rootBaseMethod = method.GetRootBaseMethod();
if (rootBaseMethod != null && rootBaseMethod != method)
{
newName = rootBaseMethod.Name;

0 comments on commit 0ecb7fc

Please sign in to comment.