1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Reflection changes - interface info, boxed type

This commit is contained in:
Brian Fiete 2020-09-14 06:54:49 -07:00
parent 5640e6b074
commit 8def1d4522
11 changed files with 350 additions and 108 deletions

View file

@ -251,6 +251,8 @@ namespace System.Reflection
} }
} }
void* funcPtr = null;
int ifaceOffset = -1;
if (mMethodData.mFlags.HasFlag(.Static)) if (mMethodData.mFlags.HasFlag(.Static))
{ {
if (target.HasValue) if (target.HasValue)
@ -260,9 +262,45 @@ namespace System.Reflection
{ {
if (!target.HasValue) if (!target.HasValue)
return .Err(.TargetExpected); return .Err(.TargetExpected);
var thisType = mTypeInstance;
if (mTypeInstance.IsInterface)
{
if (target.IsObject)
{
var targetObject = target.Get<Object>();
thisType = targetObject.GetType() as TypeInstance;
if (thisType == null)
return .Err(.InvalidTarget);
}
else
{
TypeInstance.InterfaceData* interfaceData = null;
var checkType = thisType;
CheckLoop: while (checkType != null)
{
for (int ifaceIdx < checkType.[Friend]mInterfaceCount)
{
if (checkType.[Friend]mInterfaceDataPtr[ifaceIdx].mInterfaceType == mTypeInstance.TypeId)
{
interfaceData = &checkType.[Friend]mInterfaceDataPtr[ifaceIdx];
break CheckLoop;
}
}
bool splatThis = mTypeInstance.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating); checkType = checkType.BaseType;
AddArg!::(-1, ref target, &target, mTypeInstance, splatThis); }
if (interfaceData == null)
return .Err(.InvalidTarget);
//funcPtr = *(thisType.[Friend]mInterfaceMethodTable + mMethodData.mVirtualIdx);
}
ifaceOffset = mTypeInstance.[Friend]mMemberDataOffset;
}
bool splatThis = thisType.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating);
AddArg!::(-1, ref target, &target.[Friend]mData, thisType, splatThis);
} }
if (args.Length != mMethodData.mParamCount) if (args.Length != mMethodData.mParamCount)
@ -288,7 +326,7 @@ namespace System.Reflection
{ {
let paramData = ref mMethodData.mParamData[@arg.Index]; let paramData = ref mMethodData.mParamData[@arg.Index];
let argType = Type.[Friend]GetType(paramData.mType); let argType = Type.[Friend]GetType(paramData.mType);
AddArg!::(@arg.Index, ref arg, &arg, argType, paramData.mParamFlags.HasFlag(.Splat)); AddArg!::(@arg.Index, ref arg, &arg.[Friend]mData, argType, paramData.mParamFlags.HasFlag(.Splat));
} }
FFICaller caller = .(); FFICaller caller = .();
@ -303,7 +341,9 @@ namespace System.Reflection
return .Err(.FFIError); return .Err(.FFIError);
} }
void* funcPtr = mMethodData.mFuncPtr; if (funcPtr == null)
{
funcPtr = mMethodData.mFuncPtr;
if (mMethodData.mFlags.HasFlag(.Virtual)) if (mMethodData.mFlags.HasFlag(.Virtual))
{ {
Object objTarget = target.Get<Object>(); Object objTarget = target.Get<Object>();
@ -313,7 +353,12 @@ namespace System.Reflection
#else #else
void* classVData = objTarget.[Friend]mClassVData; void* classVData = objTarget.[Friend]mClassVData;
#endif #endif
if (mMethodData.mVirtualIdx >= 0x100000) if (ifaceOffset >= 0)
{
void* ifaceVirtualTable = *(void**)((uint8*)classVData + ifaceOffset);
funcPtr = (void*)*(int*)((uint8*)ifaceVirtualTable + mMethodData.mVirtualIdx);
}
else if (mMethodData.mVirtualIdx >= 0x100000)
{ {
void* extAddr = (void*)*((int*)classVData + (mMethodData.mVirtualIdx>>20 - 1)); void* extAddr = (void*)*((int*)classVData + (mMethodData.mVirtualIdx>>20 - 1));
funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF)); funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF));
@ -323,6 +368,7 @@ namespace System.Reflection
funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx); funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx);
} }
} }
}
if (ffiArgList.Count > 0) if (ffiArgList.Count > 0)
caller.Call(funcPtr, retData, &ffiArgList[0]); caller.Call(funcPtr, retData, &ffiArgList[0]);
@ -549,6 +595,9 @@ namespace System.Reflection
} }
} }
void* funcPtr = mMethodData.mFuncPtr;
int virtualOffset = 0;
int ifaceOffset = -1;
if (mMethodData.mFlags.HasFlag(.Static)) if (mMethodData.mFlags.HasFlag(.Static))
{ {
if (target != null) if (target != null)
@ -559,8 +608,38 @@ namespace System.Reflection
if (target == null) if (target == null)
return .Err(.TargetExpected); return .Err(.TargetExpected);
bool splatThis = mTypeInstance.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating); var thisType = mTypeInstance;
AddArg!::(-1, target, &target, mTypeInstance, splatThis); if (mTypeInstance.IsInterface)
{
thisType = target.[Friend]RawGetType() as TypeInstance;
if (thisType == null)
return .Err(.InvalidTarget);
ifaceOffset = mTypeInstance.[Friend]mMemberDataOffset;
/*TypeInstance.InterfaceData* interfaceData = null;
var checkType = thisType;
CheckLoop: while (checkType != null)
{
for (int ifaceIdx < checkType.[Friend]mInterfaceCount)
{
if (checkType.[Friend]mInterfaceDataPtr[ifaceIdx].mInterfaceType == mTypeInstance.TypeId)
{
interfaceData = &checkType.[Friend]mInterfaceDataPtr[ifaceIdx];
break CheckLoop;
}
}
checkType = checkType.BaseType;
}
if (interfaceData == null)
return .Err(.InvalidTarget);
virtualOffset = interfaceData.mStartVirtualIdx * sizeof(int);*/
}
bool splatThis = thisType.IsSplattable && !mMethodData.mFlags.HasFlag(.Mutating);
AddArg!::(-1, target, &target, thisType, splatThis);
} }
if (args.Count != mMethodData.mParamCount) if (args.Count != mMethodData.mParamCount)
@ -601,7 +680,6 @@ namespace System.Reflection
return .Err(.FFIError); return .Err(.FFIError);
} }
void* funcPtr = mMethodData.mFuncPtr;
if (mMethodData.mFlags.HasFlag(.Virtual)) if (mMethodData.mFlags.HasFlag(.Virtual))
{ {
#if BF_ENABLE_OBJECT_DEBUG_FLAGS #if BF_ENABLE_OBJECT_DEBUG_FLAGS
@ -609,14 +687,19 @@ namespace System.Reflection
#else #else
void* classVData = target.[Friend]mClassVData; void* classVData = target.[Friend]mClassVData;
#endif #endif
if (mMethodData.mVirtualIdx >= 0x100000) if (ifaceOffset >= 0)
{
void* ifaceVirtualTable = *(void**)((uint8*)classVData + ifaceOffset);
funcPtr = (void*)*(int*)((uint8*)ifaceVirtualTable + mMethodData.mVirtualIdx + virtualOffset);
}
else if (mMethodData.mVirtualIdx >= 0x100000)
{ {
void* extAddr = (void*)*((int*)classVData + (mMethodData.mVirtualIdx>>20 - 1)); void* extAddr = (void*)*((int*)classVData + (mMethodData.mVirtualIdx>>20 - 1));
funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF)); funcPtr = (void*)*((int*)extAddr + (mMethodData.mVirtualIdx & 0xFFFFF) + virtualOffset);
} }
else else
{ {
funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx); funcPtr = (void*)*(int*)((uint8*)classVData + mMethodData.mVirtualIdx + virtualOffset);
} }
} }

