Browse Source

Improved the FieldToPropertyPass to be a bit more robust by checking for existing properties.

pull/65/merge
triton 12 years ago
parent
commit
0b77ef7a49
  1. 20
      src/Generator/Passes/FieldToPropertyPass.cs

20
src/Generator/Passes/FieldToPropertyPass.cs

@ -1,4 +1,5 @@
using CppSharp.AST; using System.Linq;
using CppSharp.AST;
namespace CppSharp.Passes namespace CppSharp.Passes
{ {
@ -6,6 +7,9 @@ namespace CppSharp.Passes
{ {
public override bool VisitFieldDecl(Field field) public override bool VisitFieldDecl(Field field)
{ {
if (AlreadyVisited(field))
return false;
var @class = field.Namespace as Class; var @class = field.Namespace as Class;
if (@class == null) if (@class == null)
return false; return false;
@ -16,6 +20,17 @@ namespace CppSharp.Passes
if (ASTUtils.CheckIgnoreField(field)) if (ASTUtils.CheckIgnoreField(field))
return false; return false;
// Check if we already have a synthetized property.
var existingProp = @class.Properties.FirstOrDefault(property =>
property.Name == field.Name &&
property.QualifiedType == field.QualifiedType);
if (existingProp != null)
{
field.ExplicityIgnored = true;
return false;
}
var prop = new Property var prop = new Property
{ {
Name = field.Name, Name = field.Name,
@ -26,6 +41,9 @@ namespace CppSharp.Passes
}; };
@class.Properties.Add(prop); @class.Properties.Add(prop);
Driver.Diagnostics.EmitMessage(DiagnosticId.PropertySynthetized,
"Property created from field: {0}::{1}", @class.Name, field.Name);
field.ExplicityIgnored = true; field.ExplicityIgnored = true;
return false; return false;

Loading…
Cancel
Save