Browse Source

Fixed the renaming pass to ignore operators, consider IDisposable.Dispose and take care to avoid naming conflicts.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/76/head
Dimitar Dobrev 12 years ago
parent
commit
8c77618c69
  1. 40
      src/Generator/Passes/RenamePass.cs

40
src/Generator/Passes/RenamePass.cs

@ -1,4 +1,6 @@ @@ -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 @@ -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 @@ -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<Declaration> declarations = new List<Declaration>();
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;
}

Loading…
Cancel
Save