Browse Source

Converted return types to their complementary interfaces, if any.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/68/head
Dimitar Dobrev 12 years ago
parent
commit
07beb47048
  1. 2
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 2
      src/Generator/Passes/MultipleInheritancePass.cs
  3. 28
      src/Generator/Passes/ParamTypeToInterfacePass.cs
  4. 1
      tests/CSharpTemp/CSharpTemp.Tests.cs
  5. 5
      tests/CSharpTemp/CSharpTemp.cpp
  6. 1
      tests/CSharpTemp/CSharpTemp.h

2
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -277,7 +277,7 @@ namespace CppSharp.Generators.CSharp @@ -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);

2
src/Generator/Passes/MultipleInheritancePass.cs

@ -85,9 +85,9 @@ namespace CppSharp.Passes @@ -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) });
}
interfaces.Add(@base, @interface);
return @interface;

28
src/Generator/Passes/ParamTypeToInterfacePass.cs

@ -4,12 +4,32 @@ namespace CppSharp.Passes @@ -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 @@ -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;
}
}
}

1
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -43,5 +43,6 @@ public class CSharpTempTests @@ -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));
}
}

5
tests/CSharpTemp/CSharpTemp.cpp

@ -50,3 +50,8 @@ int Baz::takesQux(const Qux& qux) @@ -50,3 +50,8 @@ int Baz::takesQux(const Qux& qux)
{
return qux.farAwayFunc();
}
Qux Baz::returnQux()
{
return Qux();
}

1
tests/CSharpTemp/CSharpTemp.h

@ -39,4 +39,5 @@ class DLL_API Baz : public Foo, public Bar @@ -39,4 +39,5 @@ class DLL_API Baz : public Foo, public Bar
{
public:
int takesQux(const Qux& qux);
Qux returnQux();
};

Loading…
Cancel
Save