View file

@ -22,6 +22,7 @@ namespace System
protected int32 mSize; protected int32 mSize;
protected TypeId mTypeId; protected TypeId mTypeId;
protected TypeId mBoxedType;
protected TypeFlags mTypeFlags; protected TypeFlags mTypeFlags;
protected int32 mMemberDataOffset; protected int32 mMemberDataOffset;
protected TypeCode mTypeCode; protected TypeCode mTypeCode;
@ -198,6 +199,14 @@ namespace System
} }
} }
public bool IsInterface
{
get
{
return (mTypeFlags & TypeFlags.Interface) != 0;
}
}
public bool IsValueType public bool IsValueType
{ {
get get
@ -630,6 +639,7 @@ namespace System.Reflection
public TypeId mReturnType; public TypeId mReturnType;
public int16 mParamCount; public int16 mParamCount;
public MethodFlags mFlags; public MethodFlags mFlags;
public int32 mMethodIdx;
public int32 mVirtualIdx; public int32 mVirtualIdx;
public int32 mCustomAttributesIdx; public int32 mCustomAttributesIdx;
} }
@ -650,6 +660,13 @@ namespace System.Reflection
public int32 mDefaultIdx; public int32 mDefaultIdx;
} }
public struct InterfaceData
{
public TypeId mInterfaceType;
public int32 mStartInterfaceTableIdx;
public int32 mStartVirtualIdx;
}
ClassVData* mTypeClassVData; ClassVData* mTypeClassVData;
String mName; String mName;
String mNamespace; String mNamespace;
@ -668,7 +685,8 @@ namespace System.Reflection
int16 mPropertyDataCount; int16 mPropertyDataCount;
int16 mFieldDataCount; int16 mFieldDataCount;
void* mInterfaceDataPtr; InterfaceData* mInterfaceDataPtr;
void** mInterfaceMethodTable;
MethodData* mMethodDataPtr; MethodData* mMethodDataPtr;
void* mPropertyDataPtr; void* mPropertyDataPtr;
FieldData* mFieldDataPtr; FieldData* mFieldDataPtr;
@ -1035,13 +1053,14 @@ namespace System.Reflection
Boxed = 0x0010, Boxed = 0x0010,
Pointer = 0x0020, Pointer = 0x0020,
Struct = 0x0040, Struct = 0x0040,
Primitive = 0x0080, Interface = 0x0080,
TypedPrimitive = 0x0100, Primitive = 0x0100,
Tuple = 0x0200, TypedPrimitive = 0x0200,
Nullable = 0x0400, Tuple = 0x0400,
SizedArray = 0x0800, Nullable = 0x0800,
Splattable = 0x1000, SizedArray = 0x1000,
Union = 0x2000, Splattable = 0x2000,
Union = 0x4000,
// //
WantsMark = 0x8000, WantsMark = 0x8000,
Delegate = 0x10000, Delegate = 0x10000,

View file

