Browse Source

Fixed the wrapping of mapped types with operators.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/526/head
Dimitar Dobrev 10 years ago
parent
commit
b6c16051af
  1. 11
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 4
      tests/CSharpTemp/CSharpTemp.Tests.cs
  3. 9
      tests/CSharpTemp/CSharpTemp.cpp
  4. 20
      tests/CSharpTemp/CSharpTemp.cs
  5. 7
      tests/CSharpTemp/CSharpTemp.h

11
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -356,6 +356,14 @@ namespace CppSharp.Generators.CSharp
if (@class.IsIncomplete) if (@class.IsIncomplete)
return; return;
System.Type typeMap = null;
if (Driver.TypeDatabase.TypeMaps.ContainsKey(@class.Name))
{
typeMap = Driver.TypeDatabase.TypeMaps[@class.Name];
// disable the type map for the mapped class itself so that operator params are not mapped
Driver.TypeDatabase.TypeMaps.Remove(@class.Name);
}
PushBlock(CSharpBlockKind.Class); PushBlock(CSharpBlockKind.Class);
GenerateDeclarationCommon(@class); GenerateDeclarationCommon(@class);
@ -413,6 +421,9 @@ namespace CppSharp.Generators.CSharp
exit: exit:
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
if (typeMap != null)
Driver.TypeDatabase.TypeMaps.Add(@class.Name, typeMap);
} }
private void GenerateClassMarshals(Class @class) private void GenerateClassMarshals(Class @class)

4
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -42,6 +42,10 @@ public class CSharpTempTests : GeneratorTestFixture
using (ComplexType complexType = TestFlag.Flag1) using (ComplexType complexType = TestFlag.Flag1)
{ {
} }
using (var typeMappedWithOperator = new TypeMappedWithOperator())
{
int i = typeMappedWithOperator | 5;
}
} }
[Test] [Test]

9
tests/CSharpTemp/CSharpTemp.cpp

@ -663,3 +663,12 @@ void InheritsProtectedVirtualFromSecondaryBase::protectedVirtual()
void freeFunctionWithUnsupportedDefaultArg(Foo foo) void freeFunctionWithUnsupportedDefaultArg(Foo foo)
{ {
} }
TypeMappedWithOperator::TypeMappedWithOperator()
{
}
int TypeMappedWithOperator::operator |(int i)
{
return 0;
}

20
tests/CSharpTemp/CSharpTemp.cs

@ -78,6 +78,26 @@ namespace CppSharp.Tests
} }
} }
[TypeMap("TypeMappedWithOperator")]
public class TypeMappedWithOperator : TypeMap
{
public override string CSharpSignature(CSharpTypePrinterContext ctx)
{
// doesn't matter, we just need it to compile
return "int";
}
public override void CSharpMarshalToNative(MarshalContext ctx)
{
ctx.Return.Write(ctx.Parameter.Name);
}
public override void CSharpMarshalToManaged(MarshalContext ctx)
{
ctx.Return.Write(ctx.ReturnVarName);
}
}
public class TestAttributesPass : TranslationUnitPass public class TestAttributesPass : TranslationUnitPass
{ {
public override bool VisitFunctionDecl(Function function) public override bool VisitFunctionDecl(Function function)

7
tests/CSharpTemp/CSharpTemp.h

@ -593,3 +593,10 @@ protected:
}; };
void DLL_API freeFunctionWithUnsupportedDefaultArg(Foo foo = Foo()); void DLL_API freeFunctionWithUnsupportedDefaultArg(Foo foo = Foo());
class DLL_API TypeMappedWithOperator
{
public:
TypeMappedWithOperator();
int operator |(int i);
};

Loading…
Cancel
Save