mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Protected protection improvements
This commit is contained in:
parent
670de8d4dc
commit
8852e7e194
7 changed files with 94 additions and 36 deletions
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -112,6 +112,7 @@ enum BfProtectionCheckFlags
|
|||
BfProtectionCheckFlag_CheckedPrivate = 2,
|
||||
BfProtectionCheckFlag_AllowProtected = 4,
|
||||
BfProtectionCheckFlag_AllowPrivate = 8,
|
||||
BfProtectionCheckFlag_InstanceLookup = 0x10
|
||||
};
|
||||
|
||||
enum BfEmbeddedStatementFlags
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue