|
|
|
@ -6,8 +6,21 @@ namespace CppSharp.Passes
@@ -6,8 +6,21 @@ namespace CppSharp.Passes
|
|
|
|
|
{ |
|
|
|
|
public class ParamTypeToInterfacePass : TranslationUnitPass |
|
|
|
|
{ |
|
|
|
|
public ParamTypeToInterfacePass() |
|
|
|
|
{ |
|
|
|
|
VisitOptions.VisitClassBases = false; |
|
|
|
|
VisitOptions.VisitClassFields = false; |
|
|
|
|
VisitOptions.VisitEventParameters = false; |
|
|
|
|
VisitOptions.VisitNamespaceEnums = false; |
|
|
|
|
VisitOptions.VisitNamespaceEvents = false; |
|
|
|
|
VisitOptions.VisitTemplateArguments = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override bool VisitFunctionDecl(Function function) |
|
|
|
|
{ |
|
|
|
|
if (!base.VisitFunctionDecl(function)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
if (!function.IsOperator || function.Parameters.Count > 1) |
|
|
|
|
{ |
|
|
|
|
var originalReturnType = function.OriginalReturnType; |
|
|
|
@ -17,32 +30,57 @@ namespace CppSharp.Passes
@@ -17,32 +30,57 @@ namespace CppSharp.Passes
|
|
|
|
|
|
|
|
|
|
if (function.OperatorKind != CXXOperatorKind.Conversion && |
|
|
|
|
function.OperatorKind != CXXOperatorKind.ExplicitConversion) |
|
|
|
|
foreach (var parameter in function.Parameters.Where(p => p.Kind != ParameterKind.OperatorParameter)) |
|
|
|
|
foreach (var parameter in function.Parameters.Where( |
|
|
|
|
p => p.Kind != ParameterKind.OperatorParameter)) |
|
|
|
|
{ |
|
|
|
|
var qualifiedType = parameter.QualifiedType; |
|
|
|
|
ChangeToInterfaceType(ref qualifiedType); |
|
|
|
|
parameter.QualifiedType = qualifiedType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return base.VisitFunctionDecl(function); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override bool VisitProperty(Property property) |
|
|
|
|
{ |
|
|
|
|
if (!base.VisitProperty(property)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
var type = property.QualifiedType; |
|
|
|
|
ChangeToInterfaceType(ref type); |
|
|
|
|
property.QualifiedType = type; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void ChangeToInterfaceType(ref QualifiedType type) |
|
|
|
|
{ |
|
|
|
|
var tagType = (type.Type.GetFinalPointee() ?? type.Type) as TagType; |
|
|
|
|
if (tagType != null) |
|
|
|
|
var finalType = (type.Type.GetFinalPointee() ?? type.Type).Desugar(); |
|
|
|
|
Class @class; |
|
|
|
|
if (!finalType.TryGetClass(out @class)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
var specialization = @class as ClassTemplateSpecialization; |
|
|
|
|
Class @interface = null; |
|
|
|
|
if (specialization == null) |
|
|
|
|
{ |
|
|
|
|
var @class = tagType.Declaration as Class; |
|
|
|
|
if (@class != null) |
|
|
|
|
{ |
|
|
|
|
var @interface = @class.Namespace.Classes.Find(c => c.OriginalClass == @class); |
|
|
|
|
if (@interface != null) |
|
|
|
|
{ |
|
|
|
|
type.Type = (Type) type.Type.Clone(); |
|
|
|
|
((TagType) (type.Type.GetFinalPointee() ?? type.Type)).Declaration = @interface; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@interface = @class.Namespace.Classes.Find( |
|
|
|
|
c => c.OriginalClass == @class && c.IsInterface); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
Class template = specialization.TemplatedDecl.TemplatedClass; |
|
|
|
|
Class templatedInterface = @class.Namespace.Classes.Find( |
|
|
|
|
c => c.OriginalClass == template && c.IsInterface); |
|
|
|
|
if (templatedInterface != null) |
|
|
|
|
@interface = templatedInterface.Specializations.FirstOrDefault( |
|
|
|
|
s => s.OriginalClass == specialization); |
|
|
|
|
} |
|
|
|
|
if (@interface == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
type.Type = (Type) type.Type.Clone(); |
|
|
|
|
finalType = (type.Type.GetFinalPointee() ?? type.Type).Desugar(); |
|
|
|
|
finalType.TryGetClass(out @class, @interface); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|