Browse Source

The extension method Type.IsPointerTo<T> will take attributed types into account.

Fixed generation of attributed delegate types in my case.
pull/225/head
Elias Holzer 11 years ago
parent
commit
15f1394aaf
  1. 19
      src/AST/TypeExtensions.cs
  2. 8
      tests/Basic/Basic.Tests.cs
  3. 8
      tests/Basic/Basic.h

19
src/AST/TypeExtensions.cs

@ -94,21 +94,14 @@
public static bool IsPointerTo<T>(this Type t, out T type) where T : Type public static bool IsPointerTo<T>(this Type t, out T type) where T : Type
{ {
var ptr = t as PointerType; var pointee = t.GetPointee();
type = pointee as T;
if (ptr == null) if (type == null)
{ {
var functionPointer = t as MemberPointerType; var attributedType = pointee as AttributedType;
if (functionPointer != null) if (attributedType != null)
{ type = attributedType.Modified.Type as T;
type = functionPointer.Pointee as T;
return type != null;
}
type = null;
return false;
} }
type = ptr.Pointee as T;
return type != null; return type != null;
} }

8
tests/Basic/Basic.Tests.cs

@ -178,6 +178,14 @@ public class BasicTests : GeneratorTestFixture
Assert.AreEqual(8, doubleSum); Assert.AreEqual(8, doubleSum);
} }
[Test]
public void TestAttributedDelegate()
{
var attributedDelegate = basic.GetAttributedDelegate();
var result = attributedDelegate(2);
Assert.AreEqual(4, result);
}
[Test] [Test]
public void TestUnion() public void TestUnion()
{ {

8
tests/Basic/Basic.h

@ -259,6 +259,14 @@ struct DLL_API TestDelegates
MemberDelegate C; MemberDelegate C;
}; };
// Tests delegate generation for attributed function types
typedef int(__cdecl *AttributedDelegate)(int n);
DLL_API int __cdecl Double(int n) { return n * 2; }
DLL_API AttributedDelegate GetAttributedDelegate()
{
return Double;
}
// Tests memory leaks in constructors // Tests memory leaks in constructors
// C#: Marshal.FreeHGlobal(arg0); // C#: Marshal.FreeHGlobal(arg0);
struct DLL_API TestMemoryLeaks struct DLL_API TestMemoryLeaks

Loading…
Cancel
Save