From 0b77ef7a495ecc6dbc1a8fc9160ef7612b0ca87a Mon Sep 17 00:00:00 2001 From: triton Date: Mon, 16 Sep 2013 19:15:41 +0100 Subject: [PATCH] Improved the FieldToPropertyPass to be a bit more robust by checking for existing properties. --- src/Generator/Passes/FieldToPropertyPass.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Generator/Passes/FieldToPropertyPass.cs b/src/Generator/Passes/FieldToPropertyPass.cs index a719ea80..6d9bd468 100644 --- a/src/Generator/Passes/FieldToPropertyPass.cs +++ b/src/Generator/Passes/FieldToPropertyPass.cs @@ -1,4 +1,5 @@ -using CppSharp.AST; +using System.Linq; +using CppSharp.AST; namespace CppSharp.Passes { @@ -6,6 +7,9 @@ namespace CppSharp.Passes { public override bool VisitFieldDecl(Field field) { + if (AlreadyVisited(field)) + return false; + var @class = field.Namespace as Class; if (@class == null) return false; @@ -16,6 +20,17 @@ namespace CppSharp.Passes if (ASTUtils.CheckIgnoreField(field)) 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 { Name = field.Name, @@ -26,6 +41,9 @@ namespace CppSharp.Passes }; @class.Properties.Add(prop); + Driver.Diagnostics.EmitMessage(DiagnosticId.PropertySynthetized, + "Property created from field: {0}::{1}", @class.Name, field.Name); + field.ExplicityIgnored = true; return false;