@ -22,6 +22,7 @@ namespace System
protected int32 mSize; protected int32 mSize;
protected TypeId mTypeId; protected TypeId mTypeId;
protected TypeId mBoxedType;
protected TypeFlags mTypeFlags; protected TypeFlags mTypeFlags;
protected int32 mMemberDataOffset; protected int32 mMemberDataOffset;
protected TypeCode mTypeCode; protected TypeCode mTypeCode;
@ -462,7 +463,6 @@ namespace System
public virtual Type GetBaseType() public virtual Type GetBaseType()
{ {
//return mBaseType;
return null; return null;
} }
@ -475,6 +475,11 @@ namespace System
return type == this; return type == this;
} }
public virtual bool CheckInterface(Type interfaceType)
{
return false;
}
public virtual Result<FieldInfo> GetField(String fieldName) public virtual Result<FieldInfo> GetField(String fieldName)
{ {
return .Err; return .Err;
@ -598,6 +603,7 @@ namespace System.Reflection
public int16 mParamCount; public int16 mParamCount;
public MethodFlags mFlags; public MethodFlags mFlags;
public int32 mVirtualIdx; public int32 mVirtualIdx;
public int32 mMethodIdx;
public int32 mCustomAttributesIdx; public int32 mCustomAttributesIdx;
} }
@ -617,6 +623,13 @@ namespace System.Reflection
public int32 mDefaultIdx; public int32 mDefaultIdx;
} }
public struct InterfaceData
{
public TypeId mInterfaceType;
public int32 mStartInterfaceTableIdx;
public int32 mStartVirtualIdx;
}
ClassVData* mTypeClassVData; ClassVData* mTypeClassVData;
String mName; String mName;
String mNamespace; String mNamespace;
@ -635,7 +648,8 @@ namespace System.Reflection
int16 mPropertyDataCount; int16 mPropertyDataCount;
int16 mFieldDataCount; int16 mFieldDataCount;
void* mInterfaceDataPtr; InterfaceData* mInterfaceDataPtr;
void** mInterfaceMethodTable;
MethodData* mMethodDataPtr; MethodData* mMethodDataPtr;
void* mPropertyDataPtr; void* mPropertyDataPtr;
FieldData* mFieldDataPtr; FieldData* mFieldDataPtr;
@ -697,6 +711,11 @@ namespace System.Reflection
} }
} }
public override Type GetBaseType()
{
return Type.[Friend]GetType(mBaseType);
}
public override bool IsSubtypeOf(Type checkBaseType) public override bool IsSubtypeOf(Type checkBaseType)
{ {
TypeInstance curType = this; TypeInstance curType = this;
@ -710,6 +729,17 @@ namespace System.Reflection
} }
} }
public override bool CheckInterface(Type interfaceType)
{
for (int i < mInterfaceCount)
if (mInterfaceDataPtr[i].mInterfaceType == interfaceType.TypeId)
return true;
let baseType = GetBaseType();
if (baseType != null)
return baseType.CheckInterface(interfaceType);
return false;
}
public override void GetFullName(String strBuffer) public override void GetFullName(String strBuffer)
{ {
if (mTypeFlags.HasFlag(TypeFlags.Tuple)) if (mTypeFlags.HasFlag(TypeFlags.Tuple))

View file

@ -418,6 +418,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly)
mReflectFieldSplatDataDef = NULL; mReflectFieldSplatDataDef = NULL;
mReflectMethodDataDef = NULL; mReflectMethodDataDef = NULL;
mReflectParamDataDef = NULL; mReflectParamDataDef = NULL;
mReflectInterfaceDataDef = NULL;
mReflectPointerType = NULL; mReflectPointerType = NULL;
mReflectRefType = NULL; mReflectRefType = NULL;
mReflectSizedArrayType = NULL; mReflectSizedArrayType = NULL;
@ -1422,7 +1423,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
if (bfModule->mBfIRBuilder->DbgHasInfo()) if (bfModule->mBfIRBuilder->DbgHasInfo())
{ {
auto dbgArrayType = bfModule->mBfIRBuilder->DbgCreateArrayType(stringList.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, bfModule->mBfIRBuilder->DbgGetType(stringPtrType), (int)stringList.size()); auto dbgArrayType = bfModule->mBfIRBuilder->DbgCreateArrayType(stringList.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, bfModule->mBfIRBuilder->DbgGetType(stringPtrType), (int)stringList.size());
bfModule->mBfIRBuilder->DbgCreateGlobalVariable(bfModule->mDICompileUnit, stringsVariableName, stringsVariableName, NULL, 0, dbgArrayType, false, stringArrayVar); bfModule->mBfIRBuilder->DbgCreateGlobalVariable(bfModule->mDICompileUnit, stringsVariableName, stringsVariableName, BfIRMDNode(), 0, dbgArrayType, false, stringArrayVar);
} }
} }
@ -1450,7 +1451,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
if (bfModule->mBfIRBuilder->DbgHasInfo()) if (bfModule->mBfIRBuilder->DbgHasInfo())
{ {
auto dbgArrayType = bfModule->mBfIRBuilder->DbgCreateArrayType(stringList.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, bfModule->mBfIRBuilder->DbgGetType(stringPtrType), (int)stringList.size()); auto dbgArrayType = bfModule->mBfIRBuilder->DbgCreateArrayType(stringList.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, bfModule->mBfIRBuilder->DbgGetType(stringPtrType), (int)stringList.size());
bfModule->mBfIRBuilder->DbgCreateGlobalVariable(bfModule->mDICompileUnit, stringsVariableName, stringsVariableName, NULL, 0, dbgArrayType, false, stringArrayVar); bfModule->mBfIRBuilder->DbgCreateGlobalVariable(bfModule->mDICompileUnit, stringsVariableName, stringsVariableName, BfIRMDNode(), 0, dbgArrayType, false, stringArrayVar);
} }
} }
@ -1974,7 +1975,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
String name = "__BFTLS_EXTRA"; String name = "__BFTLS_EXTRA";
auto irVal = bfModule->mBfIRBuilder->CreateGlobalVariable(irArrType, false, BfIRLinkageType_External, bfModule->mBfIRBuilder->CreateConstStructZero(irArrType), name, true); auto irVal = bfModule->mBfIRBuilder->CreateGlobalVariable(irArrType, false, BfIRLinkageType_External, bfModule->mBfIRBuilder->CreateConstStructZero(irArrType), name, true);
BfIRMDNode dbgArrayType = bfModule->mBfIRBuilder->DbgCreateArrayType(dataSize * 8, 8, bfModule->mBfIRBuilder->DbgGetType(int8Type), dataSize); BfIRMDNode dbgArrayType = bfModule->mBfIRBuilder->DbgCreateArrayType(dataSize * 8, 8, bfModule->mBfIRBuilder->DbgGetType(int8Type), dataSize);
bfModule->mBfIRBuilder->DbgCreateGlobalVariable(bfModule->mDICompileUnit, name, name, NULL, 0, dbgArrayType, false, irVal); bfModule->mBfIRBuilder->DbgCreateGlobalVariable(bfModule->mDICompileUnit, name, name, BfIRMDNode(), 0, dbgArrayType, false, irVal);
} }
if (isPosixDynLib) if (isPosixDynLib)
@ -2740,7 +2741,8 @@ void BfCompiler::GenerateSlotNums()
auto typeInstance = type->ToTypeInstance(); auto typeInstance = type->ToTypeInstance();
if ((typeInstance->mSlotNum <= 0) || (!isHotCompile)) if ((typeInstance->mSlotNum <= 0) || (!isHotCompile))
{ {
if (mContext->mReferencedIFaceSlots.Contains(typeInstance)) if ((mContext->mReferencedIFaceSlots.Contains(typeInstance)) ||
(typeInstance->mHasBeenInstantiated) || (typeInstance->mIncludeAllMethods))
{ {
if (typeInstance->mSlotNum == -2) if (typeInstance->mSlotNum == -2)
typeInstance->mSlotNum = -1; typeInstance->mSlotNum = -1;
@ -6326,6 +6328,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
mReflectFieldSplatDataDef = _GetRequiredType("System.Reflection.TypeInstance.FieldSplatData"); mReflectFieldSplatDataDef = _GetRequiredType("System.Reflection.TypeInstance.FieldSplatData");
mReflectMethodDataDef = _GetRequiredType("System.Reflection.TypeInstance.MethodData"); mReflectMethodDataDef = _GetRequiredType("System.Reflection.TypeInstance.MethodData");
mReflectParamDataDef = _GetRequiredType("System.Reflection.TypeInstance.ParamData"); mReflectParamDataDef = _GetRequiredType("System.Reflection.TypeInstance.ParamData");
mReflectInterfaceDataDef = _GetRequiredType("System.Reflection.TypeInstance.InterfaceData");
mReflectPointerType = _GetRequiredType("System.Reflection.PointerType"); mReflectPointerType = _GetRequiredType("System.Reflection.PointerType");
mReflectRefType = _GetRequiredType("System.Reflection.RefType"); mReflectRefType = _GetRequiredType("System.Reflection.RefType");
mReflectSizedArrayType = _GetRequiredType("System.Reflection.SizedArrayType"); mReflectSizedArrayType = _GetRequiredType("System.Reflection.SizedArrayType");

View file

@ -368,6 +368,7 @@ public:
BfTypeDef* mReflectFieldSplatDataDef; BfTypeDef* mReflectFieldSplatDataDef;
BfTypeDef* mReflectMethodDataDef; BfTypeDef* mReflectMethodDataDef;
BfTypeDef* mReflectParamDataDef; BfTypeDef* mReflectParamDataDef;
BfTypeDef* mReflectInterfaceDataDef;
BfTypeDef* mReflectPointerType; BfTypeDef* mReflectPointerType;
BfTypeDef* mReflectRefType; BfTypeDef* mReflectRefType;
BfTypeDef* mReflectSizedArrayType; BfTypeDef* mReflectSizedArrayType;

View file

@ -1097,7 +1097,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
// code as we walk the AST // code as we walk the AST
//mBfIRBuilder->mDbgVerifyCodeGen = true; //mBfIRBuilder->mDbgVerifyCodeGen = true;
if ( if (
(mModuleName == "BeefTest_TestProgram") (mModuleName == "-")
//|| (mModuleName == "BeefTest2_ClearColorValue") //|| (mModuleName == "BeefTest2_ClearColorValue")
//|| (mModuleName == "Tests_FuncRefs") //|| (mModuleName == "Tests_FuncRefs")
) )
@ -4819,6 +4819,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
} }
if (type->IsStruct()) if (type->IsStruct())
typeFlags |= BfTypeFlags_Struct; typeFlags |= BfTypeFlags_Struct;
if (type->IsInterface())
typeFlags |= BfTypeFlags_Interface;
if (type->IsBoxed()) if (type->IsBoxed())
{ {
typeFlags |= BfTypeFlags_Boxed; typeFlags |= BfTypeFlags_Boxed;
@ -4846,8 +4848,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (type->WantsGCMarking()) if (type->WantsGCMarking())
typeFlags |= BfTypeFlags_WantsMarking; typeFlags |= BfTypeFlags_WantsMarking;
int virtSlotIdx = -1;
if ((typeInstance != NULL) && (typeInstance->mSlotNum >= 0))
virtSlotIdx = typeInstance->mSlotNum + 1 + mCompiler->GetDynCastVDataCount();
int memberDataOffset = 0; int memberDataOffset = 0;
if (typeInstance != NULL) if (type->IsInterface())
memberDataOffset = virtSlotIdx * mSystem->mPtrSize;
else if (typeInstance != NULL)
{ {
for (auto& fieldInstance : typeInstance->mFieldInstances) for (auto& fieldInstance : typeInstance->mFieldInstances)
{ {
@ -4858,11 +4865,21 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
} }
} }
} }
int boxedTypeId = 0;
if (type->IsValueType())
{
auto boxedType = CreateBoxedType(type, false);
if ((boxedType != NULL) && (boxedType->mIsReified))
boxedTypeId = boxedType->mTypeId;
}
SizedArray<BfIRValue, 8> typeDataParams = SizedArray<BfIRValue, 8> typeDataParams =
{ {
objectData, objectData,
GetConstValue(type->mSize, intType), // mSize GetConstValue(type->mSize, intType), // mSize
GetConstValue(type->mTypeId, typeIdType), // mTypeId GetConstValue(type->mTypeId, typeIdType), // mTypeId
GetConstValue(boxedTypeId, typeIdType), // mBoxedType
GetConstValue(typeFlags, intType), // mTypeFlags GetConstValue(typeFlags, intType), // mTypeFlags
GetConstValue(memberDataOffset, intType), // mMemberDataOffset GetConstValue(memberDataOffset, intType), // mMemberDataOffset
GetConstValue(typeCode, byteType), // mTypeCode GetConstValue(typeCode, byteType), // mTypeCode
@ -4982,8 +4999,6 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (typeInstance->mSlotNum >= 0) if (typeInstance->mSlotNum >= 0)
{ {
// For interfaces we ONLY emit the slot num // For interfaces we ONLY emit the slot num
int virtSlotIdx = typeInstance->mSlotNum + 1 + mCompiler->GetDynCastVDataCount();
StringT<128> slotVarName; StringT<128> slotVarName;
BfMangler::MangleStaticFieldName(slotVarName, mCompiler->GetMangleKind(), typeInstance, "sBfSlotOfs"); BfMangler::MangleStaticFieldName(slotVarName, mCompiler->GetMangleKind(), typeInstance, "sBfSlotOfs");
auto intType = GetPrimitiveType(BfTypeCode_Int32); auto intType = GetPrimitiveType(BfTypeCode_Int32);
@ -6212,7 +6227,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
methodFlags = (MethodFlags)(methodFlags | MethodFlags_Public); methodFlags = (MethodFlags)(methodFlags | MethodFlags_Public);
if (methodDef->mIsStatic) if (methodDef->mIsStatic)
methodFlags = (MethodFlags)(methodFlags | MethodFlags_Static); methodFlags = (MethodFlags)(methodFlags | MethodFlags_Static);
if (methodDef->mIsVirtual) if ((methodDef->mIsVirtual) || (moduleMethodInstance.mMethodInstance->mVirtualTableIdx != -1))
methodFlags = (MethodFlags)(methodFlags | MethodFlags_Virtual); methodFlags = (MethodFlags)(methodFlags | MethodFlags_Virtual);
if (methodDef->mCallingConvention == BfCallingConvention_Fastcall) if (methodDef->mCallingConvention == BfCallingConvention_Fastcall)
methodFlags = (MethodFlags)(methodFlags | MethodFlags_FastCall); methodFlags = (MethodFlags)(methodFlags | MethodFlags_FastCall);
@ -6279,6 +6294,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (defaultMethod->mVirtualTableIdx != -1) if (defaultMethod->mVirtualTableIdx != -1)
{ {
int vDataIdx = -1; int vDataIdx = -1;
if (type->IsInterface())
{
vDataIdx = defaultMethod->mVirtualTableIdx;
}
else
{
vDataIdx = 1 + mCompiler->GetDynCastVDataCount() + mCompiler->mMaxInterfaceSlots; vDataIdx = 1 + mCompiler->GetDynCastVDataCount() + mCompiler->mMaxInterfaceSlots;
if ((mCompiler->mOptions.mHasVDataExtender) && (mCompiler->IsHotCompile())) if ((mCompiler->mOptions.mHasVDataExtender) && (mCompiler->IsHotCompile()))
{ {
@ -6301,6 +6323,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
{ {
vDataIdx += defaultMethod->mVirtualTableIdx; vDataIdx += defaultMethod->mVirtualTableIdx;
} }
}
if (vDataVal == -1) if (vDataVal == -1)
vDataVal = vDataIdx * mSystem->mPtrSize; vDataVal = vDataIdx * mSystem->mPtrSize;
} }
@ -6314,6 +6337,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
GetConstValue(defaultMethod->mReturnType->mTypeId, typeIdType), GetConstValue(defaultMethod->mReturnType->mTypeId, typeIdType),
GetConstValue((int)paramVals.size(), shortType), GetConstValue((int)paramVals.size(), shortType),
GetConstValue(methodFlags, shortType), GetConstValue(methodFlags, shortType),
GetConstValue(methodIdx, intType),
GetConstValue(vDataVal, intType), GetConstValue(vDataVal, intType),
GetConstValue(customAttrIdx, intType), GetConstValue(customAttrIdx, intType),
}; };
@ -6336,6 +6360,72 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
///// /////
int interfaceCount = 0;
BfIRValue interfaceDataPtr;
BfType* reflectInterfaceDataType = ResolveTypeDef(mCompiler->mReflectInterfaceDataDef);
BfIRType interfaceDataPtrType = mBfIRBuilder->GetPointerTo(mBfIRBuilder->MapType(reflectInterfaceDataType));
if (typeInstance->mInterfaces.IsEmpty())
interfaceDataPtr = mBfIRBuilder->CreateConstNull(interfaceDataPtrType);
else
{
SizedArray<BfIRValue, 16> interfaces;
for (auto& interface : typeInstance->mInterfaces)
{
SizedArray<BfIRValue, 8> interfaceDataVals =
{
emptyValueType,
GetConstValue(interface.mInterfaceType->mTypeId, typeIdType),
GetConstValue(interface.mStartInterfaceTableIdx, intType),
GetConstValue(interface.mStartVirtualIdx, intType),
};
auto interfaceData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectInterfaceDataType->ToTypeInstance(), BfIRPopulateType_Full), interfaceDataVals);
interfaces.push_back(interfaceData);
}
BfIRType interfaceDataArrayType = mBfIRBuilder->GetSizedArrayType(mBfIRBuilder->MapType(reflectInterfaceDataType, BfIRPopulateType_Full), (int)interfaces.size());
BfIRValue interfaceDataConst = mBfIRBuilder->CreateConstArray(interfaceDataArrayType, interfaces);
BfIRValue interfaceDataArray = mBfIRBuilder->CreateGlobalVariable(interfaceDataArrayType, true, BfIRLinkageType_Internal,
interfaceDataConst, "interfaces." + typeDataName);
interfaceDataPtr = mBfIRBuilder->CreateBitCast(interfaceDataArray, interfaceDataPtrType);
interfaceCount = (int)interfaces.size();
}
BfIRValue interfaceMethodTable;
if ((!typeInstance->IsInterface()) && (typeInstance->mIsReified) && (!typeInstance->IsUnspecializedType())
&& (!typeInstance->mInterfaceMethodTable.IsEmpty()))
{
SizedArray<BfIRValue, 16> methods;
for (auto& methodEntry : typeInstance->mInterfaceMethodTable)
{
BfIRValue funcVal = voidPtrNull;
if (!methodEntry.mMethodRef.IsNull())
{
BfMethodInstance* methodInstance = methodEntry.mMethodRef;
if ((methodInstance->mIsReified) && (methodInstance->mMethodInstanceGroup->IsImplemented()) && (!methodInstance->mIsUnspecialized))
{
auto moduleMethodInstance = ReferenceExternalMethodInstance(methodInstance);
if (moduleMethodInstance.mFunc)
funcVal = mBfIRBuilder->CreateBitCast(moduleMethodInstance.mFunc, voidPtrIRType);
}
}
methods.Add(funcVal);
}
while ((!methods.IsEmpty()) && (methods.back() == voidPtrNull))
methods.pop_back();
BfIRType methodDataArrayType = mBfIRBuilder->GetSizedArrayType(mBfIRBuilder->MapType(voidPtrType, BfIRPopulateType_Full), (int)methods.size());
BfIRValue methodDataConst = mBfIRBuilder->CreateConstArray(methodDataArrayType, methods);
BfIRValue methodDataArray = mBfIRBuilder->CreateGlobalVariable(methodDataArrayType, true, BfIRLinkageType_Internal,
methodDataConst, "imethods." + typeDataName);
interfaceMethodTable = mBfIRBuilder->CreateBitCast(methodDataArray, voidPtrPtrIRType);
}
else
interfaceMethodTable = mBfIRBuilder->CreateConstNull(voidPtrPtrIRType);
/////
int underlyingType = 0; int underlyingType = 0;
if ((typeInstance->IsTypedPrimitive()) || (typeInstance->IsBoxed())) if ((typeInstance->IsTypedPrimitive()) || (typeInstance->IsBoxed()))
{ {
@ -6349,6 +6439,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
outerTypeId = outerType->mTypeId; outerTypeId = outerType->mTypeId;
} }
//
BfIRValue customAttrDataPtr; BfIRValue customAttrDataPtr;
if (customAttrs.size() > 0) if (customAttrs.size() > 0)
{ {
@ -6380,12 +6472,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
GetConstValue(typeInstance->mInheritanceCount, intType), // mInheritanceCount GetConstValue(typeInstance->mInheritanceCount, intType), // mInheritanceCount
GetConstValue(typeInstance->mSlotNum, byteType), // mInterfaceSlot GetConstValue(typeInstance->mSlotNum, byteType), // mInterfaceSlot
GetConstValue(0, byteType), // mInterfaceCount GetConstValue(interfaceCount, byteType), // mInterfaceCount
GetConstValue((int)methodTypes.size(), shortType), // mMethodDataCount GetConstValue((int)methodTypes.size(), shortType), // mMethodDataCount
GetConstValue(0, shortType), // mPropertyDataCount GetConstValue(0, shortType), // mPropertyDataCount
GetConstValue((int)fieldTypes.size(), shortType), // mFieldDataCount GetConstValue((int)fieldTypes.size(), shortType), // mFieldDataCount
voidPtrNull, // mInterfaceDataPtr interfaceDataPtr, // mInterfaceDataPtr
interfaceMethodTable, // mInterfaceMethodTable
methodDataPtr, // mMethodDataPtr methodDataPtr, // mMethodDataPtr
voidPtrNull, // mPropertyDataPtr voidPtrNull, // mPropertyDataPtr
fieldDataPtr, // mFieldDataPtr fieldDataPtr, // mFieldDataPtr
@ -6470,7 +6563,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (mBfIRBuilder->DbgHasInfo()) if (mBfIRBuilder->DbgHasInfo())
{ {
mBfIRBuilder->DbgCreateGlobalVariable(mDICompileUnit, typeDataName, typeDataName, NULL, 0, mBfIRBuilder->DbgGetTypeInst(typeInstanceType->ToTypeInstance()), false, typeDataVar); mBfIRBuilder->DbgCreateGlobalVariable(mDICompileUnit, typeDataName, typeDataName, BfIRMDNode(), 0, mBfIRBuilder->DbgGetTypeInst(typeInstanceType->ToTypeInstance()), false, typeDataVar);
} }
} }
else else
@ -6502,7 +6595,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfType* classVDataType = ResolveTypeDef(mCompiler->mClassVDataTypeDef); BfType* classVDataType = ResolveTypeDef(mCompiler->mClassVDataTypeDef);
BfIRMDNode arrayType = mBfIRBuilder->DbgCreateArrayType(vData.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, mBfIRBuilder->DbgGetType(voidPtrType), vData.size()); BfIRMDNode arrayType = mBfIRBuilder->DbgCreateArrayType(vData.size() * mSystem->mPtrSize * 8, mSystem->mPtrSize * 8, mBfIRBuilder->DbgGetType(voidPtrType), vData.size());
mBfIRBuilder->DbgCreateGlobalVariable(mDICompileUnit, classVDataName, classVDataName, NULL, 0, arrayType, false, classVDataVar); mBfIRBuilder->DbgCreateGlobalVariable(mDICompileUnit, classVDataName, classVDataName, BfIRMDNode(), 0, arrayType, false, classVDataVar);
} }
} }
@ -17337,7 +17430,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
defLine + 1, diFuncType, false, true, defLine + 1, diFuncType, false, true,
llvm::dwarf::DW_VIRTUALITY_none, llvm::dwarf::DW_VIRTUALITY_none,
0, 0,
nullptr, flags, IsOptimized(), llvmFunction, genericArgs, genericConstValueArgs); BfIRMDNode(), flags, IsOptimized(), llvmFunction, genericArgs, genericConstValueArgs);
} }
} }

