Browse Source

Moved the checks for operators and Dispose to IsRenameableDecl. Moved the checking for conflicts to a separate function.

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

25
src/Generator/Passes/RenamePass.cs

@ -29,8 +29,12 @@ namespace CppSharp.Passes
{ {
if (decl is Class) return true; if (decl is Class) return true;
if (decl is Field) return true; if (decl is Field) return true;
if (decl is Method) return true; var function = decl as Function;
if (decl is Function) return true; if (function != null)
{
// special case the IDisposable.Dispose that could be added later
return !function.IsOperator && function.Name != "dispose";
}
if (decl is Parameter) return true; if (decl is Parameter) return true;
if (decl is Enumeration) return true; if (decl is Enumeration) return true;
if (decl is Property) return true; if (decl is Property) return true;
@ -46,7 +50,7 @@ namespace CppSharp.Passes
// this is why this pass has to rename entries in the v-table as well; // 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 // this should be fixed in the parser: it should reuse method objects
foreach (var method in VTables.GatherVTableMethodEntries(@class).Where( foreach (var method in VTables.GatherVTableMethodEntries(@class).Where(
e => e.Method != null && !e.Method.IsOperator).Select(e => e.Method)) e => e.Method != null && IsRenameableDecl(e.Method)).Select(e => e.Method))
{ {
Rename(method); Rename(method);
} }
@ -65,7 +69,7 @@ namespace CppSharp.Passes
Visited.Add(decl); Visited.Add(decl);
if (decl.Name == null || (decl is Function && ((Function) decl).IsOperator)) if (decl.Name == null)
return true; return true;
return Rename(decl); return Rename(decl);
@ -74,8 +78,12 @@ namespace CppSharp.Passes
private bool Rename(Declaration decl) private bool Rename(Declaration decl)
{ {
string newName; string newName;
// special case the IDisposable.Dispose that could be added later if (Rename(decl.Name, out newName) && AreThereConflicts(decl, newName))
if (Rename(decl.Name, out newName) && newName != "Dispose") decl.Name = newName;
return true;
}
private static bool AreThereConflicts(Declaration decl, string newName)
{ {
List<Declaration> declarations = new List<Declaration>(); List<Declaration> declarations = new List<Declaration>();
declarations.AddRange(decl.Namespace.Classes); declarations.AddRange(decl.Namespace.Classes);
@ -83,10 +91,7 @@ namespace CppSharp.Passes
declarations.AddRange(decl.Namespace.Events); declarations.AddRange(decl.Namespace.Events);
declarations.AddRange(decl.Namespace.Functions); declarations.AddRange(decl.Namespace.Functions);
declarations.AddRange(decl.Namespace.Variables); declarations.AddRange(decl.Namespace.Variables);
if (declarations.All(d => d == decl || d.Name != newName)) return declarations.All(d => d == decl || d.Name != newName);
decl.Name = newName;
}
return true;
} }
public override bool VisitEnumItem(Enumeration.Item item) public override bool VisitEnumItem(Enumeration.Item item)

Loading…
Cancel
Save