Browse Source

Added new extension method Type.GetPointee() which returns the pointee of either a Pointer- or MemberPointerType.

pull/225/head
Elias Holzer 12 years ago
parent
commit
92568fadbf
  1. 55
      src/AST/TypeExtensions.cs

55
src/AST/TypeExtensions.cs

@ -156,32 +156,37 @@
return t; return t;
} }
public static Type GetFinalPointee(this PointerType pointer) /// <summary>
/// If t is a pointer type the type pointed to by t will be returned.
/// Otherwise null.
/// </summary>
public static Type GetPointee(this Type t)
{ {
var pointee = pointer.Pointee; var ptr = t as PointerType;
while (pointee.IsPointer()) if (ptr != null)
{ return ptr.Pointee;
var p = pointee as PointerType; var memberPtr = t as MemberPointerType;
if (p != null) if (memberPtr != null)
pointee = p.Pointee; return memberPtr.Pointee;
else return null;
return GetFinalPointee(pointee as MemberPointerType); }
}
return pointee; /// <summary>
} /// If t is a pointer type the type pointed to by t will be returned
/// after fully dereferencing it. Otherwise null.
public static Type GetFinalPointee(this MemberPointerType pointer) /// For example int** -> int.
{ /// </summary>
var pointee = pointer.Pointee; public static Type GetFinalPointee(this Type t)
while (pointee.IsPointer()) {
{ var finalPointee = t.GetPointee();
var p = pointee as MemberPointerType; var pointee = finalPointee;
if (p != null) while (pointee != null)
pointee = p.Pointee; {
else pointee = pointee.GetPointee();
return GetFinalPointee(pointee as PointerType); if (pointee != null)
} finalPointee = pointee;
return pointee; }
return finalPointee;
} }
} }
} }
Loading…
Cancel
Save