From c8da62878289ae7a3fae5948e38dc01a6a1717ce Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 4 Aug 2015 01:16:15 +0300 Subject: [PATCH] Fixed the renaming of overrides in a certain situation. Signed-off-by: Dimitar Dobrev --- src/AST/ASTVisitor.cs | 5 ++++- src/AST/ClassExtensions.cs | 6 +++--- src/Generator/Passes/RenamePass.cs | 21 ++++----------------- tests/CSharpTemp/CSharpTemp.Tests.cs | 3 ++- tests/CSharpTemp/CSharpTemp.cpp | 16 ++++++++++++++++ tests/CSharpTemp/CSharpTemp.h | 17 +++++++++++++++++ 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/AST/ASTVisitor.cs b/src/AST/ASTVisitor.cs index 5ca784a4..fe47b9a3 100644 --- a/src/AST/ASTVisitor.cs +++ b/src/AST/ASTVisitor.cs @@ -291,7 +291,10 @@ namespace CppSharp.AST if (!VisitDeclaration(property)) return false; - return property.Type.Visit(this); + if (Options.VisitFunctionReturnType) + return property.Type.Visit(this); + + return true; } public bool VisitFriend(Friend friend) diff --git a/src/AST/ClassExtensions.cs b/src/AST/ClassExtensions.cs index b98fe249..4b282041 100644 --- a/src/AST/ClassExtensions.cs +++ b/src/AST/ClassExtensions.cs @@ -57,7 +57,7 @@ namespace CppSharp.AST public static Method GetRootBaseMethod(this Class c, Method @override, bool onlyFirstBase = false) { return (from @base in c.Bases - where @base.IsClass && (!onlyFirstBase || !@base.Class.IsInterface) + where @base.IsClass && @base.Class.OriginalClass != c && (!onlyFirstBase || !@base.Class.IsInterface) let baseMethod = ( from method in @base.Class.Methods where @@ -74,7 +74,7 @@ namespace CppSharp.AST public static Property GetRootBaseProperty(this Class c, Property @override, bool onlyFirstBase = false) { return (from @base in c.Bases - where (!onlyFirstBase || !@base.Class.IsInterface) && @base.IsClass + where @base.IsClass && @base.Class.OriginalClass != c && (!onlyFirstBase || !@base.Class.IsInterface) let baseProperty = ( from property in @base.Class.Properties where @@ -82,7 +82,7 @@ namespace CppSharp.AST property.Parameters.SequenceEqual(@override.Parameters, new ParameterTypeComparer()) select property).FirstOrDefault() - let rootBaseProperty = @base.Class.GetRootBaseProperty(@override) ?? baseProperty + let rootBaseProperty = @base.Class.GetRootBaseProperty(@override, onlyFirstBase) ?? baseProperty where rootBaseProperty != null || onlyFirstBase select rootBaseProperty).FirstOrDefault(); } diff --git a/src/Generator/Passes/RenamePass.cs b/src/Generator/Passes/RenamePass.cs index 705aefa8..a33f381e 100644 --- a/src/Generator/Passes/RenamePass.cs +++ b/src/Generator/Passes/RenamePass.cs @@ -30,9 +30,13 @@ namespace CppSharp.Passes protected RenamePass() { + Options.VisitFunctionReturnType = false; + Options.VisitFunctionParameters = false; + Options.VisitTemplateArguments = false; } protected RenamePass(RenameTargets targets) + : this() { Targets = targets; } @@ -85,23 +89,6 @@ namespace CppSharp.Passes return false; } - 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 has to rename entries in the v-table as well; - // this should be fixed in the parser: it should reuse method objects - foreach (var method in VTables.GatherVTableMethodEntries(@class).Where( - e => e.Method != null && IsRenameableDecl(e.Method)).Select(e => e.Method)) - { - Rename(method); - } - } - - return base.VisitClassDecl(@class); - } - public override bool VisitDeclaration(Declaration decl) { if (AlreadyVisited(decl)) diff --git a/tests/CSharpTemp/CSharpTemp.Tests.cs b/tests/CSharpTemp/CSharpTemp.Tests.cs index a1dc54df..fe3d2368 100644 --- a/tests/CSharpTemp/CSharpTemp.Tests.cs +++ b/tests/CSharpTemp/CSharpTemp.Tests.cs @@ -27,6 +27,8 @@ public class CSharpTempTests : GeneratorTestFixture var isNoParams = foo.IsNoParams; foo.SetNoParams(); } + using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType()) + hasOverride.CauseRenamingError(); // TODO: remove when the bug in question is fixed if (Type.GetType("Mono.Runtime") != null) { @@ -343,5 +345,4 @@ public class CSharpTempTests : GeneratorTestFixture foo.AttributedFunctionPtr = null; } } - } \ No newline at end of file diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index 89cd312c..ace57f32 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -672,3 +672,19 @@ int TypeMappedWithOperator::operator |(int i) { return 0; } + +HasPropertyWithDerivedType::HasPropertyWithDerivedType() +{ +} + +void HasPropertyWithDerivedType::causeRenamingError() +{ +} + +HasOverrideOfHasPropertyWithDerivedType::HasOverrideOfHasPropertyWithDerivedType() +{ +} + +void HasOverrideOfHasPropertyWithDerivedType::causeRenamingError() +{ +} diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index 32d5341f..d4a74db9 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -600,3 +600,20 @@ public: TypeMappedWithOperator(); int operator |(int i); }; + +class HasOverrideOfHasPropertyWithDerivedType; + +class DLL_API HasPropertyWithDerivedType +{ +public: + HasPropertyWithDerivedType(); + HasOverrideOfHasPropertyWithDerivedType* hasPropertyWithDerivedTypeSubclass; + virtual void causeRenamingError(); +}; + +class DLL_API HasOverrideOfHasPropertyWithDerivedType : public HasPropertyWithDerivedType +{ +public: + HasOverrideOfHasPropertyWithDerivedType(); + virtual void causeRenamingError(); +};