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

Internal protection, 'using internal <type or namespace>;`

This commit is contained in:
Brian Fiete 2020-10-14 11:33:41 -07:00
parent 7349cdf50f
commit 6b27f0f0b2
25 changed files with 313 additions and 96 deletions

View file

@ -2508,7 +2508,7 @@ void BfModule::SetIllegalExprSrcPos(BfSrcPosFlags flags)
//SetIllegalSrcPos((BfSrcPosFlags)(flags | BfSrcPosFlag_Expression));
}
bool BfModule::CheckProtection(BfProtection protection, bool allowProtected, bool allowPrivate)
bool BfModule::CheckProtection(BfProtection protection, BfTypeDef* checkType, bool allowProtected, bool allowPrivate)
{
if ((protection == BfProtection_Public) ||
((protection == BfProtection_Protected) && (allowProtected)) ||
@ -2519,6 +2519,11 @@ bool BfModule::CheckProtection(BfProtection protection, bool allowProtected, boo
mAttributeState->mUsed = true;
return true;
}
if ((protection == BfProtection_Internal) && (checkType != NULL))
{
if (CheckInternalProtection(checkType))
return true;
}
return false;
}
@ -2627,6 +2632,12 @@ bool BfModule::CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* me
return true;
}
if ((memberProtection == BfProtection_Internal) && (memberOwner != NULL))
{
if (CheckInternalProtection(memberOwner->mTypeDef))
return true;
}
return false;
}
@ -3074,7 +3085,7 @@ void BfModule::NotImpl(BfAstNode* astNode)
Fail("INTERNAL ERROR: Not implemented", astNode);
}
bool BfModule::CheckAccessMemberProtection(BfProtection protection, BfType* memberType)
bool BfModule::CheckAccessMemberProtection(BfProtection protection, BfTypeInstance* memberType)
{
bool allowPrivate = (memberType == mCurTypeInstance) || (IsInnerType(mCurTypeInstance, memberType));
if (!allowPrivate)
@ -3083,7 +3094,7 @@ bool BfModule::CheckAccessMemberProtection(BfProtection protection, BfType* memb
//TODO: We had this commented out, but this makes accessing protected properties fail
if (mCurTypeInstance != NULL)
allowProtected |= TypeIsSubTypeOf(mCurTypeInstance, memberType->ToTypeInstance());
if (!CheckProtection(protection, allowProtected, allowPrivate))
if (!CheckProtection(protection, memberType->mTypeDef, allowProtected, allowPrivate))
{
return false;
}
@ -3393,6 +3404,42 @@ BfStaticSearch* BfModule::GetStaticSearch()
return NULL;
}
BfInternalAccessSet* BfModule::GetInternalAccessSet()
{
auto activeTypeDef = GetActiveTypeDef();
BfInternalAccessSet* internalAccessSet = NULL;
if ((mCurTypeInstance != NULL) && (mCurTypeInstance->mInternalAccessMap.TryGetValue(activeTypeDef, &internalAccessSet)))
return internalAccessSet;
if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mInternalAccessMap.TryGetValue(activeTypeDef, &internalAccessSet)))
return internalAccessSet;
return NULL;
}
bool BfModule::CheckInternalProtection(BfTypeDef* usingTypeDef)
{
auto internalAccessSet = GetInternalAccessSet();
if (internalAccessSet == NULL)
return false;
for (auto& nameComposite : internalAccessSet->mNamespaces)
{
if (usingTypeDef->mNamespace.StartsWith(nameComposite))
return true;
}
for (auto internalType : internalAccessSet->mTypes)
{
auto checkTypeDef = usingTypeDef;
while (checkTypeDef != NULL)
{
if (checkTypeDef == internalType->mTypeDef)
return true;
checkTypeDef = checkTypeDef->mOuterType;
}
}
return false;
}
void PrintUsers(llvm::MDNode* md);
BfModuleOptions BfModule::GetModuleOptions()
@ -10688,7 +10735,7 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
if ((checkMethod->mIsStatic) || (checkMethod->mMethodType != BfMethodType_Ctor))
continue;
if ((!isFailurePass) && (!CheckProtection(checkMethod->mProtection, false, false)))
if ((!isFailurePass) && (!CheckProtection(checkMethod->mProtection, attrTypeInst->mTypeDef, false, false)))
continue;
methodMatcher.CheckMethod(NULL, attrTypeInst, checkMethod, isFailurePass);