mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 15:24:10 +02:00
Added RefType, changed how CRepr types are represented
This commit is contained in:
parent
716f7b3638
commit
0c946de3ca
13 changed files with 311 additions and 40 deletions
|
@ -12,7 +12,7 @@ namespace System
|
|||
// including the vtable and interface slots
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
public class Type
|
||||
{
|
||||
extern const Type* sTypes;
|
||||
|
@ -35,6 +35,14 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public static Enumerator Types
|
||||
{
|
||||
get
|
||||
{
|
||||
return .();
|
||||
}
|
||||
}
|
||||
|
||||
public int32 Size
|
||||
{
|
||||
get
|
||||
|
@ -461,6 +469,35 @@ namespace System
|
|||
{
|
||||
return FieldInfo.Enumerator(null, bindingFlags);
|
||||
}
|
||||
|
||||
public Result<T> GetCustomAttribute<T>() where T : Attribute
|
||||
{
|
||||
if (var typeInstance = this as TypeInstance)
|
||||
return typeInstance.[Friend]GetCustomAttribute<T>(typeInstance.[Friend]mCustomAttributesIdx);
|
||||
return .Err;
|
||||
}
|
||||
|
||||
public override void ToString(String strBuffer)
|
||||
{
|
||||
GetFullName(strBuffer);
|
||||
}
|
||||
|
||||
public struct Enumerator : IEnumerator<Type>
|
||||
{
|
||||
int32 mCurId;
|
||||
|
||||
public Result<Type> GetNext() mut
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (mCurId >= sTypeCount)
|
||||
return .Err;
|
||||
let type = sTypes[mCurId++];
|
||||
if (type != null)
|
||||
return .Ok(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum TypeCode : uint8
|
||||
|
@ -521,7 +558,7 @@ namespace System.Reflection
|
|||
}
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
public class TypeInstance : Type
|
||||
{
|
||||
[CRepr, AlwaysInclude]
|
||||
|
@ -588,15 +625,14 @@ namespace System.Reflection
|
|||
uint8 mInterfaceCount;
|
||||
int16 mMethodDataCount;
|
||||
int16 mPropertyDataCount;
|
||||
int16 mFieldDataCount;
|
||||
int16 mFieldDataCount;
|
||||
|
||||
void* mInterfaceDataPtr;
|
||||
MethodData* mMethodDataPtr;
|
||||
void* mPropertyDataPtr;
|
||||
FieldData* mFieldDataPtr;
|
||||
FieldData* mFieldDataPtr;
|
||||
void** mCustomAttrDataPtr;
|
||||
|
||||
|
||||
public override int32 InstanceSize
|
||||
{
|
||||
get
|
||||
|
@ -716,9 +752,25 @@ namespace System.Reflection
|
|||
{
|
||||
return FieldInfo.Enumerator(this, bindingFlags);
|
||||
}
|
||||
|
||||
Result<T> GetCustomAttribute<T>(int customAttributeIdx) where T : Attribute
|
||||
{
|
||||
if (customAttributeIdx == -1)
|
||||
return .Err;
|
||||
|
||||
void* data = mCustomAttrDataPtr[customAttributeIdx];
|
||||
|
||||
T attrInst = ?;
|
||||
switch (AttributeInfo.GetCustomAttribute(data, typeof(T), &attrInst))
|
||||
{
|
||||
case .Ok: return .Ok(attrInst);
|
||||
default:
|
||||
return .Err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
class PointerType : Type
|
||||
{
|
||||
TypeId mElementType;
|
||||
|
@ -738,7 +790,43 @@ namespace System.Reflection
|
|||
}
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
class RefType : Type
|
||||
{
|
||||
public enum RefKind
|
||||
{
|
||||
Ref,
|
||||
Out,
|
||||
Mut
|
||||
}
|
||||
|
||||
TypeId mElementType;
|
||||
RefKind mRefKind;
|
||||
|
||||
public RefKind RefKind => mRefKind;
|
||||
|
||||
public override Type UnderlyingType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Type.[Friend]GetType(mElementType);
|
||||
}
|
||||
}
|
||||
|
||||
public override void GetFullName(String strBuffer)
|
||||
{
|
||||
switch (mRefKind)
|
||||
{
|
||||
case .Ref: strBuffer.Append("ref ");
|
||||
case .Out: strBuffer.Append("out ");
|
||||
case .Mut: strBuffer.Append("mut ");
|
||||
}
|
||||
|
||||
UnderlyingType.GetFullName(strBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
class SizedArrayType : Type
|
||||
{
|
||||
TypeId mElementType;
|
||||
|
@ -769,7 +857,7 @@ namespace System.Reflection
|
|||
}
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
class UnspecializedGenericType : TypeInstance
|
||||
{
|
||||
[CRepr, AlwaysInclude]
|
||||
|
@ -782,7 +870,7 @@ namespace System.Reflection
|
|||
}
|
||||
|
||||
// Only for resolved types
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
class SpecializedGenericType : TypeInstance
|
||||
{
|
||||
TypeId mUnspecializedType;
|
||||
|
@ -828,7 +916,7 @@ namespace System.Reflection
|
|||
}
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
|
||||
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
|
||||
class ArrayType : SpecializedGenericType
|
||||
{
|
||||
int32 mElementSize;
|
||||
|
@ -890,7 +978,7 @@ namespace System.Reflection
|
|||
EnumDiscriminator = 0x0200
|
||||
}
|
||||
|
||||
public enum MethodFlags : int16
|
||||
public enum MethodFlags : uint16
|
||||
{
|
||||
MethodAccessMask = 0x0007,
|
||||
PrivateScope = 0x0000, // Member not referenceable.
|
||||
|
@ -923,6 +1011,7 @@ namespace System.Reflection
|
|||
StdCall = 0x1000,
|
||||
FastCall = 0x2000,
|
||||
ThisCall = 0x3000, // Purposely resuing StdCall|FastCall
|
||||
Mutating = 0x4000
|
||||
Mutating = 0x4000,
|
||||
Constructor = 0x8000,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue