Browse Source

Added optional visiting of property accessors.

pull/1005/head
Joao Matos 8 years ago
parent
commit
f334e447be
  1. 14
      src/AST/ASTVisitor.cs
  2. 16
      src/Generator/Generators/CodeGenerator.cs

14
src/AST/ASTVisitor.cs

@ -13,7 +13,7 @@ namespace CppSharp.AST @@ -13,7 +13,7 @@ namespace CppSharp.AST
public interface IAstVisitor<out T> : ITypeVisitor<T>, IDeclVisitor<T>
{
AstVisitorOptions VisitOptions { get; }
}
public class AstVisitorOptions
@ -23,6 +23,7 @@ namespace CppSharp.AST @@ -23,6 +23,7 @@ namespace CppSharp.AST
public bool VisitClassProperties = true;
public bool VisitClassMethods = true;
public bool VisitClassTemplateSpecializations { get; set; } = true;
public bool VisitPropertyAccessors = false;
public bool VisitNamespaceEnums = true;
public bool VisitNamespaceTemplates = true;
@ -376,7 +377,16 @@ namespace CppSharp.AST @@ -376,7 +377,16 @@ namespace CppSharp.AST
return false;
if (VisitOptions.VisitFunctionReturnType)
return property.Type.Visit(this);
property.Type.Visit(this);
if (VisitOptions.VisitPropertyAccessors)
{
if (property.GetMethod != null)
property.GetMethod.Visit(this);
if (property.SetMethod != null)
property.SetMethod.Visit(this);
}
return true;
}

16
src/Generator/Generators/CodeGenerator.cs

@ -46,6 +46,8 @@ namespace CppSharp.Generators @@ -46,6 +46,8 @@ namespace CppSharp.Generators
public ISet<object> Visited { get; } = new HashSet<object>();
public AstVisitorOptions VisitOptions { get; } = new AstVisitorOptions();
protected CodeGenerator(BindingContext context, TranslationUnit unit)
: this(context, new List<TranslationUnit> { unit })
{
@ -331,7 +333,19 @@ namespace CppSharp.Generators @@ -331,7 +333,19 @@ namespace CppSharp.Generators
public virtual bool VisitProperty(Property property)
{
throw new NotImplementedException();
if (!VisitDeclaration(property))
return false;
if (VisitOptions.VisitPropertyAccessors)
{
if (property.GetMethod != null)
property.GetMethod.Visit(this);
if (property.SetMethod != null)
property.SetMethod.Visit(this);
}
return true;
}
public virtual bool VisitFriend(Friend friend)

Loading…
Cancel
Save