From f09a49b3535c6da62b48e0f1f38e2aefc4d08936 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 28 Jun 2015 02:45:05 +0300 Subject: [PATCH] Removed three hacks about method objects in v-tables. Signed-off-by: Dimitar Dobrev --- src/AST/ClassExtensions.cs | 8 +++----- .../Generators/CSharp/CSharpTextTemplate.cs | 6 ++---- src/Generator/Passes/CleanInvalidDeclNamesPass.cs | 13 ------------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/AST/ClassExtensions.cs b/src/AST/ClassExtensions.cs index 2420ff25..f27881f5 100644 --- a/src/AST/ClassExtensions.cs +++ b/src/AST/ClassExtensions.cs @@ -61,7 +61,7 @@ namespace CppSharp.AST let baseMethod = ( from method in @base.Class.Methods where - method.Name == @override.Name && + method.OriginalName == @override.OriginalName && method.ReturnType == @override.ReturnType && method.Parameters.SequenceEqual(@override.Parameters, new ParameterTypeComparer()) @@ -78,7 +78,7 @@ namespace CppSharp.AST let baseProperty = ( from property in @base.Class.Properties where - property.Name == @override.Name && + property.OriginalName == @override.OriginalName && property.Parameters.SequenceEqual(@override.Parameters, new ParameterTypeComparer()) select property).FirstOrDefault() @@ -123,9 +123,7 @@ namespace CppSharp.AST public static Method GetMethodByName(this Class c, string methodName) { - var method = c.Methods.FirstOrDefault( - // HACK: because of the non-shared v-table entries bug one copy may have been renamed and the other not - m => string.Compare(m.Name, methodName, StringComparison.OrdinalIgnoreCase) == 0); + var method = c.Methods.FirstOrDefault(m => m.Name == methodName); if (method != null) return method; diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 1047098c..1d908bfd 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1461,15 +1461,13 @@ namespace CppSharp.Generators.CSharp if (hasReturn) Write("var {0} = ", Helpers.ReturnIdentifier); - // 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) + if (method.IsGenerated) { WriteLine("target.{0}({1});", method.Name, string.Join(", ", marshals)); } else { - InvokeProperty(m, marshals); + InvokeProperty(method, marshals); } if (hasReturn) diff --git a/src/Generator/Passes/CleanInvalidDeclNamesPass.cs b/src/Generator/Passes/CleanInvalidDeclNamesPass.cs index 19a4c172..e433f44d 100644 --- a/src/Generator/Passes/CleanInvalidDeclNamesPass.cs +++ b/src/Generator/Passes/CleanInvalidDeclNamesPass.cs @@ -56,19 +56,6 @@ namespace CppSharp.Passes public override bool VisitClassDecl(Class @class) { - if (@class.IsDynamic) - { - // HACK: entries in v-tables are not shared (as objects) with the virtual methods they represent; - // this is why this pass fixes only the arg names used with real methods, - // while the v-table entries could remain with empty names; - // this should be fixed in the parser: it should reuse method objects - foreach (var parameter in VTables.GatherVTableMethodEntries(@class).Where( - entry => entry.Method != null).SelectMany(entry => entry.Method.Parameters)) - { - parameter.Name = CheckName(parameter.Name); - } - } - var currentUniqueName = this.uniqueName; this.uniqueName = 0; var ret = base.VisitClassDecl(@class);