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

Protected protection improvements

This commit is contained in:
Brian Fiete 2020-12-06 07:32:01 -08:00
parent 670de8d4dc
commit 8852e7e194
7 changed files with 94 additions and 36 deletions

View file

@ -2129,7 +2129,20 @@ bool BfMethodMatcher::CheckType(BfTypeInstance* typeInstance, BfTypedValue targe
if (curTypeDef->mMethodSet.TryGetWith(mMethodName, &entry))
nextMethodDef = (BfMethodDef*)entry->mMemberDef;
}
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
if (target)
{
if (mBypassVirtual)
{
// Not an "instance lookup"
}
else
{
protectionCheckFlags = (BfProtectionCheckFlags)(protectionCheckFlags | BfProtectionCheckFlag_InstanceLookup);
}
}
while (nextMethodDef != NULL)
{
bool allowExplicitInterface = curTypeInst->IsInterface() && mBypassVirtual;
@ -2199,9 +2212,9 @@ bool BfMethodMatcher::CheckType(BfTypeInstance* typeInstance, BfTypedValue targe
if ((!curTypeInst->IsTypeMemberIncluded(checkMethod->mDeclaringType, activeTypeDef, mModule)) ||
(!curTypeInst->IsTypeMemberAccessible(checkMethod->mDeclaringType, visibleProjectSet)))
continue;
}
}
MatchFailKind matchFailKind = MatchFailKind_None;
MatchFailKind matchFailKind = MatchFailKind_None;
if (!mModule->CheckProtection(protectionCheckFlags, curTypeInst, checkMethod->mDeclaringType->mProject, checkMethod->mProtection, typeInstance))
{
if ((mBypassVirtual) && (checkMethod->mProtection == BfProtection_Protected) && (mModule->TypeIsSubTypeOf(mModule->mCurTypeInstance, typeInstance)))
@ -3933,6 +3946,18 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
}
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
if (target)
{
if ((flags & (BfLookupFieldFlag_IsImplicitThis | BfLookupFieldFlag_BaseLookup)) != 0)
{
// Not an "instance lookup"
}
else
{
protectionCheckFlags = (BfProtectionCheckFlags)(protectionCheckFlags | BfProtectionCheckFlag_InstanceLookup);
}
}
BfFieldDef* matchedField = NULL;
while (nextField != NULL)
{
@ -8607,7 +8632,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
}
if (mPropDef == NULL)
mResult = LookupField(nameRight, lookupVal, fieldName);
mResult = LookupField(nameRight, lookupVal, fieldName, CheckIsBase(nameLeft) ? BfLookupFieldFlag_BaseLookup : BfLookupFieldFlag_None);
if ((!mResult) && (mPropDef == NULL) && (lookupType->IsGenericParam()))
{
@ -17888,12 +17913,9 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
// Try first as a non-static indexer, then as a static indexer
for (int pass = 0; pass < 2; pass++)
{
// SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, (mModule->mIgnoreErrors) || (pass == 0));
// SetAndRestoreValue<bool> prevHadIgnoredError(mModule->mHadIgnoredError, false);
///
{
SetAndRestoreValue<BfEvalExprFlags> prevFlags(mBfEvalExprFlags, (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_NoLookupError));
SetAndRestoreValue<BfEvalExprFlags> prevFlags(mBfEvalExprFlags, (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_NoLookupError), pass == 0);
VisitChild(indexerExpr->mTarget);
}
ResolveGenericType();

View file

@ -319,9 +319,10 @@ enum BfLookupFieldFlags
{
BfLookupFieldFlag_None = 0,
BfLookupFieldFlag_IsImplicitThis = 1,
BfLookupFieldFlag_CheckingOuter = 2,
BfLookupFieldFlag_IgnoreProtection = 4,
BfLookupFieldFlag_BindOnly = 8
BfLookupFieldFlag_BaseLookup = 2,
BfLookupFieldFlag_CheckingOuter = 4,
BfLookupFieldFlag_IgnoreProtection = 8,
BfLookupFieldFlag_BindOnly = 0x10
};
enum BfUnaryOpFlags

View file

@ -2584,19 +2584,37 @@ bool BfModule::CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* me
curCheckType = mixinOwner;
}
auto lookupCheckType = lookupStartType;
while (lookupCheckType->mInheritDepth >= curCheckType->mInheritDepth)
if ((flags & BfProtectionCheckFlag_InstanceLookup) != 0)
{
if (lookupCheckType == curCheckType)
auto lookupCheckType = lookupStartType;
while (lookupCheckType->mInheritDepth >= curCheckType->mInheritDepth)
{
allowProtected = true;
break;
if (lookupCheckType == curCheckType)
{
allowProtected = true;
break;
}
if (lookupCheckType == memberOwner)
break;
lookupCheckType = lookupCheckType->mBaseType;
if (lookupCheckType == NULL)
break;
}
}
else
{
auto lookupCheckType = curCheckType;
while (lookupCheckType->mInheritDepth >= memberOwner->mInheritDepth)
{
if (lookupCheckType == memberOwner)
{
allowProtected = true;
break;
}
lookupCheckType = lookupCheckType->mBaseType;
if (lookupCheckType == NULL)
break;
}
if (lookupCheckType == memberOwner)
break;
lookupCheckType = lookupCheckType->mBaseType;
if (lookupCheckType == NULL)
break;
}
if (!allowProtected)

View file

@ -112,6 +112,7 @@ enum BfProtectionCheckFlags
BfProtectionCheckFlag_CheckedPrivate = 2,
BfProtectionCheckFlag_AllowProtected = 4,
BfProtectionCheckFlag_AllowPrivate = 8,
BfProtectionCheckFlag_InstanceLookup = 0x10
};
enum BfEmbeddedStatementFlags