Browse Source

Refactoring fixes in ParamTypeToInterfacePass.

pull/1300/head
João Matos 6 years ago committed by João Matos
parent
commit
4ac2427afc
  1. 22
      src/Generator/Passes/ParamTypeToInterfacePass.cs

22
src/Generator/Passes/ParamTypeToInterfacePass.cs

@ -5,6 +5,10 @@ using CppSharp.AST.Extensions; @@ -5,6 +5,10 @@ using CppSharp.AST.Extensions;
namespace CppSharp.Passes
{
/// <summary>
/// Replaces all references to secondary bases with their respective interface
/// type that is generated by MultipleInheritancePass.
/// </summary>
public class ParamTypeToInterfacePass : TranslationUnitPass
{
public ParamTypeToInterfacePass()
@ -29,7 +33,8 @@ namespace CppSharp.Passes @@ -29,7 +33,8 @@ namespace CppSharp.Passes
// parameters and returns from a specialised interface
// must not be replaced if the templated interface uses a template parameter
Function templateInterfaceFunction = GetTemplateInterfaceFunction(function);
var interfaceFunction = GetInterfaceFunction(function);
var templateInterfaceFunction = interfaceFunction?.InstantiatedFrom;
if ((!function.IsOperator || function.Parameters.Count > 1) &&
(templateInterfaceFunction == null ||
@ -53,11 +58,13 @@ namespace CppSharp.Passes @@ -53,11 +58,13 @@ namespace CppSharp.Passes
templateInterfaceFunction.Parameters.Where(
p => p.Kind != ParameterKind.OperatorParameter &&
p.Kind != ParameterKind.IndirectReturnType));
for (int i = 0; i < parameters.Count; i++)
{
if (templateFunctionParameters.Any() &&
IsTemplateParameter(templateFunctionParameters[i].QualifiedType))
continue;
var qualifiedType = parameters[i].QualifiedType;
ChangeToInterfaceType(ref qualifiedType);
parameters[i].QualifiedType = qualifiedType;
@ -84,14 +91,13 @@ namespace CppSharp.Passes @@ -84,14 +91,13 @@ namespace CppSharp.Passes
return true;
}
private static Function GetTemplateInterfaceFunction(Function function)
private static Function GetInterfaceFunction(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;
var @class = function.OriginalNamespace as Class;
if (@class == null || !@class.IsInterface)
return null;
return @class.Methods.First(m => m.OriginalFunction == function.OriginalFunction);
}
private static Property GetTemplateInterfaceProperty(Property property)

Loading…
Cancel
Save