From b16bb0a9793d07ba29cc761ffab1292a149c4e91 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 12 Sep 2016 15:49:58 +0300 Subject: [PATCH] Moved the change of order when visiting properties to just the renaming pass. Signed-off-by: Dimitar Dobrev --- src/AST/ASTVisitor.cs | 6 ++---- src/Generator/Passes/RenamePass.cs | 16 ++++++++++++++++ tests/CSharp/CSharp.Tests.cs | 6 ++++++ tests/CSharp/CSharp.cpp | 21 +++++++++++++++++++++ tests/CSharp/CSharp.h | 6 +++++- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/AST/ASTVisitor.cs b/src/AST/ASTVisitor.cs index 1cb847f4..77775d46 100644 --- a/src/AST/ASTVisitor.cs +++ b/src/AST/ASTVisitor.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; namespace CppSharp.AST { @@ -309,7 +307,7 @@ namespace CppSharp.AST VisitFieldDecl(field); if (VisitOptions.VisitClassProperties) - foreach (var property in @class.Properties.OrderByDescending(p => p.Access)) + foreach (var property in @class.Properties) VisitProperty(property); if (VisitOptions.VisitClassMethods) diff --git a/src/Generator/Passes/RenamePass.cs b/src/Generator/Passes/RenamePass.cs index 0f0fe590..622028ef 100644 --- a/src/Generator/Passes/RenamePass.cs +++ b/src/Generator/Passes/RenamePass.cs @@ -33,6 +33,9 @@ namespace CppSharp.Passes VisitOptions.VisitFunctionReturnType = false; VisitOptions.VisitFunctionParameters = false; VisitOptions.VisitTemplateArguments = false; + // properties need to be visited but in a different order (see VisitClassDecl) so disable the default order + VisitOptions.VisitClassProperties = false; + VisitOptions.VisitClassMethods = false; } protected RenamePass(RenameTargets targets) @@ -176,6 +179,19 @@ namespace CppSharp.Passes return true; } + public override bool VisitClassDecl(Class @class) + { + var result = base.VisitClassDecl(@class); + + foreach (var property in @class.Properties.OrderByDescending(p => p.Access)) + VisitProperty(property); + + foreach (var method in @class.Methods) + VisitMethodDecl(method); + + return result; + } + public override bool VisitFieldDecl(Field field) { if (!Targets.HasFlag(RenameTargets.Field)) diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 48c27258..e6005625 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -20,6 +20,12 @@ public unsafe class CSharpTests : GeneratorTestFixture public void TestUncompilableCode() { ALLCAPS_UNDERSCORES a; + using (var testRenaming = new TestRenaming()) + { + testRenaming.name(); + testRenaming.Name(); + testRenaming.Property.GetHashCode(); + } new ForceCreationOfInterface().Dispose(); new InheritsProtectedVirtualFromSecondaryBase().Dispose(); new InheritanceBuffer().Dispose(); diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 0299dfe3..9a4a74a9 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -363,6 +363,27 @@ TestCopyConstructorVal::TestCopyConstructorVal(const TestCopyConstructorVal& oth B = other.B; } +TestRenaming::TestRenaming() +{ +} + +TestRenaming::~TestRenaming() +{ +} + +void TestRenaming::name() +{ +} + +void TestRenaming::Name() +{ +} + +int TestRenaming::property() +{ + return 1; +} + UsesPointerToEnumInParamOfVirtual::UsesPointerToEnumInParamOfVirtual() { } diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index cc2b7fcb..ee0c2c34 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -30,7 +30,6 @@ public: protected: int P; - int _method; TemplateInAnotherUnit templateInAnotherUnit; }; @@ -262,8 +261,13 @@ public: class DLL_API TestRenaming { public: + TestRenaming(); + ~TestRenaming(); void name(); void Name(); + int property(); +protected: + int _property; }; enum class Flags