View file

@ -1646,7 +1646,7 @@ public:
BfPointerType* CreatePointerType(BfType* resolvedType); BfPointerType* CreatePointerType(BfType* resolvedType);
BfPointerType* CreatePointerType(BfTypeReference* typeRef); BfPointerType* CreatePointerType(BfTypeReference* typeRef);
BfConstExprValueType* CreateConstExprValueType(const BfTypedValue& typedValue); BfConstExprValueType* CreateConstExprValueType(const BfTypedValue& typedValue);
BfBoxedType* CreateBoxedType(BfType* resolvedTypeRef); BfBoxedType* CreateBoxedType(BfType* resolvedTypeRef, bool allowCreate = true);
BfTypeInstance* CreateTupleType(const BfTypeVector& fieldTypes, const Array<String>& fieldNames, bool allowVar = false); BfTypeInstance* CreateTupleType(const BfTypeVector& fieldTypes, const Array<String>& fieldNames, bool allowVar = false);
BfTypeInstance* SantizeTupleType(BfTypeInstance* tupleType); BfTypeInstance* SantizeTupleType(BfTypeInstance* tupleType);
BfRefType* CreateRefType(BfType* resolvedTypeRef, BfRefType::RefKind refKind = BfRefType::RefKind_Ref); BfRefType* CreateRefType(BfType* resolvedTypeRef, BfRefType::RefKind refKind = BfRefType::RefKind_Ref);
@ -1662,7 +1662,7 @@ public:
void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs); void FixIntUnknown(BfTypedValue& lhs, BfTypedValue& rhs);
bool TypeEquals(BfTypedValue& val, BfType* type); bool TypeEquals(BfTypedValue& val, BfType* type);
BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None); BfTypeDef* ResolveGenericInstanceDef(BfGenericInstanceTypeRef* genericTypeRef, BfType** outType = NULL, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
BfType* ResolveType(BfType* lookupType, BfPopulateType populateType = BfPopulateType_Data); BfType* ResolveType(BfType* lookupType, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
void ResolveGenericParamConstraints(BfGenericParamInstance* genericParamInstance, bool isUnspecialized); void ResolveGenericParamConstraints(BfGenericParamInstance* genericParamInstance, bool isUnspecialized);
String GenericParamSourceToString(const BfGenericParamSource& genericParamSource); String GenericParamSourceToString(const BfGenericParamSource& genericParamSource);
bool CheckGenericConstraints(const BfGenericParamSource& genericParamSource, BfType* checkArgType, BfAstNode* checkArgTypeRef, BfGenericParamInstance* genericParamInst, BfTypeVector* methodGenericArgs = NULL, BfError** errorOut = NULL); bool CheckGenericConstraints(const BfGenericParamSource& genericParamSource, BfType* checkArgType, BfAstNode* checkArgTypeRef, BfGenericParamInstance* genericParamInst, BfTypeVector* methodGenericArgs = NULL, BfError** errorOut = NULL);
@ -1718,8 +1718,8 @@ public:
BfType* ResolveTypeRefAllowUnboundGenerics(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool resolveGenericParam = true); BfType* ResolveTypeRefAllowUnboundGenerics(BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool resolveGenericParam = true);
BfType* ResolveTypeRef(BfAstNode* astNode, const BfSizedArray<BfTypeReference*>* genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); BfType* ResolveTypeRef(BfAstNode* astNode, const BfSizedArray<BfTypeReference*>* genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
//BfType* ResolveTypeRef(BfIdentifierNode* identifier, const BfSizedArray<BfTypeReference*>& genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); //BfType* ResolveTypeRef(BfIdentifierNode* identifier, const BfSizedArray<BfTypeReference*>& genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
BfType* ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType = BfPopulateType_Data); BfType* ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
BfType* ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& genericArgs, BfPopulateType populateType = BfPopulateType_Data); BfType* ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& genericArgs, BfPopulateType populateType = BfPopulateType_Data, BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_None);
BfType* ResolveInnerType(BfType* outerType, BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool ignoreErrors = false, int numGenericArgs = 0); BfType* ResolveInnerType(BfType* outerType, BfTypeReference* typeRef, BfPopulateType populateType = BfPopulateType_Data, bool ignoreErrors = false, int numGenericArgs = 0);
BfType* ResolveInnerType(BfType* outerType, BfIdentifierNode* identifier, BfPopulateType populateType = BfPopulateType_Data, bool ignoreErrors = false); BfType* ResolveInnerType(BfType* outerType, BfIdentifierNode* identifier, BfPopulateType populateType = BfPopulateType_Data, bool ignoreErrors = false);
BfTypeDef* GetCombinedPartialTypeDef(BfTypeDef* type); BfTypeDef* GetCombinedPartialTypeDef(BfTypeDef* type);

