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. 45
      src/AST/TypeExtensions.cs

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