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

Support for top-level internal protection, autocomplete internal fixes

This commit is contained in:
Brian Fiete 2021-11-23 14:25:07 -08:00
parent 0592701576
commit 870c9914be
4 changed files with 23 additions and 10 deletions

View file

@ -586,8 +586,13 @@ void BfAutoComplete::AddTypeDef(BfTypeDef* typeDef, const StringImpl& filter, bo
}
}
bool BfAutoComplete::CheckProtection(BfProtection protection, bool allowProtected, bool allowPrivate)
bool BfAutoComplete::CheckProtection(BfProtection protection, BfTypeDef* typeDef, bool allowProtected, bool allowPrivate)
{
if ((protection == BfProtection_Internal) && (typeDef != NULL))
{
return mModule->CheckProtection(protection, typeDef, allowProtected, allowPrivate);
}
return (mHasFriendSet) || (protection == BfProtection_Public) ||
((protection == BfProtection_Protected) && (allowProtected)) ||
((protection == BfProtection_Private) && (allowPrivate));
@ -609,7 +614,7 @@ void BfAutoComplete::AddInnerTypes(BfTypeInstance* typeInst, const StringImpl& f
{
for (auto innerType : typeInst->mTypeDef->mNestedTypes)
{
if (CheckProtection(innerType->mProtection, allowProtected, allowPrivate))
if (CheckProtection(innerType->mProtection, innerType, allowProtected, allowPrivate))
AddTypeDef(innerType, filter);
}
@ -633,7 +638,7 @@ void BfAutoComplete::AddCurrentTypes(BfTypeInstance* typeInst, const StringImpl&
continue;
}
if (CheckProtection(nestedTypeDef->mProtection, allowProtected, allowPrivate))
if (CheckProtection(nestedTypeDef->mProtection, nestedTypeDef, allowProtected, allowPrivate))
AddTypeDef(nestedTypeDef, filter, onlyAttribute);
}
@ -887,7 +892,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn
if (fieldDef->mIsNoShow)
continue;
if ((fieldDef->mIsStatic) && (CheckProtection(fieldDef->mProtection, allowProtected, allowPrivate)))
if ((fieldDef->mIsStatic) && (CheckProtection(fieldDef->mProtection, fieldDef->mDeclaringType, allowProtected, allowPrivate)))
{
if (!mModule->CanCast(BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), fieldInst.mResolvedType), selfType))
continue;
@ -920,7 +925,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn
bool canUseMethod;
canUseMethod = (methodDef->mMethodType == BfMethodType_Normal) || (methodDef->mMethodType == BfMethodType_Mixin);
canUseMethod &= CheckProtection(methodDef->mProtection, allowProtected, allowPrivate);
canUseMethod &= CheckProtection(methodDef->mProtection, methodDef->mDeclaringType, allowProtected, allowPrivate);
if (methodDef->mMethodType != BfMethodType_Normal)
continue;
@ -973,7 +978,7 @@ void BfAutoComplete::AddSelfResultTypeMembers(BfTypeInstance* typeInst, BfTypeIn
if (methodInstance->mReturnType != selfType)
continue;
if (CheckProtection(propDef->mProtection, allowProtected, allowPrivate))
if (CheckProtection(propDef->mProtection, propDef->mDeclaringType, allowProtected, allowPrivate))
{
if (propDef->HasExplicitInterface())
continue;
@ -1038,7 +1043,7 @@ void BfAutoComplete::AddEnumTypeMembers(BfTypeInstance* typeInst, const StringIm
auto fieldDef = fieldInst.GetFieldDef();
if ((fieldDef != NULL) && (fieldDef->mIsConst) &&
((fieldInst.mResolvedType == typeInst) || (fieldInst.mIsEnumPayloadCase)) &&
(CheckProtection(fieldDef->mProtection, allowProtected, allowPrivate)))
(CheckProtection(fieldDef->mProtection, fieldDef->mDeclaringType, allowProtected, allowPrivate)))
{
if ((!typeInst->IsTypeMemberIncluded(fieldDef->mDeclaringType, activeTypeDef, mModule)) ||
(!typeInst->IsTypeMemberAccessible(fieldDef->mDeclaringType, activeTypeDef)))
@ -1088,7 +1093,7 @@ void BfAutoComplete::AddExtensionMethods(BfTypeInstance* targetType, BfTypeInsta
continue;
bool canUseMethod = true;
canUseMethod &= CheckProtection(methodDef->mProtection, allowProtected, allowPrivate);
canUseMethod &= CheckProtection(methodDef->mProtection, methodDef->mDeclaringType, allowProtected, allowPrivate);
auto methodInstance = mModule->GetRawMethodInstanceAtIdx(extensionContainer, methodDef->mIdx);
if (methodInstance == NULL)

View file

@ -179,7 +179,7 @@ public:
int mDefTypeGenericParamIdx;
public:
bool CheckProtection(BfProtection protection, bool allowProtected, bool allowPrivate);
bool CheckProtection(BfProtection protection, BfTypeDef* typeDef, bool allowProtected, bool allowPrivate);
String GetFilter(BfAstNode* node);
const char* GetTypeName(BfType* type);
int GetCursorIdx(BfAstNode* node);

View file

@ -1449,7 +1449,9 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
mCurTypeDef->mProtection = (outerTypeDef == NULL) ? BfProtection_Public : BfProtection_Private;
if (typeDeclaration->mProtectionSpecifier != NULL)
{
if ((outerTypeDef == NULL) && (typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Public))
if ((outerTypeDef == NULL) &&
(typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Public) &&
(typeDeclaration->mProtectionSpecifier->GetToken() != BfToken_Internal))
{
//CS1527
Fail("Elements defined in a namespace cannot be explicitly declared as private or protected", typeDeclaration->mProtectionSpecifier);

View file

@ -8499,6 +8499,12 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
populateModule->PopulateType(resolvedTypeRef, populateType);
if ((typeInstance != NULL) && (typeInstance->mTypeDef != NULL) && (typeInstance->mTypeDef->mProtection == BfProtection_Internal) && (typeInstance->mTypeDef->mOuterType == NULL))
{
if (!CheckProtection(typeInstance->mTypeDef->mProtection, typeInstance->mTypeDef, false, false))
Fail(StrFormat("'%s' is inaccessible due to its protection level", TypeToString(typeInstance).c_str()), typeRef); // CS0122
}
if ((populateType > BfPopulateType_Identity) && (!ResolveTypeResult_Validate(typeRef, resolvedTypeRef)))
return NULL;