Browse Source

Fixed a bug when having protected properties in a secondary base.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/488/head
Dimitar Dobrev 10 years ago
parent
commit
14f5358daa
  1. 2
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 59
      src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs
  3. 13
      tests/CSharpTemp/CSharpTemp.cpp
  4. 2
      tests/CSharpTemp/CSharpTemp.h

2
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -462,7 +462,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock); 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); PushBlock(CSharpBlockKind.Property);
var type = prop.Type; var type = prop.Type;

59
src/Generator/Passes/GetterSetterToPropertyAdvancedPass.cs

@ -132,17 +132,23 @@ namespace CppSharp.Passes
private static void GenerateProperty(DeclarationContext context, Method getter, Method setter = null) 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 || if (type.Properties.All(p => getter.Name != p.Name ||
p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl)) p.ExplicitInterfaceImpl != getter.ExplicitInterfaceImpl))
{ {
Property property = new Property(); var property = new Property
property.Name = GetPropertyName(getter.Name); {
property.Namespace = type; Access = getter.Access == AccessSpecifier.Public ||
property.QualifiedType = getter.OriginalReturnType; (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)) if (getter.IsOverride || (setter != null && setter.IsOverride))
{ {
Property baseVirtualProperty = type.GetRootBaseProperty(property); var baseVirtualProperty = type.GetRootBaseProperty(property);
if (baseVirtualProperty.SetMethod == null) if (baseVirtualProperty.SetMethod == null)
setter = null; setter = null;
} }
@ -155,22 +161,7 @@ namespace CppSharp.Passes
} }
if (getter.Comment != null) if (getter.Comment != null)
{ {
var comment = new RawComment(); property.Comment = CombineComments(getter, setter);
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;
} }
type.Properties.Add(property); type.Properties.Add(property);
getter.GenerationKind = GenerationKind.Internal; 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) private static string GetPropertyName(string name)
{ {
if (GetFirstWord(name) == "get" && name != "get") if (GetFirstWord(name) == "get" && name != "get")

13
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::VirtualMember()
{ {
} }
void TestOverrideFromSecondaryBase::setProperty(int value)
{
}

2
tests/CSharpTemp/CSharpTemp.h

@ -499,6 +499,8 @@ public:
void function(); void function();
protected: protected:
void protectedFunction(); void protectedFunction();
int protectedProperty();
void setProtectedProperty(int value);
}; };
class DLL_API TestOverrideFromSecondaryBase : public Foo, public SecondaryBase class DLL_API TestOverrideFromSecondaryBase : public Foo, public SecondaryBase

Loading…
Cancel
Save