|
|
@ -10,7 +10,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
public static bool IsPrimitiveType(this Type t, out PrimitiveType primitive) |
|
|
|
public static bool IsPrimitiveType(this Type t, out PrimitiveType primitive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var builtin = t.Desugar() as BuiltinType; |
|
|
|
var builtin = t.Desugar() as BuiltinType; |
|
|
|
if (builtin != null) |
|
|
|
if (builtin != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
primitive = builtin.Type; |
|
|
|
primitive = builtin.Type; |
|
|
@ -105,55 +105,55 @@ |
|
|
|
return type != null; |
|
|
|
return type != null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool IsClass(this Type t) |
|
|
|
public static bool IsClass(this Type t) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Class @class; |
|
|
|
Class @class; |
|
|
|
return t.TryGetClass(out @class); |
|
|
|
return t.TryGetClass(out @class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool TryGetClass(this Type t, out Class @class) |
|
|
|
public static bool TryGetClass(this Type t, out Class @class) |
|
|
|
{ |
|
|
|
{ |
|
|
|
t = t.Desugar(); |
|
|
|
t = t.Desugar(); |
|
|
|
|
|
|
|
|
|
|
|
var tag = t as TagType; |
|
|
|
var tag = t as TagType; |
|
|
|
if (tag != null) |
|
|
|
if (tag != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@class = tag.Declaration as Class; |
|
|
|
@class = tag.Declaration as Class; |
|
|
|
return @class != null; |
|
|
|
return @class != null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var type = t as TemplateSpecializationType; |
|
|
|
var type = t as TemplateSpecializationType; |
|
|
|
if (type != null) |
|
|
|
if (type != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var templatedClass = ((ClassTemplate)type.Template).TemplatedClass; |
|
|
|
var templatedClass = ((ClassTemplate)type.Template).TemplatedClass; |
|
|
|
@class = templatedClass.CompleteDeclaration == null |
|
|
|
@class = templatedClass.CompleteDeclaration == null |
|
|
|
? templatedClass |
|
|
|
? templatedClass |
|
|
|
: (Class)templatedClass.CompleteDeclaration; |
|
|
|
: (Class)templatedClass.CompleteDeclaration; |
|
|
|
return @class != null; |
|
|
|
return @class != null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@class = null; |
|
|
|
@class = null; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool IsEnum(this Type t) |
|
|
|
public static bool IsEnum(this Type t) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Enumeration @enum; |
|
|
|
Enumeration @enum; |
|
|
|
return t.TryGetEnum(out @enum); |
|
|
|
return t.TryGetEnum(out @enum); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool TryGetEnum(this Type t, out Enumeration @enum) |
|
|
|
public static bool TryGetEnum(this Type t, out Enumeration @enum) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var tag = t.Desugar() as TagType; |
|
|
|
var tag = t.Desugar() as TagType; |
|
|
|
|
|
|
|
|
|
|
|
if (tag == null) |
|
|
|
if (tag == null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@enum = null; |
|
|
|
@enum = null; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@enum = tag.Declaration as Enumeration; |
|
|
|
@enum = tag.Declaration as Enumeration; |
|
|
|
return @enum != null; |
|
|
|
return @enum != null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Type Desugar(this Type t) |
|
|
|
public static Type Desugar(this Type t) |
|
|
@ -184,39 +184,39 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return t; |
|
|
|
return t; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// If t is a pointer type the type pointed to by t will be returned.
|
|
|
|
/// If t is a pointer type the type pointed to by t will be returned.
|
|
|
|
/// Otherwise null.
|
|
|
|
/// Otherwise null.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static Type GetPointee(this Type t) |
|
|
|
public static Type GetPointee(this Type t) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var ptr = t as PointerType; |
|
|
|
var ptr = t as PointerType; |
|
|
|
if (ptr != null) |
|
|
|
if (ptr != null) |
|
|
|
return ptr.Pointee; |
|
|
|
return ptr.Pointee; |
|
|
|
var memberPtr = t as MemberPointerType; |
|
|
|
var memberPtr = t as MemberPointerType; |
|
|
|
if (memberPtr != null) |
|
|
|
if (memberPtr != null) |
|
|
|
return memberPtr.Pointee; |
|
|
|
return memberPtr.Pointee; |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// If t is a pointer type the type pointed to by t will be returned
|
|
|
|
/// If t is a pointer type the type pointed to by t will be returned
|
|
|
|
/// after fully dereferencing it. Otherwise null.
|
|
|
|
/// after fully dereferencing it. Otherwise null.
|
|
|
|
/// For example int** -> int.
|
|
|
|
/// For example int** -> int.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static Type GetFinalPointee(this Type t) |
|
|
|
public static Type GetFinalPointee(this Type t) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var finalPointee = t.GetPointee(); |
|
|
|
var finalPointee = t.GetPointee(); |
|
|
|
var pointee = finalPointee; |
|
|
|
var pointee = finalPointee; |
|
|
|
while (pointee != null) |
|
|
|
while (pointee != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
pointee = pointee.GetPointee(); |
|
|
|
pointee = pointee.GetPointee(); |
|
|
|
if (pointee != null) |
|
|
|
if (pointee != null) |
|
|
|
finalPointee = pointee; |
|
|
|
finalPointee = pointee; |
|
|
|
} |
|
|
|
} |
|
|
|
return finalPointee; |
|
|
|
return finalPointee; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |