diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index c7bf8353..4ede156b 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -277,7 +277,7 @@ namespace CppSharp.Generators.CSharp } Context.Return.Write("new {0}({1})", - QualifiedIdentifier(@class) + + QualifiedIdentifier(@class.OriginalClass ?? @class) + (Context.Driver.Options.GenerateAbstractImpls && @class.IsAbstract ? "Internal" : ""), instance); diff --git a/src/Generator/Passes/MultipleInheritancePass.cs b/src/Generator/Passes/MultipleInheritancePass.cs index d9c7b8e3..4651ab83 100644 --- a/src/Generator/Passes/MultipleInheritancePass.cs +++ b/src/Generator/Passes/MultipleInheritancePass.cs @@ -85,9 +85,9 @@ namespace CppSharp.Passes { ImplementInterfaceMethods(@class, @interface); ImplementInterfaceProperties(@class, @interface); - if (@base.Bases.All(b => b.Class != @interface)) - @base.Bases.Add(new BaseClassSpecifier { Type = new TagType(@interface) }); } + if (@base.Bases.All(b => b.Class != @interface)) + @base.Bases.Add(new BaseClassSpecifier { Type = new TagType(@interface) }); interfaces.Add(@base, @interface); return @interface; diff --git a/src/Generator/Passes/ParamTypeToInterfacePass.cs b/src/Generator/Passes/ParamTypeToInterfacePass.cs index c561d066..5e0e12d0 100644 --- a/src/Generator/Passes/ParamTypeToInterfacePass.cs +++ b/src/Generator/Passes/ParamTypeToInterfacePass.cs @@ -4,12 +4,32 @@ namespace CppSharp.Passes { public class ParamTypeToInterfacePass : TranslationUnitPass { + public override bool VisitFunctionDecl(Function function) + { + if (function.HasIndirectReturnTypeParameter) + { + var parameter = function.Parameters.Find(p => p.Kind == ParameterKind.IndirectReturnType); + parameter.QualifiedType = GetInterfaceType(parameter.QualifiedType); + } + else + { + function.ReturnType = GetInterfaceType(function.ReturnType); + } + return base.VisitFunctionDecl(function); + } + public override bool VisitParameterDecl(Parameter parameter) { - var tagType = parameter.QualifiedType.Type as TagType; + parameter.QualifiedType = GetInterfaceType(parameter.QualifiedType); + return base.VisitParameterDecl(parameter); + } + + private static QualifiedType GetInterfaceType(QualifiedType type) + { + var tagType = type.Type as TagType; if (tagType == null) { - var pointerType = parameter.QualifiedType.Type as PointerType; + var pointerType = type.Type as PointerType; if (pointerType != null) tagType = pointerType.Pointee as TagType; } @@ -20,10 +40,10 @@ namespace CppSharp.Passes { var @interface = @class.Namespace.Classes.Find(c => c.OriginalClass == @class); if (@interface != null) - parameter.QualifiedType = new QualifiedType(new TagType(@interface)); + return new QualifiedType(new TagType(@interface)); } } - return base.VisitParameterDecl(parameter); + return type; } } } diff --git a/tests/CSharpTemp/CSharpTemp.Tests.cs b/tests/CSharpTemp/CSharpTemp.Tests.cs index 8e05e774..449ede61 100644 --- a/tests/CSharpTemp/CSharpTemp.Tests.cs +++ b/tests/CSharpTemp/CSharpTemp.Tests.cs @@ -43,5 +43,6 @@ public class CSharpTempTests Assert.That(bar[0].A, Is.EqualTo(1000)); Assert.That(baz.farAwayFunc(), Is.EqualTo(20)); Assert.That(baz.takesQux(baz), Is.EqualTo(20)); + Assert.That(baz.returnQux().farAwayFunc(), Is.EqualTo(20)); } } \ No newline at end of file diff --git a/tests/CSharpTemp/CSharpTemp.cpp b/tests/CSharpTemp/CSharpTemp.cpp index 01826516..3a48155e 100644 --- a/tests/CSharpTemp/CSharpTemp.cpp +++ b/tests/CSharpTemp/CSharpTemp.cpp @@ -50,3 +50,8 @@ int Baz::takesQux(const Qux& qux) { return qux.farAwayFunc(); } + +Qux Baz::returnQux() +{ + return Qux(); +} diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index 608e7899..6453d89f 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -39,4 +39,5 @@ class DLL_API Baz : public Foo, public Bar { public: int takesQux(const Qux& qux); + Qux returnQux(); };