Browse Source

Fixed invalid generated C# code when having a field renamed the same as a method.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/696/head
Dimitar Dobrev 9 years ago
parent
commit
829422cc86
  1. 3
      src/AST/ASTVisitor.cs
  2. 12
      src/Generator/Passes/RenamePass.cs
  3. 1
      tests/CSharp/CSharp.h

3
src/AST/ASTVisitor.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace CppSharp.AST namespace CppSharp.AST
{ {
@ -308,7 +309,7 @@ namespace CppSharp.AST
VisitFieldDecl(field); VisitFieldDecl(field);
if (VisitOptions.VisitClassProperties) if (VisitOptions.VisitClassProperties)
foreach (var property in @class.Properties) foreach (var property in @class.Properties.OrderByDescending(p => p.Access))
VisitProperty(property); VisitProperty(property);
if (VisitOptions.VisitClassMethods) if (VisitOptions.VisitClassMethods)

12
src/Generator/Passes/RenamePass.cs

@ -138,11 +138,15 @@ namespace CppSharp.Passes
if (result) if (result)
return true; return true;
var method = decl as Method; if (decl is Method && decl.IsGenerated)
if (method == null || !method.IsGenerated) return ((Class) decl.Namespace).GetPropertyByName(newName) != null;
return false;
return ((Class) method.Namespace).GetPropertyByName(newName) != null; var property = decl as Property;
if (property != null && property.Field != null)
return ((Class) decl.Namespace).Properties.FirstOrDefault(
p => p != decl && p.Name == newName) != null;
return false;
} }
private static IEnumerable<Function> GetFunctionsWithTheSameParams(Function function) private static IEnumerable<Function> GetFunctionsWithTheSameParams(Function function)

1
tests/CSharp/CSharp.h

@ -30,6 +30,7 @@ public:
protected: protected:
int P; int P;
int _method;
TemplateInAnotherUnit<int> templateInAnotherUnit; TemplateInAnotherUnit<int> templateInAnotherUnit;
}; };

Loading…
Cancel
Save