1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 23:34:10 +02:00

Removed 'internal' protection - it's all about [Friend] now

This commit is contained in:
Brian Fiete 2020-03-09 06:34:16 -07:00
parent 81af04a1ce
commit 14ac27c977
119 changed files with 1339 additions and 1388 deletions

View file

@ -196,7 +196,7 @@ namespace System
protected override void GCMarkMembers()
{
let type = typeof(T);
if ((type.mTypeFlags & .WantsMark) == 0)
if ((type.[Friend]mTypeFlags & .WantsMark) == 0)
return;
for (int i = 0; i < mLength; i++)
{

View file

@ -6,31 +6,33 @@ namespace System
public enum AttributeTargets
{
Assembly = 0x0001,
Module = 0x0002,
Class = 0x0004,
Struct = 0x0008,
Enum = 0x0010,
Constructor = 0x0020,
Method = 0x0040,
Property = 0x0080,
Field = 0x0100,
StaticField = 0x0200,
Interface = 0x0400,
Parameter = 0x0800,
Delegate = 0x1000,
Assembly = 0x0001,
Module = 0x0002,
Class = 0x0004,
Struct = 0x0008,
Enum = 0x0010,
Constructor = 0x0020,
Method = 0x0040,
Property = 0x0080,
Field = 0x0100,
StaticField = 0x0200,
Interface = 0x0400,
Parameter = 0x0800,
Delegate = 0x1000,
Function = 0x2000,
ReturnValue = 0x4000,
//@todo GENERICS: document GenericParameter
GenericParameter = 0x8000,
ReturnValue = 0x4000,
//@todo GENERICS: document GenericParameter
GenericParameter = 0x8000,
Invocation = 0x10000,
MemberAccess = 0x20000,
Alloc = 0x40000,
Delete = 0x80000,
All = Assembly | Module | Class | Struct | Enum | Constructor |
Method | Property | Field | StaticField | Interface | Parameter |
Delegate | Function | ReturnValue | GenericParameter | Invocation | MemberAccess,
}
All = Assembly | Module | Class | Struct | Enum | Constructor |
Method | Property | Field | StaticField | Interface | Parameter |
Delegate | Function | ReturnValue | GenericParameter | Invocation | MemberAccess |
Alloc | Delete,
}
public enum ReflectKind
{
@ -58,22 +60,22 @@ namespace System
public sealed struct AttributeUsageAttribute : Attribute
{
internal AttributeTargets mAttributeTarget = AttributeTargets.All;
internal AttributeFlags mAttributeFlags = .None;
internal ReflectKind mReflectUser = .None;
AttributeTargets mAttributeTarget = .All;
AttributeFlags mAttributeFlags = .None;
ReflectKind mReflectUser = .None;
public this(AttributeTargets validOn)
{
mAttributeTarget = validOn;
}
internal this(AttributeTargets validOn, AttributeFlags flags)
public this(AttributeTargets validOn, AttributeFlags flags)
{
mAttributeTarget = validOn;
mAttributeFlags = flags;
}
internal this(AttributeTargets validOn, bool allowMultiple, bool inherited)
public this(AttributeTargets validOn, bool allowMultiple, bool inherited)
{
mAttributeTarget = validOn;
if (!allowMultiple)
@ -126,7 +128,7 @@ namespace System
}
}
[AttributeUsage(.MemberAccess)]
[AttributeUsage(.MemberAccess | .Alloc | .Delete)]
public struct FriendAttribute : Attribute
{

View file

@ -532,7 +532,7 @@ namespace System.Collections.Generic
#endif
private T* mCurrent;
internal this(List<T> list)
public this(List<T> list)
{
mList = list;
mIndex = 0;

View file

@ -16,7 +16,7 @@ namespace System.Collections.Generic
private int mCount;
private Comparison<T> comparer;
internal this(T* keys, T2* items, int count, Comparison<T> comparer)
public this(T* keys, T2* items, int count, Comparison<T> comparer)
{
this.keys = keys;
this.items = items;
@ -24,7 +24,7 @@ namespace System.Collections.Generic
this.comparer = comparer;
}
internal static int FloorLog2(int n)
public static int FloorLog2(int n)
{
int result = 0;
int val = n;
@ -44,7 +44,7 @@ namespace System.Collections.Generic
return low + ((hi - low) >> 1);
}
internal void SwapIfGreaterWithItems(int a, int b)
public void SwapIfGreaterWithItems(int a, int b)
{
if (a != b)
{
@ -77,7 +77,7 @@ namespace System.Collections.Generic
}
}
internal void Sort(int left, int length)
public void Sort(int left, int length)
{
IntrospectiveSort(left, length);
}

View file

@ -37,7 +37,7 @@ namespace System
public const double PositiveInfinity = (double)1.0 / (double)(0.0);
public const double NaN = (double)0.0 / (double)0.0;
internal static double NegativeZero = BitConverter.Int64BitsToDouble((int64)(0x8000000000000000UL));
public static double NegativeZero = BitConverter.Int64BitsToDouble((int64)(0x8000000000000000UL));
public static int operator<=>(Double lhs, Double rhs)
{
@ -95,7 +95,7 @@ namespace System
}
}
internal bool IsNegative
public bool IsNegative
{
get
{

View file

@ -8,19 +8,19 @@ namespace System
static readonly string NewLine = new string("\n");
#endif // !PLATFORM_UNIX
internal static String GetResourceString(String key)
public static String GetResourceString(String key)
{
return key;
//return GetResourceFromDefault(key);
}
internal static String GetResourceString(String key, params Object[] values)
public static String GetResourceString(String key, params Object[] values)
{
return key;
//return GetResourceFromDefault(key);
}
internal static String GetRuntimeResourceString(String key, String defaultValue = null)
public static String GetRuntimeResourceString(String key, String defaultValue = null)
{
if (defaultValue != null)
return defaultValue;

View file

@ -6,8 +6,8 @@ namespace System
{
struct Nullable<T> where T : struct
{
internal T mValue;
internal bool mHasValue;
T mValue;
bool mHasValue;
public this(T value)
{

View file

@ -71,16 +71,16 @@ namespace System
#else
type = mClassVData.mType;
#endif
if ((type.mTypeFlags & TypeFlags.Boxed) != 0)
if ((type.[Friend]mTypeFlags & TypeFlags.Boxed) != 0)
{
//int32 underlyingType = (int32)((TypeInstance)type).mUnderlyingType;
type = Type.GetType(((TypeInstance)type).mUnderlyingType);
type = Type.[Friend]GetType(((TypeInstance)type).[Friend]mUnderlyingType);
}
return type;
}
[NoShow]
internal Type RawGetType()
Type RawGetType()
{
Type type;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
@ -96,7 +96,7 @@ namespace System
[NoShow]
public virtual Object DynamicCastToTypeId(int32 typeId)
{
if (typeId == (int32)RawGetType().mTypeId)
if (typeId == (int32)RawGetType().[Friend]mTypeId)
return this;
return null;
}
@ -477,8 +477,8 @@ namespace System
var typeInst = (TypeInstance)typeof(T);
for (var field in typeInst.GetFields())
{
if (str == field.mFieldData.mName)
return .Ok(*((T*)(&field.mFieldData.mConstValue)));
if (str == field.[Friend]mFieldData.mName)
return .Ok(*((T*)(&field.[Friend]mFieldData.mConstValue)));
}
return .Err;

View file

@ -5,8 +5,14 @@ namespace System.Reflection
[CRepr, AlwaysInclude]
public struct FieldInfo
{
internal TypeInstance mTypeInstance;
internal TypeInstance.FieldData* mFieldData;
public enum Error
{
InvalidTargetType,
InvalidValueType
}
TypeInstance mTypeInstance;
TypeInstance.FieldData* mFieldData;
public this(TypeInstance typeInstance, TypeInstance.FieldData* fieldData)
{
@ -26,7 +32,7 @@ namespace System.Reflection
{
get
{
return Type.GetType(mFieldData.mFieldTypeId);
return Type.[Friend]GetType(mFieldData.mFieldTypeId);
}
}
@ -38,56 +44,76 @@ namespace System.Reflection
}
}
public Result<void> SetValue(Object obj, Object value)
public Result<void, Error> SetValue(Object obj, Object value)
{
int32 dataOffsetAdjust = 0;
if (mTypeInstance.IsStruct)
{
Type boxedType = obj.RawGetType();
Type boxedType = obj.[Friend]RawGetType();
bool typeMatched = false;
if (boxedType.IsBoxed)
{
if (mTypeInstance == boxedType.UnderlyingType)
{
dataOffsetAdjust = boxedType.mMemberDataOffset;
dataOffsetAdjust = boxedType.[Friend]mMemberDataOffset;
typeMatched = true;
}
}
if (!typeMatched)
return .Err; // "Invalid target type");
return .Err(.InvalidTargetType); // "Invalid target type");
}
Type fieldType = Type.GetType(mFieldData.mFieldTypeId);
//Type objType = obj.GetType();
void* dataAddr = ((uint8*)(void*)obj) + mFieldData.mDataOffset + dataOffsetAdjust;
Type fieldType = Type.[Friend]GetType(mFieldData.mFieldTypeId);
void* fieldDataAddr = ((uint8*)(void*)obj) + mFieldData.mDataOffset + dataOffsetAdjust;
switch (fieldType.mTypeCode)
{
case TypeCode.Int32:
Type rawValueType = value.[Friend]RawGetType();
void* valueDataAddr = ((uint8*)(void*)value) + rawValueType.[Friend]mMemberDataOffset;
Type valueType = value.GetType();
if ((valueType != fieldType) && (valueType.IsTypedPrimitive))
valueType = valueType.UnderlyingType;
if (valueType == fieldType)
{
Internal.MemCpy(fieldDataAddr, valueDataAddr, fieldType.[Friend]mSize);
}
else
{
return .Err(.InvalidValueType);
}
/*switch (fieldType.mTypeCode)
{
case .Boolean:
if (!value is bool)
return .Err(.InvalidValueType);
*(bool*)(uint8*)dataAddr = (.)value;
break;
case .Int32:
if (!value is int32)
return .Err; //("Invalid type");
*(int32*)(uint8*)dataAddr = (int32)value;
return .Err(.InvalidValueType);
*(int32*)(uint8*)dataAddr = (.)value;
break;
default:
return .Err; //("Invalid type");
}
return .Err(.InvalidValueType);
}*/
return .Ok;
}
public Result<void> SetValue(Object obj, Variant value)
{
int32 dataOffsetAdjust = 0;
if (mTypeInstance.IsStruct)
{
Type boxedType = obj.RawGetType();
Type boxedType = obj.[Friend]RawGetType();
bool typeMatched = false;
if (boxedType.IsBoxed)
{
if (mTypeInstance == boxedType.UnderlyingType)
{
dataOffsetAdjust = boxedType.mMemberDataOffset;
dataOffsetAdjust = boxedType.[Friend]mMemberDataOffset;
typeMatched = true;
}
}
@ -95,8 +121,7 @@ namespace System.Reflection
return .Err;//("Invalid target type");
}
Type fieldType = Type.GetType(mFieldData.mFieldTypeId);
//Type objType = obj.GetType();
Type fieldType = Type.[Friend]GetType(mFieldData.mFieldTypeId);
void* dataAddr = ((uint8*)(void*)obj) + mFieldData.mDataOffset + dataOffsetAdjust;
@ -105,26 +130,6 @@ namespace System.Reflection
value.CopyValueData(dataAddr);
//TypeCode typeCode = fieldType.mTypeCode;
/*if (typeCode == TypeCode.Enum)
typeCode = fieldType.GetUnderlyingType().mTypeCode;
switch (typeCode)
{
case TypeCode.Int32:
*(int32*)dataAddr = value.Get<int32>();
break;
case TypeCode.Boolean:
*(bool*)dataAddr = value.Get<bool>();
break;
case TypeCode.Object:
*(Object*)dataAddr = value.Get<Object>();
break;
default:
return .Err;//("Invalid type");
}*/
return .Ok;
}
@ -135,12 +140,10 @@ namespace System.Reflection
public Result<T> GetCustomAttribute<T>() where T : Attribute
{
return .Err;
/*if (mFieldData.mCustomAttributesIdx == -1)
return .Err;
void* data = mTypeInstance.mCustomAttrDataPtr[mFieldData.mCustomAttributesIdx];
void* data = mTypeInstance.[Friend]mCustomAttrDataPtr[mFieldData.mCustomAttributesIdx];
T attrInst = ?;
switch (AttributeInfo.GetCustomAttribute(data, typeof(T), &attrInst))
@ -149,21 +152,17 @@ namespace System.Reflection
default:
return .Err;
}*/
return .Err;
}
void* GetDataPtrAndType(Object value, out Type type)
{
type = value.RawGetType();
type = value.[Friend]RawGetType();
/*if (type.IsStruct)
return &value;*/
if (type.IsStruct)
{
NOP!();
}
if (type.IsBoxed)
return ((uint8*)(void*)value) + type.mMemberDataOffset;
return ((uint8*)(void*)value) + type.[Friend]mMemberDataOffset;
return ((uint8*)(void*)value);
}
@ -173,37 +172,26 @@ namespace System.Reflection
Type tTarget;
void* targetDataAddr = GetDataPtrAndType(target, out tTarget);
//Type tTarget = target.RawGetType();
//void* targetDataAddr = (void*)&target;
Type tMember = typeof(TMember);
targetDataAddr = (uint8*)targetDataAddr + mFieldData.mDataOffset;
Type fieldType = Type.GetType(mFieldData.mFieldTypeId);
Type fieldType = Type.[Friend]GetType(mFieldData.mFieldTypeId);
if (tMember.mTypeCode == TypeCode.Object)
if (tMember.[Friend]mTypeCode == TypeCode.Object)
{
if (!tTarget.IsSubtypeOf(mTypeInstance))
Runtime.FatalError();
value = *(TMember*)targetDataAddr;
}
else if (tMember.mTypeCode == TypeCode.Int32)
{
if (fieldType.mTypeCode == TypeCode.Int32)
{
if (tMember.mTypeCode != TypeCode.Int32)
Runtime.FatalError("Expected int");
*(int32*)&value = *(int32*)targetDataAddr;
}
else
{
return .Err;//("Invalid type");
}
}
else if (fieldType.[Friend]mTypeCode == tMember.[Friend]mTypeCode)
{
Internal.MemCpy(&value, targetDataAddr, tMember.Size);
}
else
{
return .Err;//("Invalid type");
return .Err;
}
return .Ok;
@ -215,67 +203,28 @@ namespace System.Reflection
Type tTarget;
void* targetDataAddr = GetDataPtrAndType(target, out tTarget);
//Type tTarget = target.RawGetType();
//void* targetDataAddr = (void*)&target;
if (!tTarget.IsSubtypeOf(mTypeInstance))
Runtime.FatalError("Invalid type");
targetDataAddr = (uint8*)targetDataAddr + mFieldData.mDataOffset;
Type fieldType = Type.GetType(mFieldData.mFieldTypeId);
Type fieldType = Type.[Friend]GetType(mFieldData.mFieldTypeId);
/*if (fieldType.IsNullable)
{
var specializedType = (SpecializedGenericType)fieldType;
var genericArg = specializedType.GetGenericArg(0);
bool hasValue = *(bool*)((uint8*)targetDataAddr + genericArg.mSize);
if (!hasValue)
return .Err;
fieldType = genericArg;
}*/
//value.mStructType = (int)(void*)fieldType;
TypeCode typeCode = fieldType.mTypeCode;
TypeCode typeCode = fieldType.[Friend]mTypeCode;
if (typeCode == TypeCode.Enum)
typeCode = fieldType.UnderlyingType.mTypeCode;
typeCode = fieldType.UnderlyingType.[Friend]mTypeCode;
/*if (typeCode == TypeCode.Int32)
if (typeCode == TypeCode.Object)
{
*(int32*)&value.mData = *(int32*)targetDataAddr;
}
else if (typeCode == TypeCode.Boolean)
{
*(bool*)&value.mData = *(bool*)targetDataAddr;
}
else */if (typeCode == TypeCode.Object)
{
value.mStructType = 0;
value.mData = *(int*)targetDataAddr;
value.[Friend]mStructType = 0;
value.[Friend]mData = *(int*)targetDataAddr;
}
else
{
value = Variant.Create(fieldType, targetDataAddr);
}
/*else if (fieldType.mSize <= sizeof(int))
{
value.mStructType = (int)(void*)fieldType;
Internal.MemCpy(&value.mData, targetDataAddr, fieldType.mSize);
}
else
{
value.mStructType = (int)(void*)fieldType;
void* data = new uint8[fieldType.mSize]*;
Internal.MemCpy(data, targetDataAddr, fieldType.mSize);
value.mData = (int)data;
}*/
/*{
return .Err;
}*/
return value;
}
@ -296,21 +245,21 @@ namespace System.Reflection
#unwarn
void* targetDataAddr = (void*)(int)mFieldData.mConstValue;
Type fieldType = Type.GetType(mFieldData.mFieldTypeId);
value.mStructType = (int)(void*)fieldType;
Type fieldType = Type.[Friend]GetType(mFieldData.mFieldTypeId);
value.[Friend]mStructType = (int)(void*)fieldType;
TypeCode typeCode = fieldType.mTypeCode;
TypeCode typeCode = fieldType.[Friend]mTypeCode;
if (typeCode == TypeCode.Enum)
typeCode = fieldType.UnderlyingType.mTypeCode;
typeCode = fieldType.UnderlyingType.[Friend]mTypeCode;
if (typeCode == TypeCode.Int32)
{
*(int32*)&value.mData = *(int32*)targetDataAddr;
*(int32*)&value.[Friend]mData = *(int32*)targetDataAddr;
}
else if (typeCode == TypeCode.Object)
{
value.mStructType = 0;
value.mData = (int)targetDataAddr;
value.[Friend]mStructType = 0;
value.[Friend]mData = (int)targetDataAddr;
}
else
{
@ -320,13 +269,13 @@ namespace System.Reflection
return value;
}
internal struct Enumerator : IEnumerator<FieldInfo>
public struct Enumerator : IEnumerator<FieldInfo>
{
BindingFlags mBindingFlags;
TypeInstance mTypeInstance;
int32 mIdx;
internal this(TypeInstance typeInst, BindingFlags bindingFlags)
public this(TypeInstance typeInst, BindingFlags bindingFlags)
{
mTypeInstance = typeInst;
mBindingFlags = bindingFlags;
@ -350,9 +299,9 @@ namespace System.Reflection
for (;;)
{
mIdx++;
if (mIdx == mTypeInstance.mFieldDataCount)
if (mIdx == mTypeInstance.[Friend]mFieldDataCount)
return false;
var fieldData = &mTypeInstance.mFieldDataPtr[mIdx];
var fieldData = &mTypeInstance.[Friend]mFieldDataPtr[mIdx];
bool matches = (mBindingFlags.HasFlag(BindingFlags.Static) && (fieldData.mFlags.HasFlag(FieldFlags.Static)));
matches |= (mBindingFlags.HasFlag(BindingFlags.Instance) && (!fieldData.mFlags.HasFlag(FieldFlags.Static)));
if (matches)
@ -365,7 +314,7 @@ namespace System.Reflection
{
get
{
var fieldData = &mTypeInstance.mFieldDataPtr[mIdx];
var fieldData = &mTypeInstance.[Friend]mFieldDataPtr[mIdx];
return FieldInfo(mTypeInstance, fieldData);
}
}

View file

@ -150,7 +150,7 @@ namespace System
static Type Object_GetType(Object obj)
{
#if BF_DBG_RUNTIME
return obj.RawGetType();
return obj.[Friend]RawGetType();
#else
return null;
#endif

View file

@ -145,7 +145,7 @@ namespace System
private int mIndex;
private T* mCurrent;
internal this(Span<T> list)
public this(Span<T> list)
{
mList = list;
mIndex = 0;

View file

@ -328,7 +328,7 @@ namespace System
}
}
internal static bool EqualsHelper(char8* a, char8* b, int length)
public static bool EqualsHelper(char8* a, char8* b, int length)
{
for (int i = 0; i < length; i++)
if (a[i] != b[i])
@ -409,7 +409,7 @@ namespace System
mAllocSizeAndFlags = (uint32)newSize | DynAllocFlag | StrPtrFlag;
}
internal void Append(char8* appendPtr, int length)
public void Append(char8* appendPtr, int length)
{
int32 newCurrentIndex = (int32)(mLength + length);
if (newCurrentIndex >= AllocSize)

View file

@ -9,4 +9,18 @@ class Foogie<T> where T : IHashable
T val = default;
val.GetHashCode();
}
}
struct Zorbble
{
public int mA;
public void MainMethod()
{
}
static void Zoff()
{
}
}

View file

@ -3,7 +3,7 @@ namespace System.Threading
using System;
using System.Diagnostics;
internal delegate Object InternalCrossContextDelegate(Object[] args);
public delegate Object InternalCrossContextDelegate(Object[] args);
public delegate void ThreadStart();
public delegate void ParameterizedThreadStart(Object obj);

View file

@ -19,7 +19,7 @@ namespace System.Threading {
//public static readonly TimeSpan InfiniteTimeSpan = TimeSpan(0, 0, 0, 0, Timeout.Infinite);
public const int32 Infinite = -1;
internal const uint32 UnsignedInfinite = unchecked((uint32)-1);
public const uint32 UnsignedInfinite = unchecked((uint32)-1);
}
}

View file

@ -22,20 +22,20 @@ namespace System
private const int32 MillisPerHour = MillisPerMinute * 60; // 3,600,000
private const int32 MillisPerDay = MillisPerHour * 24; // 86,400,000
internal const int64 MaxSeconds = Int64.MaxValue / TicksPerSecond;
internal const int64 MinSeconds = Int64.MinValue / TicksPerSecond;
private const int64 MaxSeconds = Int64.MaxValue / TicksPerSecond;
private const int64 MinSeconds = Int64.MinValue / TicksPerSecond;
internal const int64 MaxMilliSeconds = Int64.MaxValue / TicksPerMillisecond;
internal const int64 MinMilliSeconds = Int64.MinValue / TicksPerMillisecond;
private const int64 MaxMilliSeconds = Int64.MaxValue / TicksPerMillisecond;
private const int64 MinMilliSeconds = Int64.MinValue / TicksPerMillisecond;
internal const int64 TicksPerTenthSecond = TicksPerMillisecond * 100;
private const int64 TicksPerTenthSecond = TicksPerMillisecond * 100;
//public static readonly TimeSpan Zero = new TimeSpan(0);
//public static readonly TimeSpan MaxValue = new TimeSpan(Int64.MaxValue);
//public static readonly TimeSpan MinValue = new TimeSpan(Int64.MinValue);
internal int64 _ticks;
private int64 _ticks;
//public TimeSpan() {
// _ticks = 0;

View file

@ -15,16 +15,16 @@ namespace System
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
public class Type
{
internal extern const Type* sTypes;
extern const Type* sTypes;
protected const BindingFlags cDefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
internal int32 mSize;
internal TypeId mTypeId;
internal TypeFlags mTypeFlags;
internal int32 mMemberDataOffset;
internal TypeCode mTypeCode;
internal uint8 mAlign;
protected int32 mSize;
protected TypeId mTypeId;
protected TypeFlags mTypeFlags;
protected int32 mMemberDataOffset;
protected TypeCode mTypeCode;
protected uint8 mAlign;
public int32 Size
{
@ -213,6 +213,14 @@ namespace System
}
}
public bool IsPointer
{
get
{
return (mTypeFlags & (TypeFlags.Boxed | TypeFlags.Pointer)) == TypeFlags.Pointer;
}
}
public bool IsBoxed
{
get
@ -221,6 +229,14 @@ namespace System
}
}
public bool IsBoxedStructPtr
{
get
{
return (mTypeFlags & (TypeFlags.Boxed | TypeFlags.Pointer)) == TypeFlags.Boxed | TypeFlags.Pointer;
}
}
public bool IsEnum
{
get
@ -333,6 +349,15 @@ namespace System
}
}
public virtual int32 MinValue
{
[Error("This property can only be accessed directly from a typeof() expression")]
get
{
return 0;
}
}
public virtual int32 MaxValue
{
[Error("This property can only be accessed directly from a typeof() expression")]
@ -342,18 +367,17 @@ namespace System
}
}
public int32 GetTypeId()
{
return (int32)mTypeId;
}
internal static Type GetType(TypeId typeId)
protected static Type GetType(TypeId typeId)
{
return sTypes[(int32)typeId];
}
internal static Type GetType_(int32 typeId)
protected static Type GetType_(int32 typeId)
{
return sTypes[typeId];
}
@ -419,9 +443,9 @@ namespace System
return type == this;
}
public virtual FieldInfo? GetField(String fieldName)
public virtual Result<FieldInfo> GetField(String fieldName)
{
return null;
return .Err;
}
public virtual FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)
@ -469,50 +493,50 @@ namespace System
namespace System.Reflection
{
internal struct TypeId : int32
public struct TypeId : int32
{
public Type ToType()
{
return Type.sTypes[(int32)this];
return Type.[Friend]sTypes[(int32)this];
}
}
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
internal class TypeInstance : Type
public class TypeInstance : Type
{
[CRepr, AlwaysInclude]
internal struct FieldData
public struct FieldData
{
internal String mName;
internal int64 mConstValue;
internal int32 mDataOffset;
internal TypeId mFieldTypeId;
internal FieldFlags mFlags;
internal int32 mCustomAttributesIdx;
public String mName;
public int64 mConstValue;
public int32 mDataOffset;
public TypeId mFieldTypeId;
public FieldFlags mFlags;
public int32 mCustomAttributesIdx;
}
// This is only valid if there is no FieldData on a splattable struct
[CRepr, AlwaysInclude]
internal struct FieldSplatData
public struct FieldSplatData
{
internal TypeId[3] mSplatTypes;
internal int32[3] mSplatOffsets;
public TypeId[3] mSplatTypes;
public int32[3] mSplatOffsets;
}
[CRepr, AlwaysInclude]
internal struct MethodData
public struct MethodData
{
internal String mName; // mName
internal void* mFuncPtr;
internal ParamData* mParamData;
internal TypeId mReturnType;
internal int16 mParamCount;
internal MethodFlags mFlags;
internal int32 mVirtualIdx;
internal int32 mCustomAttributesIdx;
public String mName; // mName
public void* mFuncPtr;
public ParamData* mParamData;
public TypeId mReturnType;
public int16 mParamCount;
public MethodFlags mFlags;
public int32 mVirtualIdx;
public int32 mCustomAttributesIdx;
}
internal enum ParamFlags : int16
public enum ParamFlags : int16
{
None = 0,
Splat = 1,
@ -520,39 +544,39 @@ namespace System.Reflection
}
[CRepr, AlwaysInclude]
internal struct ParamData
public struct ParamData
{
internal String mName;
internal TypeId mType;
internal ParamFlags mParamFlags;
internal int32 mDefaultIdx;
public String mName;
public TypeId mType;
public ParamFlags mParamFlags;
public int32 mDefaultIdx;
}
internal ClassVData* mTypeClassVData;
internal String mName;
internal String mNamespace;
internal int32 mInstSize;
internal int32 mInstAlign;
internal int32 mCustomAttributesIdx;
internal TypeId mBaseType;
internal TypeId mUnderlyingType;
internal TypeId mOuterType;
internal int32 mInheritanceId;
internal int32 mInheritanceCount;
ClassVData* mTypeClassVData;
String mName;
String mNamespace;
int32 mInstSize;
int32 mInstAlign;
int32 mCustomAttributesIdx;
TypeId mBaseType;
TypeId mUnderlyingType;
TypeId mOuterType;
int32 mInheritanceId;
int32 mInheritanceCount;
internal uint8 mInterfaceSlot;
internal uint8 mInterfaceCount;
internal int16 mMethodDataCount;
internal int16 mPropertyDataCount;
internal int16 mFieldDataCount;
internal int16 mConstructorDataCount;
uint8 mInterfaceSlot;
uint8 mInterfaceCount;
int16 mMethodDataCount;
int16 mPropertyDataCount;
int16 mFieldDataCount;
int16 mConstructorDataCount;
internal void* mInterfaceDataPtr;
internal MethodData* mMethodDataPtr;
internal void* mPropertyDataPtr;
internal FieldData* mFieldDataPtr;
internal void* mConstructorDataPtr;
internal void** mCustomAttrDataPtr;
void* mInterfaceDataPtr;
MethodData* mMethodDataPtr;
void* mPropertyDataPtr;
FieldData* mFieldDataPtr;
void* mConstructorDataPtr;
void** mCustomAttrDataPtr;
public override int32 InstanceSize
@ -583,7 +607,7 @@ namespace System.Reflection
{
get
{
return (TypeInstance)Type.GetType(mBaseType);
return (TypeInstance)Type.[Friend]GetType(mBaseType);
}
}
@ -591,7 +615,7 @@ namespace System.Reflection
{
get
{
return (TypeInstance)Type.GetType(mOuterType);
return (TypeInstance)Type.[Friend]GetType(mOuterType);
}
}
@ -599,7 +623,7 @@ namespace System.Reflection
{
get
{
return Type.GetType(mUnderlyingType);
return Type.[Friend]GetType(mUnderlyingType);
}
}
@ -620,7 +644,7 @@ namespace System.Reflection
return true;
if (curType.mBaseType == 0)
return false;
curType = (TypeInstance)Type.GetType(curType.mBaseType);
curType = (TypeInstance)Type.[Friend]GetType(curType.mBaseType);
}
}
@ -633,7 +657,7 @@ namespace System.Reflection
{
if (fieldIdx > 0)
strBuffer.Append(", ");
GetType(mFieldDataPtr[fieldIdx].mFieldTypeId).GetFullName(strBuffer);
GetType(mFieldDataPtr[fieldIdx].[Friend]mFieldTypeId).GetFullName(strBuffer);
}
strBuffer.Append(')');
}
@ -659,15 +683,15 @@ namespace System.Reflection
strBuffer.Append(mName);
}
public override FieldInfo? GetField(String fieldName)
public override Result<FieldInfo> GetField(String fieldName)
{
for (int32 i = 0; i < mFieldDataCount; i++)
{
FieldData* fieldData = &mFieldDataPtr[i];
if (fieldData.mName == fieldName)
if (fieldData.[Friend]mName == fieldName)
return FieldInfo(this, fieldData);
}
return null;
return .Err;
}
public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)
@ -677,15 +701,15 @@ namespace System.Reflection
}
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
internal class PointerType : Type
class PointerType : Type
{
internal TypeId mElementType;
TypeId mElementType;
public override Type UnderlyingType
{
get
{
return Type.GetType(mElementType);
return Type.[Friend]GetType(mElementType);
}
}
@ -697,16 +721,16 @@ namespace System.Reflection
}
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
internal class SizedArrayType : Type
class SizedArrayType : Type
{
internal TypeId mElementType;
internal int32 mElementCount;
TypeId mElementType;
int32 mElementCount;
public override Type UnderlyingType
{
get
{
return Type.GetType(mElementType);
return Type.[Friend]GetType(mElementType);
}
}
@ -728,31 +752,31 @@ namespace System.Reflection
}
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
internal class UnspecializedGenericType : TypeInstance
class UnspecializedGenericType : TypeInstance
{
[CRepr, AlwaysInclude]
internal struct GenericParam
struct GenericParam
{
internal String mName;
String mName;
}
internal uint8 mGenericParamCount;
uint8 mGenericParamCount;
}
// Only for resolved types
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
internal class SpecializedGenericType : TypeInstance
class SpecializedGenericType : TypeInstance
{
internal TypeId mUnspecializedType;
internal TypeId* mResolvedTypeRefs;
TypeId mUnspecializedType;
TypeId* mResolvedTypeRefs;
public override int32 GenericParamCount
{
get
{
var unspecializedTypeG = Type.GetType(mUnspecializedType);
var unspecializedTypeG = Type.[Friend]GetType(mUnspecializedType);
var unspecializedType = (UnspecializedGenericType)unspecializedTypeG;
return unspecializedType.mGenericParamCount;
return unspecializedType.[Friend]mGenericParamCount;
}
}
@ -763,7 +787,7 @@ namespace System.Reflection
public override void GetFullName(String strBuffer)
{
var unspecializedTypeG = Type.GetType(mUnspecializedType);
var unspecializedTypeG = Type.[Friend]GetType(mUnspecializedType);
var unspecializedType = (UnspecializedGenericType)unspecializedTypeG;
base.GetFullName(strBuffer);
@ -772,14 +796,14 @@ namespace System.Reflection
if (outerType != null)
outerGenericCount = outerType.GenericParamCount;
if (outerGenericCount < unspecializedType.mGenericParamCount)
if (outerGenericCount < unspecializedType.[Friend]mGenericParamCount)
{
strBuffer.Append('<');
for (int i = outerGenericCount; i < unspecializedType.mGenericParamCount; i++)
for (int i = outerGenericCount; i < unspecializedType.[Friend]mGenericParamCount; i++)
{
if (i > 0)
strBuffer.Append(", ");
Type.GetType(mResolvedTypeRefs[i]).GetFullName(strBuffer);
Type.[Friend]GetType(mResolvedTypeRefs[i]).GetFullName(strBuffer);
}
strBuffer.Append('>');
}
@ -787,15 +811,15 @@ namespace System.Reflection
}
[CRepr, AlwaysInclude(AssumeInstantiated=true)]
internal class ArrayType : SpecializedGenericType
class ArrayType : SpecializedGenericType
{
internal int32 mElementSize;
internal uint8 mRank;
internal uint8 mElementsDataOffset;
int32 mElementSize;
uint8 mRank;
uint8 mElementsDataOffset;
public override void GetFullName(String strBuffer)
{
Type.GetType(mResolvedTypeRefs[0]).GetFullName(strBuffer);
Type.[Friend]GetType(mResolvedTypeRefs[0]).GetFullName(strBuffer);
strBuffer.Append('[');
for (int commaNum < mRank - 1)
strBuffer.Append(',');
@ -820,7 +844,7 @@ namespace System.Reflection
SizedArray = 0x0800,
Splattable = 0x1000,
Union = 0x2000,
Sys_PointerT = 0x4000, // System.Pointer<T>
//
WantsMark = 0x8000,
Delegate = 0x10000,
HasDestructor = 0x20000,
@ -848,7 +872,6 @@ namespace System.Reflection
EnumDiscriminator = 0x0200
}
[AllowDuplicates]
public enum MethodFlags : int16
{
MethodAccessMask = 0x0007,
@ -870,8 +893,9 @@ namespace System.Reflection
// vtable layout mask - Use this mask to retrieve vtable attributes.
VtableLayoutMask = 0x0100,
#unwarn
ReuseSlot = 0x0000, // The default.
#unwarn
NewSlot = 0x0100, // Method always gets a new slot in the vtable.
// end vtable layout mask
@ -880,6 +904,7 @@ namespace System.Reflection
SpecialName = 0x0800, // Method is special. Name describes how.
StdCall = 0x1000,
FastCall = 0x2000,
ThisCall = 0x3000, // Purposely resuing StdCall|FastCall
Mutating = 0x4000
}
}

View file

@ -4,8 +4,8 @@ namespace System
{
struct Variant
{
internal int mStructType; // 0 = unowned object, 1 = owned object, 2 = null value (mData is type), otherwise is struct type
internal int mData; // This is either an Object reference, struct data, or a pointer to struct data
int mStructType; // 0 = unowned object, 1 = owned object, 2 = null value (mData is type), otherwise is struct type
int mData; // This is either an Object reference, struct data, or a pointer to struct data
public bool OwnsMemory
{
@ -49,7 +49,6 @@ namespace System
}
}
#if BF_ENABLE_REALTIME_LEAK_CHECK
protected override void GCMarkMembers()
{
if ((mStructType == 1) || (mStructType == 0))
@ -58,7 +57,6 @@ namespace System
GC.Mark(obj);
}
}
#endif
public void Dispose() mut
{
@ -137,12 +135,12 @@ namespace System
if (type.Size <= sizeof(int))
{
variant.mData = 0;
Internal.MemCpy(&variant.mData, val, type.mSize);
Internal.MemCpy(&variant.mData, val, type.[Friend]mSize);
}
else
{
void* data = new uint8[type.mSize]*;
Internal.MemCpy(data, val, type.mSize);
void* data = new uint8[type.[Friend]mSize]*;
Internal.MemCpy(data, val, type.[Friend]mSize);
variant.mData = (int)data;
}
return variant;
@ -166,27 +164,21 @@ namespace System
}
else
{
void* data = new uint8[type.mSize]*;
void* data = new uint8[type.[Friend]mSize]*;
variant.mData = (int)data;
return data;
}
}
}
public void Get<T>(ref T val)
{
if (VariantType != typeof(T))
return;
val = Get<T>();
}
public T Get<T>() where T : class
{
Debug.Assert(IsObject);
if (mStructType == 2)
return (T)null;
Type type = typeof(T);
T obj = (T)Internal.UnsafeCastToObject((void*)mData);
Debug.Assert(obj.GetType().IsSubtypeOf(typeof(T)));
Debug.Assert(obj.GetType().IsSubtypeOf(type));
return obj;
}
@ -218,6 +210,13 @@ namespace System
return *(T*)(void*)mData;
}
/*public void Get<T>(ref T val)
{
if (VariantType != typeof(T))
return;
val = Get<T>();
}*/
public void CopyValueData(void* dest)
{
if (IsObject)
@ -269,9 +268,9 @@ namespace System
return false;
let type = v1.VariantType;
if (type.mSize <= sizeof(int))
if (type.[Friend]mSize <= sizeof(int))
return v1.mData == v2.mData;
for (int i < type.mSize)
for (int i < type.[Friend]mSize)
{
if (((uint8*)(void*)v1.mData)[i] != ((uint8*)(void*)v2.mData)[i])
return false;