From 0e37a62726d7cf25255c2870a3208177b3f915c3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 5 Nov 2013 16:16:12 +0200 Subject: [PATCH] Changed the check whether to invoke a property in the v-tables to work around the non-shared methods in v-tables. Set the function signature to an empty string rather that null by default. Signed-off-by: Dimitar Dobrev --- src/AST/Class.cs | 18 ++++++++++++++++++ src/AST/Function.cs | 1 + .../Generators/CSharp/CSharpTextTemplate.cs | 6 ++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/AST/Class.cs b/src/AST/Class.cs index a9601dd7..fbb874b7 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -245,6 +245,24 @@ namespace CppSharp.AST select rootBaseProperty).FirstOrDefault(); } + public Method GetMethodByName(string methodName) + { + var method = Methods.FirstOrDefault(m => m.Name == methodName); + if (method != null) + return method; + method = Methods.FirstOrDefault(m => m.Name == methodName); + if (method != null) + return method; + Declaration decl; + foreach (BaseClassSpecifier @base in Bases.Where(b => b.Type.IsTagDecl(out decl))) + { + method = @base.Class.GetMethodByName(methodName); + if (method != null) + return method; + } + return null; + } + public override T Visit(IDeclVisitor visitor) { return visitor.VisitClassDecl(this); diff --git a/src/AST/Function.cs b/src/AST/Function.cs index 60ef944c..32d2ded4 100644 --- a/src/AST/Function.cs +++ b/src/AST/Function.cs @@ -87,6 +87,7 @@ namespace CppSharp.AST CallingConvention = CallingConvention.Default; IsVariadic = false; IsInline = false; + Signature = string.Empty; } public Function(Function function) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 68c72012..d6423103 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1319,13 +1319,15 @@ namespace CppSharp.Generators.CSharp if (hasReturn) Write("var _ret = "); - if (method.IsGenerated) + // HACK: because of the non-shared v-table entries bug we must look for the real method by name + Method m = ((Class) method.Namespace).GetMethodByName(method.Name); + if (m.IsGenerated) { WriteLine("target.{0}({1});", SafeIdentifier(method.Name), string.Join(", ", marshals)); } else { - InvokeProperty(method, marshals); + InvokeProperty(m, marshals); } if (hasReturn)