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

8
tests/Basic/Basic.Tests.cs

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

8
tests/Basic/Basic.h

@ -259,6 +259,14 @@ struct DLL_API TestDelegates @@ -259,6 +259,14 @@ struct DLL_API TestDelegates
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
// C#: Marshal.FreeHGlobal(arg0);
struct DLL_API TestMemoryLeaks

Loading…
Cancel
Save