1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-18 16:10:26 +02:00
Beef/BeefLibs/corlib/src/Object.bf

136 lines
3.1 KiB
Beef
Raw Normal View History

2019-08-23 11:56:54 -07:00
using System;
using System.Reflection;
using System.Collections;
2019-08-23 11:56:54 -07:00
using System.Diagnostics;
namespace System
{
class Object : IHashable
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
int mClassVData;
int mDbgAllocInfo;
#else
ClassVData* mClassVData;
#endif
public virtual ~this()
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
mClassVData = ((mClassVData & ~0x08) | 0x80);
#endif
}
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
[NoShow]
int32 GetFlags()
2019-08-23 11:56:54 -07:00
{
return (int32)mClassVData & 0xFF;
}
[DisableObjectAccessChecks, NoShow]
public bool IsDeleted()
{
return (int32)mClassVData & 0x80 != 0;
}
#else
[SkipCall]
public bool IsDeleted()
{
return false;
}
#endif
2020-12-19 14:19:33 -08:00
extern Type ConstEval_GetType();
2019-08-23 11:56:54 -07:00
public Type GetType()
{
2020-12-19 14:19:33 -08:00
if (Compiler.IsConstEval)
return ConstEval_GetType();
2019-08-23 11:56:54 -07:00
Type type;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
ClassVData* maskedVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
2019-08-23 11:56:54 -07:00
type = maskedVData.mType;
#else
type = mClassVData.mType;
#endif
if ((type.[Friend]mTypeFlags & TypeFlags.Boxed) != 0)
2019-08-23 11:56:54 -07:00
{
//int32 underlyingType = (int32)((TypeInstance)type).mUnderlyingType;
type = Type.[Friend]GetType(((TypeInstance)type).[Friend]mUnderlyingType);
2019-08-23 11:56:54 -07:00
}
return type;
}
[NoShow]
Type RawGetType()
2019-08-23 11:56:54 -07:00
{
2020-12-19 14:19:33 -08:00
if (Compiler.IsConstEval)
return ConstEval_GetType();
2019-08-23 11:56:54 -07:00
Type type;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
ClassVData* maskedVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
2019-08-23 11:56:54 -07:00
type = maskedVData.mType;
#else
type = mClassVData.mType;
#endif
return type;
}
2019-12-11 16:56:09 -08:00
#if BF_DYNAMIC_CAST_CHECK || BF_ENABLE_REALTIME_LEAK_CHECK
2019-08-23 11:56:54 -07:00
[NoShow]
public virtual Object DynamicCastToTypeId(int32 typeId)
{
if (typeId == (int32)RawGetType().[Friend]mTypeId)
2019-08-23 11:56:54 -07:00
return this;
return null;
}
[NoShow]
public virtual Object DynamicCastToInterface(int32 typeId)
{
return null;
}
#endif
int IHashable.GetHashCode()
{
return (int)Internal.UnsafeCastToPtr(this);
2019-08-23 11:56:54 -07:00
}
public virtual void ToString(String strBuffer)
{
let t = RawGetType();
if (t.IsBoxedStructPtr)
{
let ti = (TypeInstance)t;
let innerPtr = *(void**)((uint8*)Internal.UnsafeCastToPtr(this) + ti.[Friend]mMemberDataOffset);
strBuffer.Append("(");
ti.UnderlyingType.GetFullName(strBuffer);
strBuffer.AppendF("*)0x{0:A}", (uint)(void*)innerPtr);
return;
}
t.GetFullName(strBuffer);
strBuffer.Append("@0x");
((int)Internal.UnsafeCastToPtr(this)).ToString(strBuffer, "A", null);
2019-08-23 11:56:54 -07:00
}
2020-06-25 05:52:42 -07:00
private static void ToString(Object obj, String strBuffer)
{
if (obj == null)
strBuffer.Append("null");
else
obj.ToString(strBuffer);
}
2019-08-23 11:56:54 -07:00
[SkipCall, NoShow]
protected virtual void GCMarkMembers()
{
//PrintF("Object.GCMarkMembers %08X\n", this);
}
}
}