1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Hide internal generated methods from reflection, fix ctor/dtor names

This commit is contained in:
Brian Fiete 2023-10-10 13:20:35 -07:00
parent 70ab03529e
commit 078727c4a7
10 changed files with 73 additions and 15 deletions

View file

@ -7292,6 +7292,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
continue;
if (defaultMethod->mMethodDef->mMethodType == BfMethodType_CtorNoBody)
continue;
if (!defaultMethod->mMethodDef->CanReflect())
continue;
auto methodReflectKind = (BfReflectKind)(reflectKind & ~BfReflectKind_User);
@ -7394,7 +7396,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
funcVal = mBfIRBuilder->CreateBitCast(moduleMethodInstance.mFunc, voidPtrIRType);
}
BfIRValue methodNameConst = GetStringObjectValue(methodDef->mName, !mIsComptimeModule);
BfIRValue methodNameConst = GetStringObjectValue(methodDef->GetReflectName(), !mIsComptimeModule);
BfMethodFlags methodFlags = defaultMethod->GetMethodFlags();

View file

@ -842,6 +842,14 @@ BfMethodFlags BfMethodInstance::GetMethodFlags()
return methodFlags;
}
BfComptimeMethodFlags BfMethodInstance::GetComptimeMethodFlags()
{
BfComptimeMethodFlags methodFlags = (BfComptimeMethodFlags)0;
if (!mMethodDef->CanReflect())
methodFlags = (BfComptimeMethodFlags)(methodFlags | BfComptimeMethodFlags_NoReflect);
return methodFlags;
}
void BfMethodInstance::UndoDeclaration(bool keepIRFunction)
{
if (mMethodInfoEx != NULL)

View file

@ -973,6 +973,7 @@ public:
BfImportKind GetImportKind();
BfMethodFlags GetMethodFlags();
BfComptimeMethodFlags GetComptimeMethodFlags();
void UndoDeclaration(bool keepIRFunction = false);
BfTypeInstance* GetOwner();
BfModule* GetModule();

View file

@ -648,6 +648,15 @@ String BfMethodDef::ToString()
return methodText;
}
String BfMethodDef::GetReflectName()
{
if (mMethodType == BfMethodType_Ctor)
return "this";
if (mMethodType == BfMethodType_Dtor)
return "~this";
return mName;
}
int BfMethodDef::GetExplicitParamCount()
{
for (int i = 0; i < (int)mParams.size(); i++)
@ -675,6 +684,15 @@ void BfMethodDef::BuildParamNameMap()
(*mParamNameMap)[mParams[i]->mName] = i - startIdx;
}
bool BfMethodDef::CanReflect()
{
if (mMethodDeclaration != NULL)
return true;
if (mMethodType == BfMethodType_Ctor)
return true;
return false;
}
///
void BfTypeDef::Reset()

View file

@ -240,6 +240,12 @@ enum BfMethodFlags
BfMethodFlags_Constructor = 0x8000
};
enum BfComptimeMethodFlags
{
BfComptimeMethodFlags_None = 0,
BfComptimeMethodFlags_NoReflect = 1
};
enum BfObjectFlags : uint8
{
BfObjectFlag_None = 0,
@ -970,8 +976,10 @@ public:
bool IsDefaultCtor();
bool IsCtorOrInit();
String ToString();
String GetReflectName();
int GetExplicitParamCount();
void BuildParamNameMap();
bool CanReflect();
};
class BfOperatorDef : public BfMethodDef

View file

@ -6220,7 +6220,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
return false;
}
CeSetAddrVal(stackPtr + 0, GetString(methodInstance->mMethodDef->mName), ptrSize);
CeSetAddrVal(stackPtr + 0, GetString(methodInstance->mMethodDef->GetReflectName()), ptrSize);
_FixVariables();
}
else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetInfo)
@ -6231,7 +6231,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
// int16 mFlags
// int32 mMethodIdx
int64 methodHandle = *(int64*)((uint8*)stackPtr + 4+4+4+2+4);
int64 methodHandle = *(int64*)((uint8*)stackPtr + 4+4+4+2+1+4);
auto methodInstance = mCeMachine->GetMethodInstance(methodHandle);
if (methodInstance == NULL)
@ -6248,7 +6248,8 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
*(int32*)(stackPtr + 4) = methodInstance->GetParamCount();
*(int32*)(stackPtr + 4+4) = genericArgCount;
*(int16*)(stackPtr + 4+4+4) = methodInstance->GetMethodFlags();
*(int32*)(stackPtr + 4+4+4+2) = methodInstance->mMethodDef->mIdx;
*(int32*)(stackPtr + 4+4+4+2) = methodInstance->GetComptimeMethodFlags();
*(int32*)(stackPtr + 4+4+4+2+1) = methodInstance->mMethodDef->mIdx;
}
else if (checkFunction->mFunctionKind == CeFunctionKind_Method_GetParamInfo)
{