From 14f5358daa2c329c79cc41ed82319a0b98c6a6f6 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 17 Jun 2015 00:55:15 +0300 Subject: [PATCH] Fixed a bug when having protected properties in a secondary base. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTextTemplate.cs | 2 +- .../GetterSetterToPropertyAdvancedPass.cs | 59 +++++++++++-------- tests/CSharpTemp/CSharpTemp.cpp | 13 ++++ tests/CSharpTemp/CSharpTemp.h | 2 + 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index eea86a11..a4530866 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -462,7 +462,7 @@ namespace CppSharp.Generators.CSharp PopBlock(NewLineKind.BeforeNextBlock); } - foreach (var prop in @class.Properties.Where(p => p.IsGenerated)) + foreach (var prop in @class.Properties.Where(p => p.IsGenerated && p.Access == AccessSpecifier.Public)) { PushBlock(CSharpBlockKind.Property); var type = prop.Type; diff --git a/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs b/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs index 275ca48b..6753c08c 100644 --- a/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs @@ -132,17 +132,23 @@ namespace CppSharp.Passes private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) { - Class type = (Class) context; + var type = (Class) context; if (type.Properties.All(p => getter.Name != p.Name || - p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) + p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) { - Property property = new Property(); - property.Name = GetPropertyName(getter.Name); - property.Namespace = type; - property.QualifiedType = getter.OriginalReturnType; + var property = new Property + { + Access = getter.Access == AccessSpecifier.Public || + (setter != null && setter.Access == AccessSpecifier.Public) + ? AccessSpecifier.Public + : AccessSpecifier.Protected, + Name = GetPropertyName(getter.Name), + Namespace = type, + QualifiedType = getter.OriginalReturnType + }; if (getter.IsOverride || (setter != null && setter.IsOverride)) { - Property baseVirtualProperty = type.GetRootBaseProperty(property); + var baseVirtualProperty = type.GetRootBaseProperty(property); if (baseVirtualProperty.SetMethod == null) setter = null; } @@ -155,22 +161,7 @@ namespace CppSharp.Passes } if (getter.Comment != null) { - var comment = new RawComment(); - comment.Kind = getter.Comment.Kind; - comment.BriefText = getter.Comment.BriefText; - comment.Text = getter.Comment.Text; - if (getter.Comment.FullComment != null) - { - comment.FullComment = new FullComment(); - comment.FullComment.Blocks.AddRange(getter.Comment.FullComment.Blocks); - if (setter != null && setter.Comment != null) - { - comment.BriefText += Environment.NewLine + setter.Comment.BriefText; - comment.Text += Environment.NewLine + setter.Comment.Text; - comment.FullComment.Blocks.AddRange(setter.Comment.FullComment.Blocks); - } - } - property.Comment = comment; + property.Comment = CombineComments(getter, setter); } type.Properties.Add(property); getter.GenerationKind = GenerationKind.Internal; @@ -179,6 +170,28 @@ namespace CppSharp.Passes } } + private static RawComment CombineComments(Declaration getter, Declaration setter) + { + var comment = new RawComment + { + Kind = getter.Comment.Kind, + BriefText = getter.Comment.BriefText, + Text = getter.Comment.Text + }; + if (getter.Comment.FullComment != null) + { + comment.FullComment = new FullComment(); + comment.FullComment.Blocks.AddRange(getter.Comment.FullComment.Blocks); + if (setter != null && setter.Comment != null) + { + comment.BriefText += Environment.NewLine + setter.Comment.BriefText; + comment.Text += Environment.NewLine + setter.Comment.Text; + comment.FullComment.Blocks.AddRange(setter.Comment.FullComment.Blocks); + } + } + return comment; + } + private static string GetPropertyName(string name) { if (GetFirstWord(name) == "get" && name != "get") diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index 58cb06ab..be8365f2 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -491,6 +491,19 @@ void SecondaryBase::protectedFunction() { } +int SecondaryBase::protectedProperty() +{ + return 0; +} + +void SecondaryBase::setProtectedProperty(int value) +{ +} + void TestOverrideFromSecondaryBase::VirtualMember() { } + +void TestOverrideFromSecondaryBase::setProperty(int value) +{ +} diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index 5ddb085c..1057e43b 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -499,6 +499,8 @@ public: void function(); protected: void protectedFunction(); + int protectedProperty(); + void setProtectedProperty(int value); }; class DLL_API TestOverrideFromSecondaryBase : public Foo, public SecondaryBase