View file

@ -5349,20 +5349,19 @@ BfTypeInstance* BfModule::GetPrimitiveStructType(BfTypeCode typeCode)
return typeInst; return typeInst;
} }
BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef) BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef, bool allowCreate)
{ {
bool isStructPtr = false; bool isStructPtr = false;
BfPopulateType populateType = allowCreate ? BfPopulateType_Data : BfPopulateType_Identity;
BfResolveTypeRefFlags resolveFlags = allowCreate ? BfResolveTypeRefFlag_None : BfResolveTypeRefFlag_NoCreate;
if (resolvedTypeRef->IsPrimitiveType()) if (resolvedTypeRef->IsPrimitiveType())
{ {
auto primType = (BfPrimitiveType*)resolvedTypeRef; auto primType = (BfPrimitiveType*)resolvedTypeRef;
resolvedTypeRef = GetPrimitiveStructType(primType->mTypeDef->mTypeCode); resolvedTypeRef = GetPrimitiveStructType(primType->mTypeDef->mTypeCode);
if (resolvedTypeRef == NULL) if (resolvedTypeRef == NULL)
{
BFMODULE_FATAL(this, "Unable to find primitive type");
return NULL; return NULL;
} }
}
else if (resolvedTypeRef->IsPointer()) else if (resolvedTypeRef->IsPointer())
{ {
BfPointerType* pointerType = (BfPointerType*)resolvedTypeRef; BfPointerType* pointerType = (BfPointerType*)resolvedTypeRef;
@ -5375,7 +5374,9 @@ BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef)
{ {
BfTypeVector typeVector; BfTypeVector typeVector;
typeVector.Add(pointerType->mElementType); typeVector.Add(pointerType->mElementType);
resolvedTypeRef = ResolveTypeDef(mCompiler->mPointerTTypeDef, typeVector, BfPopulateType_Data)->ToTypeInstance(); resolvedTypeRef = ResolveTypeDef(mCompiler->mPointerTTypeDef, typeVector, populateType, resolveFlags);
if (resolvedTypeRef == NULL)
return NULL;
} }
} }
else if (resolvedTypeRef->IsMethodRef()) else if (resolvedTypeRef->IsMethodRef())
@ -5383,7 +5384,9 @@ BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef)
BfMethodRefType* methodRefType = (BfMethodRefType*)resolvedTypeRef; BfMethodRefType* methodRefType = (BfMethodRefType*)resolvedTypeRef;
BfTypeVector typeVector; BfTypeVector typeVector;
typeVector.Add(methodRefType); typeVector.Add(methodRefType);
resolvedTypeRef = ResolveTypeDef(mCompiler->mMethodRefTypeDef, typeVector, BfPopulateType_Data)->ToTypeInstance(); resolvedTypeRef = ResolveTypeDef(mCompiler->mMethodRefTypeDef, typeVector, populateType, resolveFlags);
if (resolvedTypeRef == NULL)
return NULL;
} }
else if (resolvedTypeRef->IsSizedArray()) else if (resolvedTypeRef->IsSizedArray())
{ {
@ -5392,7 +5395,9 @@ BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef)
typeVector.Add(sizedArrayType->mElementType); typeVector.Add(sizedArrayType->mElementType);
auto sizeValue = BfTypedValue(GetConstValue(sizedArrayType->mElementCount), GetPrimitiveType(BfTypeCode_IntPtr)); auto sizeValue = BfTypedValue(GetConstValue(sizedArrayType->mElementCount), GetPrimitiveType(BfTypeCode_IntPtr));
typeVector.Add(CreateConstExprValueType(sizeValue)); typeVector.Add(CreateConstExprValueType(sizeValue));
resolvedTypeRef = ResolveTypeDef(mCompiler->mSizedArrayTypeDef, typeVector, BfPopulateType_Data)->ToTypeInstance(); resolvedTypeRef = ResolveTypeDef(mCompiler->mSizedArrayTypeDef, typeVector, populateType, resolveFlags);
if (resolvedTypeRef == NULL)
return NULL;
} }
BfTypeInstance* typeInst = resolvedTypeRef->ToTypeInstance(); BfTypeInstance* typeInst = resolvedTypeRef->ToTypeInstance();
@ -5407,7 +5412,7 @@ BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef)
else else
boxedType->mTypeDef = mCompiler->mValueTypeTypeDef; boxedType->mTypeDef = mCompiler->mValueTypeTypeDef;
boxedType->mBoxedFlags = isStructPtr ? BfBoxedType::BoxedFlags_StructPtr : BfBoxedType::BoxedFlags_None; boxedType->mBoxedFlags = isStructPtr ? BfBoxedType::BoxedFlags_StructPtr : BfBoxedType::BoxedFlags_None;
auto resolvedBoxedType = ResolveType(boxedType); auto resolvedBoxedType = ResolveType(boxedType, populateType, resolveFlags);
if (resolvedBoxedType != boxedType) if (resolvedBoxedType != boxedType)
mContext->mBoxedTypePool.GiveBack(boxedType); mContext->mBoxedTypePool.GiveBack(boxedType);
return (BfBoxedType*)resolvedBoxedType; return (BfBoxedType*)resolvedBoxedType;
@ -5549,7 +5554,7 @@ BfPointerType* BfModule::CreatePointerType(BfTypeReference* typeRef)
return CreatePointerType(resolvedTypeRef); return CreatePointerType(resolvedTypeRef);
} }
BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType) BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags)
{ {
//BF_ASSERT(typeDef->mTypeCode != BfTypeCode_Extension); //BF_ASSERT(typeDef->mTypeCode != BfTypeCode_Extension);
BF_ASSERT(!typeDef->mIsPartial || typeDef->mIsCombinedPartial); BF_ASSERT(!typeDef->mIsPartial || typeDef->mIsCombinedPartial);
@ -5558,7 +5563,7 @@ BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, BfPopulateType populateType
BF_ASSERT((typeDef->mOuterType == NULL) || (typeDef->mOuterType->mDefState != BfTypeDef::DefState_Deleted)); BF_ASSERT((typeDef->mOuterType == NULL) || (typeDef->mOuterType->mDefState != BfTypeDef::DefState_Deleted));
if (typeDef->mGenericParamDefs.size() != 0) if (typeDef->mGenericParamDefs.size() != 0)
return ResolveTypeDef(typeDef, BfTypeVector(), populateType); return ResolveTypeDef(typeDef, BfTypeVector(), populateType, resolveFlags);
auto typeDefTypeRef = mContext->mTypeDefTypeRefPool.Get(); auto typeDefTypeRef = mContext->mTypeDefTypeRefPool.Get();
typeDefTypeRef->mTypeDef = typeDef; typeDefTypeRef->mTypeDef = typeDef;
@ -5856,10 +5861,10 @@ bool BfModule::IsInnerType(BfTypeDef* checkInnerType, BfTypeDef* checkOuterType)
} }
} }
BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& genericArgs, BfPopulateType populateType) BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& genericArgs, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags)
{ {
if (typeDef->mGenericParamDefs.size() == 0) if (typeDef->mGenericParamDefs.size() == 0)
return ResolveTypeDef(typeDef, populateType); return ResolveTypeDef(typeDef, populateType, resolveFlags);
if ((typeDef == mCompiler->mArray1TypeDef) || (typeDef == mCompiler->mArray2TypeDef)) if ((typeDef == mCompiler->mArray1TypeDef) || (typeDef == mCompiler->mArray2TypeDef))
{ {
@ -5892,7 +5897,7 @@ BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& generic
} }
} }
auto resolvedType = ResolveType(arrayInstType, populateType); auto resolvedType = ResolveType(arrayInstType, populateType, resolveFlags);
if (resolvedType != arrayInstType) if (resolvedType != arrayInstType)
{ {
delete arrayInstType->mGenericTypeInfo; delete arrayInstType->mGenericTypeInfo;
@ -5960,7 +5965,7 @@ BfType* BfModule::ResolveTypeDef(BfTypeDef* typeDef, const BfTypeVector& generic
// } // }
// else // else
{ {
resolvedType = ResolveType(genericInstType, populateType); resolvedType = ResolveType(genericInstType, populateType, resolveFlags);
} }
@ -6546,12 +6551,17 @@ BfType* BfModule::ResolveGenericType(BfType* unspecializedType, BfTypeVector* ty
return unspecializedType; return unspecializedType;
} }
BfType* BfModule::ResolveType(BfType* lookupType, BfPopulateType populateType) BfType* BfModule::ResolveType(BfType* lookupType, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags)
{ {
BfResolvedTypeSet::LookupContext lookupCtx; BfResolvedTypeSet::LookupContext lookupCtx;
lookupCtx.mModule = this; lookupCtx.mModule = this;
lookupCtx.mResolveFlags = resolveFlags;
BfResolvedTypeSet::Entry* resolvedEntry = NULL; BfResolvedTypeSet::Entry* resolvedEntry = NULL;
bool inserted = mContext->mResolvedTypes.Insert(lookupType, &lookupCtx, &resolvedEntry); bool inserted = mContext->mResolvedTypes.Insert(lookupType, &lookupCtx, &resolvedEntry);
if (resolvedEntry == NULL)
return NULL;
if (!inserted) if (!inserted)
{ {
auto resolvedTypeRef = resolvedEntry->mValue; auto resolvedTypeRef = resolvedEntry->mValue;

View file

@ -631,7 +631,6 @@ public:
public: public:
BfDeferredMethodCallData() BfDeferredMethodCallData()
{ {
mDeferDIType = NULL;
mAlign = 0; mAlign = 0;
mSize = 0; mSize = 0;
mMethodId = 0; mMethodId = 0;
@ -2426,6 +2425,9 @@ public:
BF_ASSERT(tryCount < 10); BF_ASSERT(tryCount < 10);
} }
if ((ctx->mResolveFlags & BfResolveTypeRefFlag_NoCreate) != 0)
return false;
mCount++; mCount++;
Entry* entry = (Entry*)BfResolvedTypeSetFuncs::Allocate(sizeof(Entry), alignof(Entry)); Entry* entry = (Entry*)BfResolvedTypeSetFuncs::Allocate(sizeof(Entry), alignof(Entry));
entry->mValue = NULL; entry->mValue = NULL;

View file

@ -457,7 +457,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
} }
else else
{ {
BfIRMDNode diForwardDecl = NULL; BfIRMDNode diForwardDecl;
SizedArray<BfIRMDNode, 8> diFieldTypes; SizedArray<BfIRMDNode, 8> diFieldTypes;
if ((mBfIRBuilder->DbgHasInfo()) && (mHasFullDebugInfo)) if ((mBfIRBuilder->DbgHasInfo()) && (mHasFullDebugInfo))
{ {

View file

@ -170,13 +170,14 @@ enum BfTypeFlags
BfTypeFlags_Boxed = 0x0010, BfTypeFlags_Boxed = 0x0010,
BfTypeFlags_Pointer = 0x0020, BfTypeFlags_Pointer = 0x0020,
BfTypeFlags_Struct = 0x0040, BfTypeFlags_Struct = 0x0040,
BfTypeFlags_Primitive = 0x0080, BfTypeFlags_Interface = 0x0080,
BfTypeFlags_TypedPrimitive = 0x0100, BfTypeFlags_Primitive = 0x0100,
BfTypeFlags_Tuple = 0x0200, BfTypeFlags_TypedPrimitive = 0x0200,
BfTypeFlags_Nullable = 0x0400, BfTypeFlags_Tuple = 0x0400,
BfTypeFlags_SizedArray = 0x0800, BfTypeFlags_Nullable = 0x0800,
BfTypeFlags_Splattable = 0x1000, BfTypeFlags_SizedArray = 0x1000,
BfTypeFlags_Union = 0x2000, BfTypeFlags_Splattable = 0x2000,
BfTypeFlags_Union = 0x4000,
// //
BfTypeFlags_WantsMarking = 0x8000, BfTypeFlags_WantsMarking = 0x8000,
BfTypeFlags_Delegate = 0x10000, BfTypeFlags_Delegate = 0x10000,