Browse Source

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

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/904/head
Dimitar Dobrev 8 years ago
parent
commit
0ecb7fc156
  1. 7
      src/AST/Method.cs
  2. 2
      src/Generator/Passes/EqualiseAccessOfOverrideAndBasePass.cs
  3. 2
      src/Generator/Passes/FixDefaultParamValuesOfOverridesPass.cs
  4. 1
      src/Generator/Passes/MultipleInheritancePass.cs
  5. 6
      src/Generator/Passes/ObjectOverridesPass.cs
  6. 7
      src/Generator/Passes/RenamePass.cs

7
src/AST/Method.cs

@ -118,6 +118,7 @@ namespace CppSharp.AST @@ -118,6 +118,7 @@ namespace CppSharp.AST
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 @@ namespace CppSharp.AST @@ -165,6 +166,12 @@ namespace CppSharp.AST
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);

2
src/Generator/Passes/EqualiseAccessOfOverrideAndBasePass.cs

@ -25,7 +25,7 @@ namespace CppSharp.Passes @@ -25,7 +25,7 @@ namespace CppSharp.Passes
if (!base.VisitMethodDecl(method) || !method.IsOverride)
return false;
var baseMethod = ((Class) method.Namespace).GetBaseMethod(method);
var baseMethod = method.GetRootBaseMethod();
if (!baseMethod.IsGenerated)
return false;

2
src/Generator/Passes/FixDefaultParamValuesOfOverridesPass.cs

@ -9,7 +9,7 @@ namespace CppSharp.Passes @@ -9,7 +9,7 @@ namespace CppSharp.Passes
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];

1
src/Generator/Passes/MultipleInheritancePass.cs

@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.CSharp;
namespace CppSharp.Passes
{

6
src/Generator/Passes/ObjectOverridesPass.cs

@ -64,7 +64,7 @@ namespace CppSharp @@ -64,7 +64,7 @@ namespace CppSharp
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 @@ namespace CppSharp @@ -86,7 +86,7 @@ namespace CppSharp
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 @@ namespace CppSharp @@ -129,7 +129,7 @@ namespace CppSharp
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}",

7
src/Generator/Passes/RenamePass.cs

@ -49,7 +49,12 @@ namespace CppSharp.Passes @@ -49,7 +49,12 @@ namespace CppSharp.Passes
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;

Loading…
Cancel
Save