|
|
|
|
@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
|
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using CppSharp.AST; |
|
|
|
|
using CppSharp.AST.Extensions; |
|
|
|
|
|
|
|
|
|
@ -21,7 +22,13 @@ namespace CppSharp.Passes
@@ -21,7 +22,13 @@ namespace CppSharp.Passes
|
|
|
|
|
if (!base.VisitFunctionDecl(function)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
if (!function.IsOperator || function.Parameters.Count > 1) |
|
|
|
|
// parameters and returns from a specialised interface
|
|
|
|
|
// must not be replaced if the templated interface uses a template parameter
|
|
|
|
|
Function templateInterfaceFunction = GetTemplateInterfaceFunction(function); |
|
|
|
|
|
|
|
|
|
if ((!function.IsOperator || function.Parameters.Count > 1) && |
|
|
|
|
(templateInterfaceFunction == null || |
|
|
|
|
!IsTemplateParameter(templateInterfaceFunction.OriginalReturnType))) |
|
|
|
|
{ |
|
|
|
|
var originalReturnType = function.OriginalReturnType; |
|
|
|
|
ChangeToInterfaceType(ref originalReturnType); |
|
|
|
|
@ -30,13 +37,27 @@ namespace CppSharp.Passes
@@ -30,13 +37,27 @@ namespace CppSharp.Passes
|
|
|
|
|
|
|
|
|
|
if (function.OperatorKind != CXXOperatorKind.Conversion && |
|
|
|
|
function.OperatorKind != CXXOperatorKind.ExplicitConversion) |
|
|
|
|
foreach (var parameter in function.Parameters.Where( |
|
|
|
|
p => p.Kind != ParameterKind.OperatorParameter)) |
|
|
|
|
{ |
|
|
|
|
IList<Parameter> parameters = function.Parameters.Where( |
|
|
|
|
p => p.Kind != ParameterKind.OperatorParameter && |
|
|
|
|
p.Kind != ParameterKind.IndirectReturnType).ToList(); |
|
|
|
|
|
|
|
|
|
var templateFunctionParameters = new List<Parameter>(); |
|
|
|
|
if (templateInterfaceFunction != null) |
|
|
|
|
templateFunctionParameters.AddRange( |
|
|
|
|
templateInterfaceFunction.Parameters.Where( |
|
|
|
|
p => p.Kind != ParameterKind.OperatorParameter && |
|
|
|
|
p.Kind != ParameterKind.IndirectReturnType)); |
|
|
|
|
for (int i = 0; i < parameters.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var qualifiedType = parameter.QualifiedType; |
|
|
|
|
if (templateFunctionParameters.Any() && |
|
|
|
|
IsTemplateParameter(templateFunctionParameters[i].QualifiedType)) |
|
|
|
|
continue; |
|
|
|
|
var qualifiedType = parameters[i].QualifiedType; |
|
|
|
|
ChangeToInterfaceType(ref qualifiedType); |
|
|
|
|
parameter.QualifiedType = qualifiedType; |
|
|
|
|
parameters[i].QualifiedType = qualifiedType; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -46,12 +67,55 @@ namespace CppSharp.Passes
@@ -46,12 +67,55 @@ namespace CppSharp.Passes
|
|
|
|
|
if (!base.VisitProperty(property)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
var templateInterfaceProperty = GetTemplateInterfaceProperty(property); |
|
|
|
|
|
|
|
|
|
if (templateInterfaceProperty != null && |
|
|
|
|
IsTemplateParameter(templateInterfaceProperty.QualifiedType)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
var type = property.QualifiedType; |
|
|
|
|
ChangeToInterfaceType(ref type); |
|
|
|
|
property.QualifiedType = type; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Function GetTemplateInterfaceFunction(Function function) |
|
|
|
|
{ |
|
|
|
|
Function templateInterfaceFunction = null; |
|
|
|
|
Class @class = function.OriginalNamespace as Class; |
|
|
|
|
if (@class != null && @class.IsInterface) |
|
|
|
|
templateInterfaceFunction = @class.Methods.First( |
|
|
|
|
m => m.OriginalFunction == function.OriginalFunction).InstantiatedFrom; |
|
|
|
|
return templateInterfaceFunction; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Property GetTemplateInterfaceProperty(Property property) |
|
|
|
|
{ |
|
|
|
|
if (property.GetMethod != null && |
|
|
|
|
property.GetMethod.SynthKind == FunctionSynthKind.InterfaceInstance) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
Property templateInterfaceProperty = null; |
|
|
|
|
Class @class = property.OriginalNamespace as Class; |
|
|
|
|
if (@class != null && @class.IsInterface) |
|
|
|
|
{ |
|
|
|
|
var specialization = @class as ClassTemplateSpecialization; |
|
|
|
|
if (specialization != null) |
|
|
|
|
{ |
|
|
|
|
Class template = specialization.TemplatedDecl.TemplatedClass; |
|
|
|
|
templateInterfaceProperty = template.Properties.FirstOrDefault( |
|
|
|
|
p => p.Name == property.Name); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return templateInterfaceProperty; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static bool IsTemplateParameter(QualifiedType type) |
|
|
|
|
{ |
|
|
|
|
return (type.Type.Desugar().GetFinalPointee() ?? type.Type).Desugar() is TemplateParameterType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void ChangeToInterfaceType(ref QualifiedType type) |
|
|
|
|
{ |
|
|
|
|
var finalType = (type.Type.GetFinalPointee() ?? type.Type).Desugar(); |
|
|
|
|
|