Re-work how managed properties are stored in the AST and visiting behavior.
We now only store top-level property AST nodes instead of getter/setter nodes attached to leaf nodes.
This commit is contained in:
Родитель
de7d37fb2b
Коммит
a4dac13389
|
@ -260,6 +260,15 @@ namespace Embeddinator.Generators
|
|||
if (IsSystemObjectMethod(method))
|
||||
continue;
|
||||
|
||||
var properties = method.DeclaringType.__GetDeclaredProperties();
|
||||
var isPropertyAccessor = properties.Any(prop =>
|
||||
{
|
||||
return (prop.GetMethod == method) || (prop.SetMethod == method);
|
||||
});
|
||||
|
||||
if (isPropertyAccessor)
|
||||
continue;
|
||||
|
||||
var decl = VisitMethod(method);
|
||||
@class.Declarations.Add(decl);
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ namespace Embeddinator.Generators
|
|||
TranslationUnit unit) : base(context, unit)
|
||||
{
|
||||
Unit = unit;
|
||||
VisitOptions.VisitPropertyAccessors = true;
|
||||
}
|
||||
|
||||
public override string GeneratedIdentifier(string id)
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
using CppSharp;
|
||||
using System.Linq;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
using CppSharp.Generators.AST;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Embeddinator.Passes;
|
||||
|
||||
namespace Embeddinator.Generators
|
||||
|
@ -170,23 +168,6 @@ namespace Embeddinator.Generators
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool VisitProperty(Property property)
|
||||
{
|
||||
if (!VisitDeclaration(@property))
|
||||
return false;
|
||||
|
||||
if (property.Field == null)
|
||||
return false;
|
||||
|
||||
var getter = property.GetMethod;
|
||||
VisitMethodDecl(getter);
|
||||
|
||||
var setter = property.SetMethod;
|
||||
VisitMethodDecl(setter);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -433,7 +433,15 @@ namespace Embeddinator.Generators
|
|||
return false;
|
||||
|
||||
if (property.Field == null)
|
||||
return false;
|
||||
{
|
||||
if (property.GetMethod != null)
|
||||
property.GetMethod.Visit(this);
|
||||
|
||||
if (property.SetMethod != null)
|
||||
property.SetMethod.Visit(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GenerateFieldGetter(property);
|
||||
NewLine();
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Embeddinator.Generators
|
|||
: base(context, new List<TranslationUnit> { unit })
|
||||
{
|
||||
TypePrinter = new JavaTypePrinter(context);
|
||||
VisitOptions.VisitPropertyAccessors = true;
|
||||
}
|
||||
|
||||
public Declaration Declaration;
|
||||
|
@ -432,25 +433,6 @@ namespace Embeddinator.Generators
|
|||
return true;
|
||||
}
|
||||
|
||||
public override bool VisitProperty(Property property)
|
||||
{
|
||||
if (!VisitDeclaration(property))
|
||||
return false;
|
||||
|
||||
if (property.Field == null)
|
||||
return false;
|
||||
|
||||
var getter = property.GetMethod;
|
||||
if (getter != null)
|
||||
VisitMethodDecl(getter);
|
||||
|
||||
var setter = property.SetMethod;
|
||||
if (setter != null)
|
||||
VisitMethodDecl(setter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool VisitFieldDecl(Field field)
|
||||
{
|
||||
// Ignore fields since they're converted to properties (getter/setter pairs).
|
||||
|
|
|
@ -9,6 +9,11 @@ namespace Embeddinator.Passes
|
|||
{
|
||||
public static string ObjectParameterId => "object";
|
||||
|
||||
public FixMethodParametersPass()
|
||||
{
|
||||
VisitOptions.VisitPropertyAccessors = true;
|
||||
}
|
||||
|
||||
void AddObjectParameterToMethod(Method method, Class @class)
|
||||
{
|
||||
var ptrType = new QualifiedType(
|
||||
|
@ -79,19 +84,5 @@ namespace Embeddinator.Passes
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool VisitProperty(Property property)
|
||||
{
|
||||
if (!VisitDeclaration(property))
|
||||
return false;
|
||||
|
||||
if (property.GetMethod != null)
|
||||
property.GetMethod.Visit(this);
|
||||
|
||||
if (property.SetMethod != null)
|
||||
property.SetMethod.Visit(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace Embeddinator.Passes
|
|||
{
|
||||
Arrays = new Dictionary<string, QualifiedType>();
|
||||
Declarations = new List<TypedefDecl>();
|
||||
VisitOptions.VisitPropertyAccessors = true;
|
||||
}
|
||||
|
||||
public override bool VisitTranslationUnit(TranslationUnit unit)
|
||||
|
|
|
@ -90,23 +90,49 @@ namespace Embeddinator.Passes
|
|||
if (!method.IsPure || method.IsFinal)
|
||||
continue;
|
||||
|
||||
var methodImpl = new Method(method)
|
||||
{
|
||||
IsPure = false,
|
||||
IsImplicit = true,
|
||||
IsOverride = true,
|
||||
SynthKind = FunctionSynthKind.InterfaceInstance,
|
||||
ExplicitInterfaceImpl = @interface,
|
||||
Namespace = impl,
|
||||
CompleteDeclaration = method
|
||||
};
|
||||
var methodImpl = CreateMethod(@interface, impl, method);
|
||||
|
||||
impl.Declarations.Add(methodImpl);
|
||||
}
|
||||
|
||||
foreach (var property in @interface.Declarations.OfType<Property>())
|
||||
{
|
||||
if (property.IsImplicit)
|
||||
continue;
|
||||
|
||||
if (!property.IsPure)
|
||||
continue;
|
||||
|
||||
if (property.GetMethod != null)
|
||||
{
|
||||
var getMethodImpl = CreateMethod(@interface, impl, property.GetMethod);
|
||||
impl.Declarations.Add(getMethodImpl);
|
||||
}
|
||||
|
||||
if (property.SetMethod != null)
|
||||
{
|
||||
var setMethodImpl = CreateMethod(@interface, impl, property.SetMethod);
|
||||
impl.Declarations.Add(setMethodImpl);
|
||||
}
|
||||
}
|
||||
|
||||
InterfaceImplementations.Add(impl);
|
||||
}
|
||||
|
||||
static Method CreateMethod(Class @interface, Class impl, Method method)
|
||||
{
|
||||
return new Method(method)
|
||||
{
|
||||
IsPure = false,
|
||||
IsImplicit = true,
|
||||
IsOverride = true,
|
||||
SynthKind = FunctionSynthKind.InterfaceInstance,
|
||||
ExplicitInterfaceImpl = @interface,
|
||||
Namespace = impl,
|
||||
CompleteDeclaration = method
|
||||
};
|
||||
}
|
||||
|
||||
void AddObjectGetterToInterface(Class @interface)
|
||||
{
|
||||
var type = new BuiltinType(PrimitiveType.IntPtr);
|
||||
|
|
Загрузка…
Ссылка в новой задаче