From 8c77618c698338eede61e3c40785970c32776532 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sat, 28 Sep 2013 22:17:33 +0300 Subject: [PATCH] Fixed the renaming pass to ignore operators, consider IDisposable.Dispose and take care to avoid naming conflicts. Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/RenamePass.cs | 40 ++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Generator/Passes/RenamePass.cs b/src/Generator/Passes/RenamePass.cs index aa7a6b4b..351deb8d 100644 --- a/src/Generator/Passes/RenamePass.cs +++ b/src/Generator/Passes/RenamePass.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using CppSharp.AST; @@ -36,6 +38,23 @@ 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 && !e.Method.IsOperator).Select(e => e.Method)) + { + Rename(method); + } + } + + return base.VisitClassDecl(@class); + } + public override bool VisitDeclaration(Declaration decl) { if (!IsRenameableDecl(decl)) @@ -46,16 +65,27 @@ namespace CppSharp.Passes Visited.Add(decl); - if (decl.Name == null) + if (decl.Name == null || (decl is Function && ((Function) decl).IsOperator)) return true; + return Rename(decl); + } + + private bool Rename(Declaration decl) + { string newName; - if (Rename(decl.Name, out newName)) + // special case the IDisposable.Dispose that could be added later + if (Rename(decl.Name, out newName) && newName != "Dispose") { - decl.Name = newName; - return true; + List declarations = new List(); + declarations.AddRange(decl.Namespace.Classes); + declarations.AddRange(decl.Namespace.Enums); + declarations.AddRange(decl.Namespace.Events); + declarations.AddRange(decl.Namespace.Functions); + declarations.AddRange(decl.Namespace.Variables); + if (declarations.All(d => d == decl || d.Name != newName)) + decl.Name = newName; } - return true; }