Browse Source

Added tests about the dereference and prefix/postfix operators. Fixed multiple inheritance not to include operators in interfaces.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/81/head
Dimitar Dobrev 12 years ago
parent
commit
47f03ae68c
  1. 2
      src/Generator/Passes/MultipleInheritancePass.cs
  2. 31
      src/Generator/Passes/ParamTypeToInterfacePass.cs
  3. 5
      tests/CSharpTemp/CSharpTemp.Tests.cs
  4. 24
      tests/CSharpTemp/CSharpTemp.cpp
  5. 5
      tests/CSharpTemp/CSharpTemp.h

2
src/Generator/Passes/MultipleInheritancePass.cs

@ -68,7 +68,7 @@ namespace CppSharp.Passes @@ -68,7 +68,7 @@ namespace CppSharp.Passes
@interface.Methods.AddRange(
from m in @base.Methods
where !m.IsConstructor && !m.IsDestructor && !m.IsStatic && !m.Ignore
where !m.IsConstructor && !m.IsDestructor && !m.IsStatic && !m.Ignore && !m.IsOperator
select new Method(m) { Namespace = @interface });
@interface.Properties.AddRange(

31
src/Generator/Passes/ParamTypeToInterfacePass.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using CppSharp.AST;
using System.Linq;
using CppSharp.AST;
namespace CppSharp.Passes
{
@ -6,24 +7,26 @@ namespace CppSharp.Passes @@ -6,24 +7,26 @@ namespace CppSharp.Passes
{
public override bool VisitFunctionDecl(Function function)
{
if (function.HasIndirectReturnTypeParameter)
if (!function.IsOperator)
{
var parameter = function.Parameters.Find(p => p.Kind == ParameterKind.IndirectReturnType);
parameter.QualifiedType = GetInterfaceType(parameter.QualifiedType);
}
else
{
function.ReturnType = GetInterfaceType(function.ReturnType);
if (function.HasIndirectReturnTypeParameter)
{
var parameter = function.Parameters.Find(p => p.Kind == ParameterKind.IndirectReturnType);
parameter.QualifiedType = GetInterfaceType(parameter.QualifiedType);
}
else
{
function.ReturnType = GetInterfaceType(function.ReturnType);
}
foreach (Parameter parameter in function.Parameters.Where(
p => p.Kind != ParameterKind.IndirectReturnType))
{
parameter.QualifiedType = GetInterfaceType(parameter.QualifiedType);
}
}
return base.VisitFunctionDecl(function);
}
public override bool VisitParameterDecl(Parameter parameter)
{
parameter.QualifiedType = GetInterfaceType(parameter.QualifiedType);
return base.VisitParameterDecl(parameter);
}
private static QualifiedType GetInterfaceType(QualifiedType type)
{
var tagType = type.Type as TagType;

5
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
using System;
using System.Reflection;
using System.Reflection;
using CSharpTemp;
using NUnit.Framework;
using Foo = CSharpTemp.Foo;
@ -8,7 +7,7 @@ using Foo = CSharpTemp.Foo; @@ -8,7 +7,7 @@ using Foo = CSharpTemp.Foo;
public class CSharpTempTests
{
[Test]
public unsafe void TestIndexer()
public void TestIndexer()
{
var foo = new Foo();

24
tests/CSharpTemp/CSharpTemp.cpp

@ -46,6 +46,30 @@ Foo& Bar::operator[](int i) @@ -46,6 +46,30 @@ Foo& Bar::operator[](int i)
return m_foo;
}
Bar Bar::operator *()
{
return *this;
}
const Bar& Bar::operator *(int m)
{
index *= m;
return *this;
}
const Bar& Bar::operator ++()
{
++index;
return *this;
}
Bar Bar::operator ++(int i)
{
Bar bar = *this;
index++;
return bar;
}
Baz::Nested::operator int() const
{
return 300;

5
tests/CSharpTemp/CSharpTemp.h

@ -31,8 +31,13 @@ public: @@ -31,8 +31,13 @@ public:
int method();
const Foo& operator[](int i) const;
Foo& operator[](int i);
Bar operator*();
const Bar& operator*(int m);
const Bar& operator++();
Bar operator++(int i);
private:
int index;
Foo m_foo;
};

Loading…
Cancel
Save